Bug 833220 - Optimization changes behaviour of division by zero
Summary: Optimization changes behaviour of division by zero
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 17
Hardware: x86_64
OS: Linux
unspecified
low
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-06-18 22:05 UTC by r3obh
Modified: 2012-06-19 15:41 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-06-18 22:07:14 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description r3obh 2012-06-18 22:05:32 UTC
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 22:07:14 UTC
The testcase is invoking undefined behavior, therefore it is invalid and anything can happen.

Comment 2 r3obh 2012-06-19 15:41:17 UTC
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.