At -O0, emit an @llvm.trap() call at the end of a value-returning function which

fails to return a value, to make debugging this issue easier.

llvm-svn: 165914
This commit is contained in:
Richard Smith 2012-10-15 00:23:07 +00:00
parent feea5d6fb4
commit 6b4ebcc653
2 changed files with 11 additions and 3 deletions

View File

@ -547,6 +547,8 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
EmitCheck(Builder.getFalse(), "missing_return",
EmitCheckSourceLocation(FD->getLocation()),
llvm::ArrayRef<llvm::Value*>());
else if (CGM.getCodeGenOpts().OptimizationLevel == 0)
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::trap));
Builder.CreateUnreachable();
Builder.ClearInsertionPoint();
}

View File

@ -1,6 +1,12 @@
// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
// RUN: %clang_cc1 -emit-llvm -O -o - %s | FileCheck %s --check-prefix=CHECK-OPT
// CHECK: @_Z9no_return
// CHECK: @_Z9no_return
// CHECK-OPT: @_Z9no_return
int no_return() {
// CHECK: unreachable
// CHECK: call void @llvm.trap
// CHECK-NEXT: unreachable
// CHECK-OPT-NOT: call void @llvm.trap
// CHECK-OPT: unreachable
}