Skip to content

Instantly share code, notes, and snippets.

@endrift
Last active August 29, 2015 14:17
Show Gist options
  • Save endrift/7b96e35fceb5e935227c to your computer and use it in GitHub Desktop.
Save endrift/7b96e35fceb5e935227c to your computer and use it in GitHub Desktop.
clang bad constant folding
#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