summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-04-02 01:03:55 +0000
committerMike Stump <mrs@apple.com>2009-04-02 01:03:55 +0000
commit40968598c728678bccdf649ebfb57d67087897e5 (patch)
treeea29823ba8790b7169159a74b2104f3f9badd7f0 /clang/lib/CodeGen
parent1e5d9439b81aaf89f40294bb42cb12fd88df1109 (diff)
downloadbcm5719-llvm-40968598c728678bccdf649ebfb57d67087897e5.tar.gz
bcm5719-llvm-40968598c728678bccdf649ebfb57d67087897e5.zip
Fixup -ftrapv to be more gcc compatible. -ftrapu (for want of a
better name) is the option that SmallTalk can use to intercept all overflows, including unsigned. I added some testcases so we don't break anything. Also included is another patch from David for += and friends. llvm-svn: 68267
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index b47d5787346..1d2da0ddf89 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -262,7 +262,9 @@ public:
// Binary Operators.
Value *EmitMul(const BinOpInfo &Ops) {
- if (CGF.getContext().getLangOptions().OverflowChecking)
+ if (CGF.getContext().getLangOptions().UnsignedOverflowChecking
+ || (CGF.getContext().getLangOptions().OverflowChecking
+ && Ops.Ty->isSignedIntegerType()))
return EmitOverflowCheckedBinOp(Ops);
return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul");
}
@@ -834,21 +836,26 @@ Value *ScalarExprEmitter::EmitRem(const BinOpInfo &Ops) {
Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) {
unsigned IID;
unsigned OpID = 0;
+
if (Ops.Ty->isSignedIntegerType()) {
switch (Ops.E->getOpcode()) {
case BinaryOperator::Add:
+ case BinaryOperator::AddAssign:
OpID = 1;
IID = llvm::Intrinsic::sadd_with_overflow;
break;
case BinaryOperator::Sub:
+ case BinaryOperator::SubAssign:
OpID = 2;
IID = llvm::Intrinsic::ssub_with_overflow;
break;
case BinaryOperator::Mul:
+ case BinaryOperator::MulAssign:
OpID = 3;
IID = llvm::Intrinsic::smul_with_overflow;
break;
default:
+ fprintf(stderr, "Opcode: %d\n", Ops.E->getOpcode());
assert(false && "Unsupported operation for overflow detection");
}
OpID <<= 1;
@@ -859,14 +866,17 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) {
"Must be either a signed or unsigned integer op");
switch (Ops.E->getOpcode()) {
case BinaryOperator::Add:
+ case BinaryOperator::AddAssign:
OpID = 1;
IID = llvm::Intrinsic::uadd_with_overflow;
break;
case BinaryOperator::Sub:
+ case BinaryOperator::SubAssign:
OpID = 2;
IID = llvm::Intrinsic::usub_with_overflow;
break;
case BinaryOperator::Mul:
+ case BinaryOperator::MulAssign:
OpID = 3;
IID = llvm::Intrinsic::umul_with_overflow;
break;
@@ -935,7 +945,9 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) {
Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) {
if (!Ops.Ty->isPointerType()) {
- if (CGF.getContext().getLangOptions().OverflowChecking)
+ if (CGF.getContext().getLangOptions().UnsignedOverflowChecking
+ || (CGF.getContext().getLangOptions().OverflowChecking
+ && Ops.Ty->isSignedIntegerType()))
return EmitOverflowCheckedBinOp(Ops);
return Builder.CreateAdd(Ops.LHS, Ops.RHS, "add");
}
@@ -986,7 +998,9 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) {
Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) {
if (!isa<llvm::PointerType>(Ops.LHS->getType())) {
- if (CGF.getContext().getLangOptions().OverflowChecking)
+ if (CGF.getContext().getLangOptions().UnsignedOverflowChecking
+ || (CGF.getContext().getLangOptions().OverflowChecking
+ && Ops.Ty->isSignedIntegerType()))
return EmitOverflowCheckedBinOp(Ops);
return Builder.CreateSub(Ops.LHS, Ops.RHS, "sub");
}
OpenPOWER on IntegriCloud