[llvm-dev] Mem2reg: load before single store
Johannes Doerfert via llvm-dev
llvm-dev at lists.llvm.org
Mon Sep 14 09:46:07 PDT 2020
On 9/14/20 9:30 AM, James Y Knight via llvm-dev wrote:
> On Mon, Sep 14, 2020 at 3:19 AM László Radnai via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> A problem arises, and I am not sure if it is really a problem or just
>> weird C-compliant behavior.
>>
>> int a; // or, equally, int a=0;
>>
>> int main(){
>> int b;
>> if (b) // (*)
>>
> At this line, you invoke undefined behavior by reading the value of "b",
> before it's been initialized. At this point, the compiler may do whatever
> it likes.
FTR, it is *not* UB to read the value of b, you will read undef which is
totally fine. It is however UB to branch on undef.
At that point we can stop discussing what "happens next".
~ Johannes
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
More information about the llvm-dev
mailing list