diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-07-20 21:07:09 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-07-20 21:07:09 +0000 |
| commit | f2f387018903c5f0c8ec0c655392454be83f43ed (patch) | |
| tree | 50bafd9ad6d2995d1362181680b87fe018ca6027 /clang/lib/CodeGen/CodeGenFunction.cpp | |
| parent | bb610d90535bddf87dc4d9b90c695e9c0add69d3 (diff) | |
| download | llvm-f2f387018903c5f0c8ec0c655392454be83f43ed.zip llvm-f2f387018903c5f0c8ec0c655392454be83f43ed.tar.gz llvm-f2f387018903c5f0c8ec0c655392454be83f43ed.tar.bz2 | |
Follow the implementation approach suggested by PR6687,
which generates more efficient and more obviously conformant
code. We now test for overflow of the multiply then force
the result to -1 if so. On X86, this generates nice code
like this:
__Z4testl: ## @_Z4testl
## BB#0: ## %entry
subl $12, %esp
movl $4, %eax
mull 16(%esp)
testl %edx, %edx
movl $-1, %ecx
cmovel %eax, %ecx
movl %ecx, (%esp)
call __Znam
addl $12, %esp
ret
llvm-svn: 108927
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 40 |
1 files changed, 1 insertions, 39 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 5e5e2a4..eb6c436 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -36,7 +36,7 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm) DidCallStackSave(false), UnreachableBlock(0), CXXThisDecl(0), CXXThisValue(0), CXXVTTDecl(0), CXXVTTValue(0), ConditionalBranchLevel(0), TerminateLandingPad(0), TerminateHandler(0), - TrapBB(0), ThrowLengthErrorBB(0) { + TrapBB(0) { // Get some frequently used types. LLVMPointerWidth = Target.getPointerWidth(0); @@ -155,13 +155,6 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { Builder.ClearInsertionPoint(); } - // If someone called operator new[] and needs a throw_length_error block, emit - // it at the end of the function. - if (ThrowLengthErrorBB) { - EmitBlock(ThrowLengthErrorBB); - Builder.ClearInsertionPoint(); - } - // Remove the AllocaInsertPt instruction, which is just a convenience for us. llvm::Instruction *Ptr = AllocaInsertPt; AllocaInsertPt = 0; @@ -185,37 +178,6 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { EmitDeclMetadata(); } -/// getThrowLengthErrorBB - Create a basic block that will call -/// std::__throw_length_error to throw a std::length_error exception. -llvm::BasicBlock *CodeGenFunction::getThrowLengthErrorBB() { - if (ThrowLengthErrorBB) return ThrowLengthErrorBB; - - llvm::IRBuilder<>::InsertPoint SavedIP = Builder.saveIP(); - - ThrowLengthErrorBB = createBasicBlock("throw_length_error"); - Builder.SetInsertPoint(ThrowLengthErrorBB); - - // Call to void std::__throw_length_error("length_error"); - const llvm::Type *ResultType = Builder.getVoidTy(); - const llvm::Type *PtrToInt8Ty = Builder.getInt8PtrTy(); - std::vector<const llvm::Type*> ArgTys(1, PtrToInt8Ty); - llvm::Constant *Fn = - CGM.CreateRuntimeFunction(llvm::FunctionType::get(ResultType, ArgTys, false), - "_ZSt20__throw_length_errorPKc"); - - llvm::Value *C = CGM.GetAddrOfConstantCString("length_error"); - C = Builder.CreateStructGEP(C, 0, "arraydecay"); - llvm::CallInst *TheCall = Builder.CreateCall(Fn, C); - TheCall->setDoesNotReturn(); - - Builder.CreateUnreachable(); - - - Builder.restoreIP(SavedIP); - return ThrowLengthErrorBB; -} - - /// ShouldInstrumentFunction - Return true if the current function should be /// instrumented with __cyg_profile_func_* calls bool CodeGenFunction::ShouldInstrumentFunction() { |
