]> granicus.if.org Git - clang/commitdiff
Switch codegen for -fcatch-undefined-bahavior over to __builtin_trap
authorMike Stump <mrs@apple.com>
Tue, 15 Dec 2009 00:35:12 +0000 (00:35 +0000)
committerMike Stump <mrs@apple.com>
Tue, 15 Dec 2009 00:35:12 +0000 (00:35 +0000)
instead of abort to improve codesize and codegen.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91374 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenFunction.h

index b9334d0a84bba88ae7e54ed476161d21e33c28e6..975f7492555f53c934c5456d5f7f5117f1c3cdd5 100644 (file)
@@ -17,6 +17,7 @@
 #include "CGObjCRuntime.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
+#include "llvm/Intrinsics.h"
 #include "llvm/Target/TargetData.h"
 using namespace clang;
 using namespace CodeGen;
@@ -1012,34 +1013,27 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
   }
 }
 
-static llvm::Constant *getAbortFn(CodeGenFunction &CGF) {
-  // void abort();
-
-  const llvm::FunctionType *FTy =
-    llvm::FunctionType::get(llvm::Type::getVoidTy(CGF.getLLVMContext()), false);
-
-  return CGF.CGM.CreateRuntimeFunction(FTy, "abort");
-}
-
-llvm::BasicBlock*CodeGenFunction::getAbortBB() {
-  if (AbortBB)
-    return AbortBB;
+llvm::BasicBlock*CodeGenFunction::getTrapBB() {
+  if (TrapBB)
+    return TrapBB;
 
   llvm::BasicBlock *Cont = 0;
   if (HaveInsertPoint()) {
     Cont = createBasicBlock("cont");
     EmitBranch(Cont);
   }
-  AbortBB = createBasicBlock("abort");
-  EmitBlock(AbortBB);
-  llvm::CallInst *AbortCall = Builder.CreateCall(getAbortFn(*this));
-  AbortCall->setDoesNotReturn();
-  AbortCall->setDoesNotThrow();
+  TrapBB = createBasicBlock("trap");
+  EmitBlock(TrapBB);
+
+  llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::trap, 0, 0);
+  llvm::CallInst *TrapCall = Builder.CreateCall(F);
+  TrapCall->setDoesNotReturn();
+  TrapCall->setDoesNotThrow();
   Builder.CreateUnreachable();
 
   if (Cont)
     EmitBlock(Cont);
-  return AbortBB;
+  return TrapBB;
 }
 
 LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
@@ -1080,7 +1074,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
             llvm::BasicBlock *Cont = createBasicBlock("cont");
             Builder.CreateCondBr(Builder.CreateICmpULE(Idx,
                                   llvm::ConstantInt::get(Idx->getType(), Size)),
-                                 Cont, getAbortBB());
+                                 Cont, getTrapBB());
             EmitBlock(Cont);
           }
         }
index a25e369766548a8cddc4d88cd016a86c2da2c285..2f31c051a78d889be08819c5b08142df60d8b12d 100644 (file)
@@ -1532,7 +1532,7 @@ Value *ScalarExprEmitter::EmitShl(const BinOpInfo &Ops) {
     llvm::BasicBlock *Cont = CGF.createBasicBlock("cont");
     CGF.Builder.CreateCondBr(Builder.CreateICmpULT(RHS,
                                  llvm::ConstantInt::get(RHS->getType(), Width)),
-                             Cont, CGF.getAbortBB());
+                             Cont, CGF.getTrapBB());
     CGF.EmitBlock(Cont);
   }
 
@@ -1552,7 +1552,7 @@ Value *ScalarExprEmitter::EmitShr(const BinOpInfo &Ops) {
     llvm::BasicBlock *Cont = CGF.createBasicBlock("cont");
     CGF.Builder.CreateCondBr(Builder.CreateICmpULT(RHS,
                                  llvm::ConstantInt::get(RHS->getType(), Width)),
-                             Cont, CGF.getAbortBB());
+                             Cont, CGF.getTrapBB());
     CGF.EmitBlock(Cont);
   }
 
index c3bae0768c31ab6de49bafcc7f142e0239ea5e70..28df9e4d78613baeab85ecb5e198eb8cdd7a6d0a 100644 (file)
@@ -31,7 +31,7 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm)
     DebugInfo(0), IndirectBranch(0),
     SwitchInsn(0), CaseRangeBlock(0), InvokeDest(0),
     CXXThisDecl(0), CXXVTTDecl(0),
-    ConditionalBranchLevel(0), TerminateHandler(0), AbortBB(0),
+    ConditionalBranchLevel(0), TerminateHandler(0), TrapBB(0),
     UniqueAggrDestructorCount(0) {
   LLVMIntTy = ConvertType(getContext().IntTy);
   LLVMPointerWidth = Target.getPointerWidth(0);
index a44e53b4e3d2341e90500cab9371253b427b1c70..12e636c89702a0f814f2c8e376dcfbdd67f0f918 100644 (file)
@@ -425,7 +425,7 @@ private:
   unsigned getByRefValueLLVMField(const ValueDecl *VD) const;
 
   llvm::BasicBlock *TerminateHandler;
-  llvm::BasicBlock *AbortBB;
+  llvm::BasicBlock *TrapBB;
 
   int UniqueAggrDestructorCount;
 public:
@@ -1196,9 +1196,9 @@ public:
   void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
                             llvm::BasicBlock *FalseBlock);
 
-  /// getAbortBB - Create a basic block that will call abort.  We'll generate
-  /// a branch around the created basic block as necessary.
-  llvm::BasicBlock* getAbortBB();
+  /// getTrapBB - Create a basic block that will call the trap intrinsic.  We'll
+  /// generate a branch around the created basic block as necessary.
+  llvm::BasicBlock* getTrapBB();
 private:
 
   void EmitReturnOfRValue(RValue RV, QualType Ty);