llvm / llvm-project

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

Passing -ftrapv causes clang to crash #8563

Closed llvmbot closed 14 years ago

llvmbot commented 14 years ago
Bugzilla Link 8191
Resolution DUPLICATE
Resolved on Oct 30, 2010 08:05
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @lattner

Extended Description

ExpandIntegerResult #​0: 0xbf71568: i64,i1 = smulo 0xbf7e5e8, 0xbf7ae08 [ORD=159] [ID=0] dbg:cpfs.c:355:5

Do not know how to expand the result of this operator! UNREACHABLE executed at LegalizeIntegerTypes.cpp:947! 0 clang 0x09bd75a3 1 clang 0x09bd7330 2 0xb7831400 __kernel_sigreturn + 0 3 libc.so.6 0xb758fa82 abort + 386 4 clang 0x09bac264 llvm::SmallVector<char, 64u>::~SmallVector() + 0 5 clang 0x096aa934 6 clang 0x0965ea98 7 clang 0x09662b88 llvm::SelectionDAG::LegalizeTypes() + 68 8 clang 0x096192b0 llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 1022 9 clang 0x09618a79 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator, llvm::ilist_iterator, bool&) + 219 10 clang 0x0961aa5c llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 1712 11 clang 0x096181b4 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 600 12 clang 0x09754521 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 87 13 clang 0x09b071d5 llvm::FPPassManager::runOnFunction(llvm::Function&) + 313 14 clang 0x09b0738f llvm::FPPassManager::runOnModule(llvm::Module&) + 109 15 clang 0x09b0767a llvm::MPPassManager::runOnModule(llvm::Module&) + 400 16 clang 0x09b07b30 llvm::PassManagerImpl::run(llvm::Module&) + 122 17 clang 0x09b08021 llvm::PassManager::run(llvm::Module&) + 39 18 clang 0x08ba2ee8 19 clang 0x08ba2f73 clang::EmitBackendOutput(clang::Diagnostic&, clang::CodeGenOptions const&, clang::TargetOptions const&, llvm::Module, clang::BackendAction, llvm::raw_ostream) + 70 20 clang 0x08b9f1d5 21 clang 0x08cf2fd3 clang::ParseAST(clang::Sema&, bool) + 599 22 clang 0x08a85a56 clang::ASTFrontendAction::ExecuteAction() + 254 23 clang 0x08b9ffe9 clang::CodeGenAction::ExecuteAction() + 913 24 clang 0x08a856aa clang::FrontendAction::Execute() + 316 25 clang 0x08a712ac clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 780 26 clang 0x08a2562a clang::ExecuteCompilerInvocation(clang::CompilerInstance) + 787 27 clang 0x08a1931f cc1_main(char const, char const, char const, void*) + 976 28 clang 0x08a21791 main + 521 29 libc.so.6 0xb7578bd6 __libc_start_main + 230 30 clang 0x08a18a21 Stack dump:

  1. Program arguments: /home/matt/bin/clang -cc1 -triple i386-pc-linux-gnu -S -disable-free -main-file-name cpfs.c -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.20.1 -g -resource-dir /home/matt/lib/clang/2.9 -D _GNU_SOURCE -D _FILE_OFFSET_BITS=64 -D CPFS_SIMD_ALIGNED -D CPFS_USE_SSSE3 -D FUSE_USE_VERSION=28 -O0 -Wshadow -Wextra -Wmissing-format-attribute -Wall -Wfloat-equal -Werror-implicit-function-declaration -Werror=return-type -std=gnu99 -ferror-limit 19 -fmessage-length 80 -ftrapv -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/cc-Sip4s5.s -x c cpfs.c
  2. parser at end of file
  3. Code generation
  4. Running pass 'Function Pass Manager' on module 'cpfs.c'.
  5. Running pass 'X86 DAG->DAG Instruction Selection' on function '@cpfs_load' clang: error: clang frontend command failed due to signal 6 (use -v to see invocation)

The line of code it mentions: assert(geo->bitmap_length * geo->bitmap_density >= geo->data_length);

which becomes

((geo->bitmap_length geo->bitmap_density >= geo->data_length) ? (void) (0) : __assert_fail ("geo->bitmap_length geo->bitmap_density >= geo->data_length", "cpfs.c", 355, __PRETTY_FUNCTION__));

All 3 variables are of type int64_t.

I can provide any and all other details as required.

llvmbot commented 14 years ago

This bug has been marked as a duplicate of bug llvm/llvm-project#8210

llvmbot commented 14 years ago

Yeah, that looks pretty straightforward.

lattner commented 14 years ago

Bill is going to work on this, using the grade school decomposition.

llvmbot commented 14 years ago

The trivial implementation I mentioned is useless as well as inefficient, since it would generate a 128 bit multiplication on a 32 bit machine, which libgcc at least doesn't support.

lattner commented 14 years ago

add,sub,div all seem ok, just mul is the problem.

lattner commented 14 years ago

Trivial testcase:

long long a, b; void foo() { a = a* b; }

$ clang t.c -ftrapv -m32

llvmbot commented 14 years ago

I can't say I'm interested. That said, it would be easy enough to do it as follows: do the multiplication in an i128 and check that nothing non-trivial ended up in the top half. I could probably be persuaded to do this :) Doubtless something much cleverer could be done, but I don't have time to think about it properly.

lattner commented 14 years ago

Duncan, do you have any interest in implementing this legalization?