<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Feb 25, 2016 at 10:40 PM Justin Bogner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sanjoy Das via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> writes:<br>
> On Thu, Feb 25, 2016 at 6:35 PM, Duncan P. N. Exon Smith<br>
> <<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>> wrote:<br>
>>>  // In C<br>
>>>  void foo() {<br>
>>>    int c;<br>
>>>    if (c) print("X");<br>
>>>    escape(&c);  // escape is an empty function<br>
>>>  }<br>
>>><br>
>>> which I think is not UB in C (is it?), but will boil down to the kind<br>
>>> of IR above.<br>
>><br>
>> I'm pretty sure the `if (c)` is UB because it's branching on an uninitialized<br>
>> value, which could have a trap representation.<br>
><br>
> I am *way* out of my depth here, but what if 'c' was an 'unsigned<br>
> char' (and not an 'int')?  Wouldn't that prevent UB, since it is<br>
> escaped (cannot be a register variable), and is an 'unsigned char'<br>
> (doesn't have a trap representation)?<br>
<br>
Nah, C's pretty explicit that using uninitialized locals is undefined<br>
behaviour, regardless of type. From C11 J.2:<br>
<br>
  The value of an object with automatic storage duration is used while<br>
  it is indeterminate (6.2.4, 6.7.9, 6.8).<br>
<br>
It's also stated in 6.2.4 that "the initial value of the object is<br>
indeterminate."<br></blockquote><div><br></div><div>Reading an indeterminate value isn't UB in C. Even branching on it isn't.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>