[Bug c/43987] New: [4.5 regression] type-punning causes broken binaries unless -O0 is used

2010-05-04 Thread thomas at archlinux dot org
I noticed this when building busybox 1.16.1, but I also saw this in other code:

When building with -O2 I get warnings like:
'warning: dereferencing type-punned pointer will break strict-aliasing rules'

The produced binary is broken, in the case of busybox, the 'sed' applet
segfaults.

When adding -fno-strict-aliasing, the warnings disappear, but the resulting
binary is still broken (with no warning or error indicating that something is
broken). The same also happens with -O1 or -Os, only a -O0 binary will work.

This used to work fine in gcc 4.4. I don't know how a test case would look
like, as I don't know the code that breaks that closely.

In my opinion, one of the following should happen:
a) gcc 4.5 should produce code that works
b) gcc 4.5 should throw a warning or error indicating that the code is
incorrect


-- 
   Summary: [4.5 regression] type-punning causes broken binaries
unless -O0 is used
   Product: gcc
   Version: 4.5.0
Status: UNCONFIRMED
  Severity: critical
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: thomas at archlinux dot org
 GCC build triplet: x86_64-unknown-linux-gnu / i686-pc-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu / i686-pc-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu / i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43987



[Bug middle-end/43987] [4.5 regression] type-punning causes broken binaries unless -O0 is used

2010-05-04 Thread thomas at archlinux dot org


--- Comment #3 from thomas at archlinux dot org  2010-05-04 23:06 ---
What is -fwrapv supposed to do? I don't see any changes in behaviour or
compiler output.


As I said, I don't know exactly what to put into a test case (I didn't write
any of the code that breaks), but I can try my best to find one.


I first encountered this problem in gap (http://www.gap-system.org), and it was
fixed by this patch:
http://www.math.leidenuniv.nl/~wpalenst/sage/gap_gcc45_strict_aliasing.patch
(look at the sysinfo.c part, that was what caused the problems apparently).

I now encountered it again in busybox's 'sed' applet. I will try to take that
code apart until I find out what's going wrong and hopefully produce a test
case.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43987



[Bug middle-end/43987] [4.5 regression] type-punning causes broken binaries unless -O0 is used

2010-05-04 Thread thomas at archlinux dot org


--- Comment #5 from thomas at archlinux dot org  2010-05-04 23:49 ---
I am still not able to produce a short test case, but maybe this will help:
http://git.busybox.net/busybox/tree/editors/sed.c?h=1_16_stable&id=1_16_1#n738

In the function add_input_file(), the 'file' argument is not a NULL pointer,
but at the end of the function, G.input_file_list[G.input_file_count-1]==NULL
(and !=file in particular), which ultimately leads to the segfault.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43987



[Bug middle-end/43987] [4.5 regression] type-punning causes broken binaries unless -O0 is used

2010-05-05 Thread thomas at archlinux dot org


--- Comment #7 from thomas at archlinux dot org  2010-05-05 07:23 ---
It has its own file:
http://git.busybox.net/busybox/tree/libbb/xrealloc_vector.c?h=1_16_stable&id=1_16_1


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43987



[Bug middle-end/43987] [4.5 regression] type-punning causes broken binaries unless -O0 is used

2010-05-05 Thread thomas at archlinux dot org


--- Comment #9 from thomas at archlinux dot org  2010-05-05 10:53 ---
Created an attachment (id=20561)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20561&action=view)
Preprocessor output of sed.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43987



[Bug middle-end/43987] [4.5 regression] type-punning causes broken binaries unless -O0 is used

2010-05-05 Thread thomas at archlinux dot org


--- Comment #10 from thomas at archlinux dot org  2010-05-05 10:58 ---
(In reply to comment #8)
> Waiting for a testcase (which could be just preprocessed source of
> sed.c).

Attached. If I find a better (shorter) test case, I'll add that too.

> Can you reproduce the issue when you add -fno-inline?

Yes.

> Can you reproduce the issue with the current 4.5 branch?

We've scheduled to build the latest snapshot next week. Maybe I can do it
before then, I'll let you know as soon as I get to try.

> As you can reproduce with -O1 I doubt this is an issue with type-punning.

That was my thought too, but it seems to happen only in places where
type-punning occurs.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43987



[Bug middle-end/43987] [4.5 regression] type-punning causes broken binaries unless -O0 is used

2010-05-05 Thread thomas at archlinux dot org


--- Comment #11 from thomas at archlinux dot org  2010-05-05 11:57 ---
The problem persists with the 4.5-20100429 snapshot.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43987



[Bug middle-end/43987] [4.5/4.6 Regression] type-punning causes broken binaries unless -O0 is used

2010-05-05 Thread thomas at archlinux dot org


--- Comment #17 from thomas at archlinux dot org  2010-05-05 14:10 ---
> I have a patch.  Workaround for 4.5.0: -fno-pta.

There is no -fno-pta option in 4.5.0, but I can confirm that -fno-tree-pta
fixes the problem in the testcase and in busybox.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43987



[Bug middle-end/43987] [4.5 Regression] type-punning causes broken binaries unless -O0 is used

2010-05-21 Thread thomas at archlinux dot org


--- Comment #24 from thomas at archlinux dot org  2010-05-21 08:16 ---
Preliminary tests with a recent gcc snapshot from the 4.5 branch shows that the
problem is entirely solved by this patch (maybe in combination with other
fixes).

Thanks for the quick responses and fixes.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43987