[cfe-dev] Some assembly fails in clang and succeeds in gcc

Yuri yuri at rawbw.com
Wed Aug 6 15:42:55 PDT 2014


On 08/06/2014 13:05, Reid Kleckner wrote:
> 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:
> _main:
>         #APP
> Ltmp0:
>         jmp     1  # Not right...
>         #NO_APP
>         movl    $0, %eax
>         retl
>

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:
main:
         #APP
.Ltmp0:
         jmp     .Ltmp0
         #NO_APP
         movl    $0, %eax
         retq
.Ltmp1:
         .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() {
   func(0);
}

$ 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.

Yuri



More information about the cfe-dev mailing list