[llvm-commits] [llvm-gcc-4.2] r76208 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm-convert.cpp

Eli Friedman eli.friedman at gmail.com
Fri Jul 17 13:11:15 PDT 2009


On Fri, Jul 17, 2009 at 12:58 PM, Anton
Korobeynikov<anton at korobeynikov.info> wrote:
>>> void foo(void) {
>>>  register int* bar __asm__("baz");
>>>  quux(*bar, bar+1);
>>> }
>>>
>>> We completely ignored asm specifier previously.
>>
>> I don't see anything wrong with that... tying a local variable to a
>> register only guarantees that variable is in the tied register in
>> inline asm blocks.
> Answer is simple:
> 1. Ignoring asm specifier will make variable unitialized (just plain alloca)
> 2. This leads that dereferencing of it such variable yeild undefined behaviour
> 3. Optimizers will replace all code in question with unreachable

LLVM definitely does not replace a load of an uninitialized variable
with unreachable; many optimizations depend on that not happening.

> The example in question was derived from newlib code (foo there is
> naked, thus "baz" is a stack pointer register, so the whole code is
> well-defined).

So the code in question depends on a local variable tied to a specific
register being initialized with whatever happens to be in the register
at the start of the function?  I think that crosses the line into
undefined behavior.

-Eli




More information about the llvm-commits mailing list