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

Reid Kleckner rnk at google.com
Wed Aug 6 16:31:36 PDT 2014


Should be fixed in r215031.


On Wed, Aug 6, 2014 at 4:01 PM, Reid Kleckner <rnk at google.com> wrote:

> This is http://llvm.org/bugs/show_bug.cgi?id=18916
>
>
> On Wed, Aug 6, 2014 at 3:42 PM, Yuri <yuri at rawbw.com> wrote:
>
>> 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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140806/f7d3e16b/attachment.html>


More information about the cfe-dev mailing list