Bug 833220 - Optimization changes behaviour of division by zero
Optimization changes behaviour of division by zero
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
17
x86_64 Linux
unspecified Severity low
: ---
: ---
Assigned To: Jakub Jelinek
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-18 18:05 EDT by r3obh
Modified: 2012-06-19 11:41 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-06-18 18:07:14 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description r3obh 2012-06-18 18:05:32 EDT
Description of problem:
Compiling with -O produces a different result:

$ cat bla.c
#include <stdio.h>

int main() {

  printf( "%d\n", 0 / 0 );

  return 0;
}
$ gcc bla.c
bla.c: In function 'main':
bla.c:5:21: warning: division by zero [-Wdiv-by-zero]
$ ./a.out 
Floating point exception
$ gcc -O bla.c
bla.c: In function 'main':
bla.c:5:21: warning: division by zero [-Wdiv-by-zero]
$ ./a.out 
0

Version-Release number of selected component (if applicable):
gcc version 4.7.0 20120507 (Red Hat 4.7.0-5) (GCC) 

How reproducible:
Always.
Comment 1 Jakub Jelinek 2012-06-18 18:07:14 EDT
The testcase is invoking undefined behavior, therefore it is invalid and anything can happen.
Comment 2 r3obh 2012-06-19 11:41:17 EDT
The behaviour in this case is left up to the implementation.  A good implementation should throw an exception at runtime.

Note You need to log in before you can comment on or make changes to this bug.