Bug 49525 - [4.4] wrong code and wrong warning for bitfield related operations
Summary: [4.4] wrong code and wrong warning for bitfield related operations
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.5
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-24 22:19 UTC by Marcin Ślusarz
Modified: 2011-10-09 15:00 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.0, 4.6.1, 4.7.0
Known to fail:
Last reconfirmed:


Attachments
testcase (657 bytes, text/plain)
2011-06-24 22:19 UTC, Marcin Ślusarz
Details
g++ -v -save-temps -O2 -Wall -c all.c (1.18 KB, text/plain)
2011-06-24 22:20 UTC, Marcin Ślusarz
Details
standalone app testing this bug (1.22 KB, application/gzip)
2011-06-24 22:23 UTC, Marcin Ślusarz
Details
all.ii (691 bytes, text/plain)
2011-06-24 22:37 UTC, Marcin Ślusarz
Details
all.s (1.20 KB, text/plain)
2011-06-24 22:38 UTC, Marcin Ślusarz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marcin Ślusarz 2011-06-24 22:19:42 UTC
Created attachment 24595 [details]
testcase

Compilation of attached file generates wrong warning:
$ g++-4.4.5 -c -O2 -Wall all.c
all.c: In function ‘void test(const st_src_reg*, ureg_dst)’:
all.c:118: warning: ‘reg’ is used uninitialized in this function
all.c:118: note: ‘reg’ was declared here

And produces wrong code - at random after "test" function, src[i].Negate (one bit unsigned bit-field) becomes 1 when src_reg[i]->negate == 0 - something which should not happen.

The bug does not manifest when compiled with gcc instead of g++ or with g++ 4.3.5 or 4.5.2.
Comment 1 Marcin Ślusarz 2011-06-24 22:20:24 UTC
Created attachment 24596 [details]
g++ -v -save-temps -O2 -Wall -c all.c
Comment 2 Marcin Ślusarz 2011-06-24 22:23:56 UTC
Created attachment 24597 [details]
standalone app testing this bug

I'm attaching sources of standalone app which tests this bug.

It should print:
0
0
0
0

Sometimes it prints:
1
1
1
1
a.out: main.c:14: void check_output(ureg_src*): Assertion `sum == 0' failed.
Comment 3 Marcin Ślusarz 2011-06-24 22:37:44 UTC
Created attachment 24598 [details]
all.ii
Comment 4 Marcin Ślusarz 2011-06-24 22:38:06 UTC
Created attachment 24599 [details]
all.s
Comment 5 Mikael Pettersson 2011-06-25 12:23:48 UTC
I can't reproduce the runtime failure with gcc-4.6-20110621 on x86_64-linux.

I see you're using Gentoo's modified gcc-4.4.5.  Can you please try again with a g++ built from vanilla unmodified gcc-4.4.5 (or later 4.4.x) sources?
Comment 6 Mikael Pettersson 2011-06-25 12:54:28 UTC
(In reply to comment #5)
> I can't reproduce the runtime failure with gcc-4.6-20110621 on x86_64-linux.

Of course I meant to write gcc-4.4-20110621 not 4.6...
Comment 7 Bryan Cain 2011-06-25 15:46:32 UTC
I have this problem using the gcc 4.4.5 build in Ubuntu 10.10, which reports itself as "gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5".  So it's not Gentoo-specific.
Comment 8 Mikael Pettersson 2011-06-25 16:40:42 UTC
(In reply to comment #7)
> I have this problem using the gcc 4.4.5 build in Ubuntu 10.10, which reports
> itself as "gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5".  So it's not
> Gentoo-specific.

That's also a heavily modified vendor compiler.

Please try with an unmodified 4.4.5 or 4.4.6.
Comment 9 Marcin Ślusarz 2011-06-25 18:46:53 UTC
Gentoo does not patch gcc severely.

See: http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sys-devel/gcc/gcc-4.4.5.ebuild?revision=1.10&view=markup

which adds only 2 patches:
http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sys-devel/gcc/files/gcc-spec-env.patch?revision=1.6&view=markup
http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sys-devel/gcc/files/4.4.0/gcc-4.4.0-softfloat.patch?revision=1.1&view=markup (arm specific)

If that does not convince you, I can compile gcc without these patches. Just say so.

Please note that runtime failure occurs in ~30-40% runs.
Comment 10 Mikael Pettersson 2011-06-25 20:23:26 UTC
I don't think that .ebuild file describes everything in detail, specifically I strongly suspect they also apply 27 patches from gcc-4.4.5-patches-1.2.tar.bz2.

I just recompiled the test case with a freshly built gcc-4.4.5 on x86_64-linux, and ran it 100 times.  It failed zero times.
Comment 11 Marcin Ślusarz 2011-06-26 12:48:05 UTC
Ok, you are right. I didn't know about these patches.

Now I compiled gcc-4.4.5 with "vanilla" USE flag - which disables all these patches - and it still fails at runtime.
Comment 12 Paolo Carlini 2011-10-09 15:00:06 UTC
Can't reproduce with current 4_4-branch, 4_5-branch, 4_6-branch, and mainline.