public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/30088]  New: Unexpected compilation results: -O1 vs. -O1 -fstrict-aliasing
@ 2006-12-06 16:59 heikki dot tauriainen at tkk dot fi
  2006-12-06 17:01 ` [Bug c++/30088] " heikki dot tauriainen at tkk dot fi
                   ` (21 more replies)
  0 siblings, 22 replies; 23+ messages in thread
From: heikki dot tauriainen at tkk dot fi @ 2006-12-06 16:59 UTC (permalink / raw)
  To: gcc-bugs

The following C++ program (preprocessed source attached) produces unexpected
results when compiled with -O1 -fstrict-aliasing (as opposed to -O1 only) or
with any higher level of optimization (-O2 or -O3).  No compilation warnings
are emitted in any of the cases.


#include <cassert>
#include <string>

struct A
{
  A() : _x(0.0), _y(0.0) { }
  float& f(const int& i) { return (i == 0 ? _x : _y); }
  float _x, _y;
};

struct B
{
  B(const char* s) : _s(s) { }
  std::string g() { return std::string(_s); }
  const char* _s;
};

A h(const char* s)
{
  if (s == 0)
    return A();
  A a;
  B b(s);
  if (b.g().compare(std::string("")) == 0)
    a.f(0) = a.f(1) = 1.0;
  else if (b.g().compare(std::string("")))
    b.g().compare(std::string(""));
  return a;
}

int main()
{
  A a(h(""));
  assert(a._x > 0.0 && a._y > 0.0);
  return 0;
}


Compilation results:

$ g++ -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../src/configure --prefix=/opt/gcc-4.1.1
Thread model: posix
gcc version 4.1.1
$ g++ -W -Wall -O1 testcase.cc      
$ ./a.out
$ g++ -W -Wall -O1 -fstrict-aliasing testcase.cc
$ ./a.out
a.out: testcase.cc:34: int main(): Assertion `a._x > 0.0 && a._y > 0.0' failed.
Aborted


The assertion ceases to fail (with -O1 -fstrict-aliasing) when adding any
(single one) of the options -fno-tree-copy-prop, -fno-tree-dce,
-fno-tree-salias or -fno-inline to the compiler command line.


-- 
           Summary: Unexpected compilation results: -O1 vs. -O1 -fstrict-
                    aliasing
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: heikki dot tauriainen at tkk dot fi
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

end of thread, other threads:[~2009-03-30 19:44 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-06 16:59 [Bug c++/30088] New: Unexpected compilation results: -O1 vs. -O1 -fstrict-aliasing heikki dot tauriainen at tkk dot fi
2006-12-06 17:01 ` [Bug c++/30088] " heikki dot tauriainen at tkk dot fi
2006-12-07  7:17 ` bangerth at dealii dot org
2006-12-07  7:23 ` [Bug tree-optimization/30088] " bangerth at dealii dot org
2006-12-27  0:06 ` [Bug tree-optimization/30088] [4.1 Regression] " pinskia at gcc dot gnu dot org
2007-01-25  5:59 ` mmitchel at gcc dot gnu dot org
2007-02-05 12:17 ` rguenth at gcc dot gnu dot org
2007-02-05 12:30 ` rguenth at gcc dot gnu dot org
2007-02-05 14:08 ` rguenth at gcc dot gnu dot org
2007-02-05 14:10 ` rguenth at gcc dot gnu dot org
2007-02-05 14:52 ` rguenth at gcc dot gnu dot org
2007-02-14  9:01 ` mmitchel at gcc dot gnu dot org
2007-04-25  0:12 ` janis at gcc dot gnu dot org
2007-04-25  0:17 ` pinskia at gcc dot gnu dot org
2007-11-14 10:00 ` steven at gcc dot gnu dot org
2007-11-14 17:51 ` janis at gcc dot gnu dot org
2007-11-14 18:36 ` manu at gcc dot gnu dot org
2007-12-26 16:17 ` [Bug tree-optimization/30088] [4.1/4.2 Regression] Unexpected compilation results: -O1 vs. -O2 reichelt at gcc dot gnu dot org
2007-12-26 16:19 ` reichelt at gcc dot gnu dot org
2007-12-26 16:38 ` [Bug tree-optimization/30088] [4.1/4.2 Regression] Unexpected compilation results: -O1 vs. -O1 -fstrict-aliasing reichelt at gcc dot gnu dot org
2008-02-04 16:10 ` rguenth at gcc dot gnu dot org
2008-07-04 21:45 ` [Bug tree-optimization/30088] [4.2 " jsm28 at gcc dot gnu dot org
2009-03-30 19:44 ` jsm28 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).