From: Richard Smith Date: Thu, 1 Nov 2012 22:13:39 +0000 (+0000) Subject: Remove divison-by-zero checks from -ftrapv. These checks were incompatible with X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e29c441a89143912091c159d4baa4443e589d607;p=platform%2Fupstream%2Fllvm.git Remove divison-by-zero checks from -ftrapv. These checks were incompatible with g++'s -ftrapv, failed to call the -ftrapv overflow handler, and are still available under -fcatch-undefined-behavior. llvm-svn: 167258 --- diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 91b10b2..2354f31 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -418,10 +418,6 @@ public: return Builder.CreateFMul(Ops.LHS, Ops.RHS, "mul"); return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul"); } - bool isTrapvOverflowBehavior() { - return CGF.getContext().getLangOpts().getSignedOverflowBehavior() - == LangOptions::SOB_Trapping || CGF.CatchUndefined; - } /// Create a binary op that checks for overflow. /// Currently only supports +, - and *. Value *EmitOverflowCheckedBinOp(const BinOpInfo &Ops); @@ -1946,7 +1942,7 @@ void ScalarExprEmitter::EmitUndefinedBehaviorIntegerDivAndRemCheck( } Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) { - if (isTrapvOverflowBehavior()) { + if (CGF.CatchUndefined) { llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty)); if (Ops.Ty->isIntegerType()) @@ -1974,7 +1970,7 @@ Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) { Value *ScalarExprEmitter::EmitRem(const BinOpInfo &Ops) { // Rem in C can't be a floating point type: C99 6.5.5p2. - if (isTrapvOverflowBehavior()) { + if (CGF.CatchUndefined) { llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty)); if (Ops.Ty->isIntegerType()) diff --git a/clang/test/CodeGen/trapv.c b/clang/test/CodeGen/trapv.c index a259ebd..bc8bc70 100644 --- a/clang/test/CodeGen/trapv.c +++ b/clang/test/CodeGen/trapv.c @@ -50,3 +50,12 @@ void test2() { // CHECK-NEXT: br i1 [[T5]] // CHECK: call void @llvm.trap() } + +// CHECK: define void @test3( +void test3(int a, int b, float c, float d) { + // CHECK-NOT: @llvm.trap + (void)(a / b); + (void)(a % b); + (void)(c / d); + // CHECK: } +}