From bc9e1b2ad4ecb054e8a9ad8ddb4096411d3d5075 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 29 Apr 2014 01:07:59 +0000 Subject: Debug info: Improve line table for functions with cleanups an early exit and no return expr at the end of the function. The "function has only simple returns" check in FinishFunction tests whether the number of simple return exprs equals the number of return exprs, but so far a fallthrough at the end of a function was not counted as a return, which would result in cleanup code being associated with the wrong source line. rdar://problem/16733984. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207480 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenFunction.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/CodeGen/CodeGenFunction.cpp') diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 95e4ee498d..e8f48afb3b 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -498,6 +498,22 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, OpenCLKernelMetadata->addOperand(kernelMDNode); } +/// Determine whether the function F ends with a return stmt. +static bool endsWithReturn(const Decl* F) { + const Stmt *Body = nullptr; + if (auto *FD = dyn_cast_or_null(F)) + Body = FD->getBody(); + else if (auto *OMD = dyn_cast_or_null(F)) + Body = OMD->getBody(); + + if (auto *CS = dyn_cast_or_null(Body)) { + auto LastStmt = CS->body_rbegin(); + if (LastStmt != CS->body_rend()) + return isa(*LastStmt); + } + return false; +} + void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, @@ -593,6 +609,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, if (RetTy->isVoidType()) { // Void type; nothing to return. ReturnValue = 0; + + // Count the implicit return. + if (!endsWithReturn(D)) + ++NumReturnExprs; } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect && !hasScalarEvaluationKind(CurFnInfo->getReturnType())) { // Indirect aggregate return; emit returned value directly into sret slot. -- cgit v1.2.3