llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

asm labels are ignored for static local variables

Open regehr opened this issue 17 years ago • 13 comments

Bugzilla Link 4777
Resolution FIXED
Resolved on Nov 20, 2011 16:10
Version unspecified
OS Linux
CC @Abramo-Bagnara,@asl,@d0k,@echristo,@ismail

Extended Description

regehr@john-home:~/z/tinyos-2.x/apps/Null/build/telosb$ cat p1.c

unsigned char foo (unsigned char x) { static volatile unsigned char P1OUT __asm ("0x0021"); unsigned char tmp = P1OUT; P1OUT = x; return tmp; }

regehr@john-home:~/z/tinyos-2.x/apps/Null/build/telosb$ clang -ccc-host-triple msp430-generic-generic -ccc-clang-archs msp430 -x c -S -w -O2 p1.c

p1.c:3:26: error: cannot compile this asm yet volatile unsigned char P1OUT __asm ("0x0021"); ^ 1 diagnostic generated.

The emitted code should be identical to placing the register in file scope:

regehr@john-home:~/z/tinyos-2.x/apps/Null/build/telosb$ msp430-gcc -O p1.c -S -o - foo: mov.b &0x0021, r14 mov.b r15, &0x0021 mov.b r14, r15 ret

regehr avatar Aug 25 '09 19:08 regehr

mentioned in issue llvm/llvm-bugzilla-archive#8956

asl avatar Nov 27 '21 06:11 asl

Aaah. Meant to be a label. Confusing :)

echristo avatar Nov 21 '11 00:11 echristo

Fixed in r145015. Note that this is not the explicit reg var extension.

d0k avatar Nov 20 '11 23:11 d0k

This should probably be rejected as a global asm variable.

echristo avatar Nov 20 '11 22:11 echristo

Works fine with r133867, I think espindola fixed this.

ismail avatar Jun 25 '11 22:06 ismail

This is breaking the assembly code inside VLC, would be nice to get this fixed.

ismail avatar Apr 14 '11 10:04 ismail

Retitled to outline that this is not msp430-only problem

asl avatar Jan 12 '11 01:01 asl

*** Bug llvm/llvm-bugzilla-archive#8956 has been marked as a duplicate of this bug. ***

asl avatar Jan 12 '11 01:01 asl

Your GCC quote says "does not make sense to use this feature with a non-static local variable." However, the variable in the example is static. So is it legal? The TinyOS people aren't going to be very interested in changing legal code.

Oops, you're absolutely right. Hmm, in CodeGenFunction::EmitBlockVarDecl in clang/lib/CodeGen/CGDecl.cpp, the variable declaration gets checked for the asm attribute before its storage class gets considered -- i.e. you can't give any block variable an __asm attribute, regardless of its storage class.

I don't have the chops to implement support for static __asm block variables, so I wonder what Anton thinks about this. (Seems like allowing them might add some bookkeeping overhead?)

llvmbot avatar Dec 16 '09 18:12 llvmbot

The "cannot compile this asm yet" error comes from CodeGenFunction::EmitBlockVarDecl(). At present we're not allowed to tack an AsmLabelAttr to a block variable.

I'm not sure it's a bug. Here's what GCC says:

"It does not make sense to use this feature with a non-static local variable since such variables do not have assembler names. If you are trying to put the variable in a particular register, see Explicit Reg Vars. GCC presently accepts such code with a warning, but will probably be changed to issue an error, rather than a warning, in the future." [http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Asm-Labels.html#Asm-Labels]

If I read that correctly, John's p1.c should instead declare P1OUT in file scope.

Hi Ben-

Your GCC quote says "does not make sense to use this feature with a non-static local variable." However, the variable in the example is static. So is it legal? The TinyOS people aren't going to be very interested in changing legal code.

I just checked again and this is still the problem that is holding up compilation of TinyOS apps for msp430 platforms.

regehr avatar Dec 16 '09 06:12 regehr

The "cannot compile this asm yet" error comes from CodeGenFunction::EmitBlockVarDecl(). At present we're not allowed to tack an AsmLabelAttr to a block variable.

I'm not sure it's a bug. Here's what GCC says:

"It does not make sense to use this feature with a non-static local variable since such variables do not have assembler names. If you are trying to put the variable in a particular register, see Explicit Reg Vars. GCC presently accepts such code with a warning, but will probably be changed to issue an error, rather than a warning, in the future." [http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Asm-Labels.html#Asm-Labels]

If I read that correctly, John's p1.c should instead declare P1OUT in file scope.

llvmbot avatar Nov 09 '09 21:11 llvmbot

Ok, this is the one that's actually holding up compilation of TinyOS apps.

regehr avatar Oct 16 '09 05:10 regehr

This is generic bug, not msp-only.

asl avatar Sep 18 '09 19:09 asl