linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* typedefs and alignment
@ 2010-02-08 10:35 Dan Carpenter
  2010-02-10  1:36 ` Christopher Li
  2010-02-10  9:46 ` Chris Li
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2010-02-08 10:35 UTC (permalink / raw)
  To: linux-sparse

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;
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: typedefs and alignment
  2010-02-08 10:35 typedefs and alignment Dan Carpenter
@ 2010-02-10  1:36 ` Christopher Li
  2010-02-10  9:46 ` Chris Li
  1 sibling, 0 replies; 4+ messages in thread
From: Christopher Li @ 2010-02-10  1:36 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-sparse

On Mon, Feb 8, 2010 at 2:35 AM, Dan Carpenter <error27@gmail.com> wrote:
> 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



>
> regards,
> dan carpenter
>
> #include <stdio.h>
>
> 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


>
> int mainx(void)
> {
>        struct foo bar;
>
>        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 majordomo@vger.kernel.org
> 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: typedefs and alignment
  2010-02-08 10:35 typedefs and alignment Dan Carpenter
  2010-02-10  1:36 ` Christopher Li
@ 2010-02-10  9:46 ` Chris Li
  2010-02-10 10:11   ` Dan Carpenter
  1 sibling, 1 reply; 4+ messages in thread
From: Chris Li @ 2010-02-10  9:46 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-sparse

[-- Attachment #1: Type: text/plain, Size: 379 bytes --]

On Mon, Feb 8, 2010 at 2:35 AM, Dan Carpenter <error27@gmail.com> wrote:
> 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

[-- Attachment #2: 0002-Pointer-don-t-inherent-the-alignment-from-base-type.patch --]
[-- Type: application/octet-stream, Size: 756 bytes --]

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

Signed-off-by: Christopher Li <sparse@chrisli.org>
---
 parse.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/parse.c b/parse.c
index 66b8112..f81b19f 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: typedefs and alignment
  2010-02-10  9:46 ` Chris Li
@ 2010-02-10 10:11   ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2010-02-10 10:11 UTC (permalink / raw)
  To: Chris Li; +Cc: linux-sparse

On Wed, Feb 10, 2010 at 01:46:39AM -0800, Chris Li wrote:
> On Mon, Feb 8, 2010 at 2:35 AM, Dan Carpenter <error27@gmail.com> wrote:
> > 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

> Thanks
> 
> Chris


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-02-10 10:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-08 10:35 typedefs and alignment Dan Carpenter
2010-02-10  1:36 ` Christopher Li
2010-02-10  9:46 ` Chris Li
2010-02-10 10:11   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).