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

Anton Korobeynikov anton at korobeynikov.info
Fri Jul 17 12:58:14 PDT 2009


>> 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

This is definitely wrong.

There is surely no warranty about the value of the register between
assembler block. However sometimes we shouldn't care (consider e.g.
we're wanting to do some stack traces, etc - so we need just have
'approximate' position of the stack frame). Frontend just replaces
this construct into equivalent inline assembler node which has some
more or less well-defined behaviour.

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).

> I don't see why.  It's a meaningless construct:
No, see the difference mentioned above.

> it doesn't guarantee
> anything about where the variable is either immediately before or
> immediately after the asm.
Right. I do not want full register tie. I just want the variable to
contain the value of the register at the time of execution. And vice
versa (store to the register).

-- 
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University




More information about the llvm-commits mailing list