[cfe-commits] r110490 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/trapv.c
Chris Lattner
sabre at nondot.org
Fri Aug 6 17:20:46 PDT 2010
Author: lattner
Date: Fri Aug 6 19:20:46 2010
New Revision: 110490
URL: http://llvm.org/viewvc/llvm-project?rev=110490&view=rev
Log:
Correct -ftrapv to trap on errors, instead of calling the
__overflow_handler entrypoint that David Chisnall made up.
Calling __overflow_handler is not part of the contract of
-ftrapv provided by GCC, and should never have been checked
in in the first place.
According to:
http://permalink.gmane.org/gmane.comp.compilers.clang.devel/8699
David is using this for some of arbitrary precision integer stuff
or something, which is not an appropriate thing to implement on
this.
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGen/trapv.c
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=110490&r1=110489&r2=110490&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Aug 6 19:20:46 2010
@@ -1548,54 +1548,21 @@
Value *overflow = Builder.CreateExtractValue(resultAndOverflow, 1);
// Branch in case of overflow.
- llvm::BasicBlock *initialBB = Builder.GetInsertBlock();
- llvm::BasicBlock *overflowBB =
- CGF.createBasicBlock("overflow", CGF.CurFn);
- llvm::BasicBlock *continueBB =
- CGF.createBasicBlock("overflow.continue", CGF.CurFn);
+ llvm::BasicBlock *overflowBB = CGF.createBasicBlock("overflow", CGF.CurFn);
+ llvm::BasicBlock *continueBB = CGF.createBasicBlock("nooverflow", CGF.CurFn);
Builder.CreateCondBr(overflow, overflowBB, continueBB);
- // Handle overflow
-
+ // Handle overflow with llvm.trap.
+ // TODO: it would be better to generate one of these blocks per function.
Builder.SetInsertPoint(overflowBB);
-
- // Handler is:
- // long long *__overflow_handler)(long long a, long long b, char op,
- // char width)
- std::vector<const llvm::Type*> handerArgTypes;
- handerArgTypes.push_back(CGF.Int64Ty);
- handerArgTypes.push_back(CGF.Int64Ty);
- handerArgTypes.push_back(llvm::Type::getInt8Ty(VMContext));
- handerArgTypes.push_back(llvm::Type::getInt8Ty(VMContext));
- llvm::FunctionType *handlerTy =
- llvm::FunctionType::get(CGF.Int64Ty, handerArgTypes, false);
- llvm::Value *handlerFunction =
- CGF.CGM.getModule().getOrInsertGlobal("__overflow_handler",
- llvm::PointerType::getUnqual(handlerTy));
- handlerFunction = Builder.CreateLoad(handlerFunction);
-
- llvm::Value *lhs = Builder.CreateSExt(Ops.LHS, CGF.Int64Ty);
- llvm::Value *rhs = Builder.CreateSExt(Ops.RHS, CGF.Int64Ty);
-
- llvm::Value *handlerResult =
- Builder.CreateCall4(handlerFunction, lhs, rhs,
- Builder.getInt8(OpID),
- Builder.getInt8(cast<llvm::IntegerType>(opTy)->getBitWidth()));
-
- handlerResult = Builder.CreateTrunc(handlerResult, opTy);
-
- Builder.CreateBr(continueBB);
-
- // Set up the continuation
+ llvm::Function *Trap = CGF.CGM.getIntrinsic(llvm::Intrinsic::trap);
+ Builder.CreateCall(Trap);
+ Builder.CreateUnreachable();
+
+ // Continue on.
Builder.SetInsertPoint(continueBB);
- // Get the correct result
- llvm::PHINode *phi = Builder.CreatePHI(opTy);
- phi->reserveOperandSpace(2);
- phi->addIncoming(result, initialBB);
- phi->addIncoming(handlerResult, overflowBB);
-
- return phi;
+ return result;
}
Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) {
Modified: cfe/trunk/test/CodeGen/trapv.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/trapv.c?rev=110490&r1=110489&r2=110490&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/trapv.c (original)
+++ cfe/trunk/test/CodeGen/trapv.c Fri Aug 6 19:20:46 2010
@@ -20,14 +20,7 @@
// CHECK-NEXT: [[T4:%.*]] = extractvalue [[I32O]] [[T3]], 0
// CHECK-NEXT: [[T5:%.*]] = extractvalue [[I32O]] [[T3]], 1
// CHECK-NEXT: br i1 [[T5]]
- // CHECK: [[F:%.*]] = load i64 (i64, i64, i8, i8)** @__overflow_handler
- // CHECK-NEXT: [[T6:%.*]] = sext i32 [[T1]] to i64
- // CHECK-NEXT: [[T7:%.*]] = sext i32 [[T2]] to i64
- // CHECK-NEXT: [[T8:%.*]] = call i64 [[F]](i64 [[T6]], i64 [[T7]], i8 3, i8 32)
- // CHECK-NEXT: [[T9:%.*]] = trunc i64 [[T8]] to i32
- // CHECK-NEXT: br label
- // CHECK: [[T10:%.*]] = phi i32 [ [[T4]], {{.*}} ], [ [[T9]], {{.*}} ]
- // CHECK-NEXT: store i32 [[T10]], i32* @i
+ // CHECK: call void @llvm.trap()
i = j + k;
}
@@ -41,14 +34,7 @@
// CHECK-NEXT: [[T3:%.*]] = extractvalue [[I32O]] [[T2]], 0
// CHECK-NEXT: [[T4:%.*]] = extractvalue [[I32O]] [[T2]], 1
// CHECK-NEXT: br i1 [[T4]]
- // CHECK: [[F:%.*]] = load i64 (i64, i64, i8, i8)** @__overflow_handler
- // CHECK-NEXT: [[T5:%.*]] = sext i32 [[T1]] to i64
- // CHECK-NEXT: [[T6:%.*]] = call i64 [[F]](i64 [[T5]], i64 1, i8 3, i8 32)
- // CHECK-NEXT: [[T7:%.*]] = trunc i64 [[T6]] to i32
- // CHECK-NEXT: br label
- // CHECK: [[T8:%.*]] = phi i32 [ [[T3]], {{.*}} ], [ [[T7]], {{.*}} ]
- // CHECK-NEXT: store i32 [[T8]], i32* @i
- // CHECK-NEXT: call void @opaque(i32 [[T1]])
+ // CHECK: call void @llvm.trap()
}
// CHECK: define void @test2()
@@ -61,12 +47,5 @@
// CHECK-NEXT: [[T3:%.*]] = extractvalue [[I32O]] [[T2]], 0
// CHECK-NEXT: [[T4:%.*]] = extractvalue [[I32O]] [[T2]], 1
// CHECK-NEXT: br i1 [[T4]]
- // CHECK: [[F:%.*]] = load i64 (i64, i64, i8, i8)** @__overflow_handler
- // CHECK-NEXT: [[T5:%.*]] = sext i32 [[T1]] to i64
- // CHECK-NEXT: [[T6:%.*]] = call i64 [[F]](i64 [[T5]], i64 1, i8 3, i8 32)
- // CHECK-NEXT: [[T7:%.*]] = trunc i64 [[T6]] to i32
- // CHECK-NEXT: br label
- // CHECK: [[T8:%.*]] = phi i32 [ [[T3]], {{.*}} ], [ [[T7]], {{.*}} ]
- // CHECK-NEXT: store i32 [[T8]], i32* @i
- // CHECK-NEXT: call void @opaque(i32 [[T8]])
+ // CHECK: call void @llvm.trap()
}
More information about the cfe-commits
mailing list