<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Clang integrated assembler doesn't accept asm macro defined in one asm directive and used in another"
   href="http://llvm.org/bugs/show_bug.cgi?id=19749">19749</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang integrated assembler doesn't accept asm macro defined in one asm directive and used in another
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jonathan@codesourcery.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Integrated assembler refuses to accept code where an asm macro is defined
outside a function but the use is in a different asm block. This example also
demonstrates a workaround, on case others stumble across this bug too.

$ cat foobar.c
#if defined(MACRO_OUTSIDE)
asm(
    ".macro  RETURN    cond=\n\t"
    "bx\\cond    lr\n\t"
    ".endm\n\t"
    );
#endif

char* __attribute__((naked))
foo(char* bar)
{
  asm (
#if !defined(MACRO_OUTSIDE)
    ".macro  RETURN    cond=\n\t"
    "bx\\cond    lr\n\t"
    ".endm\n\t"
#endif
    "RETURN\n"
       );
}
$ clang -target arm-none-eabi -march=armv7 -g -O2 -c foobar.c -fintegrated-as
$ clang -target arm-none-eabi -march=armv7 -g -O2 -c foobar.c
-fno-integrated-as
$ clang -target arm-none-eabi -march=armv7 -g -O2 -c foobar.c
-fno-integrated-as -DMACRO_OUTSIDE
$ clang -target arm-none-eabi -march=armv7 -g -O2 -c foobar.c -fintegrated-as
-DMACRO_OUTSIDE
foobar.c:18:5: error: invalid instruction
    "RETURN\n"
    ^
<inline asm>:1:2: note: instantiated into assembly here
        RETURN
        ^~~~~~
1 error generated.
[15:01:37] ✘ jroelofs@build1-lucid-cs arm-none-eabi-lite$</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>