Skip to contentSkip to conversation

typedefs and alignment

DISCUSSION Dan Carpenter 3 participants 4 messages Feb 8, 2010 – Feb 10, 2010 Sparse checker

lore
Share & tools
lore
#0 lore raw

I've found an issue handling typedefs and alignment. In the appended code sparse things 'ptr' has to be aligned so the size of 'bar' is 1024. I haven't looked at how to fix this at all, I thought I would ask the experts for hints first.

regards,
dan carpenter

#include <stdio.h>

typedef struct aligned_struct {
	int a;
}  __attribute__ ((aligned(1024))) ali_t;
struct foo {
	int b;
	ali_t *ptr;
};

int mainx(void)

{
	struct foo bar;

	printf("%d\n", sizeof(bar));
	return 0;
}
maintainer
#1 lore raw
Quoted 4 lines · Dan Carpenter

I've found an issue handling typedefs and alignment.  In the appended code sparse things 'ptr' has to be aligned so the size of 'bar' is 1024. I haven't looked at how to fix this at all, I thought I would ask the experts for hints first.

Hmm, there is a bug there.

For the simplified code:

typedef struct aligned_struct {
       int a;
}  __attribute__ ((aligned(1024))) ali_t;

ali_t *ppr;

running test-parsing will show:

.align 1024
struct aligned_struct [usertype] *[addressable] [toplevel] ppr

I am looking at it right now.

Chris

Quoted 6 lines

regards,
dan carpenter

#include <stdio.h>

Quoted 8 lines

typedef struct aligned_struct {
       int a;
}  __attribute__ ((aligned(1024))) ali_t;

struct foo {
       int b;
       ali_t *ptr;
};

It does look wrong. The easier way to expose it

Quoted 5 lines

int mainx(void)
{
       struct foo bar;

Quoted 8 lines

       printf("%d\n", sizeof(bar));
       return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Dan Carpenter
Quoted 4 lines · Dan Carpenter

I've found an issue handling typedefs and alignment.  In the appended code sparse things 'ptr' has to be aligned so the size of 'bar' is 1024. I haven't looked at how to fix this at all, I thought I would ask the experts for hints first.

Can you try this one line patch?

Thanks

Chris

From 27af04c47164d6c6a49f64c568d24d99a902e449 Mon Sep 17 00:00:00 2001
From: Christopher Li <chrisl@heli.(none)>
Date: Wed, 10 Feb 2010 01:32:30 -0800
Subject: [PATCH 2/2] Pointer don't inherent the alignment from base type

---
 parse.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
parse.c +1 -0
index 66b8112..f81b19f 100644
@@ -1698,6 +1698,7 @@ static struct token *pointer(struct token *token, struct decl_state *ctx)
 		ctx->ctype.base_type = ptr;
 		ctx->ctype.as = 0;
 		ctx->ctype.contexts = NULL;
+		ctx->ctype.alignment = 0;
 
 		token = handle_qualifiers(token->next, ctx);
 		ctx->ctype.base_type->endpos = token->pos;
Signature · 1 line
1.6.2.5
#3 lore raw
Quoted 8 lines · Chris Li
Quoted 4 lines · Dan Carpenter

I've found an issue handling typedefs and alignment.  In the appended code sparse things 'ptr' has to be aligned so the size of 'bar' is 1024. I haven't looked at how to fix this at all, I thought I would ask the experts for hints first.

Can you try this one line patch?

Works great. Thanks so much.

regards,
dan carpenter

Quoted 3 lines

Thanks

Chris

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html