public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51270] New: constness violation is accepted without any warning but leads to a required function call being eliminated during optimization
@ 2011-11-22 15:41 michiel_dewilde at agilent dot com
  2011-11-22 15:45 ` [Bug c++/51270] " michiel_dewilde at agilent dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: michiel_dewilde at agilent dot com @ 2011-11-22 15:41 UTC (permalink / raw)
  To: gcc-bugs

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)


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-11-22 19:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-22 15:41 [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
2011-11-22 15:45 ` [Bug c++/51270] " michiel_dewilde at agilent dot com
2011-11-22 15:50 ` redi at gcc dot gnu.org
2011-11-22 16:10 ` redi at gcc dot gnu.org
2011-11-22 16:11 ` redi at gcc dot gnu.org
2011-11-22 16:55 ` [Bug c++/51270] missed warning about returning reference to temporary redi at gcc dot gnu.org
2011-11-22 18:50 ` michiel_dewilde at agilent dot com
2011-11-22 19:23 ` redi at gcc dot gnu.org
2011-11-22 20:49 ` redi at gcc dot gnu.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).