Last active
August 29, 2015 14:17
-
-
Save endrift/7b96e35fceb5e935227c to your computer and use it in GitHub Desktop.
clang bad constant folding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <limits.h> | |
// gcc detects the weirdness, clang does not! | |
// Try different optimization levels, architectures and OSes for more fun. | |
int main() { | |
// Unclobberred arguement | |
printf("%x\n", INT_MIN / -1); | |
// Unclobbered variable | |
int x = INT_MIN / -1; | |
printf("%x\n", x); | |
// This shouldn't crash if the constant is "properly" folded, but will if it's not | |
x = INT_MIN; | |
printf("%x\n", x / -1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment