[cfe-users] Rendering of variable declarations specifying register allocation

Matthew Fernandez matthew.fernandez at gmail.com
Mon Sep 22 04:30:56 PDT 2014


Hi all,

Apologies if this is the wrong place to post this or if this is intended behaviour.

GCC allows you to specify a register to use during a variable declaration 
(https://gcc.gnu.org/onlinedocs/gcc/Local-Reg-Vars.html#Local-Reg-Vars). Clang seems to understand 
these declarations, but does not correctly render these when pretty printing the AST:

  $ cat foo.c
  void foo(void) {
      register int x asm("eax");
  }
  $ clang-3.2.7 -c foo.c # compiles without error
  $ clang-3.2.7 -cc1 -ast-print foo.c
  void foo() {
      register int x;
  }
  $ clang-r207601 -cc1 -ast-print foo.c
  void foo() {
     register int x asm("eax");
}

  $ cat bar.c
  void bar(void) {
      register int x asm("eax") = 1;
  }
  $ clang-3.2.7 -c bar.c # compiles without error
  $ clang-3.2.7 -cc1 -ast-print bar.c
  void bar() {
      register int x = 1;
  }
  $ clang-r207601 -cc1 -ast-print bar.c
  void bar() {
      register int x = 1 asm("eax");
  }

As you can see from the above, the two Clang versions I've tested have different behaviour, though 
neither seem correct. The versions generated by the second version of Clang do not seem to be 
syntactically valid. I have not yet tried with the current tip, but the two above are:
  - Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
  - clang version 3.5.0 (trunk 207601)

This seems to be independent of the target platform; at least I get similar results for ARM and x86. 
What is the intended behaviour here?

Thanks,
Matt



More information about the cfe-users mailing list