From: Richard Smith Date: Mon, 15 Oct 2012 00:23:07 +0000 (+0000) Subject: At -O0, emit an @llvm.trap() call at the end of a value-returning function which X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6b4ebcc653b63c544a9eca39441e85a5a18f140f;p=platform%2Fupstream%2Fllvm.git 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 --- diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 8562d79..5f71af8 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -547,6 +547,8 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn, EmitCheck(Builder.getFalse(), "missing_return", EmitCheckSourceLocation(FD->getLocation()), llvm::ArrayRef()); + else if (CGM.getCodeGenOpts().OptimizationLevel == 0) + Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::trap)); Builder.CreateUnreachable(); Builder.ClearInsertionPoint(); } diff --git a/clang/test/CodeGenCXX/return.cpp b/clang/test/CodeGenCXX/return.cpp index 2af1a526..43d40ae9 100644 --- a/clang/test/CodeGenCXX/return.cpp +++ b/clang/test/CodeGenCXX/return.cpp @@ -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 }