Bug 36593 - [4.4 Regression]: gfortran.dg/default_format_1.f90, 22_locale/num_get/get/char/2.cc
Summary: [4.4 Regression]: gfortran.dg/default_format_1.f90, 22_locale/num_get/get/cha...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-06-22 03:00 UTC by Hans-Peter Nilsson
Modified: 2008-06-24 02:38 UTC (History)
2 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: cris-axis-elf
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-06-22 03:02:18


Attachments
preprocessed offending code (7.76 KB, text/plain)
2008-06-23 13:30 UTC, Hans-Peter Nilsson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hans-Peter Nilsson 2008-06-22 03:00:29 UTC
With r136685, these tests passed.  They are known to fail since r136695.
Both seem to be related to formatting of floating point numbers; possibly a miscompilation of newlib.  None of the libraries or front-ends had related changes in the svn range.

The gfortran test fails at execution at all the torture options, calling abort for one of the subtests.  The libstdc++ test fails with (copypasted):
assertion "d == d1" failed: file "/tmp/hpautotest-gcc1/gcc/libstdc++-v3/testsuite/22_locale/num_get/get/char/2.cc", line 101, function: void test02()^M
program stopped with signal 6.^M

I'll add an investigation from diffed disassembled executables and simulator traces.

Author of suspect patches in this range CCed.
Comment 1 Hans-Peter Nilsson 2008-06-22 08:39:07 UTC
These tests have also regressed for mmix-knuth-mmixware 132182 -> 136827, so if it's a target-specific thing that went wrong (assuming it's the same reason; there are two more regressions in that range but that's it FWIW), it has to be at a high level, because those targets are about as different as they come.
Comment 2 Richard Biener 2008-06-22 15:43:48 UTC
I certainly belive this was uncovered by my patch for PR36345.  But I also
believe newlib is at fault here ;)  The fix simply makes strict-aliasing rules
followed even more (thus, if you build newlib with -fno-strict-aliasing the
failure should go away).
Comment 3 Hans-Peter Nilsson 2008-06-23 07:12:14 UTC
An obvious and plausible explanation.  It appears it's also correct; simulator traces and trial link-time replacement gives it's _strtod_r (in newlib/libc/stdlib/strtod.c) that's "miscompiled". On closer look it seems the cause is the ugly type-punning done in the dword0 and dword1 macros (defined in mprec.h in the same directory):

typedef union { double d; __ULong L[2]; } U;
#define dword0(x) ((U*)&x)->L[0]
#define dword1(x) ((U*)&x)->L[1]
with common use of dword0/1 as lvalues and mixing in non-cast assignments.
Ugh.
Comment 4 Hans-Peter Nilsson 2008-06-23 07:38:41 UTC
FWIW, I'm about to fix newlib...
Comment 5 rguenther@suse.de 2008-06-23 09:48:03 UTC
Subject: Re:  [4.4 Regression]: gfortran.dg/default_format_1.f90,
 22_locale/num_get/get/char/2.cc

On Mon, 23 Jun 2008, hp at gcc dot gnu dot org wrote:

> ------- Comment #3 from hp at gcc dot gnu dot org  2008-06-23 07:12 -------
> An obvious and plausible explanation.  It appears it's also correct; simulator
> traces and trial link-time replacement gives it's _strtod_r (in
> newlib/libc/stdlib/strtod.c) that's "miscompiled". On closer look it seems the
> cause is the ugly type-punning done in the dword0 and dword1 macros (defined in
> mprec.h in the same directory):
> 
> typedef union { double d; __ULong L[2]; } U;
> #define dword0(x) ((U*)&x)->L[0]
> #define dword1(x) ((U*)&x)->L[1]
> with common use of dword0/1 as lvalues and mixing in non-cast assignments.
> Ugh.

Note that this type-punning using a union is ok, so it must be something
else (or it is gccs fault in this case).

Richard.
Comment 6 Hans-Peter Nilsson 2008-06-23 13:13:34 UTC
(In reply to comment #5)
> Note that this type-punning using a union is ok, so it must be something
> else (or it is gccs fault in this case).

For the record, presumably (re our discussion on irc) you're confusing the type-punning through a union extension with type-punning through a cast using a type containing a union.  The "type-punning through a union" extension (documentation malplaced in invoke.texi @opindex fstrict-aliasing) has an example that implies that using casts invalidates the extension.  Let's defer to the gcc@ list to be safe.

Warnings are emitted with -Wstrict-aliasing=1 and 2, but not 3.
Comment 7 Hans-Peter Nilsson 2008-06-23 13:30:34 UTC
Created attachment 15806 [details]
preprocessed offending code

Use -O2; should "work" with any 32-bit target.  Note the single (U*) cast for e.g. aadj1 in _strtod_r used on the left-hand side.  The actual (non-formal) breakage at hand might be that it's used together with ordinary assignments.
Comment 8 Hans-Peter Nilsson 2008-06-24 02:38:02 UTC
Newlib patch here: <http://sourceware.org/ml/newlib/2008/msg00350.html>, also referring to a gcc documentation improvement patch.