[PATCH] Have HasSideEffects() return false for __attribute__((const)) functions
Aaron Ballman
aaron.ballman at gmail.com
Mon Mar 23 09:14:43 PDT 2015
On Mon, Mar 23, 2015 at 12:09 PM, Kuperstein, Michael M
<michael.m.kuperstein at intel.com> wrote:
> This is exactly the problem - that's what I'd expect from the warning text, but apparently, that is not what actually happens.
> For "assume(a > 0 && i++)" the entire assumption gets thrown out.
Ah, I had not picked up on the fact that this is the assume-specific
behavior, not just the usual unevaluated argument warning. Sorry for
my confusion!
~Aaron
>
> void foo(int a, int b)
> {
> __builtin_assume(a > 0 && b++);
> }
>
>>clang -O0 -c -S -o - -emit-llvm assume.c
>
> assume.c:3:20: warning: the argument to '__builtin_assume' has side effects that will be discarded [-Wassume]
> __builtin_assume(a > 0 && b++);
> ^~~~~~~~~~~~
> ; ModuleID = 'assume.c'
> target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
> target triple = "x86_64-pc-windows-msvc"
>
> ; Function Attrs: nounwind uwtable
> define void @foo(i32 %a, i32 %b) #0 {
> entry:
> %b.addr = alloca i32, align 4
> %a.addr = alloca i32, align 4
> store i32 %b, i32* %b.addr, align 4
> store i32 %a, i32* %a.addr, align 4
> ret void
> }
>
> -----Original Message-----
> From: Aaron Ballman [mailto:aaron.ballman at gmail.com]
> Sent: Monday, March 23, 2015 18:01
> To: reviews+D8548+public+9c0a033e02b7b4b5 at reviews.llvm.org
> Cc: Kuperstein, Michael M; Hal Finkel; Richard Smith; llvm cfe
> Subject: Re: [PATCH] Have HasSideEffects() return false for __attribute__((const)) functions
>
> On Mon, Mar 23, 2015 at 11:47 AM, Michael Kuperstein <michael.m.kuperstein at intel.com> wrote:
>> Also, there's something a bit odd about the warning text for an assume with side-effects.
>>
>> "the argument to '__assume' has side effects that will be discarded" suggests that only the side effects will be discarded.
>
> Which is correct. The side effects are unevaluated, but __assume is not. Think: sizeof(i++). i will not be incremented, but sizeof is still evaluated and produces a result.
>
>> This:
>> (a) doesn't make a lot of sense to me, and
>> (b) doesn't imply that nothing at all will be emitted.
>> That is, for "assume(a > 0 && i++)", the warning would make me expect that what I ended up with was equivalent to "assume(a > 0)" or perhaps "assume(a > 0 && i)".
>
> The latter is correct, not the former.
>
>>
>> Is this just a problem with how I'm reading the warning? If not, any suggestions for alternative text?
>
> I'm not certain where the confusion lies, but if there is alternative text that would be more clear, then great!
>
> ~Aaron
>
>>
>>
>> http://reviews.llvm.org/D8548
>>
>> EMAIL PREFERENCES
>> http://reviews.llvm.org/settings/panel/emailpreferences/
>>
>>
> ---------------------------------------------------------------------
> Intel Israel (74) Limited
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
More information about the cfe-commits
mailing list