llvm / llvm/llvm-project

[GVN] Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"' failed.

Open
#207,532 1 comment 0 reactions 1 assignee Claimed by @dtcxzyw View on GitHub
confirmed crash-on-valid generated by fuzzer llvm:GVN regression:23
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reduced reproducer: https://godbolt.org/z/c9Tf8czqK

```llvm
; bin/opt -passes=gvn -S test.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@g_1487 = external global i32

define fastcc ptr @func_133() {
entry:
%l_1486.sroa.0 = alloca ptr, align 8
store b64 bitcast (ptr @g_1487 to b64), ptr %l_1486.sroa.0, align 8
%l_1486.sroa.0.0.l_1486.sroa.0.0.l_1486.sroa.0.0.l_1486.sroa.0.0.l_1486.val = load ptr, ptr %l_1486.sroa.0, align 8
ret ptr %l_1486.sroa.0.0.l_1486.sroa.0.0.l_1486.sroa.0.0.l_1486.sroa.0.0.l_1486.val
}
```

```
opt: /root/llvm-project/llvm/lib/IR/Constants.cpp:2376: static llvm::Constant* llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool): Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=gvn
1. Running pass "function(gvn<>)" on module ""
2. Running pass "gvn<>" on function "func_133"
#0 0x0000000005afb108 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5afb108)
#1 0x0000000005af8024 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5af8024)
#2 0x0000000005af819a SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007a842aa45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007a842aa9eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#5 0x00007a842aa4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#6 0x00007a842aa288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#7 0x00007a842aa2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#8 0x00007a842aa3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#9 0x0000000005707793 llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5707793)
#10 0x00000000056c4f69 llvm::ConstantFoldCastInstruction(unsigned int, llvm::Constant*, llvm::Type*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x56c4f69)
#11 0x00000000057068a7 getFoldedCast(llvm::Instruction::CastOps, llvm::Constant*, llvm::Type*, bool) Constants.cpp:0:0
#12 0x0000000000b6284c llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::MDNode*, llvm::FMFSource) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xb6284c)
#13 0x0000000004dec7f5 llvm::VNCoercion::getValueForLoad(llvm::Value*, unsigned int, llvm::Type*, llvm::Instruction*, llvm::Function*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4dec7f5)
#14 0x0000000004758884 llvm::gvn::AvailableValue::MaterializeAdjustedValue(llvm::LoadInst*, llvm::Instruction*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4758884)
#15 0x00000000047670bb llvm::GVNPass::processLoad(llvm::LoadInst*) (.part.0) GVN.cpp:0:0
#16 0x0000000004769720 llvm::GVNPass::processInstruction(llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4769720)
#17 0x000000000476a0d1 llvm::GVNPass::processBlock(llvm::BasicBlock*) (.part.0) GVN.cpp:0:0
#18 0x000000000476a445 llvm::GVNPass::iterateOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x476a445)
#19 0x000000000476a9ae llvm::GVNPass::runImpl(llvm::Function&, llvm::AssumptionCache&, llvm::DominatorTree&, llvm::TargetLibraryInfo const&, llvm::AAResults&, llvm::MemoryDependenceResults*, llvm::LoopInfo&, llvm::OptimizationRemarkEmitter*, llvm::MemorySSA*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x476a9ae)
#20 0x000000000476bce4 llvm::GVNPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x476bce4)
#21 0x0000000000eea0de llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xeea0de)
#22 0x0000000005880607 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5880607)
#23 0x0000000000eeaffe llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xeeaffe)
#24 0x000000000587f176 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x587f176)
#25 0x000000000092037e llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x92037e)
#26 0x000000000587e7a7 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x587e7a7)
#27 0x000000000092a675 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x92a675)
#28 0x000000000091e7a1 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x91e7a1)
#29 0x00007a842aa2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#30 0x00007a842aa2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#31 0x0000000000914075 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x914075)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
llvm version: 7a3767e361cc0d6acc8e1568727a54d9b0d0b525

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.