llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.9k stars 11.51k forks source link

bugpoint deletes second argument to `@llvm.stackprotector` and fails #58607

Open Vexu opened 1 year ago

Vexu commented 1 year ago
; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackprotector(ptr, ptr) #11

; Function Attrs: noreturn nounwind sspstrong
define dso_local void @main() {
Entry:
  %StackGuardSlot = alloca ptr, align 8
  %StackGuard = load volatile ptr, ptr addrspace(257) inttoptr (i32 40 to ptr addrspace(257)), align 8
  call void @llvm.stackprotector(ptr %StackGuard, ptr %StackGuardSlot)
  ret void
}
$ ../zig-bootstrap/out/host/bin/bugpoint --version
LLVM (http://llvm.org/):
  LLVM version 15.0.3
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: haswell
$ ../zig-bootstrap/out/host/bin/bugpoint -run-llc a.ll
Read input file      : 'a.ll'
*** All input ok
Initializing execution environment: Found llc: /home/vexu/Documents/zig/zig-bootstrap/out/host/bin/llc
Running the code generator to test for a crash: <llc>
Generating reference output from raw program: <llc><llc><CC><program>
Reference output is: bugpoint.reference.out-8ac89f8

*** Checking the code generator...
<llc><CC><program>
*** Output matches: Debugging miscompilation!
Checking to see if '' compiles correctly: <llc><CC><program> yup.
*** Optimized program matches reference output!  No problem detected...
bugpoint can't help you with your problem!
*** Debugging code generator crash!

*** Attempting to reduce the number of function attributes in the testcase
<llc>
Checking for crash with changing conditionals to always jump to true: Entry: <llc>
Checking for crash with changing conditionals to always jump to false: Entry: <llc>
Checking for crash with only these blocks: Entry: <llc>
Checking for crash with CFG simplifying: Entry: <llc>
Checking for crash with only 3 instructions: <llc>

*** Attempting to reduce testcase by deleting instructions: Simplification Level #1
Checking instruction:   %StackGuardSlot = alloca ptr, align 8llvm.stackprotector parameter #2 must resolve to an alloca.
  call void @llvm.stackprotector(ptr %StackGuard, ptr null)
/home/vexu/Documents/zig/zig-bootstrap/out/host/bin/opt: bugpoint-input-cb3a27a.bc: error: input module is broken!
Instruction removal failed.  Sorry. :(  Please report a bug!
arsenm commented 1 year ago

Have you tried using llvm-reduce instead? bugpoint is likely to be phased out as development is more active on llvm-reduce.

Vexu commented 1 year ago

llvm-reduce does not have the same issue but it will reduce a function with a failing stack check directly into a call to __stack_chk_fail which is why I tried to see what bugpoint would do.