[cfe-dev] A problem met during using -ftrapv

peng li peterlee at cs.utah.edu
Fri May 28 00:28:26 PDT 2010


Hi There

When I tried to compile a simple program shown as follows using this 
command: clang -o add add.c -ftrapv

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

void overflow_handler(long long a, long long b, char c, char d) {
   printf("overflow occurs!\n");
}

void (*__overflow_handler)(long long, long long, char, char) = 
overflow_handler;

int main(void) {
   int64_t test = INT64_MAX + 1;
   printf("test: %lld\n", test);
}

I got the following error message:
clang: X86ISelLowering.cpp:7726: virtual void 
llvm::X86TargetLowering::ReplaceNodeResults(llvm::SDNode*, 
llvm::SmallVectorImpl<llvm::SDValue>&, llvm::SelectionDAG&) const: 
Assertion `false && "Do not know how to custom type legalize this 
operation!"' failed.
0  clang 0x08fe24c8
Stack dump:
0.      Program arguments: 
/home/peng/LLVM-INSTALL/llvm-install/bin/clang -cc1 -triple 
i386-pc-linux-gnu -S -disable-free -main-file-name division.c 
-mrelocation-model static -mdisable-fp-elim -mconstructor-aliases 
-target-cpu pentium4 -resource-dir 
/home/peng/LLVM-INSTALL/llvm-install/lib/clang/1.5 -ferror-limit 19 
-ftemplate-backtrace-limit 10 -fmessage-length 237 -ftrapv -fgnu-runtime 
-fdiagnostics-show-option -fcolor-diagnostics -o /tmp/cc-Su3esc.s -x c 
division.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'X86 DAG->DAG Instruction Selection' on function 
'@main'
clang: error: compiler command failed due to signal 6 (use -v to see 
invocation)


And, it is obvious that this snippet code will lead to integer overflow, 
when I tested the subtraction operation by replacing
   int64_t test = INT64_MAX + 1;
to
   int64_t test = INT64_MIN - 1;
The same error message still came out.

However, when I lower the 64 bit operation down to 32 bit, i.e., I 
changed INT64_MAX to INT32_MAX, then the problem disappeared, and the 
overflow could be caught successfully.Seems the problem occurs only if I 
used the 64-bit operations, it is wired!


Thanks


Peng



More information about the cfe-dev mailing list