From: Michael Wallner Date: Mon, 29 Oct 2018 07:54:21 +0000 (+0100) Subject: fix pointer size calculation X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=9aeae2c241e303c537d8be18dd6c9f8776b2f044;p=m6w6%2Fext-psi fix pointer size calculation --- diff --git a/src/types/decl_arg.c b/src/types/decl_arg.c index 32607d1..1d143ee 100644 --- a/src/types/decl_arg.c +++ b/src/types/decl_arg.c @@ -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) { diff --git a/src/types/decl_arg.h b/src/types/decl_arg.h index 01433bd..b915893 100644 --- a/src/types/decl_arg.h +++ b/src/types/decl_arg.h @@ -48,6 +48,8 @@ void psi_decl_arg_dump(int fd, struct psi_decl_arg *arg, unsigned level); bool psi_decl_arg_validate(struct psi_data *data, struct psi_decl_arg *arg, struct psi_validate_scope *scope); bool psi_decl_arg_validate_typedef(struct psi_data *data, struct psi_decl_arg *def, struct psi_validate_scope *scope); +bool psi_decl_arg_is_pointer(struct psi_decl_arg *darg); + size_t psi_decl_arg_align(struct psi_decl_arg *darg, size_t *pos, size_t *len); size_t psi_decl_arg_get_align(struct psi_decl_arg *darg); size_t psi_decl_arg_get_size(struct psi_decl_arg *darg); diff --git a/src/types/decl_struct.c b/src/types/decl_struct.c index fab2817..35818b2 100644 --- a/src/types/decl_struct.c +++ b/src/types/decl_struct.c @@ -81,7 +81,7 @@ struct psi_decl_arg *psi_decl_struct_get_arg(struct psi_decl_struct *s, bool psi_decl_struct_validate(struct psi_data *data, struct psi_decl_struct *s, struct psi_validate_scope *scope) { - size_t i, pos, len, size, align; + size_t i, pos = 0, len = 0; struct psi_decl_arg *darg, *prev_arg; if (!s) { @@ -103,6 +103,8 @@ bool psi_decl_struct_validate(struct psi_data *data, struct psi_decl_struct *s, psi_validate_scope_add_struct(scope, s->name, s); for (i = 0; psi_plist_get(s->args, i, &darg); ++i) { + size_t align; + darg->var->arg = darg; if (!psi_decl_arg_validate(data, darg, scope)) { @@ -194,6 +196,8 @@ bool psi_decl_struct_validate(struct psi_data *data, struct psi_decl_struct *s, } if (psi_plist_count(s->args)) { + size_t size; + psi_plist_sort(s->args, psi_layout_sort_cmp, NULL); psi_plist_get(s->args, psi_plist_count(s->args) - 1, &darg);