[Bug c++/51270] New: constness violation is accepted without any warning but leads to a required function call being eliminated during optimization
michiel_dewilde at agilent dot com
gcc-bugzilla@gcc.gnu.org
Tue Nov 22 15:41:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51270
Bug #: 51270
Summary: constness violation is accepted without any warning
but leads to a required function call being eliminated
during optimization
Classification: Unclassified
Product: gcc
Version: 4.6.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: michiel_dewilde@agilent.com
Created attachment 25884
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25884
Standalone source file
Bug summary: constness violation is accepted without any warning but leads to a
required function call being eliminated during optimization
The code itself has a problem in the function "faulty_compiled_function":
Feeding the return value of "pass_through" as argument to "recast_reference"
violates "const" regulations.
This error is never caught by at least g++ 4.4.2 and g++ 4.6.2 on x86_64.
Far worse, when compiling with -O1 or bigger, the optimizer eliminates the call
to "pass_through" and feeds invalid data into "recast_reference".
Proposed treatment: Either there must be an error keeping this code from
compiling, or the optimization must be able to handle it properly.
Bug triggered as follows:
Compile using "g++ -O faulty_optimization_of_invalid_const_usage.cpp"
Run "./a.out ; echo $0"
This should return exit code 0. It returns exit code 1.
Without optimization, there is no error.
The error occurs at any nonzero optimization level, even when using
-fno-strict-aliasing -fno-inline -fno-omit-stack-frame.
$ gcc -v
COLLECT_GCC=gcc_x86_64
COLLECT_LTO_WRAPPER=/gfs/belgium/gntnas01/d3/hped_build_gent/tools/gcc/4.6.2/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.6.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/hped/builds/tools/gcc/4.6.2
--enable-languages=c,c++ --with-gmp=/hfs/d1/local/dbjornba/btmp
--with-mpfr=/hfs/d1/local/dbjornba/btmp --with-mpc=/hfs/d1/local/dbjornba/btmp
Thread model: posix
gcc version 4.6.2 (GCC)
More information about the Gcc-bugs
mailing list