-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
Depending on code generation options, it is possible for INLINEASM machine instruction to fail the verification because a metadata operand is added as the last operand. This seems not to be dependent on a particular target and can be reproduced both with x86_64-linux-gnu and aarch64-linux-gnu target triples.
How to reproduce
Create the following file:
void f() {
asm volatile ("nop");
}Try compiling it with different options:
./bin/clang -S -o /dev/null /tmp/inlineasm.c -mllvm -verify-machineinstrs -target x86_64-linux-gnu
./bin/clang -S -o /dev/null /tmp/inlineasm.c -mllvm -verify-machineinstrs -target aarch64-linux-gnu
./bin/clang -S -o /dev/null /tmp/inlineasm.c -mllvm -verify-machineinstrs -target x86_64-linux-gnu -frounding-math
./bin/clang -S -o /dev/null /tmp/inlineasm.c -mllvm -verify-machineinstrs -target aarch64-linux-gnu -frounding-math
Expected result
All the above commands execute successfully.
Actual result
The first two commands (without -frounding-math) execute successfully, the other two commands (with -frounding-math) crash with a verifier error. For example, for aarch64-linux-gnu target triple the error message is
# After IRTranslator
# Machine code for function f: IsSSA, TracksLiveness
bb.1.entry:
INLINEASM &nop [sideeffect] [attdialect], implicit-def $fpcr, !6
RET_ReallyLR
# End machine code for function f.
*** Bad machine code: Expected implicit register after groups ***
- function: f
- basic block: %bb.1 entry (0x5d5c7214cd30)
- instruction: INLINEASM &nop [sideeffect] [attdialect], implicit-def $fpcr, !6
- operand 3: <0x5d5c720a6938>
fatal error: error in backend: Found 1 machine code errors.
Here is an output of ./bin/clang /tmp/inlineasm.c -mllvm -verify-machineinstrs -target aarch64-linux-gnu -frounding-math -S -o- -emit-llvm:
; ModuleID = '/tmp/inlineasm.c'
source_filename = "/tmp/inlineasm.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-unknown-linux-gnu"
; Function Attrs: noinline nounwind optnone strictfp uwtable
define dso_local void @f() #0 {
entry:
call void asm sideeffect "nop", ""() #1, !srcloc !6
ret void
}
attributes #0 = { noinline nounwind optnone strictfp uwtable "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+fp-armv8,+neon,+v8a,-fmv" }
attributes #1 = { nounwind strictfp }
!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.ident = !{!5}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{i32 7, !"frame-pointer", i32 1}
!5 = !{!"clang version 22.0.0git (git@github.com:llvm/llvm-project.git 44061d14fb03ebbd38050c628ed009ae4db2714c)"}
!6 = !{i64 29}Related: MachineVerifier::verifyInlineAsm.