[cfe-dev] Gobal register variables marked local

Renato Golin renato.golin at linaro.org
Fri May 9 04:29:24 PDT 2014


Hi Rafael,

I'm going down the route of marking the variable declaration as "named
register" in SemaDecl (ActOnVariableDeclarator) and then adding the
intrinsic at the initialization time.

Since it has no explicit initializer, it ends up in the
TentativeDefinitions array, which gets initialized in
ActOnEndOfTranslationUnit. But that's not what I want, since this
"variable" doesn't exist, per se, but I still need to keep it around
for replacing all reads/writes by an intrinsic.

Also, while parsing statements that contain a reference to this
variable, the diagnostics on the use of the global variable detect an
"undeclared local variable":

named_reg_global.c:4:10: error: reference to local variable
'current_stack_pointer' declared in enclosing context
  return current_stack_pointer;
named_reg_global.c:1:24: note: 'current_stack_pointer' declared here
register unsigned long current_stack_pointer asm("sp");

This looks like I'm not setting the right flags beforehand, so that
ParseStatement recognizes it's not a local variable, or just that I
still haven't found the right place to do the substitution.

ParseStatementOrDeclarationAfterAttributes has a switch with
"identifier" in it, but that doesn't seem a specific enough place to
add this logic. Any pointers?

The changes I made to stop marking the declaration invalid and to mark
it as "named register" is attached. Not that this would be the final
patch, but it's helping me understand the code.

cheers,
--renato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: named-regs.patch
Type: text/x-patch
Size: 3710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140509/9e8eadb5/attachment.bin>


More information about the cfe-dev mailing list