public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "heikki dot tauriainen at tkk dot fi" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/30088] New: Unexpected compilation results: -O1 vs. -O1 -fstrict-aliasing Date: Wed, 06 Dec 2006 16:59:00 -0000 [thread overview] Message-ID: <bug-30088-13701@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2006-12-06 16:59 UTC|newest] Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top 2006-12-06 16:59 heikki dot tauriainen at tkk dot fi [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-30088-13701@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).