Some assembly fails in clang and succeeds in gcc

I am looking at one project that doesn't compile with clang++.

Source in __asm__ __volatile__(...) after preprocessor looks like this:
<...skipped...>"mov [r8+((1024+7-(15))-((1024+7-(15))/(8))*(8))*4]" ", " "ecx" ";"

  "\n" "1" ":"
  "add rsi" ", " "4*16" ";"

This place breaks with this message:
sha.cpp:340:2: error: invalid instruction mnemonic 'prefix'
./cpu.h:224:17: note: expanded from macro 'ASL'
         #define ASL(x) GNU_ASL(x)
./cpu.h:218:26: note: expanded from macro 'GNU_ASL'
         #define GNU_ASL(x) "\n" #x ":"
<scratch space>:24:2: note: expanded from here

However, there is the previous instance of the similar assembly that clang doesn't complain about:
  "movdqa xmm1" ", " "[rcx+1*16]" ";"
  "\n" "0" ":"
  "movdqa [r8+((1024+7-(0+3))-((1024+7-(0+3))/(8))*(8))*4]" ", " "xmm1" ";"

gcc compiles both places.

What is wrong with the first place?


So, 1: is supposed to be a label? I suspect that is not going to work. Consider:

$ cat t.cpp
int main() {
asm (“1: jmp 1”);

$ clang -cc1 t.cpp -S -o - | grep -A10 main:

jmp 1 # Not right…
movl $0, %eax

$ clang -cc1 t.cpp -emit-obj -o t.o
Assertion failed: Target.getSymA() && “Relocation must reference a symbol!”, file …\lib\MC\WinCOFFObjectWriter.cpp, line 714

So, clearly we have bugs. As a workaround, try using textual labels that start with ‘L’ so they don’t appear in the symbol table.

However, in my case the corresponding jump label is 1b, and generated assembly is right:
$ cat t.cpp
int main() {
   asm ("1: jmp 1b");

$ clang -cc1 t.cpp -S -o - | grep -A10 main:
         jmp .Ltmp0
         movl $0, %eax
         .size main, .Ltmp1-main

I limited the testcase to this small form.
$ cat testcase.c
void func(void *state) {
__asm__ __volatile__
         "\n" "1" ":" "jb 1b;"
         ".att_syntax prefix;"
         : "c" (state)
         : "memory", "cc", "%eax"

void use() {

$ clang testcase.c
testcase.c:5:15: error: invalid instruction mnemonic 'prefix'
         "\n" "1" ":" "jb 1b;"
<inline asm>:2:21: note: instantiated into assembly here
1:jb 1b;.att_syntax prefix;
1 error generated.

gcc-4.8.0 compiles it, and clang rev.214386 doesn't.


This is

Should be fixed in r215031.