Linux SPARSE checker discussions
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Dibyendu Majumdar <mobile@majumdar.org.uk>
Cc: Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: Issue with bitfield
Date: Sat, 19 Aug 2017 22:18:15 +0200	[thread overview]
Message-ID: <20170819201812.7ug7bu6dwjqoetip@ltop.local> (raw)
In-Reply-To: <CACXZuxeuyK0iJp1h5J8b1BmtTroQVsbfJqkeENG3=uNyyqvDoQ@mail.gmail.com>

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

      reply	other threads:[~2017-08-19 20:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-19  1:24 Issue with bitfield Dibyendu Majumdar
2017-08-19 20:18 ` Luc Van Oostenryck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170819201812.7ug7bu6dwjqoetip@ltop.local \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=mobile@majumdar.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox