#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;
}
}
-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) {
llvm::BasicBlock *Cont = createBasicBlock("cont");
Builder.CreateCondBr(Builder.CreateICmpULE(Idx,
llvm::ConstantInt::get(Idx->getType(), Size)),
- Cont, getAbortBB());
+ Cont, getTrapBB());
EmitBlock(Cont);
}
}
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);
}
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);
}
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);
unsigned getByRefValueLLVMField(const ValueDecl *VD) const;
llvm::BasicBlock *TerminateHandler;
- llvm::BasicBlock *AbortBB;
+ llvm::BasicBlock *TrapBB;
int UniqueAggrDestructorCount;
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);