Weird strict-aliasing break
Thibault Castel
thibault.castel@gmail.com
Mon May 30 12:25:00 GMT 2011
Hi,
I have a weird warning when compiling my program with g++:
"dereferencing pointer ‘NAME’ does break strict-aliasing rules"
So, I tried to investigate a little bit and find some clues : I do a
memory mapping from a char buffer to a C struct to have access to
different datas into the buffer. Pretty casual. But, when I try to
access one of my inner field, the warning triggers... Huh...
To understand a bit more, I wrote a litte test program outside of my
project (really huge). See it in attachment. And I don't really
understand, because the warning is triggered only line 77, not on line
55. Only when I try to access the inner fields of a mapped structured
included into another structure.
I successfully avoid the warning with "__attribute__((__may_alias__))"
but this "cheat" bother me because :
- I don't want to fake the compiler
- I need to compile my huge project both under Linux (gcc/g++) and
Windows (Visual IDE)
- This warning is triggered a hundred times in my huge project (old C
project slowly turning into C++ :/)
I already saw some messages on this list about this warning. But the
difference here is my program IS working. pFoo->a and pFoo->b have
correct values.
I tried different scenarios
- grow or reduce the raw array
- change the definition order into TData
My gcc specs :
=======================
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian
4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.4 --enable-shared --enable-multiarch
--enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-targets=all --with-arch-32=i586
--with-tune=generic --enable-checking=release --build=i486-linux-gnu
--host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
=========================
Thanks a lot for any clue or explanation
PS: I'm french, and don't really speak english. I already apologize for that :/
Thibault
-------------- next part --------------
A non-text attachment was scrubbed...
Name: warn-strict.cpp
Type: text/x-c++src
Size: 1451 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20110530/a676f675/attachment.bin>
More information about the Gcc-help
mailing list