[llvm-dev] function inlining and undef / poison question

Peter Lawrence via llvm-dev llvm-dev at lists.llvm.org
Fri Jun 16 07:33:38 PDT 2017


John,
         the program below is not necessarily *undefined* in the C programming
sense, the C89 and C99 standards say the value of a stack auto variable that
is not initialized is “indeterminate”, not “undefined behavior”, it then goes
on to say that “indeterminate” is either “unspecified” or “trap representation”.

The standard absolutely does not require this to be “UB”, and making it
so in llvm is wrong, it leads to unexpected and unwanted transformations
that are indefensible from the users point of view.

Peter Lawrence.



C89, see section 6.5.7 Initialization.

If an object that has automatic storage duration is not initialized 
explicitely, its value is indeterminate. If an object that has static 
storage duration is not initialized explicitely, it is initialized
implicitely as if every member that has arithmetic type were assigned 
0 and every member that has pointer type were assigned a null pointer 
constant.

C99, see section 6.7.8 Initialization.

If an object that has automatic storage duration is not initialized explicitly,
its value is indeterminate. If an object that has static storage duration is
not initialized explicitly, then:
— if it has pointer type, it is initialized to a null pointer; 
— if it has arithmetic type, it is initialized to (positive or unsigned) zero; 
— if it is an aggregate, every member is initialized (recursively) according to these rules; 
— if it is a union, the first named member is initialized (recursively) according to these rules.

C89, C99 see section 3.17.2 indeterminate value

either an unspecified value or a trap representation


> 
> Date: Thu, 15 Jun 2017 17:35:55 -0600
> From: John Regehr via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>>
> To: llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
> Subject: Re: [llvm-dev] Function Inlining and undef / poison question
> 
>> void F(int a)
>> {
>>    if (a == a) do_stuff();
>> }
>> 
>> ....
>> main()
>> {
>>    int x;
>>    F(x);
>> }
> 
> This C program unconditionally executes UB and any translation at all is 
> acceptable -- end of story.
> 
> John
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170616/67b790ee/attachment.html>


More information about the llvm-dev mailing list