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: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=802cd5b1974bab2038b9d3c969d9beb0ab34f435;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165914 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 8562d79ebf..5f71af8082 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/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/test/CodeGenCXX/return.cpp b/test/CodeGenCXX/return.cpp index 2af1a5266e..43d40ae986 100644 --- a/test/CodeGenCXX/return.cpp +++ b/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 }