public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/43680]  New: G++ is too aggressive in optimizing away bounds checking with enums
@ 2010-04-07 21:51 jason at gcc dot gnu dot org
  2010-04-07 21:52 ` [Bug c++/43680] " jason at gcc dot gnu dot org
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-04-07 21:51 UTC (permalink / raw)
  To: gcc-bugs

With -O2, this testcase aborts on x86_64:

extern "C" void abort ();

enum E { A, B, C, D };

void
CheckE(const E value)
{
  long v = value;
  if (v <= D)
    abort ();
}

int main() {
  CheckE(static_cast<E>(5));
}

Presumably something in the middle- or back-end is believing what the C++ front
end sets TYPE_MAX_VALUE to and optimizing based on the assumption that "value"
cannot be greater than 3.

I think the C++ standard can definitely be read to allow this optimization, but
it means optimizing away bounds checking, which is a serious security problem. 
The standard should be fixed.


-- 
           Summary: G++ is too aggressive in optimizing away bounds checking
                    with enums
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: jason at gcc dot gnu dot org
        ReportedBy: jason at gcc dot gnu dot org
GCC target triplet: x86_64-unknown-linux-gnu


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


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

end of thread, other threads:[~2010-05-04  4:44 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-07 21:51 [Bug c++/43680] New: G++ is too aggressive in optimizing away bounds checking with enums jason at gcc dot gnu dot org
2010-04-07 21:52 ` [Bug c++/43680] " jason at gcc dot gnu dot org
2010-04-07 21:56 ` jason at gcc dot gnu dot org
2010-04-07 23:16 ` bangerth at gmail dot com
2010-04-08  2:58 ` jason at gcc dot gnu dot org
2010-04-08  3:18 ` bangerth at math dot tamu dot edu
2010-04-08  5:19 ` jason at gcc dot gnu dot org
2010-04-08  8:40 ` rguenth at gcc dot gnu dot org
2010-04-08  8:40 ` rguenth at gcc dot gnu dot org
2010-04-08  9:02 ` manu at gcc dot gnu dot org
2010-04-08 10:48 ` ebotcazou at gcc dot gnu dot org
2010-04-08 12:53 ` bangerth at gmail dot com
2010-04-08 15:57 ` jason at gcc dot gnu dot org
2010-04-08 22:30 ` pinskia at gcc dot gnu dot org
2010-04-09  4:44 ` jason at gcc dot gnu dot org
2010-04-20 20:44 ` [Bug c++/43680] [DR 1022] " mmitchel at gcc dot gnu dot org
2010-04-20 22:03 ` jason at gcc dot gnu dot org
2010-04-20 22:19 ` mark at codesourcery dot com
2010-04-20 23:11 ` jason at gcc dot gnu dot org
2010-05-03 21:17 ` jason at gcc dot gnu dot org
2010-05-04  4:44 ` jason 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).