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

u3shit via cfe-dev cfe-dev at lists.llvm.org
Sat Jun 25 22:19:14 PDT 2016


Yes, it really fixes it. Thanks.

On 2016-06-24 21:45, David Majnemer wrote:
> Should be fixed in r273711.
> 
> On Fri, Jun 24, 2016 at 11:29 AM, David Majnemer <david.majnemer at gmail.com>
> wrote:
> 
>> 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
>>>
>>
>>
> 




More information about the cfe-dev mailing list