llvm / llvm-project

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

llvm-reduce 19.1.0 crash #111817

Closed R-Goc closed 1 month ago

R-Goc commented 1 month ago
Assertion failed: isa<To>(Val) && "cast<Ty>() argument of incompatible type!", file C:\Users\rysza\lib\llvm-19\llvm\include\llvm/Support/Casting.h, line 578
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: C:\\Users\\rysza\\bin\\LLVM19-dbg\\bin\\llvm-reduce --test=test.bat reduced.ll
Exception Code: 0xC000001D
 #0 0x00007ff79bee6cdc HandleAbort C:\Users\rysza\lib\llvm-19\llvm\lib\Support\Windows\Signals.inc:429:0
 #1 0x00007ffb1c1b90ed (C:\Windows\SYSTEM32\ucrtbased.dll+0xa90ed)
 #2 0x00007ffb1c1bae49 (C:\Windows\SYSTEM32\ucrtbased.dll+0xaae49)
 #3 0x00007ffb1c1c1345 (C:\Windows\SYSTEM32\ucrtbased.dll+0xb1345)
 #4 0x00007ffb1c1c0bd7 (C:\Windows\SYSTEM32\ucrtbased.dll+0xb0bd7)
 #5 0x00007ffb1c1beba1 (C:\Windows\SYSTEM32\ucrtbased.dll+0xaeba1)
 #6 0x00007ffb1c1c18af (C:\Windows\SYSTEM32\ucrtbased.dll+0xb18af)
 #7 0x00007ff799db8570 llvm::cast<class llvm::LandingPadInst, class llvm::Instruction>(class llvm::Instruction *) C:\Users\rysza\lib\llvm-19\llvm\include\llvm\Support\Casting.h:579:0
 #8 0x00007ff799da4163 llvm::InvokeInst::getLandingPadInst(void) const C:\Users\rysza\lib\llvm-19\llvm\lib\IR\Instructions.cpp:832:0
 #9 0x00007ff79994961f replaceBranchTerminator C:\Users\rysza\lib\llvm-19\llvm\tools\llvm-reduce\deltas\ReduceBasicBlocks.cpp:50:0
#10 0x00007ff799948b14 extractBasicBlocksFromModule C:\Users\rysza\lib\llvm-19\llvm\tools\llvm-reduce\deltas\ReduceBasicBlocks.cpp:171:0
#11 0x00007ff799935054 llvm::function_ref<(class llvm::Oracle &, class llvm::ReducerWorkItem &)>::callback_fn<(class llvm::Oracle &, class llvm::ReducerWorkItem &)>(__int64, class
llvm::Oracle &, class llvm::ReducerWorkItem &) C:\Users\rysza\lib\llvm-19\llvm\include\llvm\ADT\STLFunctionalExtras.h:45:0
#12 0x00007ff799918e0b llvm::function_ref<(class llvm::Oracle &, class llvm::ReducerWorkItem &)>::operator()(class llvm::Oracle &, class llvm::ReducerWorkItem &) const C:\Users\rysza\lib\llvm-19\llvm\include\llvm\ADT\STLFunctionalExtras.h:68:0
#13 0x00007ff799917d51 CheckChunk C:\Users\rysza\lib\llvm-19\llvm\tools\llvm-reduce\deltas\Delta.cpp:112:0
#14 0x00007ff799916ff4 llvm::runDeltaPass(class llvm::TestRunner &, class llvm::function_ref<(class llvm::Oracle &, class llvm::ReducerWorkItem &)>, class llvm::StringRef) C:\Users\rysza\lib\llvm-19\llvm\tools\llvm-reduce\deltas\Delta.cpp:317:0
#15 0x00007ff799948736 llvm::reduceBasicBlocksDeltaPass(class llvm::TestRunner &) C:\Users\rysza\lib\llvm-19\llvm\tools\llvm-reduce\deltas\ReduceBasicBlocks.cpp:183:0
#16 0x00007ff7998d2776 runAllDeltaPasses C:\Users\rysza\lib\llvm-19\llvm\tools\llvm-reduce\DeltaManager.cpp:140:0
#17 0x00007ff7998d1bb2 llvm::runDeltaPasses(class llvm::TestRunner &, int) C:\Users\rysza\lib\llvm-19\llvm\tools\llvm-reduce\DeltaManager.cpp:218:0
#18 0x00007ff7999a99e7 main C:\Users\rysza\lib\llvm-19\llvm\tools\llvm-reduce\llvm-reduce.cpp:210:0
#19 0x00007ff79dbeba09 invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79:0
#20 0x00007ff79dbebb42 __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#21 0x00007ff79dbebbce __scrt_common_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331:0
#22 0x00007ff79dbebbee mainCRTStartup D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17:0
#23 0x00007ffb86b8257d (C:\Windows\System32\KERNEL32.DLL+0x1257d)
#24 0x00007ffb87eeaf08 (C:\Windows\SYSTEM32\ntdll.dll+0x5af08)
R-Goc commented 1 month ago

reduced.zip

R-Goc commented 1 month ago

Completely reduced file, with skipping basic block passes:

target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.42.34321"

; Function Attrs: nounwind willreturn memory(write)
declare void @llvm.seh.try.begin() #0

declare i32 @__C_specific_handler(...)

; Function Attrs: nounwind willreturn memory(write)
declare void @llvm.seh.try.end() #0

define ptr @"??$HandleSehExceptionsInMethodIfSupported@VTestFactoryBase@internal@testing@@PEAVTest@3@@internal@testing@@YAPEAVTest@1@PEAVTestFactoryBase@01@P8301@EAAPEAV21@XZPEBD@Z"() personality ptr @__C_specific_handler {
  invoke void @llvm.seh.try.begin()
          to label %8 unwind label %1

1:                                                ; preds = %0
  %2 = catchswitch within none [label %3] unwind to caller

3:                                                ; preds = %1
  %4 = catchpad within %2 [ptr null]
  catchret from %4 to label %5

5:                                                ; preds = %3
  invoke void @llvm.seh.try.end()
          to label %8 unwind label %6

6:                                                ; preds = %5
  %7 = cleanuppad within none []
  cleanupret from %7 unwind to caller

8:                                                ; preds = %5, %0
  ret ptr null
}

attributes #0 = { nounwind willreturn memory(write) }

!llvm.module.flags = !{!0}

!0 = !{i32 2, !"eh-asynch", i32 1}
arsenm commented 1 month ago

What's the reproducer script, or what failure point? Can I just check for the presence of the invoke?

arsenm commented 1 month ago

What's the reproducer script, or what failure point? Can I just check for the presence of the invoke?

Managed to reproduce with FIleCheck on the invoke

arsenm commented 1 month ago

I think this is an API bug in InvokeInst. It assumes that the unwind block ends in a landing pad instruction. It did not consider the possibility of unwind dest being catchswitch (which seems to be new)

R-Goc commented 1 month ago

The test script is (batch file)

"C:/Users/rysza/bin/llvm19-dbg/bin/llc.exe" %1% 2>&1 | rg "calculateSEHStateForAsynchEH"

depends on symbols being present to catch failure in this function. Couldn't get symbolizer to work, also this function can get inlined into CalculateSEHStateNumbers. So using a debug version of llvm.

R-Goc commented 1 month ago

Trying to debug https://github.com/llvm/llvm-project/issues/109576

R-Goc commented 1 month ago

This code was generated by clang-cl 19.1.0 with /EHa (async exceptions).

arsenm commented 1 month ago

I think I have a quick fix for the assert. Actual support for reducing all of these catch instructions (which I don't understand) will be more work

R-Goc commented 1 month ago

Haven't read the entire language reference either.