[llvm] Reapply [APInt] Enable APInt ctor assertion by default (PR #114539)

Mikael Holmén via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 01:49:52 PST 2025


mikaelholmen wrote:

Hi @nikic ,

Another failure like this:
```opt -passes instcombine bbi-102622.ll -o /dev/null```
Result:
```
opt: ../include/llvm/ADT/APInt.h:121: llvm::APInt::APInt(unsigned int, uint64_t, bool, bool): Assertion `llvm::isIntN(BitWidth, val) && "Value is not an N-bit signed value"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: build-all/bin/opt -passes instcombine bbi-102622.ll -o /dev/null
1.	Running pass "function(instcombine<max-iterations=1;verify-fixpoint>)" on module "bbi-102622.ll"
2.	Running pass "instcombine<max-iterations=1;verify-fixpoint>" on function "test_max_1"
 #0 0x0000564c1b952046 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build-all/bin/opt+0x448b046)
 #1 0x0000564c1b94fa8e llvm::sys::RunSignalHandlers() (build-all/bin/opt+0x4488a8e)
 #2 0x0000564c1b9528f9 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fd7d9e41cf0 __restore_rt (/lib64/libpthread.so.0+0x12cf0)
 #4 0x00007fd7d77f2acf raise (/lib64/libc.so.6+0x4eacf)
 #5 0x00007fd7d77c5ea5 abort (/lib64/libc.so.6+0x21ea5)
 #6 0x00007fd7d77c5d79 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d79)
 #7 0x00007fd7d77eb426 (/lib64/libc.so.6+0x47426)
 #8 0x0000564c1c680f7b (build-all/bin/opt+0x51b9f7b)
 #9 0x0000564c1c67e98b llvm::InstCombinerImpl::foldICmpAddConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) InstCombineCompares.cpp:0:0
#10 0x0000564c1c6828cc llvm::InstCombinerImpl::foldICmpBinOpWithConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) InstCombineCompares.cpp:0:0
#11 0x0000564c1c6824c8 llvm::InstCombinerImpl::foldICmpInstWithConstant(llvm::ICmpInst&) InstCombineCompares.cpp:0:0
#12 0x0000564c1c692d2e llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) InstCombineCompares.cpp:0:0
#13 0x0000564c1c5fa12b llvm::InstCombinerImpl::run() InstructionCombining.cpp:0:0
#14 0x0000564c1c5fd9fd combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) InstructionCombining.cpp:0:0
#15 0x0000564c1c5fcd7a llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x5135d7a)
#16 0x0000564c1cda10ed llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilderPipelines.cpp:0:0
#17 0x0000564c1bb71957 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x46aa957)
#18 0x0000564c1cda8b7d llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilderPipelines.cpp:0:0
#19 0x0000564c1bb7652e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x46af52e)
#20 0x0000564c1cda064d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) PassBuilderPipelines.cpp:0:0
#21 0x0000564c1bb70647 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x46a9647)
#22 0x0000564c1cd28bbc llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (build-all/bin/opt+0x5861bbc)
#23 0x0000564c1b914c90 optMain (build-all/bin/opt+0x444dc90)
#24 0x00007fd7d77ded85 __libc_start_main (/lib64/libc.so.6+0x3ad85)
#25 0x0000564c1b9128ae _start (build-all/bin/opt+0x444b8ae)
Abort (core dumped)
```
It fails on this in InstCombinerImpl::foldICmpAddConstant:
```
    auto ComputeTable = [&](bool Op0Val, bool Op1Val) {
      int Res = 0;
      if (Op0Val)
        Res += isa<ZExtInst>(Ext0) ? 1 : -1;
      if (Op1Val)
        Res += isa<ZExtInst>(Ext1) ? 1 : -1;
      return ICmpInst::compare(APInt(BW, Res, true), C, Pred);
    };
```
[bbi-102622.ll.gz](https://github.com/user-attachments/files/18330636/bbi-102622.ll.gz)



https://github.com/llvm/llvm-project/pull/114539


More information about the llvm-commits mailing list