From 070d6dab0fb2ac151d9b01c55dc9355b129bf5b0 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sat, 1 Sep 2018 01:32:02 +0200 Subject: [PATCH] Slightly refactor DIBuilder::EmitSubProgram() --- gen/dibuilder.cpp | 66 +++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/gen/dibuilder.cpp b/gen/dibuilder.cpp index 98fc5b775b..9f96a87b75 100644 --- a/gen/dibuilder.cpp +++ b/gen/dibuilder.cpp @@ -907,47 +907,41 @@ ldc::DISubprogram ldc::DIBuilder::EmitSubProgram(FuncDeclaration *fd) { assert(GetCU() && "Compilation unit missing or corrupted in DIBuilder::EmitSubProgram"); - ldc::DIFile file = CreateFile(fd); + const auto scope = GetSymbolScope(fd); + const auto name = fd->toChars(); + const auto linkageName = irFunc->getLLVMFuncName(); + const auto file = CreateFile(fd); + const auto lineNo = fd->loc.linnum; + const auto isLocalToUnit = fd->protection.kind == Prot::private_; + const auto isDefinition = true; + const auto scopeLine = lineNo; // FIXME + const auto flags = DIFlags::FlagPrototyped; + const auto isOptimized = isOptimizationEnabled(); - // A special case is `auto foo() { struct S{}; S s; return s; }` - // The return type is a nested struct, so for this particular chicken-and-egg case - // we need to create a temporary subprogram. - irFunc->diSubprogram = DBuilder.createTempFunctionFwdDecl( - GetSymbolScope(fd), // context - fd->toChars(), // name - irFunc->getLLVMFuncName(), // linkage name - file, // file - fd->loc.linnum, // line no - nullptr, // type - fd->protection.kind == Prot::private_, // is local to unit - true, // isdefinition - fd->loc.linnum, // FIXME: scope line - DIFlags::FlagPrototyped, // Flags - isOptimizationEnabled() // isOptimized - ); + ldc::DISubroutineType diFnType = nullptr; + if (!mustEmitFullDebugInfo()) { + diFnType = CreateEmptyFunctionType(); + } else { + // A special case is `auto foo() { struct S{}; S s; return s; }` + // The return type is a nested struct, so for this particular + // chicken-and-egg case we need to create a temporary subprogram. + irFunc->diSubprogram = DBuilder.createTempFunctionFwdDecl( + scope, name, linkageName, file, lineNo, /*ty=*/nullptr, isLocalToUnit, + isDefinition, scopeLine, flags, isOptimized); - // Create subroutine type - ldc::DISubroutineType DIFnType = mustEmitFullDebugInfo() ? - CreateFunctionType(static_cast(fd->type)) : - CreateEmptyFunctionType(); + // Now create subroutine type. + diFnType = CreateFunctionType(static_cast(fd->type)); + } // FIXME: duplicates? - auto SP = DBuilder.createFunction( - GetSymbolScope(fd), // context - fd->toChars(), // name - irFunc->getLLVMFuncName(), // linkage name - file, // file - fd->loc.linnum, // line no - DIFnType, // type - fd->protection.kind == Prot::private_, // is local to unit - true, // isdefinition - fd->loc.linnum, // FIXME: scope line - DIFlags::FlagPrototyped, // Flags - isOptimizationEnabled() // isOptimized - ); + auto SP = DBuilder.createFunction(scope, name, linkageName, file, lineNo, + diFnType, isLocalToUnit, isDefinition, + scopeLine, flags, isOptimized); - irFunc->diSubprogram = DBuilder.replaceTemporary( - llvm::TempDINode(irFunc->diSubprogram), SP); + if (mustEmitFullDebugInfo()) + DBuilder.replaceTemporary(llvm::TempDINode(irFunc->diSubprogram), SP); + + irFunc->diSubprogram = SP; return SP; }