fix pointer size calculation
[m6w6/ext-psi] / src / types / decl_arg.c
index 32607d1..1d143ee 100644 (file)
@@ -168,6 +168,19 @@ bool psi_decl_arg_validate_typedef(struct psi_data *data,
        return true;
 }
 
+bool psi_decl_arg_is_pointer(struct psi_decl_arg *darg)
+{
+       if (darg->var->pointer_level) {
+               if (darg->var->array_size) {
+                       return darg->var->pointer_level > 1;
+               }
+               return true;
+       } else if (psi_decl_type_is_weak(darg->type) && darg->type->real.def) {
+               return psi_decl_arg_is_pointer(darg->type->real.def);
+       }
+       return false;
+}
+
 size_t psi_decl_arg_align(struct psi_decl_arg *darg, size_t *pos, size_t *len)
 {
        size_t align = psi_decl_arg_get_align(darg);
@@ -184,8 +197,7 @@ size_t psi_decl_arg_get_align(struct psi_decl_arg *darg)
 {
        size_t align;
 
-       if (darg->var->pointer_level
-                       && (!darg->var->array_size || darg->var->pointer_level > 1)) {
+       if (psi_decl_arg_is_pointer(darg)) {
                align = psi_t_alignment(PSI_T_POINTER);
        } else {
                align = psi_decl_type_get_align(darg->type);
@@ -201,7 +213,7 @@ size_t psi_decl_arg_get_size(struct psi_decl_arg *darg)
 
        if (darg->var->array_size && darg->var->pointer_level > 1) {
                size = psi_t_size(PSI_T_POINTER) * darg->var->array_size;
-       } else if (!darg->var->array_size && darg->var->pointer_level) {
+       } else if (psi_decl_arg_is_pointer(darg)) {
                size = psi_t_size(PSI_T_POINTER);
        } else {
                switch (real->type) {