diff options
Diffstat (limited to 'lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 157 |
1 files changed, 92 insertions, 65 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 18b1d10a921d..caea41ec0e03 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -18,6 +18,7 @@ #include "CGRecordLayout.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" +#include "ConstantEmitter.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclFriend.h" #include "clang/AST/DeclObjC.h" @@ -28,6 +29,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Frontend/CodeGenOptions.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" @@ -95,6 +97,10 @@ void ApplyDebugLocation::init(SourceLocation TemporaryLocation, } OriginalLocation = CGF->Builder.getCurrentDebugLocation(); + + if (OriginalLocation && !DI->CGM.getExpressionLocationsEnabled()) + return; + if (TemporaryLocation.isValid()) { DI->EmitLocation(CGF->Builder, TemporaryLocation); return; @@ -218,6 +224,19 @@ llvm::DIScope *CGDebugInfo::getContextDescriptor(const Decl *Context, return Default; } +PrintingPolicy CGDebugInfo::getPrintingPolicy() const { + PrintingPolicy PP = CGM.getContext().getPrintingPolicy(); + + // If we're emitting codeview, it's important to try to match MSVC's naming so + // that visualizers written for MSVC will trigger for our class names. In + // particular, we can't have spaces between arguments of standard templates + // like basic_string and vector. + if (CGM.getCodeGenOpts().EmitCodeView) + PP.MSVCFormatting = true; + + return PP; +} + StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { assert(FD && "Invalid FunctionDecl!"); IdentifierInfo *FII = FD->getIdentifier(); @@ -238,18 +257,15 @@ StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { SmallString<128> NS; llvm::raw_svector_ostream OS(NS); - PrintingPolicy Policy(CGM.getLangOpts()); - Policy.MSVCFormatting = CGM.getCodeGenOpts().EmitCodeView; if (!UseQualifiedName) FD->printName(OS); else - FD->printQualifiedName(OS, Policy); + FD->printQualifiedName(OS, getPrintingPolicy()); // Add any template specialization args. if (Info) { const TemplateArgumentList *TArgs = Info->TemplateArguments; - TemplateSpecializationType::PrintTemplateArgumentList(OS, TArgs->asArray(), - Policy); + printTemplateArgumentList(OS, TArgs->asArray(), getPrintingPolicy()); } // Copy this name on the side and use its reference. @@ -296,7 +312,7 @@ StringRef CGDebugInfo::getClassName(const RecordDecl *RD) { if (isa<ClassTemplateSpecializationDecl>(RD)) { SmallString<128> Name; llvm::raw_svector_ostream OS(Name); - RD->getNameForDiagnostic(OS, CGM.getContext().getPrintingPolicy(), + RD->getNameForDiagnostic(OS, getPrintingPolicy(), /*Qualified*/ false); // Copy this name on the side and use its reference. @@ -483,6 +499,16 @@ void CGDebugInfo::CreateCompileUnit() { llvm::sys::path::append(MainFileDirSS, MainFileName); MainFileName = MainFileDirSS.str(); } + // If the main file name provided is identical to the input file name, and + // if the input file is a preprocessed source, use the module name for + // debug info. The module name comes from the name specified in the first + // linemarker if the input is a preprocessed source. + if (MainFile->getName() == MainFileName && + FrontendOptions::getInputKindForExtension( + MainFile->getName().rsplit('.').second) + .isPreprocessed()) + MainFileName = CGM.getModule().getName().str(); + CSKind = computeChecksum(SM.getMainFileID(), Checksum); } @@ -527,16 +553,16 @@ void CGDebugInfo::CreateCompileUnit() { // Create new compile unit. // FIXME - Eliminate TheCU. + auto &CGOpts = CGM.getCodeGenOpts(); TheCU = DBuilder.createCompileUnit( LangTag, DBuilder.createFile(remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSKind, Checksum), - Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers, - CGM.getCodeGenOpts().EnableSplitDwarf - ? "" - : CGM.getCodeGenOpts().SplitDwarfFile, - EmissionKind, 0 /* DWOid */, CGM.getCodeGenOpts().SplitDwarfInlining, - CGM.getCodeGenOpts().DebugInfoForProfiling); + Producer, LO.Optimize || CGOpts.PrepareForLTO || CGOpts.EmitSummaryIndex, + CGOpts.DwarfDebugFlags, RuntimeVers, + CGOpts.EnableSplitDwarf ? "" : CGOpts.SplitDwarfFile, EmissionKind, + 0 /* DWOid */, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling, + CGOpts.GnuPubnames); } llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) { @@ -645,6 +671,7 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) { case BuiltinType::Half: case BuiltinType::Float: case BuiltinType::LongDouble: + case BuiltinType::Float16: case BuiltinType::Float128: case BuiltinType::Double: // FIXME: For targets where long double and __float128 have the same size, @@ -805,6 +832,10 @@ CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType *Ty, llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType( getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align, llvm::DINode::FlagFwdDecl, FullName); + if (CGM.getCodeGenOpts().DebugFwdTemplateParams) + if (auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD)) + DBuilder.replaceArrays(RetTy, llvm::DINodeArray(), + CollectCXXTemplateParams(TSpecial, DefUnit)); ReplaceMap.emplace_back( std::piecewise_construct, std::make_tuple(Ty), std::make_tuple(static_cast<llvm::Metadata *>(RetTy))); @@ -909,12 +940,8 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty, SmallString<128> NS; llvm::raw_svector_ostream OS(NS); - Ty->getTemplateName().print(OS, CGM.getContext().getPrintingPolicy(), - /*qualified*/ false); - - TemplateSpecializationType::PrintTemplateArgumentList( - OS, Ty->template_arguments(), - CGM.getContext().getPrintingPolicy()); + Ty->getTemplateName().print(OS, getPrintingPolicy(), /*qualified*/ false); + printTemplateArgumentList(OS, Ty->template_arguments(), getPrintingPolicy()); auto *AliasDecl = cast<TypeAliasTemplateDecl>( Ty->getTemplateName().getAsTemplateDecl())->getTemplatedDecl(); @@ -1174,13 +1201,13 @@ void CGDebugInfo::CollectRecordNormalField( elements.push_back(FieldType); } -void CGDebugInfo::CollectRecordNestedRecord( - const RecordDecl *RD, SmallVectorImpl<llvm::Metadata *> &elements) { - QualType Ty = CGM.getContext().getTypeDeclType(RD); +void CGDebugInfo::CollectRecordNestedType( + const TypeDecl *TD, SmallVectorImpl<llvm::Metadata *> &elements) { + QualType Ty = CGM.getContext().getTypeDeclType(TD); // Injected class names are not considered nested records. if (isa<InjectedClassNameType>(Ty)) return; - SourceLocation Loc = RD->getLocation(); + SourceLocation Loc = TD->getLocation(); llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc)); elements.push_back(nestedType); } @@ -1196,9 +1223,9 @@ void CGDebugInfo::CollectRecordFields( else { const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record); - // Debug info for nested records is included in the member list only for + // Debug info for nested types is included in the member list only for // CodeView. - bool IncludeNestedRecords = CGM.getCodeGenOpts().EmitCodeView; + bool IncludeNestedTypes = CGM.getCodeGenOpts().EmitCodeView; // Field number for non-static fields. unsigned fieldNo = 0; @@ -1225,10 +1252,12 @@ void CGDebugInfo::CollectRecordFields( // Bump field number for next field. ++fieldNo; - } else if (const auto *nestedRec = dyn_cast<CXXRecordDecl>(I)) - if (IncludeNestedRecords && !nestedRec->isImplicit() && - nestedRec->getDeclContext() == record) - CollectRecordNestedRecord(nestedRec, elements); + } else if (IncludeNestedTypes) { + if (const auto *nestedType = dyn_cast<TypeDecl>(I)) + if (!nestedType->isImplicit() && + nestedType->getDeclContext() == record) + CollectRecordNestedType(nestedType, elements); + } } } @@ -1366,7 +1395,7 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction( // C++ ABI does not include all virtual methods from non-primary bases in // the vtable for the most derived class. For example, if C inherits from // A and B, C's primary vftable will not include B's virtual methods. - if (Method->begin_overridden_methods() == Method->end_overridden_methods()) + if (Method->size_overridden_methods() == 0) Flags |= llvm::DINode::FlagIntroducedVirtual; // The 'this' adjustment accounts for both the virtual and non-virtual @@ -1379,6 +1408,8 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction( ContainingType = RecordTy; } + if (Method->isStatic()) + Flags |= llvm::DINode::FlagStaticMember; if (Method->isImplicit()) Flags |= llvm::DINode::FlagArtificial; Flags |= getAccessFlag(Method->getAccess(), Method->getParent()); @@ -1590,7 +1621,7 @@ CGDebugInfo::CollectTemplateParams(const TemplateParameterList *TPList, QualType T = E->getType(); if (E->isGLValue()) T = CGM.getContext().getLValueReferenceType(T); - llvm::Constant *V = CGM.EmitConstantExpr(E, T); + llvm::Constant *V = ConstantEmitter(CGM).emitAbstract(E, T); assert(V && "Expression in template argument isn't constant"); llvm::DIType *TTy = getOrCreateType(T, Unit); TemplateParams.push_back(DBuilder.createTemplateValueParameter( @@ -1766,6 +1797,29 @@ static bool isClassOrMethodDLLImport(const CXXRecordDecl *RD) { return false; } +/// Does a type definition exist in an imported clang module? +static bool isDefinedInClangModule(const RecordDecl *RD) { + // Only definitions that where imported from an AST file come from a module. + if (!RD || !RD->isFromASTFile()) + return false; + // Anonymous entities cannot be addressed. Treat them as not from module. + if (!RD->isExternallyVisible() && RD->getName().empty()) + return false; + if (auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) { + if (!CXXDecl->isCompleteDefinition()) + return false; + auto TemplateKind = CXXDecl->getTemplateSpecializationKind(); + if (TemplateKind != TSK_Undeclared) { + // This is a template, check the origin of the first member. + if (CXXDecl->field_begin() == CXXDecl->field_end()) + return TemplateKind == TSK_ExplicitInstantiationDeclaration; + if (!CXXDecl->field_begin()->isFromASTFile()) + return false; + } + } + return true; +} + void CGDebugInfo::completeClassData(const RecordDecl *RD) { if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) if (CXXRD->isDynamicClass() && @@ -1773,6 +1827,10 @@ void CGDebugInfo::completeClassData(const RecordDecl *RD) { llvm::GlobalValue::AvailableExternallyLinkage && !isClassOrMethodDLLImport(CXXRD)) return; + + if (DebugTypeExtRefs && isDefinedInClangModule(RD->getDefinition())) + return; + completeClass(RD); } @@ -1799,29 +1857,6 @@ static bool hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I, return false; } -/// Does a type definition exist in an imported clang module? -static bool isDefinedInClangModule(const RecordDecl *RD) { - // Only definitions that where imported from an AST file come from a module. - if (!RD || !RD->isFromASTFile()) - return false; - // Anonymous entities cannot be addressed. Treat them as not from module. - if (!RD->isExternallyVisible() && RD->getName().empty()) - return false; - if (auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) { - if (!CXXDecl->isCompleteDefinition()) - return false; - auto TemplateKind = CXXDecl->getTemplateSpecializationKind(); - if (TemplateKind != TSK_Undeclared) { - // This is a template, check the origin of the first member. - if (CXXDecl->field_begin() == CXXDecl->field_end()) - return TemplateKind == TSK_ExplicitInstantiationDeclaration; - if (!CXXDecl->field_begin()->isFromASTFile()) - return false; - } - } - return true; -} - static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind, bool DebugTypeExtRefs, const RecordDecl *RD, const LangOptions &LangOpts) { @@ -3655,9 +3690,9 @@ bool operator<(const BlockLayoutChunk &l, const BlockLayoutChunk &r) { } void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, - llvm::Value *Arg, + StringRef Name, unsigned ArgNo, - llvm::Value *LocalAddr, + llvm::AllocaInst *Alloca, CGBuilderTy &Builder) { assert(DebugKind >= codegenoptions::LimitedDebugInfo); ASTContext &C = CGM.getContext(); @@ -3789,19 +3824,11 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, // Create the descriptor for the parameter. auto *debugVar = DBuilder.createParameterVariable( - scope, Arg->getName(), ArgNo, tunit, line, type, + scope, Name, ArgNo, tunit, line, type, CGM.getLangOpts().Optimize, flags); - if (LocalAddr) { - // Insert an llvm.dbg.value into the current block. - DBuilder.insertDbgValueIntrinsic( - LocalAddr, 0, debugVar, DBuilder.createExpression(), - llvm::DebugLoc::get(line, column, scope, CurInlinedAt), - Builder.GetInsertBlock()); - } - // Insert an llvm.dbg.declare into the current block. - DBuilder.insertDeclare(Arg, debugVar, DBuilder.createExpression(), + DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(), llvm::DebugLoc::get(line, column, scope, CurInlinedAt), Builder.GetInsertBlock()); } |