aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp269
1 files changed, 157 insertions, 112 deletions
diff --git a/contrib/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp b/contrib/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp
index 143408401245..99944afaad14 100644
--- a/contrib/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/contrib/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -115,8 +115,9 @@ void ApplyDebugLocation::init(SourceLocation TemporaryLocation,
// Construct a location that has a valid scope, but no line info.
assert(!DI->LexicalBlockStack.empty());
- CGF->Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
- 0, 0, DI->LexicalBlockStack.back(), DI->getInlinedAt()));
+ CGF->Builder.SetCurrentDebugLocation(
+ llvm::DILocation::get(DI->LexicalBlockStack.back()->getContext(), 0, 0,
+ DI->LexicalBlockStack.back(), DI->getInlinedAt()));
}
ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E)
@@ -253,24 +254,12 @@ StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) {
FunctionTemplateSpecializationInfo *Info =
FD->getTemplateSpecializationInfo();
- // Emit the unqualified name in normal operation. LLVM and the debugger can
- // compute the fully qualified name from the scope chain. If we're only
- // emitting line table info, there won't be any scope chains, so emit the
- // fully qualified name here so that stack traces are more accurate.
- // FIXME: Do this when emitting DWARF as well as when emitting CodeView after
- // evaluating the size impact.
- bool UseQualifiedName = DebugKind == codegenoptions::DebugLineTablesOnly &&
- CGM.getCodeGenOpts().EmitCodeView;
-
- if (!Info && FII && !UseQualifiedName)
+ if (!Info && FII)
return FII->getName();
SmallString<128> NS;
llvm::raw_svector_ostream OS(NS);
- if (!UseQualifiedName)
- FD->printName(OS);
- else
- FD->printQualifiedName(OS, getPrintingPolicy());
+ FD->printName(OS);
// Add any template specialization args.
if (Info) {
@@ -374,9 +363,8 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<32> &Checksum) const {
return None;
SourceManager &SM = CGM.getContext().getSourceManager();
- bool Invalid;
- const llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid);
- if (Invalid)
+ Optional<llvm::MemoryBufferRef> MemBuffer = SM.getBufferOrNone(FID);
+ if (!MemBuffer)
return None;
llvm::MD5 Hash;
@@ -404,17 +392,26 @@ Optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM,
}
llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
- if (!Loc.isValid())
- // If Location is not valid then use main input file.
- return TheCU->getFile();
-
SourceManager &SM = CGM.getContext().getSourceManager();
- PresumedLoc PLoc = SM.getPresumedLoc(Loc);
-
- StringRef FileName = PLoc.getFilename();
- if (PLoc.isInvalid() || FileName.empty())
- // If the location is not valid then use main input file.
- return TheCU->getFile();
+ StringRef FileName;
+ FileID FID;
+
+ if (Loc.isInvalid()) {
+ // The DIFile used by the CU is distinct from the main source file. Call
+ // createFile() below for canonicalization if the source file was specified
+ // with an absolute path.
+ FileName = TheCU->getFile()->getFilename();
+ } else {
+ PresumedLoc PLoc = SM.getPresumedLoc(Loc);
+ FileName = PLoc.getFilename();
+
+ if (FileName.empty()) {
+ FileName = TheCU->getFile()->getFilename();
+ } else {
+ FileName = PLoc.getFilename();
+ }
+ FID = PLoc.getFileID();
+ }
// Cache the results.
auto It = DIFileCache.find(FileName.data());
@@ -426,11 +423,7 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
SmallString<32> Checksum;
- // Compute the checksum if possible. If the location is affected by a #line
- // directive that refers to a file, PLoc will have an invalid FileID, and we
- // will correctly get no checksum.
- Optional<llvm::DIFile::ChecksumKind> CSKind =
- computeChecksum(PLoc.getFileID(), Checksum);
+ Optional<llvm::DIFile::ChecksumKind> CSKind = computeChecksum(FID, Checksum);
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
if (CSKind)
CSInfo.emplace(*CSKind, Checksum);
@@ -488,11 +481,10 @@ std::string CGDebugInfo::remapDIPath(StringRef Path) const {
}
unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
- if (Loc.isInvalid() && CurLoc.isInvalid())
+ if (Loc.isInvalid())
return 0;
SourceManager &SM = CGM.getContext().getSourceManager();
- PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc);
- return PLoc.isValid() ? PLoc.getLine() : 0;
+ return SM.getPresumedLoc(Loc).getLine();
}
unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) {
@@ -606,6 +598,7 @@ void CGDebugInfo::CreateCompileUnit() {
case codegenoptions::DebugInfoConstructor:
case codegenoptions::LimitedDebugInfo:
case codegenoptions::FullDebugInfo:
+ case codegenoptions::UnusedTypeInfo:
EmissionKind = llvm::DICompileUnit::FullDebug;
break;
}
@@ -725,7 +718,7 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
{
ASTContext::BuiltinVectorTypeInfo Info =
CGM.getContext().getBuiltinVectorTypeInfo(BT);
- unsigned NumElemsPerVG = (Info.EC.Min * Info.NumVectors) / 2;
+ unsigned NumElemsPerVG = (Info.EC.getKnownMinValue() * Info.NumVectors) / 2;
// Debuggers can't extract 1bit from a vector, so will display a
// bitpattern for svbool_t instead.
@@ -752,6 +745,13 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
return DBuilder.createVectorType(/*Size*/ 0, Align, ElemTy,
SubscriptArray);
}
+ // It doesn't make sense to generate debug info for PowerPC MMA vector types.
+ // So we return a safe type here to avoid generating an error.
+#define PPC_VECTOR_TYPE(Name, Id, size) \
+ case BuiltinType::Id:
+#include "clang/Basic/PPCTypes.def"
+ return CreateType(cast<const BuiltinType>(CGM.getContext().IntTy));
+
case BuiltinType::UChar:
case BuiltinType::Char_U:
Encoding = llvm::dwarf::DW_ATE_unsigned_char;
@@ -1024,12 +1024,17 @@ CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType *Ty,
if (llvm::DIType *T = getTypeOrNull(CGM.getContext().getRecordType(RD)))
return cast<llvm::DICompositeType>(T);
llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation());
- unsigned Line = getLineNumber(RD->getLocation());
+ const unsigned Line =
+ getLineNumber(RD->getLocation().isValid() ? RD->getLocation() : CurLoc);
StringRef RDName = getClassName(RD);
uint64_t Size = 0;
uint32_t Align = 0;
+ const RecordDecl *D = RD->getDefinition();
+ if (D && D->isCompleteDefinition())
+ Size = CGM.getContext().getTypeSize(Ty);
+
llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl;
// Add flag to nontrivial forward declarations. To be consistent with MSVC,
@@ -1041,7 +1046,10 @@ CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType *Ty,
Flags |= llvm::DINode::FlagNonTrivial;
// Create the type.
- SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
+ SmallString<256> Identifier;
+ // Don't include a linkage name in line tables only.
+ if (CGM.getCodeGenOpts().hasReducedDebugInfo())
+ Identifier = getTypeIdentifier(Ty, CGM, TheCU);
llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align, Flags,
Identifier);
@@ -1341,7 +1349,7 @@ CGDebugInfo::createFieldType(StringRef name, QualType type, SourceLocation loc,
// Get the location for the field.
llvm::DIFile *file = getOrCreateFile(loc);
- unsigned line = getLineNumber(loc);
+ const unsigned line = getLineNumber(loc.isValid() ? loc : CurLoc);
uint64_t SizeInBits = 0;
auto Align = AlignInBits;
@@ -1721,7 +1729,7 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
// info is emitted.
if (DebugKind == codegenoptions::DebugInfoConstructor)
if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(Method))
- completeClass(CD->getParent());
+ completeUnusedClass(*CD->getParent());
llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
llvm::DISubprogram *SP = DBuilder.createMethod(
@@ -1909,6 +1917,12 @@ CGDebugInfo::CollectTemplateParams(const TemplateParameterList *TPList,
V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
} else if (const auto *GD = dyn_cast<MSGuidDecl>(D)) {
V = CGM.GetAddrOfMSGuidDecl(GD).getPointer();
+ } else if (const auto *TPO = dyn_cast<TemplateParamObjectDecl>(D)) {
+ if (T->isRecordType())
+ V = ConstantEmitter(CGM).emitAbstract(
+ SourceLocation(), TPO->getValue(), TPO->getType());
+ else
+ V = CGM.GetAddrOfTemplateParamObject(TPO).getPointer();
}
assert(V && "Failed to find template parameter pointer");
V = V->stripPointerCasts();
@@ -2036,7 +2050,8 @@ StringRef CGDebugInfo::getDynamicInitializerName(const VarDecl *VD,
llvm::Function *InitFn) {
// If we're not emitting codeview, use the mangled name. For Itanium, this is
// arbitrary.
- if (!CGM.getCodeGenOpts().EmitCodeView)
+ if (!CGM.getCodeGenOpts().EmitCodeView ||
+ StubKind == DynamicInitKind::GlobalArrayDestructor)
return InitFn->getName();
// Print the normal qualified name for the variable, then break off the last
@@ -2061,6 +2076,7 @@ StringRef CGDebugInfo::getDynamicInitializerName(const VarDecl *VD,
switch (StubKind) {
case DynamicInitKind::NoStub:
+ case DynamicInitKind::GlobalArrayDestructor:
llvm_unreachable("not an initializer");
case DynamicInitKind::Initializer:
OS << "`dynamic initializer for '";
@@ -2084,8 +2100,7 @@ StringRef CGDebugInfo::getDynamicInitializerName(const VarDecl *VD,
}
void CGDebugInfo::CollectVTableInfo(const CXXRecordDecl *RD, llvm::DIFile *Unit,
- SmallVectorImpl<llvm::Metadata *> &EltTys,
- llvm::DICompositeType *RecordTy) {
+ SmallVectorImpl<llvm::Metadata *> &EltTys) {
// If this class is not dynamic then there is not any vtable info to collect.
if (!RD->isDynamicClass())
return;
@@ -2275,6 +2290,23 @@ static bool hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I,
return false;
}
+static bool canUseCtorHoming(const CXXRecordDecl *RD) {
+ // Constructor homing can be used for classes that cannnot be constructed
+ // without emitting code for one of their constructors. This is classes that
+ // don't have trivial or constexpr constructors, or can be created from
+ // aggregate initialization. Also skip lambda objects because they don't call
+ // constructors.
+
+ // Skip this optimization if the class or any of its methods are marked
+ // dllimport.
+ if (isClassOrMethodDLLImport(RD))
+ return false;
+
+ return !RD->isLambda() && !RD->isAggregate() &&
+ !RD->hasTrivialDefaultConstructor() &&
+ !RD->hasConstexprNonCopyMoveConstructor();
+}
+
static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
bool DebugTypeExtRefs, const RecordDecl *RD,
const LangOptions &LangOpts) {
@@ -2285,6 +2317,12 @@ static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
if (ES->hasExternalDefinitions(RD) == ExternalASTSource::EK_Always)
return true;
+ // Only emit forward declarations in line tables only to keep debug info size
+ // small. This only applies to CodeView, since we don't emit types in DWARF
+ // line tables only.
+ if (DebugKind == codegenoptions::DebugLineTablesOnly)
+ return true;
+
if (DebugKind > codegenoptions::LimitedDebugInfo)
return false;
@@ -2309,16 +2347,6 @@ static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
!isClassOrMethodDLLImport(CXXDecl))
return true;
- // In constructor debug mode, only emit debug info for a class when its
- // constructor is emitted. Skip this optimization if the class or any of
- // its methods are marked dllimport.
- if (DebugKind == codegenoptions::DebugInfoConstructor &&
- !CXXDecl->isLambda() && !CXXDecl->hasConstexprNonCopyMoveConstructor() &&
- !isClassOrMethodDLLImport(CXXDecl))
- for (const auto *Ctor : CXXDecl->ctors())
- if (Ctor->isUserProvided())
- return true;
-
TemplateSpecializationKind Spec = TSK_Undeclared;
if (const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
Spec = SD->getSpecializationKind();
@@ -2328,6 +2356,12 @@ static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
CXXDecl->method_end()))
return true;
+ // In constructor homing mode, only emit complete debug info for a class
+ // when its constructor is emitted.
+ if ((DebugKind == codegenoptions::DebugInfoConstructor) &&
+ canUseCtorHoming(CXXDecl))
+ return true;
+
return false;
}
@@ -2366,7 +2400,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
// its members. Finally, we create a descriptor for the complete type (which
// may refer to the forward decl if the struct is recursive) and replace all
// uses of the forward declaration with the final definition.
- llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty, DefUnit);
+ llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty);
const RecordDecl *D = RD->getDefinition();
if (!D || !D->isCompleteDefinition())
@@ -2390,7 +2424,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
if (CXXDecl) {
CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
- CollectVTableInfo(CXXDecl, DefUnit, EltTys, FwdDecl);
+ CollectVTableInfo(CXXDecl, DefUnit, EltTys);
}
// Collect data fields (including static variables and any initializers).
@@ -2553,12 +2587,11 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
// We use the lower 64 bits for debug info.
uint64_t Signature = 0;
- if (const auto &ModSig = Mod.getSignature()) {
- for (unsigned I = 0; I != sizeof(Signature); ++I)
- Signature |= (uint64_t)ModSig[I] << (I * 8);
- } else {
+ if (const auto &ModSig = Mod.getSignature())
+ Signature = ModSig.truncatedValue();
+ else
Signature = ~1ULL;
- }
+
llvm::DIBuilder DIB(CGM.getModule());
SmallString<0> PCM;
if (!llvm::sys::path::is_absolute(Mod.getASTFile()))
@@ -3095,10 +3128,7 @@ static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C) {
}
llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) {
-
- // Unwrap the type as needed for debug information.
- Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext());
-
+ assert(Ty == UnwrapTypeForDebugInfo(Ty, CGM.getContext()));
auto It = TypeCache.find(Ty.getAsOpaquePtr());
if (It != TypeCache.end()) {
// Verify that the debug info still exists.
@@ -3111,8 +3141,6 @@ llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) {
void CGDebugInfo::completeTemplateDefinition(
const ClassTemplateSpecializationDecl &SD) {
- if (DebugKind <= codegenoptions::DebugLineTablesOnly)
- return;
completeUnusedClass(SD);
}
@@ -3274,8 +3302,8 @@ llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit) {
llvm_unreachable("type should have been unwrapped!");
}
-llvm::DICompositeType *CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty,
- llvm::DIFile *Unit) {
+llvm::DICompositeType *
+CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty) {
QualType QTy(Ty, 0);
auto *T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
@@ -3304,9 +3332,14 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
RecordDecl *RD = Ty->getDecl();
// Get overall information about the record type for the debug info.
- llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation());
- unsigned Line = getLineNumber(RD->getLocation());
StringRef RDName = getClassName(RD);
+ const SourceLocation Loc = RD->getLocation();
+ llvm::DIFile *DefUnit = nullptr;
+ unsigned Line = 0;
+ if (Loc.isValid()) {
+ DefUnit = getOrCreateFile(Loc);
+ Line = getLineNumber(Loc);
+ }
llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
@@ -3442,7 +3475,11 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
DebugKind <= codegenoptions::DebugLineTablesOnly))
LinkageName = StringRef();
- if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
+ // Emit the function scope in line tables only mode (if CodeView) to
+ // differentiate between function names.
+ if (CGM.getCodeGenOpts().hasReducedDebugInfo() ||
+ (DebugKind == codegenoptions::DebugLineTablesOnly &&
+ CGM.getCodeGenOpts().EmitCodeView)) {
if (const NamespaceDecl *NSDecl =
dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))
FDContext = getOrCreateNamespace(NSDecl);
@@ -3451,6 +3488,8 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
}
+ }
+ if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
// Check if it is a noreturn-marked function
if (FD->isNoReturn())
Flags |= llvm::DINode::FlagNoReturn;
@@ -3695,7 +3734,10 @@ llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(const Decl *D,
QualType FnType,
llvm::DIFile *F) {
- if (!D || DebugKind <= codegenoptions::DebugLineTablesOnly)
+ // In CodeView, we emit the function types in line tables only because the
+ // only way to distinguish between functions is by display name and type.
+ if (!D || (DebugKind <= codegenoptions::DebugLineTablesOnly &&
+ !CGM.getCodeGenOpts().EmitCodeView))
// Create fake but valid subroutine type. Otherwise -verify would fail, and
// subprogram DIE will miss DW_AT_decl_file and DW_AT_decl_line fields.
return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray(None));
@@ -3762,11 +3804,9 @@ llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(const Decl *D,
return cast<llvm::DISubroutineType>(getOrCreateType(FnType, F));
}
-void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
+void CGDebugInfo::emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
SourceLocation ScopeLoc, QualType FnType,
- llvm::Function *Fn, bool CurFuncIsThunk,
- CGBuilderTy &Builder) {
-
+ llvm::Function *Fn, bool CurFuncIsThunk) {
StringRef Name;
StringRef LinkageName;
@@ -3815,7 +3855,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
if (Name.startswith("\01"))
Name = Name.substr(1);
- if (!HasDecl || D->isImplicit() || D->hasAttr<ArtificialAttr>()) {
+ if (!HasDecl || D->isImplicit() || D->hasAttr<ArtificialAttr>() ||
+ (isa<VarDecl>(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) {
Flags |= llvm::DINode::FlagArtificial;
// Artificial functions should not silently reuse CurLoc.
CurLoc = SourceLocation();
@@ -3833,7 +3874,7 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
llvm::DISubprogram::DISPFlags SPFlagsForDef =
SPFlags | llvm::DISubprogram::SPFlagDefinition;
- unsigned LineNo = getLineNumber(Loc);
+ const unsigned LineNo = getLineNumber(Loc.isValid() ? Loc : CurLoc);
unsigned ScopeLine = getLineNumber(ScopeLoc);
llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(D, FnType, Unit);
llvm::DISubprogram *Decl = nullptr;
@@ -3983,8 +4024,9 @@ void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) {
return;
llvm::MDNode *Scope = LexicalBlockStack.back();
- Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
- getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, CurInlinedAt));
+ Builder.SetCurrentDebugLocation(
+ llvm::DILocation::get(CGM.getLLVMContext(), getLineNumber(CurLoc),
+ getColumnNumber(CurLoc), Scope, CurInlinedAt));
}
void CGDebugInfo::CreateLexicalBlock(SourceLocation Loc) {
@@ -4015,9 +4057,9 @@ void CGDebugInfo::EmitLexicalBlockStart(CGBuilderTy &Builder,
setLocation(Loc);
// Emit a line table change for the current location inside the new scope.
- Builder.SetCurrentDebugLocation(
- llvm::DebugLoc::get(getLineNumber(Loc), getColumnNumber(Loc),
- LexicalBlockStack.back(), CurInlinedAt));
+ Builder.SetCurrentDebugLocation(llvm::DILocation::get(
+ CGM.getLLVMContext(), getLineNumber(Loc), getColumnNumber(Loc),
+ LexicalBlockStack.back(), CurInlinedAt));
if (DebugKind <= codegenoptions::DebugLineTablesOnly)
return;
@@ -4228,10 +4270,11 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
Flags | llvm::DINode::FlagArtificial, FieldAlign);
// Insert an llvm.dbg.declare into the current block.
- DBuilder.insertDeclare(
- Storage, D, DBuilder.createExpression(Expr),
- llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),
- Builder.GetInsertBlock());
+ DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
+ llvm::DILocation::get(CGM.getLLVMContext(), Line,
+ Column, Scope,
+ CurInlinedAt),
+ Builder.GetInsertBlock());
}
}
}
@@ -4256,7 +4299,8 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
// Insert an llvm.dbg.declare into the current block.
DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
- llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),
+ llvm::DILocation::get(CGM.getLLVMContext(), Line,
+ Column, Scope, CurInlinedAt),
Builder.GetInsertBlock());
return D;
@@ -4292,7 +4336,8 @@ void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {
// Insert an llvm.dbg.label into the current block.
DBuilder.insertLabel(L,
- llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),
+ llvm::DILocation::get(CGM.getLLVMContext(), Line, Column,
+ Scope, CurInlinedAt),
Builder.GetInsertBlock());
}
@@ -4332,7 +4377,8 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
Ty = CreateSelfType(VD->getType(), Ty);
// Get location information.
- unsigned Line = getLineNumber(VD->getLocation());
+ const unsigned Line =
+ getLineNumber(VD->getLocation().isValid() ? VD->getLocation() : CurLoc);
unsigned Column = getColumnNumber(VD->getLocation());
const llvm::DataLayout &target = CGM.getDataLayout();
@@ -4366,8 +4412,8 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
Line, Ty, false, llvm::DINode::FlagZero, Align);
// Insert an llvm.dbg.declare into the current block.
- auto DL =
- llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back(), CurInlinedAt);
+ auto DL = llvm::DILocation::get(CGM.getLLVMContext(), Line, Column,
+ LexicalBlockStack.back(), CurInlinedAt);
auto *Expr = DBuilder.createExpression(addr);
if (InsertPoint)
DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint);
@@ -4552,7 +4598,8 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
// Insert an llvm.dbg.declare into the current block.
DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
- llvm::DebugLoc::get(line, column, scope, CurInlinedAt),
+ llvm::DILocation::get(CGM.getLLVMContext(), line,
+ column, scope, CurInlinedAt),
Builder.GetInsertBlock());
}
@@ -4710,13 +4757,10 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
}
}
- llvm::DIScope *DContext = nullptr;
-
// Do not emit separate definitions for function local consts.
if (isa<FunctionDecl>(VD->getDeclContext()))
return;
- // Emit definition for static members in CodeView.
VD = cast<ValueDecl>(VD->getCanonicalDecl());
auto *VarD = dyn_cast<VarDecl>(VD);
if (VarD && VarD->isStaticDataMember()) {
@@ -4729,15 +4773,9 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
RetainedTypes.push_back(
CGM.getContext().getRecordType(RD).getAsOpaquePtr());
- if (!CGM.getCodeGenOpts().EmitCodeView)
- return;
-
- // Use the global scope for static members.
- DContext = getContextDescriptor(
- cast<Decl>(CGM.getContext().getTranslationUnitDecl()), TheCU);
- } else {
- DContext = getDeclContextDescriptor(VD);
+ return;
}
+ llvm::DIScope *DContext = getDeclContextDescriptor(VD);
auto &GV = DeclCache[VD];
if (GV)
@@ -4800,6 +4838,8 @@ void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) {
if (!NSDecl->isAnonymousNamespace() ||
CGM.getCodeGenOpts().DebugExplicitImport) {
auto Loc = UD.getLocation();
+ if (!Loc.isValid())
+ Loc = CurLoc;
DBuilder.createImportedModule(
getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())),
getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
@@ -4969,13 +5009,17 @@ void CGDebugInfo::finalize() {
DBuilder.finalize();
}
+// Don't ignore in case of explicit cast where it is referenced indirectly.
void CGDebugInfo::EmitExplicitCastType(QualType Ty) {
- if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
- return;
+ if (CGM.getCodeGenOpts().hasReducedDebugInfo())
+ if (auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
+ DBuilder.retainType(DieTy);
+}
- if (auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
- // Don't ignore in case of explicit cast where it is referenced indirectly.
- DBuilder.retainType(DieTy);
+void CGDebugInfo::EmitAndRetainType(QualType Ty) {
+ if (CGM.getCodeGenOpts().hasMaybeUnusedDebugInfo())
+ if (auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
+ DBuilder.retainType(DieTy);
}
llvm::DebugLoc CGDebugInfo::SourceLocToDebugLoc(SourceLocation Loc) {
@@ -4983,7 +5027,8 @@ llvm::DebugLoc CGDebugInfo::SourceLocToDebugLoc(SourceLocation Loc) {
return llvm::DebugLoc();
llvm::MDNode *Scope = LexicalBlockStack.back();
- return llvm::DebugLoc::get(getLineNumber(Loc), getColumnNumber(Loc), Scope);
+ return llvm::DILocation::get(CGM.getLLVMContext(), getLineNumber(Loc),
+ getColumnNumber(Loc), Scope);
}
llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const {