public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51885] New: g++ compiler options -O2 and -O3 modifies program results
@ 2012-01-17 18:59 laurentlouis.maurin at wanadoo dot fr
  2012-01-17 18:59 ` [Bug c++/51885] " paolo.carlini at oracle dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: laurentlouis.maurin at wanadoo dot fr @ 2012-01-17 18:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51885

             Bug #: 51885
           Summary: g++ compiler options -O2 and -O3 modifies program
                    results
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: laurentlouis.maurin@wanadoo.fr


Created attachment 26356
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26356
example program with comments

platform : Fedora 16 x86_64
compiler : gcc-c++-4.6.2-1.fc16.x86_64

see attaches source file ; it is an example of the quicksort algorithm written
with pointers and templates

one template is specialised and uses a reinterpret_cast (it is part of a bigger
file)

it sorts this array :  {12, -1, 2}

a) first test (compilation without any optimisation)

compilation : g++ main.cpp && ./a.out

result OK : {-1, 2, 12}

b) second test (-O2 optimisation)

compilation : g++ -O2 main.cpp && ./a.out

wrong result : {2, 12, -1}

3) third test (-O3 optimisation)

compilation : g++ -O3 main.cpp && ./a.out

wrong result : {2, 12, -1}



Strange behaviour : if i include between line #65 and line #67 (see attached
file)

std::cout<<*ptr_start<<std::endl;

then, the results are good in any case


i believe this is a bug ... the optimisation option should not change the
program result

best regards

Laurent


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

end of thread, other threads:[~2012-01-20 19:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-17 18:59 [Bug c++/51885] New: g++ compiler options -O2 and -O3 modifies program results laurentlouis.maurin at wanadoo dot fr
2012-01-17 18:59 ` [Bug c++/51885] " paolo.carlini at oracle dot com
2012-01-17 20:00 ` redi at gcc dot gnu.org
2012-01-18 10:09 ` manu at gcc dot gnu.org
2012-01-20 20:04 ` laurentlouis.maurin at wanadoo dot fr
2012-01-20 20:06 ` 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).