fprintf: Fix __attribute__((__aligned__(N)) handling for struct members

We just need to record if we printed it for a member and if so, deduce
that from the number of spaces left to print before the end of line
comment (offset, size).

Fixes: a59459bb80 ("fprintf: Account inline type __aligned__ member types for spacing")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2021-10-27 15:42:04 -03:00
parent c52f6421f2
commit 43e8216c25
1 changed files with 6 additions and 9 deletions

View File

@ -837,6 +837,7 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb
struct conf_fprintf *conf, FILE *fp)
{
const int size = member->byte_size;
int member_alignment_printed = 0;
struct conf_fprintf sconf = *conf;
uint32_t offset = member->byte_offset;
size_t printed = 0, printed_cacheline = 0;
@ -886,8 +887,10 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb
printed += fprintf(fp, ":%u", member->bitfield_size);
}
if (!sconf.suppress_aligned_attribute && member->alignment != 0)
printed += fprintf(fp, " __attribute__((__aligned__(%u)))", member->alignment);
if (!sconf.suppress_aligned_attribute && member->alignment != 0) {
member_alignment_printed = fprintf(fp, " __attribute__((__aligned__(%u)))", member->alignment);
printed += member_alignment_printed;
}
fputc(';', fp);
++printed;
@ -898,7 +901,7 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb
type__name(tag__type(type)) == NULL) {
if (!sconf.suppress_offset_comment) {
/* Check if this is a anonymous union */
int slen = cm_name ? (int)strlen(cm_name) : -1;
int slen = member_alignment_printed + (cm_name ? (int)strlen(cm_name) : -1);
int size_spacing = 5;
if (tag__is_struct(type) && tag__class(type)->is_packed && !conf->suppress_packed) {
@ -906,12 +909,6 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb
slen += packed_len;
}
if (tag__type(type)->alignment != 0 && !conf->suppress_aligned_attribute) {
char bftmp[64];
int aligned_len = snprintf(bftmp, sizeof(bftmp), " __attribute__((__aligned__(%u)))", tag__type(type)->alignment);
slen += aligned_len;
}
printed += fprintf(fp, sconf.hex_fmt ?
"%*s/* %#5x" :
"%*s/* %5u",