Skip to content

Instantly share code, notes, and snippets.

@vittorioromeo
Created February 11, 2017 20:24
Show Gist options
  • Save vittorioromeo/197b9780bf153cdbf34fc4c745858f29 to your computer and use it in GitHub Desktop.
Save vittorioromeo/197b9780bf153cdbf34fc4c745858f29 to your computer and use it in GitHub Desktop.
#define assume(cond) do { if (!(cond)) __builtin_unreachable(); } while (0)
int func(int x){
assume(x >=0 && x <= 10);
if ( x > 11 ){
return 2;
}else{
return 17;
}
}
#undef assume
#define assume(cond) do { if (!(cond)) detail::unreachable(); } while (0)
namespace detail {
[[noreturn]] void unreachable(){}
}
int func2(int x){
assume(x >=0 && x <= 10);
if ( x > 11 ){
return 2;
}else{
return 17;
}
}
#undef assume
#define assume(cond) __builtin_assume(cond)
int func3(int x){
assume(x >=0 && x <= 10);
if ( x > 11 ){
return 2;
}else{
return 17;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment