Linux SPARSE checker discussions
 help / color / mirror / Atom feed
* Issue with bitfield
@ 2017-08-19  1:24 Dibyendu Majumdar
  2017-08-19 20:18 ` Luc Van Oostenryck
  0 siblings, 1 reply; 2+ messages in thread
From: Dibyendu Majumdar @ 2017-08-19  1:24 UTC (permalink / raw)
  To: Linux-Sparse

Hi,

This test program appears to generate incorrect IR.

extern int printf(const char *s, ...);

int main(void) {
struct { char a:4; char b:4; } x = { 2, 4 };
printf("a=%d b=%d\n", (int)x.a, (int)x.b);
return 0;
}

Regards
Dibyendu

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

* Re: Issue with bitfield
  2017-08-19  1:24 Issue with bitfield Dibyendu Majumdar
@ 2017-08-19 20:18 ` Luc Van Oostenryck
  0 siblings, 0 replies; 2+ messages in thread
From: Luc Van Oostenryck @ 2017-08-19 20:18 UTC (permalink / raw)
  To: Dibyendu Majumdar; +Cc: Linux-Sparse

On Sat, Aug 19, 2017 at 02:24:59AM +0100, Dibyendu Majumdar wrote:
> Hi,
> 
> This test program appears to generate incorrect IR.
> 
> extern int printf(const char *s, ...);
> 
> int main(void) {
> struct { char a:4; char b:4; } x = { 2, 4 };
> printf("a=%d b=%d\n", (int)x.a, (int)x.b);
> return 0;
> }


It's a very surprising bug. It's not a linearization or
an optimization bug as the AST is already wrong.
With a simpler test case, like:
	struct s {
		char a:4;
		char b:4;
	};
	
	int foo(void)
	{
		struct s x = { .a = 2, .b = 4 };
	
		return x.b;
	}

you can see that the linearization produce correct
code for the initializer.
You can also see that the return statement to be
linearized is something like
	STMT_RETURN
		ret_value: EXPR_VALUE (value = 2)

The EXPR_VALUE means that the expression is a constant
(which is indeed the case but I would expect that the
optimization has to deduce this) but it's value is wrong
(a quick check seems to indicate that whatever selected
by the x.<member> expression, it's always the value
of the first member that we get here.
It needs real investigation, though.
It would guess for a bug in the expansion or something.

Nice catch!

-- Luc

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

end of thread, other threads:[~2017-08-19 20:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-19  1:24 Issue with bitfield Dibyendu Majumdar
2017-08-19 20:18 ` Luc Van Oostenryck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox