asm labels are ignored for static local variables
| 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
mentioned in issue llvm/llvm-bugzilla-archive#8956
Aaah. Meant to be a label. Confusing :)
Fixed in r145015. Note that this is not the explicit reg var extension.
This should probably be rejected as a global asm variable.
Works fine with r133867, I think espindola fixed this.
This is breaking the assembly code inside VLC, would be nice to get this fixed.
Retitled to outline that this is not msp430-only problem
*** Bug llvm/llvm-bugzilla-archive#8956 has been marked as a duplicate of this bug. ***
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?)
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.
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.
Ok, this is the one that's actually holding up compilation of TinyOS apps.
This is generic bug, not msp-only.