<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66624>66624</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Inline assembly causing crashes in llc and Clang
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
boomanaiden154
</td>
</tr>
</table>
<pre>
I'm seeing some weird behavior with inline assembly from some bitcode taken from the Linux kernel. For example, the following minified test case is taken directly a tip-of-tree kernel ([this file](https://github.com/torvalds/linux/blob/9cf26c8968b358bb14cc078f8153300a493613d4/drivers/gpu/drm/nouveau/dispnv50/ovly507e.c)) and compiled with a tip of tree `clang`:
```llvm
; ModuleID = 'bugpoint-reduced-simplified.bc'
source_filename = "drivers/gpu/drm/nouveau/dispnv50/ovly507e.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
module asm ".weak __kcfi_typeid_base507c_ntfy_reset"
module asm ".set __kcfi_typeid_base507c_ntfy_reset, 505546111"
module asm ".weak __kcfi_typeid_base507c_ntfy_set"
module asm ".set __kcfi_typeid_base507c_ntfy_set, 924527716"
module asm ".weak __kcfi_typeid_base507c_ntfy_clr"
module asm ".set __kcfi_typeid_base507c_ntfy_clr, 2186127539"
module asm ".weak __kcfi_typeid_base507c_ntfy_wait_begun"
module asm ".set __kcfi_typeid_base507c_ntfy_wait_begun, 3421798255"
module asm ".weak __kcfi_typeid_base507c_image_clr"
module asm ".set __kcfi_typeid_base507c_image_clr, 2186127539"
module asm ".weak __kcfi_typeid_base507c_update"
module asm ".set __kcfi_typeid_base507c_update, 575022393"
@.src = external dso_local unnamed_addr constant [44 x i8], align 1
define dso_local void @ovly507e_image_set() #0 align 64 !kcfi_type !7 {
entry:
br i1 poison, label %if.then, label %if.end
if.then: ; preds = %entry
ret void
if.end: ; preds = %entry
call void asm sideeffect "1:\09.byte 0x0f, 0x0b\0A.pushsection __bug_table,\22aw\22\0A2:\09.long 1b - .\09# bug_entry::bug_addr\0A\09.long ${0:c} - .\09# bug_entry::file\0A\09.word ${1:c}\09# bug_entry::line\0A\09.word ${2:c}\09# bug_entry::flags\0A\09.org 2b+${3:c}\0A.popsection\0A998:\0A\09.pushsection .discard.reachable\0A\09.long 998b - .\0A\09.popsection\0A\09", "i,i,i,i,~{dirflag},~{fpsr},~{flags}"(ptr @.src, i32 71, i32 poison, i64 12) #5
unreachable
}
attributes #0 = { "zero-call-used-regs"="used-gpr" }
!7 = !{i32 924527716}
```
`llc` crashes with the following error message:
```shell
error: invalid operand for inline asm constraint 'i'
```
`clang` crashes with the same error message at `-O0`, but doesn't at higher optimization levels, presumably because the branch on poison gets optimized away so there's no inline asm causing issues anymore.
`clang` on the original non-minified example ends up hitting the following assertion however:
```shelll
clang: /llvm-project/clang/lib/Basic/SourceManager.cpp:868: clang::FileID clang::SourceManager::getFileIDLoaded(clang::SourceLocation::UIntTy) const: Assertion `0 && "Invalid SLocOffset or bad function choice"' failed.
```
I haven't investigated throughly, but I don't think this is a case of incorrect code as I'm seeing this in quite a few places in the Linux kernel.
Also noting here that I'm gathering the bitcode by embedding it using `-Xclang -fembed-bitcode=all` to collect bitcode directly after the frontend.
I need to do some more investigation but figured I would post something here.
CC: @nickdesaulniers as this touches the kernel + inline asm.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykWF1v4zrO_jXqDZHAlr8vetGkCFBgDs7FvC-wd4Es0ba2suSV5KQ5F_vbF5KdNO3szCx6gBnXkvU8IimSIsOck71GfCTFjhTPD2z2g7GPrTEj00wK1GmRP7RGXB5fCK1GcIhS9-DMiHBGaQW0OLCTNBbO0g8gtZIagTmHY6su0FkzLqtb6bkRCJ69ol7m_YDwTer5DV7RalRbOBgL-MbGSSGh-7igM0qZc9h0lFp2EgV4dB44cwjSrXxCWuReXYCBl9PGdBtvEV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