LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 46060 - InlineAsm loses srcloc metadata with -O0
Summary: InlineAsm loses srcloc metadata with -O0
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: 10.0
Hardware: All All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-24 13:42 PDT by Amanieu d'Antras
Modified: 2021-03-27 20:43 PDT (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Amanieu d'Antras 2020-05-24 13:42:10 PDT
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.