From: Chris Lattner Date: Wed, 10 Nov 2010 23:51:50 +0000 (+0000) Subject: add a note about inline asm compatibility. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9b743f458055e1866af332f201b5961151e165ef;p=clang add a note about inline asm compatibility. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118740 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/www/compatibility.html b/www/compatibility.html index d33686d151..b068ec5827 100644 --- a/www/compatibility.html +++ b/www/compatibility.html @@ -36,6 +36,7 @@
  • Lvalue casts
  • Jumps to within __block variable scope
  • Non-initialization of __block variables
  • +
  • Inline assembly
  • Objective-C compatibility @@ -247,6 +248,49 @@ other local variables.

    Clang does not zero initialize local block variables, and programs which rely on such behavior will most likely break when built with Clang.

    + + +

    Inline assembly

    + + +

    In general, Clang is highly compatible with the GCC inline assembly +extensions, allowing the same set of constraints, modifiers and operands as GCC +inline assembly.

    + +

    On targets that use the integrated assembler (such as most X86 targets), +inline assembly is run through the integrated assembler instead of your system +assembler (which is most commonly "gas", the GNU assembler). The LLVM +integrated assembler is extremely compatible with GAS, but there are a couple of +minor places where it is more picky, particularly due to outright GAS bugs.

    + +

    One specific example is that the assembler rejects ambiguous X86 instructions +that don't have suffixes. For example:

    + +
    +  asm("add %al, (%rax)");
    +  asm("addw $4, (%rax)");
    +  asm("add $4, (%rax)");
    +
    + +

    Both clang and GAS accept the first instruction: because the first +instruction uses the 8-bit %al register as an operand, it is clear that +it is an 8-bit add. The second instruction is accepted by both because the "w" +suffix indicates that it is a 16-bit add. The last instruction is accepted by +GAS even though there is nothing that specifies the size of the instruction (and +the assembler randomly picks a 32-bit add). Because it is ambiguous, Clang +rejects the instruction with this error message: +

    + +
    +<inline asm>:3:1: error: ambiguous instructions require an explicit suffix (could be 'addb', 'addw', 'addl', or 'addq')
    +add $4, (%rax)
    +^
    +1 error generated.
    +
    + +

    To fix this compatibility issue, add an explicit suffix to the instruction: +this makes your code more clear and is compatible with both GCC and Clang.

    +

    Objective-C compatibility