[cfe-commits] r91374 - in /cfe/trunk/lib/CodeGen: CGExpr.cpp CGExprScalar.cpp CodeGenFunction.cpp CodeGenFunction.h

Mike Stump mrs at apple.com
Mon Dec 14 16:35:13 PST 2009


Author: mrs
Date: Mon Dec 14 18:35:12 2009
New Revision: 91374

URL: http://llvm.org/viewvc/llvm-project?rev=91374&view=rev
Log:
Switch codegen for -fcatch-undefined-bahavior over to __builtin_trap
instead of abort to improve codesize and codegen.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=91374&r1=91373&r2=91374&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Dec 14 18:35:12 2009
@@ -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 @@
   }
 }
 
-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 @@
             llvm::BasicBlock *Cont = createBasicBlock("cont");
             Builder.CreateCondBr(Builder.CreateICmpULE(Idx,
                                   llvm::ConstantInt::get(Idx->getType(), Size)),
-                                 Cont, getAbortBB());
+                                 Cont, getTrapBB());
             EmitBlock(Cont);
           }
         }

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=91374&r1=91373&r2=91374&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Mon Dec 14 18:35:12 2009
@@ -1532,7 +1532,7 @@
     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 @@
     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);
   }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=91374&r1=91373&r2=91374&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Dec 14 18:35:12 2009
@@ -31,7 +31,7 @@
     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);

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=91374&r1=91373&r2=91374&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Dec 14 18:35:12 2009
@@ -425,7 +425,7 @@
   unsigned getByRefValueLLVMField(const ValueDecl *VD) const;
 
   llvm::BasicBlock *TerminateHandler;
-  llvm::BasicBlock *AbortBB;
+  llvm::BasicBlock *TrapBB;
 
   int UniqueAggrDestructorCount;
 public:
@@ -1196,9 +1196,9 @@
   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);





More information about the cfe-commits mailing list