[llvm-commits] [patch] Only allow unnamed_addr in definitions

Dan Gohman gohman at apple.com
Wed Jan 12 15:30:00 PST 2011


On Jan 12, 2011, at 2:34 PM, Rafael Ávila de Espíndola wrote:

> On 11-01-12 5:12 PM, Dan Gohman wrote:
>> 
>> On Jan 12, 2011, at 8:59 AM, Rafael Ávila de Espíndola wrote:
>> 
>>> The attached patches changes llvm to only accept unnamed_addr in definitions and clang to not produce them in declarations.
>>> 
>>> I am not entirely convinced that we should do it. The reasons so far are
>>> 
>>> *) There is nothing for LLVM to do with the knowledge that a declaration might be merged in the future
>>> *) It would require us to define what the linker should do on mismatched declarations and definitions. The correct answer would probably be "ignore the bit in the declaration and keep the definition one", which also suggest that we shouldn't have this in declarations.
>> 
>> LLVM optimizes this code to 0:
>> 
>> extern const int x;
>> extern const int y;
>> 
>> int foo(void) {
>>   return&x ==&y;
>> }
>> 
>> I guess this optimization would be invalid if the variables
>> had the unnamed_addr attribute. So it would seem to apply to
>> declarations as well as definitions.
> 
> No, the optimization would be valid. The attribute says that the address is not relevant. If the code actually depends on the address, the code is invalid.

Ok, I see now. I agree that it makes sense to put the flag
on definitions only.

Dan





More information about the llvm-commits mailing list