[cfe-dev] __builtin_assume removes calls to functions with side effect

David Majnemer via cfe-dev cfe-dev at lists.llvm.org
Fri Jun 24 11:29:40 PDT 2016


This looks like a bug to me...  It seems that callers of
SimplifyInstruction are not checking to see if the replaced instruction is
side-effect free.

On Fri, Jun 24, 2016 at 10:37 AM, u3shit via cfe-dev <cfe-dev at lists.llvm.org
> wrote:

> 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.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160624/f36d4db9/attachment.html>


More information about the cfe-dev mailing list