[cfe-dev] __builtin_assume removes calls to functions with side effect
u3shit via cfe-dev
cfe-dev at lists.llvm.org
Fri Jun 24 10:37:32 PDT 2016
Hello,
[Please CC me when replying, I'm not on the list]
I've been experimenting with replacing assert with __builtin_assume in
release builds, and I've hit a problem. I did not open a bug because I'm
not sure if this is really a bug, or just the documentation is not clear
enough. Anyway, look at this simple program:
#include <stdio.h>
int global;
int foo()
{
global = 1;
return 3;
}
int main()
{
int x = foo();
__builtin_assume(x == 3);
printf("%d %d\n", x, global);
return 0;
}
If I try to run it:
$ clang++ -O2 foo.cpp && ./a.out
3 0
(If I compile with -O0, I get the expected "3 1" as output). The
documentation itself says "The argument itself is never evaluated, so
any side effects of the expression will be discarded.", but the argument
here is "x == 3", not "foo() == 3", so IMHO it shouldn't eliminate the
function call here. Am I right here?
I get the same result from clang 3.8.0 from gentoo and from the git master.
Thanks.
More information about the cfe-dev
mailing list