llvm / llvm-project

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

__builtin_mul_overflow does not support signed _ExtInt operands of more then 128 bits; reports a fatal error in the DAG legalizer #45682

Open jtmott-intel opened 4 years ago

jtmott-intel commented 4 years ago
Bugzilla Link 46337
Version trunk
OS Linux
CC @topperc,@erichkeane,@RKSimon

Extended Description

$ cat test.c

    int main() {
        _ExtInt(129) x = 1;
        _ExtInt(129) y = 1;
        _ExtInt(129) result;
        return __builtin_mul_overflow(x, y, &result);
    }

$ cat test.ll

    ; ModuleID = 'test.c'
    source_filename = "test.c"
    target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
    target triple = "x86_64-unknown-linux-gnu"

    ; Function Attrs: noinline nounwind optnone uwtable
    define dso_local i32 @​main() #​0 {
    entry:
      %retval = alloca i32, align 4
      %x = alloca i129, align 8
      %y = alloca i129, align 8
      %result = alloca i129, align 8
      store i32 0, i32* %retval, align 4
      store i129 1, i129* %x, align 8
      store i129 1, i129* %y, align 8
      %0 = load i129, i129* %x, align 8
      %1 = load i129, i129* %y, align 8
      %2 = call { i129, i1 } @​llvm.smul.with.overflow.i129(i129 %0, i129 %1)
      %3 = extractvalue { i129, i1 } %2, 1
      %4 = extractvalue { i129, i1 } %2, 0
      store i129 %4, i129* %result, align 8
      %conv = zext i1 %3 to i32
      ret i32 %conv
    }

    ; Function Attrs: nounwind readnone speculatable willreturn
    declare { i129, i1 } @​llvm.smul.with.overflow.i129(i129, i129) #​1

    attributes #​0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
    attributes #​1 = { nounwind readnone speculatable willreturn }

    !llvm.module.flags = !{#0}
    !llvm.ident = !{#1}

    !​0 = !{i32 1, !"wchar_size", i32 4}
    !​1 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 5ddd4fc5a65a452dffa2d27ad6a5c04d148d6234)"}

$ clang -rtlib=compiler-rt test.ll

    clang-11: /home/jtmott/llvm_workspace/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp:3712: void llvm::DAGTypeLegalizer::ExpandIntRes_XMULO(llvm::SDNode*, llvm::SDValue&, llvm::SDValue&): Assertion `LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported XMULO!"' failed.
    PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
    Stack dump:
    0.  Program arguments: /home/jtmott/llvm_workspace/build/bin/clang-11 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name test.ll -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /home/jtmott/llvm_workspace/build/lib/clang/11.0.0 -fdebug-compilation-dir /home/jtmott/llvm_workspace -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -o /tmp/test-f846fd.o -x ir test.ll 
    1.  Code generation
    2.  Running pass 'Function Pass Manager' on module 'test.ll'.
    3.  Running pass 'X86 DAG->DAG Instruction Selection' on function '@main'
     #​0 0x00000000039b9bb1 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/Support/Unix/Signals.inc:564:0
     #​1 0x00000000039b9c44 PrintStackTraceSignalHandler(void*) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/Support/Unix/Signals.inc:625:0
     #​2 0x00000000039b79df llvm::sys::RunSignalHandlers() /home/jtmott/llvm_workspace/llvm-project/llvm/lib/Support/Signals.cpp:68:0
     #​3 0x00000000039b952e SignalHandler(int) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/Support/Unix/Signals.inc:406:0
     #​4 0x00007fd4e8f9f390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
     #​5 0x00007fd4e80f1428 raise /build/glibc-LK5gWL/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
     #​6 0x00007fd4e80f302a abort /build/glibc-LK5gWL/glibc-2.23/stdlib/abort.c:91:0
     #​7 0x00007fd4e80e9bd7 __assert_fail_base /build/glibc-LK5gWL/glibc-2.23/assert/assert.c:92:0
     #​8 0x00007fd4e80e9c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
     #​9 0x0000000004e867c9 llvm::DAGTypeLegalizer::ExpandIntRes_XMULO(llvm::SDNode*, llvm::SDValue&, llvm::SDValue&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp:3714:0
    #​10 0x0000000004e74c91 llvm::DAGTypeLegalizer::ExpandIntegerResult(llvm::SDNode*, unsigned int) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp:2007:0
    #​11 0x0000000004de70ac llvm::DAGTypeLegalizer::run() /home/jtmott/llvm_workspace/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp:262:0
    #​12 0x0000000004deb6fe llvm::SelectionDAG::LegalizeTypes() /home/jtmott/llvm_workspace/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp:1056:0
    #​13 0x0000000004d8106f llvm::SelectionDAGISel::CodeGenAndEmitDAG() /home/jtmott/llvm_workspace/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:840:0
    #&#8203;14 0x0000000004d805b3 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:740:0
    #&#8203;15 0x0000000004d851cb llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1619:0
    #&#8203;16 0x0000000004d7eeff llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:505:0
    #&#8203;17 0x0000000002223fd5 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:195:0
    #&#8203;18 0x0000000002a9ce3b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:73:0
    #&#8203;19 0x00000000030d1ea0 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1482:0
    #&#8203;20 0x00000000030d2141 llvm::FPPassManager::runOnModule(llvm::Module&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1518:0
    #&#8203;21 0x00000000030d2569 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1583:0
    #&#8203;22 0x00000000030d2d43 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1695:0
    #&#8203;23 0x00000000030d2f3b llvm::legacy::PassManager::run(llvm::Module&) /home/jtmott/llvm_workspace/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1727:0
    #&#8203;24 0x0000000003d38ea8 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) /home/jtmott/llvm_workspace/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:959:0
    #&#8203;25 0x0000000003d3dd84 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) /home/jtmott/llvm_workspace/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1666:0
    #&#8203;26 0x0000000004e9a33c clang::CodeGenAction::ExecuteAction() /home/jtmott/llvm_workspace/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1173:0
    #&#8203;27 0x00000000045852f2 clang::FrontendAction::Execute() /home/jtmott/llvm_workspace/llvm-project/clang/lib/Frontend/FrontendAction.cpp:957:0
    #&#8203;28 0x0000000004519d36 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/jtmott/llvm_workspace/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:973:0
    #&#8203;29 0x00000000046fee99 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/jtmott/llvm_workspace/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:282:0
    #&#8203;30 0x000000000212c9d0 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/jtmott/llvm_workspace/llvm-project/clang/tools/driver/cc1_main.cpp:240:0
    #&#8203;31 0x0000000002122074 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) /home/jtmott/llvm_workspace/llvm-project/clang/tools/driver/driver.cpp:330:0
    #&#8203;32 0x0000000002122846 main /home/jtmott/llvm_workspace/llvm-project/clang/tools/driver/driver.cpp:407:0
    #&#8203;33 0x00007fd4e80dc830 __libc_start_main /build/glibc-LK5gWL/glibc-2.23/csu/../csu/libc-start.c:325:0
    #&#8203;34 0x0000000002120729 _start (/home/jtmott/llvm_workspace/build/bin/clang-11+0x2120729)
    clang-11: error: unable to execute command: Aborted (core dumped)
    clang-11: error: clang frontend command failed due to signal (use -v to see invocation)
    clang version 11.0.0 (https://github.com/llvm/llvm-project.git 5ddd4fc5a65a452dffa2d27ad6a5c04d148d6234)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix
    InstalledDir: /home/jtmott/llvm_workspace/build/bin
    clang-11: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.

Similar bug for normal division: llvm/llvm-project#44994

AaronBallman commented 2 years ago

The fatal error is now reported properly as a compile error rather than a fatal backend error. Leaving the issue open despite the crash being fixed, because it'd be good for this builtin to support arbitrary bit precisions rather than reject them.

llvmbot commented 2 years ago

@llvm/issue-subscribers-c2x