public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/45204] New: gcc generates incorrect code
@ 2010-08-05 23:48 contact at philipashmore dot com
2010-08-06 10:28 ` [Bug c/45204] " rguenth at gcc dot gnu dot org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: contact at philipashmore dot com @ 2010-08-05 23:48 UTC (permalink / raw)
To: gcc-bugs
Apologies in advance for not being able to create a small code sample.
The code is in SourceForge GIT repository for treedb.
To build treedb you will need v3c - the GIT version.
First download v3c and "make prefix=[install-location] && [sudo] make install".
cd [treedb-dir]
"make debug check" works but "make git branch=master check" fails - hangs.
The release build ("make release") is definately incorrect.
The code has some hacks for strict aliasing but contrary to the documentation,
these aren't caught with "-fstrict-aliasing -Wstrict-aliasing".
The makefile I used to build gcc and it's required libraries follows.
all:
cd build/gmp && ../../gmp-4.3.2/configure --prefix=/opt/gcc
--enable-cxx && \
make && sudo make install
cd build/mpfr && ../../mpfr-3.0.0/configure --prefix=/opt/gcc
--with-gmp=/opt/gcc && \
make && sudo make install
cd build/mpc && ../../mpc-0.8.2/configure --prefix=/opt/gcc
--with-mpfr=/opt/gcc && \
make && sudo make install
cd build/ppl && ../../ppl-0.10.2/configure --prefix=/opt/gcc
--with-libgmp-prefix=/opt/gcc --with-libgmpxx-prefix=/opt/gcc --enable-cxx
--no-create --no-recursion && \
make && sudo make install
cd build/cloog-ppl && ../../cloog-ppl-0.15.9/configure
--with-ppl=/opt/gcc --with-gmp=/opt/gcc --prefix=/opt/gcc && \
make && sudo make install
cd build/gcc-4.5.1 && ../../gcc-4.5.1/configure -v
--with-pkgversion="Philip Ashmore's build 4.5.1-1"
--with-bugurl=file:///opt/gcc/share/doc/gcc-4.5/README.Bugs
--enable-languages=c,c++ --prefix=/opt/gcc --enable-shared
--enable-linker-build-id --with-system-zlib --libexecdir=/opt/gcc/lib
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/opt/gcc/include/c++/4.5 --program-suffix=-4.5
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --with-arch-32=i586
--with-tune=core2 --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-mpc=/opt/gcc
--with-mpfr=/opt/gcc --with-gmp=/opt/gcc --with-ppl=/opt/gcc
--with-cloog=/opt/gcc && \
make && sudo make install
--
Summary: gcc generates incorrect code
Product: gcc
Version: 4.5.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: contact at philipashmore dot com
GCC build triplet: x86_64-linux-gnu
GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45204
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/45204] gcc generates incorrect code
2010-08-05 23:48 [Bug c/45204] New: gcc generates incorrect code contact at philipashmore dot com
@ 2010-08-06 10:28 ` rguenth at gcc dot gnu dot org
2010-08-06 13:37 ` contact at philipashmore dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-08-06 10:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2010-08-06 10:28 -------
We need a testcase. Also please try -fno-strict-aliasing if you know the
code is bogus.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45204
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/45204] gcc generates incorrect code
2010-08-05 23:48 [Bug c/45204] New: gcc generates incorrect code contact at philipashmore dot com
2010-08-06 10:28 ` [Bug c/45204] " rguenth at gcc dot gnu dot org
@ 2010-08-06 13:37 ` contact at philipashmore dot com
2010-08-06 13:52 ` contact at philipashmore dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: contact at philipashmore dot com @ 2010-08-06 13:37 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from contact at philipashmore dot com 2010-08-06 13:37 -------
It's exactly what I tried first - I know there are obvious cases as per your
"frequently reported bugs" section.
I wanted the compiler to tell me where the aliasing was occurring in these and
in
any less obvious places so I could disable aliasing optimizations in these
cases.
Currently it's missing even the ones the docs claims it should spot - pointer->
uintptr_t -> pointer.
Previous release of treedb didn't need -fno-strict-aliasing, or did they?
If the compiler can't spot aliasing should -fno-strict-aliasing be the default?
--
contact at philipashmore dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |contact at philipashmore dot
| |com
Status|WAITING |UNCONFIRMED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45204
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/45204] gcc generates incorrect code
2010-08-05 23:48 [Bug c/45204] New: gcc generates incorrect code contact at philipashmore dot com
2010-08-06 10:28 ` [Bug c/45204] " rguenth at gcc dot gnu dot org
2010-08-06 13:37 ` contact at philipashmore dot com
@ 2010-08-06 13:52 ` contact at philipashmore dot com
2010-08-06 13:55 ` rguenth at gcc dot gnu dot org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: contact at philipashmore dot com @ 2010-08-06 13:52 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from contact at philipashmore dot com 2010-08-06 13:52 -------
Maybe I should add that the 0.6.0-beta1 release in GIT passed uintptr_t - sized
structures by value and the compiler spotted the aliasing, which is why I
introduced the pointer -> uintptr_t -> pointer hacks to begin with.
Without passing structs by value the compiler doesn't report the aliasing
problems.
I'm being sincere when I say that if the compiler really can't spot aliasing
problems then -fno-strict-aliasing should be on by default.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45204
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/45204] gcc generates incorrect code
2010-08-05 23:48 [Bug c/45204] New: gcc generates incorrect code contact at philipashmore dot com
` (2 preceding siblings ...)
2010-08-06 13:52 ` contact at philipashmore dot com
@ 2010-08-06 13:55 ` rguenth at gcc dot gnu dot org
2010-08-07 2:01 ` contact at philipashmore dot com
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-08-06 13:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from rguenth at gcc dot gnu dot org 2010-08-06 13:55 -------
(In reply to comment #3)
> Maybe I should add that the 0.6.0-beta1 release in GIT passed uintptr_t - sized
> structures by value and the compiler spotted the aliasing, which is why I
> introduced the pointer -> uintptr_t -> pointer hacks to begin with.
>
> Without passing structs by value the compiler doesn't report the aliasing
> problems.
>
> I'm being sincere when I say that if the compiler really can't spot aliasing
> problems then -fno-strict-aliasing should be on by default.
The compiler can spot all aliasing that is permitted by the language standard.
If you are writing non-C code then you need to tell that to the compiler
via -fno-strict-aliasing. Merely adding hacks to avoid the diagnostic
(which can't be perfect, if we could detect the aliasing we wouldn't
optimize based on the fact that it isn't there).
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45204
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/45204] gcc generates incorrect code
2010-08-05 23:48 [Bug c/45204] New: gcc generates incorrect code contact at philipashmore dot com
` (3 preceding siblings ...)
2010-08-06 13:55 ` rguenth at gcc dot gnu dot org
@ 2010-08-07 2:01 ` contact at philipashmore dot com
2010-08-07 4:03 ` [Bug c/45204] gcc doesn't report aliasing problems in -isystem includes contact at philipashmore dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: contact at philipashmore dot com @ 2010-08-07 2:01 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1899 bytes --]
------- Comment #5 from contact at philipashmore dot com 2010-08-07 02:01 -------
In my projects I add "-isystem ${top_srcdir}", the top source directory being
v3c.
This way, the examples can
#include <v3c/avl.h>
Just like code you might develop yourself using treedb.
I do a lot of
gcc -E -c a.c ... -o a.cc
followed by
gcc -x c -c a.cc -o a.o ...
to track down problems in the code generated by macro expansion, and as a
last ditch effort, I decided to try to compile an object file from the
"cc" file, and debug the resulting program.
There they were - the aliasing violations!
It turns out that using -isystem for local include files was effectively
telling gcc not to report problems in header files included in this way.
You can check this yourself with these "snippets"
1: my-alias.c
#include <alias-header.h>
2: alias-header.h
#include <stdio.h>
void test()
{
short a[2];
a[0]=0x1111;
a[1]=0x1111;
*(int *)a = 0x22222222;
printf("%x %x\n", a[0], a[1]);
}
Run this:
$ gcc -c -isystem. -fstrict-aliasing -Wstrict-aliasing my-alias.c
and you will get no warnings or errors.
3: my-alias.cc
#include <stdio.h>
void test()
{
short a[2];
a[0]=0x1111;
a[1]=0x1111;
*(int *)a = 0x22222222;
printf("%x %x\n", a[0], a[1]);
}
Run this:
$ gcc -x c -c -isystem. -fstrict-aliasing -Wstrict-aliasing my-alias.cc
and you will get
my-alias.cc: In function âtestâ:
my-alias.cc:7: warning: dereferencing type-punned pointer will break
strict-aliasing rules
--
contact at philipashmore dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45204
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/45204] gcc doesn't report aliasing problems in -isystem includes
2010-08-05 23:48 [Bug c/45204] New: gcc generates incorrect code contact at philipashmore dot com
` (4 preceding siblings ...)
2010-08-07 2:01 ` contact at philipashmore dot com
@ 2010-08-07 4:03 ` contact at philipashmore dot com
2010-08-07 4:10 ` pinskia at gcc dot gnu dot org
2010-08-07 10:24 ` rguenth at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: contact at philipashmore dot com @ 2010-08-07 4:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from contact at philipashmore dot com 2010-08-07 04:03 -------
I think the rename better describes this problem - please change it if you can
think up a better title.
--
contact at philipashmore dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|gcc generates incorrect code|gcc doesn't report aliasing
| |problems in -isystem
| |includes
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45204
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/45204] gcc doesn't report aliasing problems in -isystem includes
2010-08-05 23:48 [Bug c/45204] New: gcc generates incorrect code contact at philipashmore dot com
` (5 preceding siblings ...)
2010-08-07 4:03 ` [Bug c/45204] gcc doesn't report aliasing problems in -isystem includes contact at philipashmore dot com
@ 2010-08-07 4:10 ` pinskia at gcc dot gnu dot org
2010-08-07 10:24 ` rguenth at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-08-07 4:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from pinskia at gcc dot gnu dot org 2010-08-07 04:09 -------
Use -Wsystem-headers.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45204
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/45204] gcc doesn't report aliasing problems in -isystem includes
2010-08-05 23:48 [Bug c/45204] New: gcc generates incorrect code contact at philipashmore dot com
` (6 preceding siblings ...)
2010-08-07 4:10 ` pinskia at gcc dot gnu dot org
@ 2010-08-07 10:24 ` rguenth at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-08-07 10:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from rguenth at gcc dot gnu dot org 2010-08-07 10:24 -------
See comment #7, this is a feature, not a bug.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45204
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-08-07 10:24 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-05 23:48 [Bug c/45204] New: gcc generates incorrect code contact at philipashmore dot com
2010-08-06 10:28 ` [Bug c/45204] " rguenth at gcc dot gnu dot org
2010-08-06 13:37 ` contact at philipashmore dot com
2010-08-06 13:52 ` contact at philipashmore dot com
2010-08-06 13:55 ` rguenth at gcc dot gnu dot org
2010-08-07 2:01 ` contact at philipashmore dot com
2010-08-07 4:03 ` [Bug c/45204] gcc doesn't report aliasing problems in -isystem includes contact at philipashmore dot com
2010-08-07 4:10 ` pinskia at gcc dot gnu dot org
2010-08-07 10:24 ` rguenth at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).