<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - InlineAsm loses srcloc metadata with -O0"
   href="https://bugs.llvm.org/show_bug.cgi?id=46060">46060</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>InlineAsm loses srcloc metadata with -O0
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>amanieu@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This only seems to affect some targets: X86 is not affected but ARM and AArch64
are.

$ cat clang_asm.c 
void foo() {
    asm("nowayisthisavalidinstruction");
}

$ clang -target arm-unknown-linux-gnueabihf clang_asm.c -O0
<inline asm>:1:2: error: invalid instruction
        nowayisthisavalidinstruction
        ^
1 error generated.

$ clang -target arm-unknown-linux-gnueabihf clang_asm.c -O1
clang_asm.c:2:9: error: invalid instruction
    asm("nowayisthisavalidinstruction");
        ^
<inline asm>:1:2: note: instantiated into assembly here
        nowayisthisavalidinstruction
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.


The metadata seems to get lost in the instruction selection pass:

//// -O0

*** IR Dump After Safe Stack instrumentation pass ***
; Function Attrs: noinline nounwind optnone sspstrong
define dso_local void @foo() #0 {
  call void asm sideeffect "nowayisthisavalidinstruction", ""() #1, !srcloc !5
  ret void
}
# *** IR Dump After ARM Instruction Selection ***:
# Machine code for function foo: IsSSA, TracksLiveness

bb.0 (%ir-block.0):
  INLINEASM &nowayisthisavalidinstruction [sideeffect] [attdialect]
  BX_RET 14, $noreg

# End machine code for function foo.

//// -O1

*** IR Dump After Safe Stack instrumentation pass ***
; Function Attrs: nounwind sspstrong
define dso_local void @foo() local_unnamed_addr #0 {
  call void asm sideeffect "nowayisthisavalidinstruction", ""() #1, !srcloc !5
  ret void
}
# *** IR Dump After ARM Instruction Selection ***:
# Machine code for function foo: IsSSA, TracksLiveness

bb.0 (%ir-block.0):
  INLINEASM &nowayisthisavalidinstruction [sideeffect] [attdialect], !5
  BX_RET 14, $noreg

# End machine code for function foo.</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>