2012-12-18 22:30:41 +08:00
|
|
|
//===--- CGDebugInfo.cpp - Emit Debug Information for a Module ------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-12-18 22:30:41 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This coordinates the debug information generation while generating code.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CGDebugInfo.h"
|
|
|
|
#include "CGBlocks.h"
|
2013-05-11 05:53:14 +08:00
|
|
|
#include "CGCXXABI.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "CGObjCRuntime.h"
|
2016-10-26 06:19:32 +08:00
|
|
|
#include "CGRecordLayout.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "CodeGenFunction.h"
|
|
|
|
#include "CodeGenModule.h"
|
2017-08-16 05:42:52 +08:00
|
|
|
#include "ConstantEmitter.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/DeclFriend.h"
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
|
|
|
#include "clang/AST/Expr.h"
|
|
|
|
#include "clang/AST/RecordLayout.h"
|
2018-12-11 11:18:39 +08:00
|
|
|
#include "clang/Basic/CodeGenOptions.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "clang/Basic/Version.h"
|
2017-08-17 03:36:24 +08:00
|
|
|
#include "clang/Frontend/FrontendOptions.h"
|
2015-07-01 01:39:51 +08:00
|
|
|
#include "clang/Lex/HeaderSearchOptions.h"
|
2015-09-21 00:51:35 +08:00
|
|
|
#include "clang/Lex/ModuleMap.h"
|
2015-07-01 01:39:51 +08:00
|
|
|
#include "clang/Lex/PreprocessorOptions.h"
|
2016-10-26 06:19:32 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2013-01-02 19:45:17 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/Intrinsics.h"
|
2018-10-04 02:45:04 +08:00
|
|
|
#include "llvm/IR/Metadata.h"
|
2013-01-02 19:45:17 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2016-12-25 18:12:27 +08:00
|
|
|
#include "llvm/Support/MD5.h"
|
2013-12-19 05:48:18 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::CodeGen;
|
|
|
|
|
2016-10-20 08:13:19 +08:00
|
|
|
static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext &Ctx) {
|
|
|
|
auto TI = Ctx.getTypeInfo(Ty);
|
|
|
|
return TI.AlignIsRequired ? TI.Align : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t getTypeAlignIfRequired(QualType Ty, const ASTContext &Ctx) {
|
|
|
|
return getTypeAlignIfRequired(Ty.getTypePtr(), Ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t getDeclAlignIfRequired(const Decl *D, const ASTContext &Ctx) {
|
|
|
|
return D->hasAttr<AlignedAttr>() ? D->getMaxAlignment() : 0;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
|
2013-07-15 05:12:44 +08:00
|
|
|
: CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
|
2015-08-28 03:46:20 +08:00
|
|
|
DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
|
2013-07-15 05:12:44 +08:00
|
|
|
DBuilder(CGM.getModule()) {
|
2015-10-13 04:21:08 +08:00
|
|
|
for (const auto &KV : CGM.getCodeGenOpts().DebugPrefixMap)
|
|
|
|
DebugPrefixMap[KV.first] = KV.second;
|
2012-12-18 22:30:41 +08:00
|
|
|
CreateCompileUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
CGDebugInfo::~CGDebugInfo() {
|
|
|
|
assert(LexicalBlockStack.empty() &&
|
|
|
|
"Region stack mismatch, stack not empty!");
|
|
|
|
}
|
|
|
|
|
2015-02-04 02:40:42 +08:00
|
|
|
ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF,
|
2018-09-25 02:24:18 +08:00
|
|
|
SourceLocation TemporaryLocation)
|
2015-08-13 07:49:57 +08:00
|
|
|
: CGF(&CGF) {
|
2018-09-25 02:24:18 +08:00
|
|
|
init(TemporaryLocation);
|
2014-12-31 03:39:33 +08:00
|
|
|
}
|
|
|
|
|
2015-01-14 15:38:27 +08:00
|
|
|
ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF,
|
2015-02-04 04:00:54 +08:00
|
|
|
bool DefaultToEmpty,
|
2018-09-25 02:24:18 +08:00
|
|
|
SourceLocation TemporaryLocation)
|
2015-08-13 07:49:57 +08:00
|
|
|
: CGF(&CGF) {
|
2018-09-25 02:24:18 +08:00
|
|
|
init(TemporaryLocation, DefaultToEmpty);
|
DebugInfo: Use the preferred location rather than the start location for expression line info
This causes things like assignment to refer to the '=' rather than the
LHS when attributing the store instruction, for example.
There were essentially 3 options for this:
* The beginning of an expression (this was the behavior prior to this
commit). This meant that stepping through subexpressions would bounce
around from subexpressions back to the start of the outer expression,
etc. (eg: x + y + z would go x, y, x, z, x (the repeated 'x's would be
where the actual addition occurred)).
* The end of an expression. This seems to be what GCC does /mostly/, and
certainly this for function calls. This has the advantage that
progress is always 'forwards' (never jumping backwards - except for
independent subexpressions if they're evaluated in interesting orders,
etc). "x + y + z" would go "x y z" with the additions occurring at y
and z after the respective loads.
The problem with this is that the user would still have to think
fairly hard about precedence to realize which subexpression is being
evaluated or which operator overload is being called in, say, an asan
backtrace.
* The preferred location or 'exprloc'. In this case you get sort of what
you'd expect, though it's a bit confusing in its own way due to going
'backwards'. In this case the locations would be: "x y + z +" in
lovely postfix arithmetic order. But this does mean that if the op+
were an operator overload, say, and in a backtrace, the backtrace will
point to the exact '+' that's being called, not to the end of one of
its operands.
(actually the operator overload case doesn't work yet for other reasons,
but that's being fixed - but this at least gets scalar/complex
assignments and other plain operators right)
llvm-svn: 227027
2015-01-25 09:19:10 +08:00
|
|
|
}
|
|
|
|
|
2015-02-04 02:40:42 +08:00
|
|
|
void ApplyDebugLocation::init(SourceLocation TemporaryLocation,
|
2018-09-25 02:24:18 +08:00
|
|
|
bool DefaultToEmpty) {
|
2015-08-13 07:49:57 +08:00
|
|
|
auto *DI = CGF->getDebugInfo();
|
|
|
|
if (!DI) {
|
|
|
|
CGF = nullptr;
|
|
|
|
return;
|
2015-01-14 15:38:27 +08:00
|
|
|
}
|
2015-08-13 07:49:57 +08:00
|
|
|
|
|
|
|
OriginalLocation = CGF->Builder.getCurrentDebugLocation();
|
2017-09-12 06:11:57 +08:00
|
|
|
|
|
|
|
if (OriginalLocation && !DI->CGM.getExpressionLocationsEnabled())
|
|
|
|
return;
|
|
|
|
|
2015-08-13 07:49:57 +08:00
|
|
|
if (TemporaryLocation.isValid()) {
|
2018-09-25 02:24:18 +08:00
|
|
|
DI->EmitLocation(CGF->Builder, TemporaryLocation);
|
2015-08-13 07:49:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DefaultToEmpty) {
|
|
|
|
CGF->Builder.SetCurrentDebugLocation(llvm::DebugLoc());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct a location that has a valid scope, but no line info.
|
|
|
|
assert(!DI->LexicalBlockStack.empty());
|
2017-02-28 05:30:05 +08:00
|
|
|
CGF->Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
|
|
|
|
0, 0, DI->LexicalBlockStack.back(), DI->getInlinedAt()));
|
2015-01-10 07:00:28 +08:00
|
|
|
}
|
|
|
|
|
DebugInfo: Use the preferred location rather than the start location for expression line info
This causes things like assignment to refer to the '=' rather than the
LHS when attributing the store instruction, for example.
There were essentially 3 options for this:
* The beginning of an expression (this was the behavior prior to this
commit). This meant that stepping through subexpressions would bounce
around from subexpressions back to the start of the outer expression,
etc. (eg: x + y + z would go x, y, x, z, x (the repeated 'x's would be
where the actual addition occurred)).
* The end of an expression. This seems to be what GCC does /mostly/, and
certainly this for function calls. This has the advantage that
progress is always 'forwards' (never jumping backwards - except for
independent subexpressions if they're evaluated in interesting orders,
etc). "x + y + z" would go "x y z" with the additions occurring at y
and z after the respective loads.
The problem with this is that the user would still have to think
fairly hard about precedence to realize which subexpression is being
evaluated or which operator overload is being called in, say, an asan
backtrace.
* The preferred location or 'exprloc'. In this case you get sort of what
you'd expect, though it's a bit confusing in its own way due to going
'backwards'. In this case the locations would be: "x y + z +" in
lovely postfix arithmetic order. But this does mean that if the op+
were an operator overload, say, and in a backtrace, the backtrace will
point to the exact '+' that's being called, not to the end of one of
its operands.
(actually the operator overload case doesn't work yet for other reasons,
but that's being fixed - but this at least gets scalar/complex
assignments and other plain operators right)
llvm-svn: 227027
2015-01-25 09:19:10 +08:00
|
|
|
ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E)
|
2015-08-13 07:49:57 +08:00
|
|
|
: CGF(&CGF) {
|
DebugInfo: Use the preferred location rather than the start location for expression line info
This causes things like assignment to refer to the '=' rather than the
LHS when attributing the store instruction, for example.
There were essentially 3 options for this:
* The beginning of an expression (this was the behavior prior to this
commit). This meant that stepping through subexpressions would bounce
around from subexpressions back to the start of the outer expression,
etc. (eg: x + y + z would go x, y, x, z, x (the repeated 'x's would be
where the actual addition occurred)).
* The end of an expression. This seems to be what GCC does /mostly/, and
certainly this for function calls. This has the advantage that
progress is always 'forwards' (never jumping backwards - except for
independent subexpressions if they're evaluated in interesting orders,
etc). "x + y + z" would go "x y z" with the additions occurring at y
and z after the respective loads.
The problem with this is that the user would still have to think
fairly hard about precedence to realize which subexpression is being
evaluated or which operator overload is being called in, say, an asan
backtrace.
* The preferred location or 'exprloc'. In this case you get sort of what
you'd expect, though it's a bit confusing in its own way due to going
'backwards'. In this case the locations would be: "x y + z +" in
lovely postfix arithmetic order. But this does mean that if the op+
were an operator overload, say, and in a backtrace, the backtrace will
point to the exact '+' that's being called, not to the end of one of
its operands.
(actually the operator overload case doesn't work yet for other reasons,
but that's being fixed - but this at least gets scalar/complex
assignments and other plain operators right)
llvm-svn: 227027
2015-01-25 09:19:10 +08:00
|
|
|
init(E->getExprLoc());
|
|
|
|
}
|
|
|
|
|
2015-01-14 15:38:27 +08:00
|
|
|
ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc)
|
2015-08-13 07:49:57 +08:00
|
|
|
: CGF(&CGF) {
|
|
|
|
if (!CGF.getDebugInfo()) {
|
|
|
|
this->CGF = nullptr;
|
|
|
|
return;
|
2015-01-03 06:07:26 +08:00
|
|
|
}
|
2015-08-13 07:49:57 +08:00
|
|
|
OriginalLocation = CGF.Builder.getCurrentDebugLocation();
|
|
|
|
if (Loc)
|
|
|
|
CGF.Builder.SetCurrentDebugLocation(std::move(Loc));
|
2015-01-03 06:07:26 +08:00
|
|
|
}
|
|
|
|
|
2015-01-14 15:38:27 +08:00
|
|
|
ApplyDebugLocation::~ApplyDebugLocation() {
|
|
|
|
// Query CGF so the location isn't overwritten when location updates are
|
|
|
|
// temporarily disabled (for C++ default function arguments)
|
2015-08-13 07:49:57 +08:00
|
|
|
if (CGF)
|
|
|
|
CGF->Builder.SetCurrentDebugLocation(std::move(OriginalLocation));
|
2013-07-18 08:28:02 +08:00
|
|
|
}
|
|
|
|
|
2017-02-28 05:30:05 +08:00
|
|
|
ApplyInlineDebugLocation::ApplyInlineDebugLocation(CodeGenFunction &CGF,
|
|
|
|
GlobalDecl InlinedFn)
|
|
|
|
: CGF(&CGF) {
|
|
|
|
if (!CGF.getDebugInfo()) {
|
|
|
|
this->CGF = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto &DI = *CGF.getDebugInfo();
|
|
|
|
SavedLocation = DI.getLocation();
|
|
|
|
assert((DI.getInlinedAt() ==
|
|
|
|
CGF.Builder.getCurrentDebugLocation()->getInlinedAt()) &&
|
|
|
|
"CGDebugInfo and IRBuilder are out of sync");
|
|
|
|
|
|
|
|
DI.EmitInlineFunctionStart(CGF.Builder, InlinedFn);
|
|
|
|
}
|
|
|
|
|
|
|
|
ApplyInlineDebugLocation::~ApplyInlineDebugLocation() {
|
|
|
|
if (!CGF)
|
|
|
|
return;
|
|
|
|
auto &DI = *CGF->getDebugInfo();
|
|
|
|
DI.EmitInlineFunctionEnd(CGF->Builder);
|
|
|
|
DI.EmitLocation(CGF->Builder, SavedLocation);
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void CGDebugInfo::setLocation(SourceLocation Loc) {
|
|
|
|
// If the new location isn't valid return.
|
2014-10-27 07:40:33 +08:00
|
|
|
if (Loc.isInvalid())
|
|
|
|
return;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
CurLoc = CGM.getContext().getSourceManager().getExpansionLoc(Loc);
|
|
|
|
|
|
|
|
// If we've changed files in the middle of a lexical scope go ahead
|
|
|
|
// and create a new lexical scope with file node if it's different
|
|
|
|
// from the one in the scope.
|
2014-10-27 07:40:33 +08:00
|
|
|
if (LexicalBlockStack.empty())
|
|
|
|
return;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
2015-04-30 00:40:08 +08:00
|
|
|
auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
|
2012-12-18 22:30:41 +08:00
|
|
|
PresumedLoc PCLoc = SM.getPresumedLoc(CurLoc);
|
2018-12-07 02:44:50 +08:00
|
|
|
if (PCLoc.isInvalid() || Scope->getFile() == getOrCreateFile(CurLoc))
|
2012-12-18 22:30:41 +08:00
|
|
|
return;
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
if (auto *LBF = dyn_cast<llvm::DILexicalBlockFile>(Scope)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
LexicalBlockStack.pop_back();
|
2015-04-18 08:07:30 +08:00
|
|
|
LexicalBlockStack.emplace_back(DBuilder.createLexicalBlockFile(
|
|
|
|
LBF->getScope(), getOrCreateFile(CurLoc)));
|
2015-04-30 00:40:08 +08:00
|
|
|
} else if (isa<llvm::DILexicalBlock>(Scope) ||
|
|
|
|
isa<llvm::DISubprogram>(Scope)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
LexicalBlockStack.pop_back();
|
2015-04-18 08:07:30 +08:00
|
|
|
LexicalBlockStack.emplace_back(
|
|
|
|
DBuilder.createLexicalBlockFile(Scope, getOrCreateFile(CurLoc)));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-11 02:39:45 +08:00
|
|
|
llvm::DIScope *CGDebugInfo::getDeclContextDescriptor(const Decl *D) {
|
2015-09-12 01:23:08 +08:00
|
|
|
llvm::DIScope *Mod = getParentModuleOrNull(D);
|
|
|
|
return getContextDescriptor(cast<Decl>(D->getDeclContext()),
|
|
|
|
Mod ? Mod : TheCU);
|
2015-09-11 02:39:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIScope *CGDebugInfo::getContextDescriptor(const Decl *Context,
|
|
|
|
llvm::DIScope *Default) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!Context)
|
2015-09-11 02:39:45 +08:00
|
|
|
return Default;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
auto I = RegionMap.find(Context);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (I != RegionMap.end()) {
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::Metadata *V = I->second;
|
2015-04-30 00:40:08 +08:00
|
|
|
return dyn_cast_or_null<llvm::DIScope>(V);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check namespace.
|
2017-05-13 00:23:53 +08:00
|
|
|
if (const auto *NSDecl = dyn_cast<NamespaceDecl>(Context))
|
|
|
|
return getOrCreateNamespace(NSDecl);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *RDecl = dyn_cast<RecordDecl>(Context))
|
2013-04-19 14:56:38 +08:00
|
|
|
if (!RDecl->isDependentType())
|
|
|
|
return getOrCreateType(CGM.getContext().getTypeDeclType(RDecl),
|
2018-12-12 00:58:46 +08:00
|
|
|
TheCU->getFile());
|
2015-09-11 02:39:45 +08:00
|
|
|
return Default;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2017-08-08 09:33:53 +08:00
|
|
|
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;
|
|
|
|
|
2018-12-06 02:37:44 +08:00
|
|
|
// Apply -fdebug-prefix-map.
|
|
|
|
PP.RemapFilePaths = true;
|
|
|
|
PP.remapPath = [this](StringRef Path) { return remapDIPath(Path); };
|
2017-08-08 09:33:53 +08:00
|
|
|
return PP;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) {
|
2014-10-27 07:40:33 +08:00
|
|
|
assert(FD && "Invalid FunctionDecl!");
|
2012-12-18 22:30:41 +08:00
|
|
|
IdentifierInfo *FII = FD->getIdentifier();
|
2014-10-27 07:40:33 +08:00
|
|
|
FunctionTemplateSpecializationInfo *Info =
|
|
|
|
FD->getTemplateSpecializationInfo();
|
2015-12-16 10:04:40 +08:00
|
|
|
|
2016-07-01 01:41:31 +08:00
|
|
|
// 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)
|
2012-12-18 22:30:41 +08:00
|
|
|
return FII->getName();
|
|
|
|
|
2013-02-22 23:46:01 +08:00
|
|
|
SmallString<128> NS;
|
|
|
|
llvm::raw_svector_ostream OS(NS);
|
2016-07-01 01:41:31 +08:00
|
|
|
if (!UseQualifiedName)
|
|
|
|
FD->printName(OS);
|
|
|
|
else
|
2017-08-08 09:33:53 +08:00
|
|
|
FD->printQualifiedName(OS, getPrintingPolicy());
|
2016-06-18 00:11:20 +08:00
|
|
|
|
|
|
|
// Add any template specialization args.
|
|
|
|
if (Info) {
|
|
|
|
const TemplateArgumentList *TArgs = Info->TemplateArguments;
|
2017-11-29 00:14:14 +08:00
|
|
|
printTemplateArgumentList(OS, TArgs->asArray(), getPrintingPolicy());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy this name on the side and use its reference.
|
2013-09-10 00:39:06 +08:00
|
|
|
return internString(OS.str());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StringRef CGDebugInfo::getObjCMethodName(const ObjCMethodDecl *OMD) {
|
|
|
|
SmallString<256> MethodName;
|
|
|
|
llvm::raw_svector_ostream OS(MethodName);
|
|
|
|
OS << (OMD->isInstanceMethod() ? '-' : '+') << '[';
|
|
|
|
const DeclContext *DC = OMD->getDeclContext();
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *OID = dyn_cast<ObjCImplementationDecl>(DC)) {
|
2014-10-27 07:40:33 +08:00
|
|
|
OS << OID->getName();
|
2016-07-17 08:39:12 +08:00
|
|
|
} else if (const auto *OID = dyn_cast<ObjCInterfaceDecl>(DC)) {
|
2014-10-27 07:40:33 +08:00
|
|
|
OS << OID->getName();
|
2016-07-17 08:39:12 +08:00
|
|
|
} else if (const auto *OC = dyn_cast<ObjCCategoryDecl>(DC)) {
|
Stop back-patching 'readonly' Objective-C properties with 'readwrite' ones.
A 'readonly' Objective-C property declared in the primary class can
effectively be shadowed by a 'readwrite' property declared within an
extension of that class, so long as the types and attributes of the
two property declarations are compatible.
Previously, this functionality was implemented by back-patching the
original 'readonly' property to make it 'readwrite', destroying source
information and causing some hideously redundant, incorrect
code. Simplify the implementation to express how this should actually
be modeled: as a separate property declaration in the extension that
shadows (via the name lookup rules) the declaration in the primary
class. While here, correct some broken Fix-Its, eliminate a pile of
redundant code, clean up the ARC migrator's handling of properties
declared in extensions, and fix debug info's naming of methods that
come from categories.
A wonderous side effect of doing this write is that it eliminates the
"AddedObjCPropertyInClassExtension" method from the AST mutation
listener, which in turn eliminates the last place where we rewrite
entire declarations in a chained PCH file or a module file. This
change (which fixes rdar://problem/18475765) will allow us to
eliminate the rewritten-decls logic from the serialization library,
and fixes a crash (rdar://problem/23247794) illustrated by the
test/PCH/chain-categories.m example.
llvm-svn: 251874
2015-11-03 09:15:46 +08:00
|
|
|
if (OC->IsClassExtension()) {
|
|
|
|
OS << OC->getClassInterface()->getName();
|
|
|
|
} else {
|
2016-07-17 08:39:12 +08:00
|
|
|
OS << OC->getIdentifier()->getNameStart() << '('
|
Stop back-patching 'readonly' Objective-C properties with 'readwrite' ones.
A 'readonly' Objective-C property declared in the primary class can
effectively be shadowed by a 'readwrite' property declared within an
extension of that class, so long as the types and attributes of the
two property declarations are compatible.
Previously, this functionality was implemented by back-patching the
original 'readonly' property to make it 'readwrite', destroying source
information and causing some hideously redundant, incorrect
code. Simplify the implementation to express how this should actually
be modeled: as a separate property declaration in the extension that
shadows (via the name lookup rules) the declaration in the primary
class. While here, correct some broken Fix-Its, eliminate a pile of
redundant code, clean up the ARC migrator's handling of properties
declared in extensions, and fix debug info's naming of methods that
come from categories.
A wonderous side effect of doing this write is that it eliminates the
"AddedObjCPropertyInClassExtension" method from the AST mutation
listener, which in turn eliminates the last place where we rewrite
entire declarations in a chained PCH file or a module file. This
change (which fixes rdar://problem/18475765) will allow us to
eliminate the rewritten-decls logic from the serialization library,
and fixes a crash (rdar://problem/23247794) illustrated by the
test/PCH/chain-categories.m example.
llvm-svn: 251874
2015-11-03 09:15:46 +08:00
|
|
|
<< OC->getIdentifier()->getNameStart() << ')';
|
|
|
|
}
|
2016-07-17 08:39:12 +08:00
|
|
|
} else if (const auto *OCD = dyn_cast<ObjCCategoryImplDecl>(DC)) {
|
2018-06-28 18:56:40 +08:00
|
|
|
OS << OCD->getClassInterface()->getName() << '(' << OCD->getName() << ')';
|
2013-05-18 07:58:45 +08:00
|
|
|
} else if (isa<ObjCProtocolDecl>(DC)) {
|
2013-05-18 07:49:10 +08:00
|
|
|
// We can extract the type of the class from the self pointer.
|
2014-10-27 07:40:33 +08:00
|
|
|
if (ImplicitParamDecl *SelfDecl = OMD->getSelfDecl()) {
|
2013-05-18 07:49:10 +08:00
|
|
|
QualType ClassTy =
|
2014-10-27 07:40:33 +08:00
|
|
|
cast<ObjCObjectPointerType>(SelfDecl->getType())->getPointeeType();
|
2013-05-18 07:49:10 +08:00
|
|
|
ClassTy.print(OS, PrintingPolicy(LangOptions()));
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
OS << ' ' << OMD->getSelector().getAsString() << ']';
|
|
|
|
|
2013-09-10 00:39:06 +08:00
|
|
|
return internString(OS.str());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StringRef CGDebugInfo::getSelectorName(Selector S) {
|
2013-09-10 00:39:06 +08:00
|
|
|
return internString(S.getAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-10-27 07:40:33 +08:00
|
|
|
StringRef CGDebugInfo::getClassName(const RecordDecl *RD) {
|
2016-07-02 07:12:54 +08:00
|
|
|
if (isa<ClassTemplateSpecializationDecl>(RD)) {
|
|
|
|
SmallString<128> Name;
|
2014-04-03 02:21:09 +08:00
|
|
|
llvm::raw_svector_ostream OS(Name);
|
2017-08-08 09:33:53 +08:00
|
|
|
RD->getNameForDiagnostic(OS, getPrintingPolicy(),
|
2014-04-03 02:21:09 +08:00
|
|
|
/*Qualified*/ false);
|
2016-07-02 07:12:54 +08:00
|
|
|
|
|
|
|
// Copy this name on the side and use its reference.
|
|
|
|
return internString(Name);
|
2013-02-22 23:46:01 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-07-02 07:12:54 +08:00
|
|
|
// quick optimization to avoid having to intern strings that are already
|
|
|
|
// stored reliably elsewhere
|
|
|
|
if (const IdentifierInfo *II = RD->getIdentifier())
|
|
|
|
return II->getName();
|
|
|
|
|
|
|
|
// The CodeView printer in LLVM wants to see the names of unnamed types: it is
|
|
|
|
// used to reconstruct the fully qualified type names.
|
|
|
|
if (CGM.getCodeGenOpts().EmitCodeView) {
|
|
|
|
if (const TypedefNameDecl *D = RD->getTypedefNameForAnonDecl()) {
|
|
|
|
assert(RD->getDeclContext() == D->getDeclContext() &&
|
|
|
|
"Typedef should not be in another decl context!");
|
|
|
|
assert(D->getDeclName().getAsIdentifierInfo() &&
|
|
|
|
"Typedef was not named!");
|
|
|
|
return D->getDeclName().getAsIdentifierInfo()->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CGM.getLangOpts().CPlusPlus) {
|
|
|
|
StringRef Name;
|
|
|
|
|
|
|
|
ASTContext &Context = CGM.getContext();
|
|
|
|
if (const DeclaratorDecl *DD = Context.getDeclaratorForUnnamedTagDecl(RD))
|
|
|
|
// Anonymous types without a name for linkage purposes have their
|
|
|
|
// declarator mangled in if they have one.
|
|
|
|
Name = DD->getName();
|
|
|
|
else if (const TypedefNameDecl *TND =
|
|
|
|
Context.getTypedefNameForUnnamedTagDecl(RD))
|
|
|
|
// Anonymous types without a name for linkage purposes have their
|
|
|
|
// associate typedef mangled in if they have one.
|
|
|
|
Name = TND->getName();
|
|
|
|
|
|
|
|
if (!Name.empty()) {
|
|
|
|
SmallString<256> UnnamedType("<unnamed-type-");
|
|
|
|
UnnamedType += Name;
|
|
|
|
UnnamedType += '>';
|
|
|
|
return internString(UnnamedType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return StringRef();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2018-02-13 03:47:05 +08:00
|
|
|
Optional<llvm::DIFile::ChecksumKind>
|
2016-12-25 18:12:27 +08:00
|
|
|
CGDebugInfo::computeChecksum(FileID FID, SmallString<32> &Checksum) const {
|
|
|
|
Checksum.clear();
|
|
|
|
|
2018-05-26 06:35:59 +08:00
|
|
|
if (!CGM.getCodeGenOpts().EmitCodeView &&
|
|
|
|
CGM.getCodeGenOpts().DwarfVersion < 5)
|
2018-02-13 03:47:05 +08:00
|
|
|
return None;
|
2016-12-25 18:12:27 +08:00
|
|
|
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
bool Invalid;
|
2019-04-05 05:06:41 +08:00
|
|
|
const llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid);
|
2018-05-26 06:35:59 +08:00
|
|
|
if (Invalid)
|
2018-02-13 03:47:05 +08:00
|
|
|
return None;
|
2016-12-25 18:12:27 +08:00
|
|
|
|
|
|
|
llvm::MD5 Hash;
|
|
|
|
llvm::MD5::MD5Result Result;
|
|
|
|
|
|
|
|
Hash.update(MemBuffer->getBuffer());
|
|
|
|
Hash.final(Result);
|
|
|
|
|
|
|
|
Hash.stringifyResult(Result, Checksum);
|
|
|
|
return llvm::DIFile::CSK_MD5;
|
|
|
|
}
|
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
Optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM,
|
|
|
|
FileID FID) {
|
2018-02-27 01:32:31 +08:00
|
|
|
if (!CGM.getCodeGenOpts().EmbedSource)
|
|
|
|
return None;
|
|
|
|
|
|
|
|
bool SourceInvalid = false;
|
|
|
|
StringRef Source = SM.getBufferData(FID, &SourceInvalid);
|
|
|
|
|
|
|
|
if (SourceInvalid)
|
|
|
|
return None;
|
|
|
|
|
|
|
|
return Source;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!Loc.isValid())
|
|
|
|
// If Location is not valid then use main input file.
|
2018-12-12 00:58:46 +08:00
|
|
|
return TheCU->getFile();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
|
|
|
|
|
2018-12-07 02:44:50 +08:00
|
|
|
StringRef FileName = PLoc.getFilename();
|
|
|
|
if (PLoc.isInvalid() || FileName.empty())
|
2012-12-18 22:30:41 +08:00
|
|
|
// If the location is not valid then use main input file.
|
2018-12-12 00:58:46 +08:00
|
|
|
return TheCU->getFile();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Cache the results.
|
2018-12-07 02:44:50 +08:00
|
|
|
auto It = DIFileCache.find(FileName.data());
|
2018-06-28 18:56:40 +08:00
|
|
|
if (It != DIFileCache.end()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Verify that the information still exists.
|
2018-06-28 18:56:40 +08:00
|
|
|
if (llvm::Metadata *V = It->second)
|
2015-04-30 00:40:08 +08:00
|
|
|
return cast<llvm::DIFile>(V);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2016-12-25 18:12:27 +08:00
|
|
|
SmallString<32> Checksum;
|
2019-05-22 03:40:28 +08:00
|
|
|
|
|
|
|
// 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.
|
2018-02-13 03:47:05 +08:00
|
|
|
Optional<llvm::DIFile::ChecksumKind> CSKind =
|
2019-05-22 03:40:28 +08:00
|
|
|
computeChecksum(PLoc.getFileID(), Checksum);
|
2018-02-13 03:47:05 +08:00
|
|
|
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
|
|
|
|
if (CSKind)
|
|
|
|
CSInfo.emplace(*CSKind, Checksum);
|
2018-12-12 00:58:43 +08:00
|
|
|
return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
|
|
|
|
}
|
2016-12-25 18:12:27 +08:00
|
|
|
|
2018-12-12 00:58:43 +08:00
|
|
|
llvm::DIFile *
|
|
|
|
CGDebugInfo::createFile(StringRef FileName,
|
|
|
|
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
|
|
|
|
Optional<StringRef> Source) {
|
2018-12-07 02:44:50 +08:00
|
|
|
StringRef Dir;
|
|
|
|
StringRef File;
|
|
|
|
std::string RemappedFile = remapDIPath(FileName);
|
|
|
|
std::string CurDir = remapDIPath(getCurrentDirname());
|
|
|
|
SmallString<128> DirBuf;
|
|
|
|
SmallString<128> FileBuf;
|
|
|
|
if (llvm::sys::path::is_absolute(RemappedFile)) {
|
|
|
|
// Strip the common prefix (if it is more than just "/") from current
|
|
|
|
// directory and FileName for a more space-efficient encoding.
|
|
|
|
auto FileIt = llvm::sys::path::begin(RemappedFile);
|
|
|
|
auto FileE = llvm::sys::path::end(RemappedFile);
|
|
|
|
auto CurDirIt = llvm::sys::path::begin(CurDir);
|
|
|
|
auto CurDirE = llvm::sys::path::end(CurDir);
|
|
|
|
for (; CurDirIt != CurDirE && *CurDirIt == *FileIt; ++CurDirIt, ++FileIt)
|
|
|
|
llvm::sys::path::append(DirBuf, *CurDirIt);
|
|
|
|
if (std::distance(llvm::sys::path::begin(CurDir), CurDirIt) == 1) {
|
2019-02-06 05:21:01 +08:00
|
|
|
// Don't strip the common prefix if it is only the root "/"
|
|
|
|
// since that would make LLVM diagnostic locations confusing.
|
2018-12-07 02:44:50 +08:00
|
|
|
Dir = {};
|
|
|
|
File = RemappedFile;
|
|
|
|
} else {
|
|
|
|
for (; FileIt != FileE; ++FileIt)
|
|
|
|
llvm::sys::path::append(FileBuf, *FileIt);
|
|
|
|
Dir = DirBuf;
|
|
|
|
File = FileBuf;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Dir = CurDir;
|
|
|
|
File = RemappedFile;
|
|
|
|
}
|
2018-12-12 00:58:43 +08:00
|
|
|
llvm::DIFile *F = DBuilder.createFile(File, Dir, CSInfo, Source);
|
2018-12-07 02:44:50 +08:00
|
|
|
DIFileCache[FileName.data()].reset(F);
|
2012-12-18 22:30:41 +08:00
|
|
|
return F;
|
|
|
|
}
|
|
|
|
|
2015-10-13 04:21:08 +08:00
|
|
|
std::string CGDebugInfo::remapDIPath(StringRef Path) const {
|
|
|
|
for (const auto &Entry : DebugPrefixMap)
|
|
|
|
if (Path.startswith(Entry.first))
|
|
|
|
return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
|
|
|
|
return Path.str();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
|
|
|
|
if (Loc.isInvalid() && CurLoc.isInvalid())
|
|
|
|
return 0;
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc);
|
2014-10-27 07:40:33 +08:00
|
|
|
return PLoc.isValid() ? PLoc.getLine() : 0;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-03-13 04:43:25 +08:00
|
|
|
unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// We may not want column information at all.
|
2013-03-13 04:43:25 +08:00
|
|
|
if (!Force && !CGM.getCodeGenOpts().DebugColumnInfo)
|
2012-12-18 22:30:41 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// If the location is invalid then use the current column.
|
|
|
|
if (Loc.isInvalid() && CurLoc.isInvalid())
|
|
|
|
return 0;
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc);
|
2014-10-27 07:40:33 +08:00
|
|
|
return PLoc.isValid() ? PLoc.getColumn() : 0;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StringRef CGDebugInfo::getCurrentDirname() {
|
|
|
|
if (!CGM.getCodeGenOpts().DebugCompilationDir.empty())
|
|
|
|
return CGM.getCodeGenOpts().DebugCompilationDir;
|
|
|
|
|
|
|
|
if (!CWDName.empty())
|
|
|
|
return CWDName;
|
|
|
|
SmallString<256> CWD;
|
|
|
|
llvm::sys::fs::current_path(CWD);
|
2013-09-10 00:39:06 +08:00
|
|
|
return CWDName = internString(CWD);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::CreateCompileUnit() {
|
2016-12-25 18:12:27 +08:00
|
|
|
SmallString<32> Checksum;
|
2018-02-13 03:47:05 +08:00
|
|
|
Optional<llvm::DIFile::ChecksumKind> CSKind;
|
|
|
|
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-05-14 08:29:00 +08:00
|
|
|
// Should we be asking the SourceManager for the main file name, instead of
|
|
|
|
// accepting it as an argument? This just causes the main file name to
|
|
|
|
// mismatch with source locations and create extra lexical scopes or
|
|
|
|
// mismatched debug info (a CU with a DW_AT_file of "-", because that's what
|
|
|
|
// the driver passed, but functions/other things have DW_AT_file of "<stdin>"
|
|
|
|
// because that's what the SourceManager says)
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Get absolute path name.
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
std::string MainFileName = CGM.getCodeGenOpts().MainFileName;
|
|
|
|
if (MainFileName.empty())
|
2014-05-14 08:29:00 +08:00
|
|
|
MainFileName = "<stdin>";
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// The main file name provided via the "-main-file-name" option contains just
|
|
|
|
// the file name itself with no path information. This file name may have had
|
|
|
|
// a relative path, so we look into the actual file entry for the main
|
|
|
|
// file to determine the real absolute path for the file.
|
|
|
|
std::string MainFileDir;
|
|
|
|
if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
|
2015-10-13 04:21:08 +08:00
|
|
|
MainFileDir = remapDIPath(MainFile->getDir()->getName());
|
2013-10-22 04:07:37 +08:00
|
|
|
if (MainFileDir != ".") {
|
2014-02-26 10:49:36 +08:00
|
|
|
llvm::SmallString<1024> MainFileDirSS(MainFileDir);
|
|
|
|
llvm::sys::path::append(MainFileDirSS, MainFileName);
|
|
|
|
MainFileName = MainFileDirSS.str();
|
2013-10-22 04:07:37 +08:00
|
|
|
}
|
2017-08-17 03:36:24 +08:00
|
|
|
// 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();
|
|
|
|
|
2016-12-25 18:12:27 +08:00
|
|
|
CSKind = computeChecksum(SM.getMainFileID(), Checksum);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::dwarf::SourceLanguage LangTag;
|
2012-12-18 22:30:41 +08:00
|
|
|
const LangOptions &LO = CGM.getLangOpts();
|
|
|
|
if (LO.CPlusPlus) {
|
2018-10-31 04:31:30 +08:00
|
|
|
if (LO.ObjC)
|
2012-12-18 22:30:41 +08:00
|
|
|
LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
|
|
|
|
else
|
|
|
|
LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
|
2018-10-31 04:31:30 +08:00
|
|
|
} else if (LO.ObjC) {
|
2012-12-18 22:30:41 +08:00
|
|
|
LangTag = llvm::dwarf::DW_LANG_ObjC;
|
2016-06-22 05:35:11 +08:00
|
|
|
} else if (LO.RenderScript) {
|
|
|
|
LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
|
2012-12-18 22:30:41 +08:00
|
|
|
} else if (LO.C99) {
|
|
|
|
LangTag = llvm::dwarf::DW_LANG_C99;
|
|
|
|
} else {
|
|
|
|
LangTag = llvm::dwarf::DW_LANG_C89;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Producer = getClangFullVersion();
|
|
|
|
|
|
|
|
// Figure out which version of the ObjC runtime we have.
|
|
|
|
unsigned RuntimeVers = 0;
|
2018-10-31 04:31:30 +08:00
|
|
|
if (LO.ObjC)
|
2012-12-18 22:30:41 +08:00
|
|
|
RuntimeVers = LO.ObjCRuntime.isNonFragile() ? 2 : 1;
|
|
|
|
|
2016-04-09 06:43:06 +08:00
|
|
|
llvm::DICompileUnit::DebugEmissionKind EmissionKind;
|
|
|
|
switch (DebugKind) {
|
|
|
|
case codegenoptions::NoDebugInfo:
|
|
|
|
case codegenoptions::LocTrackingOnly:
|
|
|
|
EmissionKind = llvm::DICompileUnit::NoDebug;
|
|
|
|
break;
|
|
|
|
case codegenoptions::DebugLineTablesOnly:
|
|
|
|
EmissionKind = llvm::DICompileUnit::LineTablesOnly;
|
|
|
|
break;
|
2018-08-31 21:56:14 +08:00
|
|
|
case codegenoptions::DebugDirectivesOnly:
|
|
|
|
EmissionKind = llvm::DICompileUnit::DebugDirectivesOnly;
|
|
|
|
break;
|
2016-04-09 06:43:06 +08:00
|
|
|
case codegenoptions::LimitedDebugInfo:
|
|
|
|
case codegenoptions::FullDebugInfo:
|
|
|
|
EmissionKind = llvm::DICompileUnit::FullDebug;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-14 01:53:29 +08:00
|
|
|
uint64_t DwoId = 0;
|
|
|
|
auto &CGOpts = CGM.getCodeGenOpts();
|
|
|
|
// The DIFile used by the CU is distinct from the main source
|
|
|
|
// file. Its directory part specifies what becomes the
|
|
|
|
// DW_AT_comp_dir (the compilation directory), even if the source
|
|
|
|
// file was specified with an absolute path.
|
2018-02-13 03:47:05 +08:00
|
|
|
if (CSKind)
|
|
|
|
CSInfo.emplace(*CSKind, Checksum);
|
2018-12-14 01:53:29 +08:00
|
|
|
llvm::DIFile *CUFile = DBuilder.createFile(
|
|
|
|
remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo,
|
|
|
|
getSource(SM, SM.getMainFileID()));
|
2018-02-13 03:47:05 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Create new compile unit.
|
2014-02-27 09:25:08 +08:00
|
|
|
TheCU = DBuilder.createCompileUnit(
|
2018-12-14 01:53:29 +08:00
|
|
|
LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "",
|
2018-06-23 04:23:21 +08:00
|
|
|
LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
|
2017-08-05 07:08:57 +08:00
|
|
|
CGOpts.DwarfDebugFlags, RuntimeVers,
|
2018-11-14 17:22:16 +08:00
|
|
|
(CGOpts.getSplitDwarfMode() != CodeGenOptions::NoFission)
|
|
|
|
? ""
|
2019-06-15 23:38:51 +08:00
|
|
|
: CGOpts.SplitDwarfFile,
|
2018-12-14 01:53:29 +08:00
|
|
|
EmissionKind, DwoId, CGOpts.SplitDwarfInlining,
|
2018-11-14 17:22:16 +08:00
|
|
|
CGOpts.DebugInfoForProfiling,
|
2018-08-17 07:56:32 +08:00
|
|
|
CGM.getTarget().getTriple().isNVPTX()
|
|
|
|
? llvm::DICompileUnit::DebugNameTableKind::None
|
2018-08-21 04:14:08 +08:00
|
|
|
: static_cast<llvm::DICompileUnit::DebugNameTableKind>(
|
2018-11-14 04:08:13 +08:00
|
|
|
CGOpts.DebugNameTable),
|
|
|
|
CGOpts.DebugRangesBaseAddress);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::dwarf::TypeKind Encoding;
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef BTName;
|
|
|
|
switch (BT->getKind()) {
|
|
|
|
#define BUILTIN_TYPE(Id, SingletonId)
|
2014-10-27 07:40:33 +08:00
|
|
|
#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/AST/BuiltinTypes.def"
|
|
|
|
case BuiltinType::Dependent:
|
|
|
|
llvm_unreachable("Unexpected builtin type");
|
|
|
|
case BuiltinType::NullPtr:
|
2013-06-28 06:51:01 +08:00
|
|
|
return DBuilder.createNullPtrType();
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::Void:
|
2015-04-21 02:51:48 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::ObjCClass:
|
2014-05-06 11:42:01 +08:00
|
|
|
if (!ClassTy)
|
2018-12-12 00:58:46 +08:00
|
|
|
ClassTy =
|
|
|
|
DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
|
|
|
|
"objc_class", TheCU, TheCU->getFile(), 0);
|
2012-12-18 22:30:41 +08:00
|
|
|
return ClassTy;
|
|
|
|
case BuiltinType::ObjCId: {
|
|
|
|
// typedef struct objc_class *Class;
|
|
|
|
// typedef struct objc_object {
|
|
|
|
// Class isa;
|
|
|
|
// } *id;
|
|
|
|
|
2013-07-18 08:52:50 +08:00
|
|
|
if (ObjTy)
|
2012-12-18 22:30:41 +08:00
|
|
|
return ObjTy;
|
|
|
|
|
2013-07-18 08:52:50 +08:00
|
|
|
if (!ClassTy)
|
2018-12-12 00:58:46 +08:00
|
|
|
ClassTy =
|
|
|
|
DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
|
|
|
|
"objc_class", TheCU, TheCU->getFile(), 0);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2015-04-21 02:51:48 +08:00
|
|
|
auto *ISATy = DBuilder.createPointerType(ClassTy, Size);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2018-12-12 00:58:46 +08:00
|
|
|
ObjTy = DBuilder.createStructType(TheCU, "objc_object", TheCU->getFile(), 0,
|
|
|
|
0, 0, llvm::DINode::FlagZero, nullptr,
|
|
|
|
llvm::DINodeArray());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-12-18 08:48:56 +08:00
|
|
|
DBuilder.replaceArrays(
|
2016-09-07 01:06:14 +08:00
|
|
|
ObjTy, DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
|
2018-12-12 00:58:46 +08:00
|
|
|
ObjTy, "isa", TheCU->getFile(), 0, Size, 0, 0,
|
2016-09-07 01:06:14 +08:00
|
|
|
llvm::DINode::FlagZero, ISATy)));
|
2012-12-18 22:30:41 +08:00
|
|
|
return ObjTy;
|
|
|
|
}
|
|
|
|
case BuiltinType::ObjCSel: {
|
2014-05-06 11:42:01 +08:00
|
|
|
if (!SelTy)
|
|
|
|
SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
|
|
|
|
"objc_selector", TheCU,
|
2018-12-12 00:58:46 +08:00
|
|
|
TheCU->getFile(), 0);
|
2012-12-18 22:30:41 +08:00
|
|
|
return SelTy;
|
|
|
|
}
|
2012-12-18 22:38:23 +08:00
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
|
|
|
|
case BuiltinType::Id: \
|
|
|
|
return getOrCreateStructPtrType("opencl_" #ImgType "_" #Suffix "_t", \
|
2016-04-08 21:40:33 +08:00
|
|
|
SingletonId);
|
2016-04-13 16:33:41 +08:00
|
|
|
#include "clang/Basic/OpenCLImageTypes.def"
|
2013-02-07 18:55:47 +08:00
|
|
|
case BuiltinType::OCLSampler:
|
2018-06-28 18:56:40 +08:00
|
|
|
return getOrCreateStructPtrType("opencl_sampler_t", OCLSamplerDITy);
|
2013-01-20 20:31:11 +08:00
|
|
|
case BuiltinType::OCLEvent:
|
2014-10-27 07:40:33 +08:00
|
|
|
return getOrCreateStructPtrType("opencl_event_t", OCLEventDITy);
|
2015-09-15 19:18:52 +08:00
|
|
|
case BuiltinType::OCLClkEvent:
|
|
|
|
return getOrCreateStructPtrType("opencl_clk_event_t", OCLClkEventDITy);
|
|
|
|
case BuiltinType::OCLQueue:
|
|
|
|
return getOrCreateStructPtrType("opencl_queue_t", OCLQueueDITy);
|
|
|
|
case BuiltinType::OCLReserveID:
|
|
|
|
return getOrCreateStructPtrType("opencl_reserve_id_t", OCLReserveIDDITy);
|
2018-11-08 19:25:41 +08:00
|
|
|
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
|
|
|
|
case BuiltinType::Id: \
|
|
|
|
return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty);
|
|
|
|
#include "clang/Basic/OpenCLExtensionTypes.def"
|
2012-12-18 22:38:23 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::UChar:
|
2014-10-27 07:40:33 +08:00
|
|
|
case BuiltinType::Char_U:
|
|
|
|
Encoding = llvm::dwarf::DW_ATE_unsigned_char;
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::Char_S:
|
2014-10-27 07:40:33 +08:00
|
|
|
case BuiltinType::SChar:
|
|
|
|
Encoding = llvm::dwarf::DW_ATE_signed_char;
|
|
|
|
break;
|
2018-05-01 13:02:45 +08:00
|
|
|
case BuiltinType::Char8:
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::Char16:
|
2014-10-27 07:40:33 +08:00
|
|
|
case BuiltinType::Char32:
|
|
|
|
Encoding = llvm::dwarf::DW_ATE_UTF;
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::UShort:
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
case BuiltinType::UInt128:
|
|
|
|
case BuiltinType::ULong:
|
|
|
|
case BuiltinType::WChar_U:
|
2014-10-27 07:40:33 +08:00
|
|
|
case BuiltinType::ULongLong:
|
|
|
|
Encoding = llvm::dwarf::DW_ATE_unsigned;
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::Short:
|
|
|
|
case BuiltinType::Int:
|
|
|
|
case BuiltinType::Int128:
|
|
|
|
case BuiltinType::Long:
|
|
|
|
case BuiltinType::WChar_S:
|
2014-10-27 07:40:33 +08:00
|
|
|
case BuiltinType::LongLong:
|
|
|
|
Encoding = llvm::dwarf::DW_ATE_signed;
|
|
|
|
break;
|
|
|
|
case BuiltinType::Bool:
|
|
|
|
Encoding = llvm::dwarf::DW_ATE_boolean;
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::Half:
|
|
|
|
case BuiltinType::Float:
|
|
|
|
case BuiltinType::LongDouble:
|
2017-09-08 23:15:00 +08:00
|
|
|
case BuiltinType::Float16:
|
2016-05-09 16:52:33 +08:00
|
|
|
case BuiltinType::Float128:
|
2014-10-27 07:40:33 +08:00
|
|
|
case BuiltinType::Double:
|
2016-05-09 16:52:33 +08:00
|
|
|
// FIXME: For targets where long double and __float128 have the same size,
|
|
|
|
// they are currently indistinguishable in the debugger without some
|
|
|
|
// special treatment. However, there is currently no consensus on encoding
|
|
|
|
// and this should be updated once a DWARF encoding exists for distinct
|
|
|
|
// floating point types of the same size.
|
2014-10-27 07:40:33 +08:00
|
|
|
Encoding = llvm::dwarf::DW_ATE_float;
|
|
|
|
break;
|
2018-06-05 00:07:52 +08:00
|
|
|
case BuiltinType::ShortAccum:
|
|
|
|
case BuiltinType::Accum:
|
|
|
|
case BuiltinType::LongAccum:
|
2018-06-14 22:53:51 +08:00
|
|
|
case BuiltinType::ShortFract:
|
|
|
|
case BuiltinType::Fract:
|
|
|
|
case BuiltinType::LongFract:
|
|
|
|
case BuiltinType::SatShortFract:
|
|
|
|
case BuiltinType::SatFract:
|
|
|
|
case BuiltinType::SatLongFract:
|
|
|
|
case BuiltinType::SatShortAccum:
|
|
|
|
case BuiltinType::SatAccum:
|
|
|
|
case BuiltinType::SatLongAccum:
|
2018-06-05 00:07:52 +08:00
|
|
|
Encoding = llvm::dwarf::DW_ATE_signed_fixed;
|
|
|
|
break;
|
|
|
|
case BuiltinType::UShortAccum:
|
|
|
|
case BuiltinType::UAccum:
|
|
|
|
case BuiltinType::ULongAccum:
|
2018-06-14 22:53:51 +08:00
|
|
|
case BuiltinType::UShortFract:
|
|
|
|
case BuiltinType::UFract:
|
|
|
|
case BuiltinType::ULongFract:
|
|
|
|
case BuiltinType::SatUShortAccum:
|
|
|
|
case BuiltinType::SatUAccum:
|
|
|
|
case BuiltinType::SatULongAccum:
|
|
|
|
case BuiltinType::SatUShortFract:
|
|
|
|
case BuiltinType::SatUFract:
|
|
|
|
case BuiltinType::SatULongFract:
|
2018-06-05 00:07:52 +08:00
|
|
|
Encoding = llvm::dwarf::DW_ATE_unsigned_fixed;
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (BT->getKind()) {
|
2014-10-27 07:40:33 +08:00
|
|
|
case BuiltinType::Long:
|
|
|
|
BTName = "long int";
|
|
|
|
break;
|
|
|
|
case BuiltinType::LongLong:
|
|
|
|
BTName = "long long int";
|
|
|
|
break;
|
|
|
|
case BuiltinType::ULong:
|
|
|
|
BTName = "long unsigned int";
|
|
|
|
break;
|
|
|
|
case BuiltinType::ULongLong:
|
|
|
|
BTName = "long long unsigned int";
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
default:
|
|
|
|
BTName = BT->getName(CGM.getLangOpts());
|
|
|
|
break;
|
|
|
|
}
|
2016-10-20 08:13:19 +08:00
|
|
|
// Bit size and offset of the type.
|
2012-12-18 22:30:41 +08:00
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(BT);
|
2016-10-20 08:13:19 +08:00
|
|
|
return DBuilder.createBasicType(BTName, Size, Encoding);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const ComplexType *Ty) {
|
2016-10-20 08:13:19 +08:00
|
|
|
// Bit size and offset of the type.
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::dwarf::TypeKind Encoding = llvm::dwarf::DW_ATE_complex_float;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Ty->isComplexIntegerType())
|
|
|
|
Encoding = llvm::dwarf::DW_ATE_lo_user;
|
|
|
|
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
2016-10-20 08:13:19 +08:00
|
|
|
return DBuilder.createBasicType("complex", Size, Encoding);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateQualifiedType(QualType Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
QualifierCollector Qc;
|
|
|
|
const Type *T = Qc.strip(Ty);
|
|
|
|
|
|
|
|
// Ignore these qualifiers for now.
|
|
|
|
Qc.removeObjCGCAttr();
|
|
|
|
Qc.removeAddressSpace();
|
|
|
|
Qc.removeObjCLifetime();
|
|
|
|
|
|
|
|
// We will create one Derived type for one qualifier and recurse to handle any
|
|
|
|
// additional ones.
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::dwarf::Tag Tag;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Qc.hasConst()) {
|
|
|
|
Tag = llvm::dwarf::DW_TAG_const_type;
|
|
|
|
Qc.removeConst();
|
|
|
|
} else if (Qc.hasVolatile()) {
|
|
|
|
Tag = llvm::dwarf::DW_TAG_volatile_type;
|
|
|
|
Qc.removeVolatile();
|
|
|
|
} else if (Qc.hasRestrict()) {
|
|
|
|
Tag = llvm::dwarf::DW_TAG_restrict_type;
|
|
|
|
Qc.removeRestrict();
|
|
|
|
} else {
|
|
|
|
assert(Qc.empty() && "Unknown type qualifier for debug info");
|
|
|
|
return getOrCreateType(QualType(T, 0), Unit);
|
|
|
|
}
|
|
|
|
|
2015-04-21 02:51:48 +08:00
|
|
|
auto *FromTy = getOrCreateType(Qc.apply(CGM.getContext(), T), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// No need to fill in the Name, Line, Size, Alignment, Offset in case of
|
|
|
|
// CVR derived types.
|
2015-04-21 02:51:48 +08:00
|
|
|
return DBuilder.createQualifiedType(Tag, FromTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2013-02-22 04:42:11 +08:00
|
|
|
|
|
|
|
// The frontend treats 'id' as a typedef to an ObjCObjectType,
|
|
|
|
// whereas 'id<protocol>' is treated as an ObjCPointerType. For the
|
|
|
|
// debug info, we want to emit 'id' in both cases.
|
|
|
|
if (Ty->isObjCQualifiedIdType())
|
2014-10-27 07:40:33 +08:00
|
|
|
return getOrCreateType(CGM.getContext().getObjCIdType(), Unit);
|
2013-02-22 04:42:11 +08:00
|
|
|
|
2015-04-21 02:51:48 +08:00
|
|
|
return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
|
|
|
|
Ty->getPointeeType(), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const PointerType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2013-05-16 08:45:12 +08:00
|
|
|
return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
|
2012-12-18 22:30:41 +08:00
|
|
|
Ty->getPointeeType(), Unit);
|
|
|
|
}
|
|
|
|
|
2015-06-16 07:18:16 +08:00
|
|
|
/// \return whether a C++ mangling exists for the type defined by TD.
|
|
|
|
static bool hasCXXMangling(const TagDecl *TD, llvm::DICompileUnit *TheCU) {
|
|
|
|
switch (TheCU->getSourceLanguage()) {
|
|
|
|
case llvm::dwarf::DW_LANG_C_plus_plus:
|
|
|
|
return true;
|
|
|
|
case llvm::dwarf::DW_LANG_ObjC_plus_plus:
|
|
|
|
return isa<CXXRecordDecl>(TD) || isa<EnumDecl>(TD);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-18 04:59:52 +08:00
|
|
|
// Determines if the debug info for this tag declaration needs a type
|
|
|
|
// identifier. The purpose of the unique identifier is to deduplicate type
|
|
|
|
// information for identical types across TUs. Because of the C++ one definition
|
|
|
|
// rule (ODR), it is valid to assume that the type is defined the same way in
|
|
|
|
// every TU and its debug info is equivalent.
|
|
|
|
//
|
|
|
|
// C does not have the ODR, and it is common for codebases to contain multiple
|
|
|
|
// different definitions of a struct with the same name in different TUs.
|
|
|
|
// Therefore, if the type doesn't have a C++ mangling, don't give it an
|
|
|
|
// identifer. Type information in C is smaller and simpler than C++ type
|
|
|
|
// information, so the increase in debug info size is negligible.
|
|
|
|
//
|
|
|
|
// If the type is not externally visible, it should be unique to the current TU,
|
|
|
|
// and should not need an identifier to participate in type deduplication.
|
|
|
|
// However, when emitting CodeView, the format internally uses these
|
|
|
|
// unique type name identifers for references between debug info. For example,
|
|
|
|
// the method of a class in an anonymous namespace uses the identifer to refer
|
|
|
|
// to its parent class. The Microsoft C++ ABI attempts to provide unique names
|
|
|
|
// for such types, so when emitting CodeView, always use identifiers for C++
|
|
|
|
// types. This may create problems when attempting to emit CodeView when the MS
|
|
|
|
// C++ ABI is not in use.
|
2018-06-28 18:56:40 +08:00
|
|
|
static bool needsTypeIdentifier(const TagDecl *TD, CodeGenModule &CGM,
|
2018-05-22 20:41:19 +08:00
|
|
|
llvm::DICompileUnit *TheCU) {
|
|
|
|
// We only add a type identifier for types with C++ name mangling.
|
|
|
|
if (!hasCXXMangling(TD, TheCU))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Externally visible types with C++ mangling need a type identifier.
|
|
|
|
if (TD->isExternallyVisible())
|
|
|
|
return true;
|
|
|
|
|
2018-08-18 04:59:52 +08:00
|
|
|
// CodeView types with C++ mangling need a type identifier.
|
|
|
|
if (CGM.getCodeGenOpts().EmitCodeView)
|
|
|
|
return true;
|
|
|
|
|
2018-05-22 20:41:19 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-18 04:59:52 +08:00
|
|
|
// Returns a unique type identifier string if one exists, or an empty string.
|
2018-06-28 18:56:40 +08:00
|
|
|
static SmallString<256> getTypeIdentifier(const TagType *Ty, CodeGenModule &CGM,
|
2018-05-22 20:41:19 +08:00
|
|
|
llvm::DICompileUnit *TheCU) {
|
|
|
|
SmallString<256> Identifier;
|
2013-08-30 07:19:58 +08:00
|
|
|
const TagDecl *TD = Ty->getDecl();
|
2015-06-16 07:18:16 +08:00
|
|
|
|
2018-05-22 20:41:19 +08:00
|
|
|
if (!needsTypeIdentifier(TD, CGM, TheCU))
|
|
|
|
return Identifier;
|
2019-04-26 04:05:47 +08:00
|
|
|
if (const auto *RD = dyn_cast<CXXRecordDecl>(TD))
|
|
|
|
if (RD->getDefinition())
|
|
|
|
if (RD->isDynamicClass() &&
|
|
|
|
CGM.getVTableLinkage(RD) == llvm::GlobalValue::ExternalLinkage)
|
|
|
|
return Identifier;
|
2015-06-16 07:18:16 +08:00
|
|
|
|
2013-08-30 07:19:58 +08:00
|
|
|
// TODO: This is using the RTTI name. Is there a better way to get
|
|
|
|
// a unique string for a type?
|
2018-05-22 20:41:19 +08:00
|
|
|
llvm::raw_svector_ostream Out(Identifier);
|
2013-08-30 07:19:58 +08:00
|
|
|
CGM.getCXXABI().getMangleContext().mangleCXXRTTIName(QualType(Ty, 0), Out);
|
2018-05-22 20:41:19 +08:00
|
|
|
return Identifier;
|
2013-08-30 07:19:58 +08:00
|
|
|
}
|
|
|
|
|
2018-04-06 23:14:32 +08:00
|
|
|
/// \return the appropriate DWARF tag for a composite type.
|
2015-02-12 01:45:15 +08:00
|
|
|
static llvm::dwarf::Tag getTagForRecord(const RecordDecl *RD) {
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::dwarf::Tag Tag;
|
2015-02-12 01:45:15 +08:00
|
|
|
if (RD->isStruct() || RD->isInterface())
|
|
|
|
Tag = llvm::dwarf::DW_TAG_structure_type;
|
|
|
|
else if (RD->isUnion())
|
|
|
|
Tag = llvm::dwarf::DW_TAG_union_type;
|
|
|
|
else {
|
|
|
|
// FIXME: This could be a struct type giving a default visibility different
|
|
|
|
// than C++ class type, but needs llvm metadata changes first.
|
|
|
|
assert(RD->isClass());
|
|
|
|
Tag = llvm::dwarf::DW_TAG_class_type;
|
|
|
|
}
|
|
|
|
return Tag;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *
|
2013-08-29 05:20:28 +08:00
|
|
|
CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType *Ty,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIScope *Ctx) {
|
2013-08-29 05:20:28 +08:00
|
|
|
const RecordDecl *RD = Ty->getDecl();
|
2015-04-30 00:40:08 +08:00
|
|
|
if (llvm::DIType *T = getTypeOrNull(CGM.getContext().getRecordType(RD)))
|
|
|
|
return cast<llvm::DICompositeType>(T);
|
|
|
|
llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation());
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Line = getLineNumber(RD->getLocation());
|
|
|
|
StringRef RDName = getClassName(RD);
|
|
|
|
|
2015-03-02 06:07:04 +08:00
|
|
|
uint64_t Size = 0;
|
2016-10-20 06:11:07 +08:00
|
|
|
uint32_t Align = 0;
|
2015-03-02 06:07:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Create the type.
|
2018-05-22 20:41:19 +08:00
|
|
|
SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
|
2015-03-02 06:07:04 +08:00
|
|
|
getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align,
|
2018-05-22 20:41:19 +08:00
|
|
|
llvm::DINode::FlagFwdDecl, Identifier);
|
2017-09-29 02:37:02 +08:00
|
|
|
if (CGM.getCodeGenOpts().DebugFwdTemplateParams)
|
|
|
|
if (auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
|
|
|
|
DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),
|
|
|
|
CollectCXXTemplateParams(TSpecial, DefUnit));
|
2014-12-10 02:39:32 +08:00
|
|
|
ReplaceMap.emplace_back(
|
|
|
|
std::piecewise_construct, std::make_tuple(Ty),
|
|
|
|
std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));
|
2014-05-06 11:42:01 +08:00
|
|
|
return RetTy;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
|
2015-04-21 02:51:48 +08:00
|
|
|
const Type *Ty,
|
|
|
|
QualType PointeeTy,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Bit size, align and offset of the type.
|
|
|
|
// Size is always the size of a pointer. We can't use getTypeSize here
|
|
|
|
// because that does not return the correct value for references.
|
2017-03-09 07:56:48 +08:00
|
|
|
unsigned AddressSpace = CGM.getContext().getTargetAddressSpace(PointeeTy);
|
|
|
|
uint64_t Size = CGM.getTarget().getPointerWidth(AddressSpace);
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getTypeAlignIfRequired(Ty, CGM.getContext());
|
2017-03-09 07:56:48 +08:00
|
|
|
Optional<unsigned> DWARFAddressSpace =
|
|
|
|
CGM.getTarget().getDWARFAddressSpace(AddressSpace);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-11-16 17:04:13 +08:00
|
|
|
if (Tag == llvm::dwarf::DW_TAG_reference_type ||
|
|
|
|
Tag == llvm::dwarf::DW_TAG_rvalue_reference_type)
|
|
|
|
return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit),
|
2017-03-09 07:56:48 +08:00
|
|
|
Size, Align, DWARFAddressSpace);
|
2015-11-16 17:04:13 +08:00
|
|
|
else
|
|
|
|
return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
|
2017-03-09 07:56:48 +08:00
|
|
|
Align, DWARFAddressSpace);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
|
|
|
|
llvm::DIType *&Cache) {
|
2013-07-18 08:52:50 +08:00
|
|
|
if (Cache)
|
2012-12-18 22:38:23 +08:00
|
|
|
return Cache;
|
2013-05-22 01:58:54 +08:00
|
|
|
Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
|
2018-12-12 00:58:46 +08:00
|
|
|
TheCU, TheCU->getFile(), 0);
|
2013-05-22 01:58:54 +08:00
|
|
|
unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
|
|
|
|
Cache = DBuilder.createPointerType(Cache, Size);
|
|
|
|
return Cache;
|
2012-12-18 22:38:23 +08:00
|
|
|
}
|
|
|
|
|
2018-08-08 23:56:12 +08:00
|
|
|
uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
|
|
|
|
const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
|
|
|
|
unsigned LineNo, SmallVectorImpl<llvm::Metadata *> &EltTys) {
|
|
|
|
QualType FType;
|
|
|
|
|
|
|
|
// Advanced by calls to CreateMemberType in increments of FType, then
|
|
|
|
// returned as the overall size of the default elements.
|
|
|
|
uint64_t FieldOffset = 0;
|
|
|
|
|
|
|
|
// Blocks in OpenCL have unique constraints which make the standard fields
|
|
|
|
// redundant while requiring size and align fields for enqueue_kernel. See
|
|
|
|
// initializeForBlockHeader in CGBlocks.cpp
|
|
|
|
if (CGM.getLangOpts().OpenCL) {
|
|
|
|
FType = CGM.getContext().IntTy;
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
|
|
|
|
} else {
|
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
|
|
|
|
FType = CGM.getContext().IntTy;
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
|
|
|
|
FType = CGM.getContext().getPointerType(Ty->getPointeeType());
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
|
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
|
|
|
uint64_t FieldSize = CGM.getContext().getTypeSize(Ty);
|
|
|
|
uint32_t FieldAlign = CGM.getContext().getTypeAlign(Ty);
|
|
|
|
EltTys.push_back(DBuilder.createMemberType(
|
|
|
|
Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign,
|
|
|
|
FieldOffset, llvm::DINode::FlagZero, DescTy));
|
|
|
|
FieldOffset += FieldSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FieldOffset;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const BlockPointerType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 8> EltTys;
|
2012-12-18 22:30:41 +08:00
|
|
|
QualType FType;
|
2018-08-08 23:56:12 +08:00
|
|
|
uint64_t FieldOffset;
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray Elements;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
FieldOffset = 0;
|
|
|
|
FType = CGM.getContext().UnsignedLongTy;
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "reserved", &FieldOffset));
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "Size", &FieldOffset));
|
|
|
|
|
|
|
|
Elements = DBuilder.getOrCreateArray(EltTys);
|
|
|
|
EltTys.clear();
|
|
|
|
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-04-21 02:51:48 +08:00
|
|
|
auto *EltTy =
|
2018-08-08 23:56:12 +08:00
|
|
|
DBuilder.createStructType(Unit, "__block_descriptor", nullptr, 0,
|
2015-04-21 02:51:48 +08:00
|
|
|
FieldOffset, 0, Flags, nullptr, Elements);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Bit size, align and offset of the type.
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
|
|
|
|
2015-04-21 02:51:48 +08:00
|
|
|
auto *DescTy = DBuilder.createPointerType(EltTy, Size);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2018-08-08 23:56:12 +08:00
|
|
|
FieldOffset = collectDefaultElementTypesForBlockPointer(Ty, Unit, DescTy,
|
|
|
|
0, EltTys);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
Elements = DBuilder.getOrCreateArray(EltTys);
|
|
|
|
|
2015-07-07 08:49:35 +08:00
|
|
|
// The __block_literal_generic structs are marked with a special
|
|
|
|
// DW_AT_APPLE_BLOCK attribute and are an implementation detail only
|
|
|
|
// the debugger needs to know about. To allow type uniquing, emit
|
|
|
|
// them without a name or a location.
|
2018-08-08 23:56:12 +08:00
|
|
|
EltTy = DBuilder.createStructType(Unit, "", nullptr, 0, FieldOffset, 0,
|
2018-06-28 18:56:40 +08:00
|
|
|
Flags, nullptr, Elements);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-07 08:49:35 +08:00
|
|
|
return DBuilder.createPointerType(EltTy, Size);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2014-04-07 01:14:06 +08:00
|
|
|
assert(Ty->isTypeAlias());
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *Src = getOrCreateType(Ty->getAliasedType(), Unit);
|
2014-04-07 01:14:06 +08:00
|
|
|
|
2019-06-08 08:01:21 +08:00
|
|
|
auto *AliasDecl =
|
|
|
|
cast<TypeAliasTemplateDecl>(Ty->getTemplateName().getAsTemplateDecl())
|
|
|
|
->getTemplatedDecl();
|
|
|
|
|
|
|
|
if (AliasDecl->hasAttr<NoDebugAttr>())
|
|
|
|
return Src;
|
|
|
|
|
2014-04-07 01:14:06 +08:00
|
|
|
SmallString<128> NS;
|
|
|
|
llvm::raw_svector_ostream OS(NS);
|
2017-11-29 00:14:14 +08:00
|
|
|
Ty->getTemplateName().print(OS, getPrintingPolicy(), /*qualified*/ false);
|
|
|
|
printTemplateArgumentList(OS, Ty->template_arguments(), getPrintingPolicy());
|
2014-04-07 01:14:06 +08:00
|
|
|
|
|
|
|
SourceLocation Loc = AliasDecl->getLocation();
|
2015-09-12 02:45:02 +08:00
|
|
|
return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),
|
|
|
|
getLineNumber(Loc),
|
|
|
|
getDeclContextDescriptor(AliasDecl));
|
2014-04-07 01:14:06 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2019-06-08 08:01:21 +08:00
|
|
|
llvm::DIType *Underlying =
|
|
|
|
getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit);
|
|
|
|
|
|
|
|
if (Ty->getDecl()->hasAttr<NoDebugAttr>())
|
|
|
|
return Underlying;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// We don't set size information, but do specify where the typedef was
|
|
|
|
// declared.
|
2016-04-30 09:44:38 +08:00
|
|
|
SourceLocation Loc = Ty->getDecl()->getLocation();
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2015-04-17 00:36:45 +08:00
|
|
|
// Typedefs are derived from some other type.
|
2019-06-08 08:01:21 +08:00
|
|
|
return DBuilder.createTypedef(Underlying, Ty->getDecl()->getName(),
|
|
|
|
getOrCreateFile(Loc), getLineNumber(Loc),
|
|
|
|
getDeclContextDescriptor(Ty->getDecl()));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2016-06-09 04:41:54 +08:00
|
|
|
static unsigned getDwarfCC(CallingConv CC) {
|
|
|
|
switch (CC) {
|
|
|
|
case CC_C:
|
|
|
|
// Avoid emitting DW_AT_calling_convention if the C convention was used.
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case CC_X86StdCall:
|
|
|
|
return llvm::dwarf::DW_CC_BORLAND_stdcall;
|
|
|
|
case CC_X86FastCall:
|
|
|
|
return llvm::dwarf::DW_CC_BORLAND_msfastcall;
|
|
|
|
case CC_X86ThisCall:
|
|
|
|
return llvm::dwarf::DW_CC_BORLAND_thiscall;
|
|
|
|
case CC_X86VectorCall:
|
|
|
|
return llvm::dwarf::DW_CC_LLVM_vectorcall;
|
|
|
|
case CC_X86Pascal:
|
|
|
|
return llvm::dwarf::DW_CC_BORLAND_pascal;
|
2017-07-18 04:49:45 +08:00
|
|
|
case CC_Win64:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_Win64;
|
2016-06-09 04:41:54 +08:00
|
|
|
case CC_X86_64SysV:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_X86_64SysV;
|
2016-06-09 04:41:54 +08:00
|
|
|
case CC_AAPCS:
|
2018-11-27 00:38:37 +08:00
|
|
|
case CC_AArch64VectorCall:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_AAPCS;
|
2016-06-09 04:41:54 +08:00
|
|
|
case CC_AAPCS_VFP:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_AAPCS_VFP;
|
2016-06-09 04:41:54 +08:00
|
|
|
case CC_IntelOclBicc:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_IntelOclBicc;
|
2016-06-09 04:41:54 +08:00
|
|
|
case CC_SpirFunction:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_SpirFunction;
|
2016-06-30 17:06:33 +08:00
|
|
|
case CC_OpenCLKernel:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_OpenCLKernel;
|
2016-06-09 04:41:54 +08:00
|
|
|
case CC_Swift:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_Swift;
|
2016-06-09 04:41:54 +08:00
|
|
|
case CC_PreserveMost:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_PreserveMost;
|
2016-06-09 04:41:54 +08:00
|
|
|
case CC_PreserveAll:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_PreserveAll;
|
2016-11-03 02:29:35 +08:00
|
|
|
case CC_X86RegCall:
|
2018-03-22 21:53:30 +08:00
|
|
|
return llvm::dwarf::DW_CC_LLVM_X86RegCall;
|
2016-06-09 04:41:54 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 16> EltTys;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Add the result type at least.
|
2014-01-26 00:55:45 +08:00
|
|
|
EltTys.push_back(getOrCreateType(Ty->getReturnType(), Unit));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Set up remainder of arguments if there is a prototype.
|
2014-02-26 07:42:18 +08:00
|
|
|
// otherwise emit it as a variadic function.
|
2012-12-18 22:30:41 +08:00
|
|
|
if (isa<FunctionNoProtoType>(Ty))
|
|
|
|
EltTys.push_back(DBuilder.createUnspecifiedParameter());
|
2016-07-17 08:39:12 +08:00
|
|
|
else if (const auto *FPT = dyn_cast<FunctionProtoType>(Ty)) {
|
|
|
|
for (const QualType &ParamType : FPT->param_types())
|
|
|
|
EltTys.push_back(getOrCreateType(ParamType, Unit));
|
2014-02-26 03:38:11 +08:00
|
|
|
if (FPT->isVariadic())
|
|
|
|
EltTys.push_back(DBuilder.createUnspecifiedParameter());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
|
2016-09-06 18:48:04 +08:00
|
|
|
return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
|
2016-06-09 04:41:54 +08:00
|
|
|
getDwarfCC(Ty->getCallConv()));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
/// Convert an AccessSpecifier into the corresponding DINode flag.
|
2014-08-30 06:44:27 +08:00
|
|
|
/// As an optimization, return 0 if the access specifier equals the
|
|
|
|
/// default for the containing type.
|
2016-09-07 01:06:14 +08:00
|
|
|
static llvm::DINode::DIFlags getAccessFlag(AccessSpecifier Access,
|
|
|
|
const RecordDecl *RD) {
|
2014-08-30 06:44:27 +08:00
|
|
|
AccessSpecifier Default = clang::AS_none;
|
|
|
|
if (RD && RD->isClass())
|
|
|
|
Default = clang::AS_private;
|
|
|
|
else if (RD && (RD->isStruct() || RD->isUnion()))
|
|
|
|
Default = clang::AS_public;
|
|
|
|
|
|
|
|
if (Access == Default)
|
2016-09-06 18:48:04 +08:00
|
|
|
return llvm::DINode::FlagZero;
|
2014-08-30 06:44:27 +08:00
|
|
|
|
2014-10-27 07:40:33 +08:00
|
|
|
switch (Access) {
|
|
|
|
case clang::AS_private:
|
2015-04-30 00:40:08 +08:00
|
|
|
return llvm::DINode::FlagPrivate;
|
2014-10-27 07:40:33 +08:00
|
|
|
case clang::AS_protected:
|
2015-04-30 00:40:08 +08:00
|
|
|
return llvm::DINode::FlagProtected;
|
2014-10-27 07:40:33 +08:00
|
|
|
case clang::AS_public:
|
2015-04-30 00:40:08 +08:00
|
|
|
return llvm::DINode::FlagPublic;
|
2014-10-27 07:40:33 +08:00
|
|
|
case clang::AS_none:
|
2016-09-06 18:48:04 +08:00
|
|
|
return llvm::DINode::FlagZero;
|
2014-08-30 06:44:27 +08:00
|
|
|
}
|
|
|
|
llvm_unreachable("unexpected access enumerator");
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-06-30 11:01:59 +08:00
|
|
|
llvm::DIType *CGDebugInfo::createBitFieldType(const FieldDecl *BitFieldDecl,
|
|
|
|
llvm::DIScope *RecordTy,
|
|
|
|
const RecordDecl *RD) {
|
|
|
|
StringRef Name = BitFieldDecl->getName();
|
|
|
|
QualType Ty = BitFieldDecl->getType();
|
|
|
|
SourceLocation Loc = BitFieldDecl->getLocation();
|
|
|
|
llvm::DIFile *VUnit = getOrCreateFile(Loc);
|
|
|
|
llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
|
|
|
|
|
|
|
|
// Get the location for the field.
|
|
|
|
llvm::DIFile *File = getOrCreateFile(Loc);
|
|
|
|
unsigned Line = getLineNumber(Loc);
|
|
|
|
|
|
|
|
const CGBitFieldInfo &BitFieldInfo =
|
|
|
|
CGM.getTypes().getCGRecordLayout(RD).getBitFieldInfo(BitFieldDecl);
|
|
|
|
uint64_t SizeInBits = BitFieldInfo.Size;
|
|
|
|
assert(SizeInBits > 0 && "found named 0-width bitfield");
|
|
|
|
uint64_t StorageOffsetInBits =
|
|
|
|
CGM.getContext().toBits(BitFieldInfo.StorageOffset);
|
Correct debug info bit offset calculation for big-endian targets
Summary:
The change "[CodeView] Implement support for bit fields in
Clang" (r274201, https://reviews.llvm.org/rL274201) broke the
calculation of bit offsets for the debug info describing bitfields on
big-endian targets.
Prior to commit r274201 the debug info for bitfields got their offsets
from the ASTRecordLayout in CGDebugInfo::CollectRecordFields(), the
current field offset was then passed on to
CGDebugInfo::CollectRecordNormalField() and used directly in the
DIDerivedType.
Since commit r274201, the bit offset ending up in the DIDerivedType no
longer comes directly from the ASTRecordLayout. Instead
CGDebugInfo::CollectRecordNormalField() calls the new method
CGDebugInfo::createBitFieldType(), which in turn calls
CodeGenTypes::getCGRecordLayout().getBitFieldInfo() to fetch a
CGBitFieldInfo describing the field. The 'Offset' member of
CGBitFieldInfo is then used to calculate the bit offset of the
DIDerivedType. Unfortunately the previous and current method of
calculating the bit offset are only equivalent for little endian
targets, as CGRecordLowering::setBitFieldInfo() reverses the bit
offsets for big endian targets as the last thing it does.
A simple reproducer for this error is the following module:
struct fields {
unsigned a : 4;
unsigned b : 4;
} flags = {0x0f, 0x1};
Compiled for Mips, with commit r274200 both the DIDerivedType bit
offsets on the IR-level and the DWARF information on the ELF-level
will have the expected values: the offsets of 'a' and 'b' are 0 and 4
respectively. With r274201 the offsets are switched to 4 and 0. By
noting that the static initialization of 'flags' in both cases is the
same, we can eliminate a change in record layout as the cause of the
change in the debug info. Also compiling this example with gcc,
produces the same record layout and debug info as commit r274200.
In order to restore the previous function we extend
CGDebugInfo::createBitFieldType() to compensate for the reversal done
in CGRecordLowering::setBitFieldInfo().
Patch by Frej Drejhammar!
Reviewers: cfe-commits, majnemer, rnk, aaboud, echristo, aprantl
Reviewed By: rnk, aprantl
Subscribers: aprantl, arichardson, frej
Differential Revision: https://reviews.llvm.org/D32745
llvm-svn: 305224
2017-06-13 03:57:56 +08:00
|
|
|
uint64_t Offset = BitFieldInfo.Offset;
|
|
|
|
// The bit offsets for big endian machines are reversed for big
|
|
|
|
// endian target, compensate for that as the DIDerivedType requires
|
|
|
|
// un-reversed offsets.
|
|
|
|
if (CGM.getDataLayout().isBigEndian())
|
|
|
|
Offset = BitFieldInfo.StorageSize - BitFieldInfo.Size - Offset;
|
|
|
|
uint64_t OffsetInBits = StorageOffsetInBits + Offset;
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = getAccessFlag(BitFieldDecl->getAccess(), RD);
|
2016-06-30 11:01:59 +08:00
|
|
|
return DBuilder.createBitFieldMemberType(
|
2016-10-20 08:13:19 +08:00
|
|
|
RecordTy, Name, File, Line, SizeInBits, OffsetInBits, StorageOffsetInBits,
|
|
|
|
Flags, DebugType);
|
2016-06-30 11:01:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType *
|
|
|
|
CGDebugInfo::createFieldType(StringRef name, QualType type, SourceLocation loc,
|
|
|
|
AccessSpecifier AS, uint64_t offsetInBits,
|
2016-10-20 08:13:19 +08:00
|
|
|
uint32_t AlignInBits, llvm::DIFile *tunit,
|
|
|
|
llvm::DIScope *scope, const RecordDecl *RD) {
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *debugType = getOrCreateType(type, tunit);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Get the location for the field.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *file = getOrCreateFile(loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned line = getLineNumber(loc);
|
|
|
|
|
2014-07-30 09:30:47 +08:00
|
|
|
uint64_t SizeInBits = 0;
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = AlignInBits;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!type->isIncompleteArrayType()) {
|
2014-07-30 09:30:47 +08:00
|
|
|
TypeInfo TI = CGM.getContext().getTypeInfo(type);
|
|
|
|
SizeInBits = TI.Width;
|
2016-10-20 08:13:19 +08:00
|
|
|
if (!Align)
|
|
|
|
Align = getTypeAlignIfRequired(type, CGM.getContext());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags flags = getAccessFlag(AS, RD);
|
2018-06-28 18:56:40 +08:00
|
|
|
return DBuilder.createMemberType(scope, name, file, line, SizeInBits, Align,
|
|
|
|
offsetInBits, flags, debugType);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
void CGDebugInfo::CollectRecordLambdaFields(
|
|
|
|
const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *RecordTy) {
|
2013-01-16 09:22:32 +08:00
|
|
|
// For C++11 Lambdas a Field will be the same as a Capture, but the Capture
|
|
|
|
// has the name and the location of the variable so we should iterate over
|
|
|
|
// both concurrently.
|
|
|
|
const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(CXXDecl);
|
|
|
|
RecordDecl::field_iterator Field = CXXDecl->field_begin();
|
|
|
|
unsigned fieldno = 0;
|
|
|
|
for (CXXRecordDecl::capture_const_iterator I = CXXDecl->captures_begin(),
|
2014-10-27 07:40:33 +08:00
|
|
|
E = CXXDecl->captures_end();
|
|
|
|
I != E; ++I, ++Field, ++fieldno) {
|
2014-05-11 00:31:55 +08:00
|
|
|
const LambdaCapture &C = *I;
|
2013-01-16 09:22:32 +08:00
|
|
|
if (C.capturesVariable()) {
|
2016-06-30 11:01:59 +08:00
|
|
|
SourceLocation Loc = C.getLocation();
|
|
|
|
assert(!Field->isBitField() && "lambdas don't have bitfield members!");
|
2013-01-16 09:22:32 +08:00
|
|
|
VarDecl *V = C.getCapturedVar();
|
|
|
|
StringRef VName = V->getName();
|
2016-06-30 11:01:59 +08:00
|
|
|
llvm::DIFile *VUnit = getOrCreateFile(Loc);
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getDeclAlignIfRequired(V, CGM.getContext());
|
2016-06-30 11:01:59 +08:00
|
|
|
llvm::DIType *FieldType = createFieldType(
|
|
|
|
VName, Field->getType(), Loc, Field->getAccess(),
|
2016-10-20 08:13:19 +08:00
|
|
|
layout.getFieldOffset(fieldno), Align, VUnit, RecordTy, CXXDecl);
|
2016-06-30 11:01:59 +08:00
|
|
|
elements.push_back(FieldType);
|
2014-08-28 12:28:19 +08:00
|
|
|
} else if (C.capturesThis()) {
|
2013-01-16 09:22:32 +08:00
|
|
|
// TODO: Need to handle 'this' in some way by probably renaming the
|
|
|
|
// this of the lambda class and having a field member of 'this' or
|
|
|
|
// by using AT_object_pointer for the function and having that be
|
|
|
|
// used as 'this' for semantic references.
|
|
|
|
FieldDecl *f = *Field;
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
|
2013-01-16 09:22:32 +08:00
|
|
|
QualType type = f->getType();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *fieldType = createFieldType(
|
2016-06-30 11:01:59 +08:00
|
|
|
"this", type, f->getLocation(), f->getAccess(),
|
2014-10-27 07:40:33 +08:00
|
|
|
layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
|
2013-01-16 09:22:32 +08:00
|
|
|
|
|
|
|
elements.push_back(fieldType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIDerivedType *
|
|
|
|
CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy,
|
2015-04-21 05:17:26 +08:00
|
|
|
const RecordDecl *RD) {
|
2013-01-16 09:22:32 +08:00
|
|
|
// Create the descriptor for the static variable, with or without
|
|
|
|
// constant initializers.
|
2014-10-15 06:22:17 +08:00
|
|
|
Var = Var->getCanonicalDecl();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *VUnit = getOrCreateFile(Var->getLocation());
|
|
|
|
llvm::DIType *VTy = getOrCreateType(Var->getType(), VUnit);
|
2013-01-16 09:22:32 +08:00
|
|
|
|
|
|
|
unsigned LineNumber = getLineNumber(Var->getLocation());
|
|
|
|
StringRef VName = Var->getName();
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Constant *C = nullptr;
|
2013-01-16 09:22:32 +08:00
|
|
|
if (Var->getInit()) {
|
|
|
|
const APValue *Value = Var->evaluateValue();
|
2013-01-20 09:19:17 +08:00
|
|
|
if (Value) {
|
|
|
|
if (Value->isInt())
|
|
|
|
C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt());
|
|
|
|
if (Value->isFloat())
|
|
|
|
C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat());
|
|
|
|
}
|
2013-01-16 09:22:32 +08:00
|
|
|
}
|
|
|
|
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
|
2016-10-20 08:13:19 +08:00
|
|
|
RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Align);
|
2014-12-10 02:39:32 +08:00
|
|
|
StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
|
2013-08-16 06:50:29 +08:00
|
|
|
return GV;
|
2013-01-16 09:22:32 +08:00
|
|
|
}
|
|
|
|
|
2014-10-27 07:40:33 +08:00
|
|
|
void CGDebugInfo::CollectRecordNormalField(
|
2015-04-30 00:40:08 +08:00
|
|
|
const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
|
|
|
|
SmallVectorImpl<llvm::Metadata *> &elements, llvm::DIType *RecordTy,
|
2014-10-27 07:40:33 +08:00
|
|
|
const RecordDecl *RD) {
|
2013-01-16 09:22:32 +08:00
|
|
|
StringRef name = field->getName();
|
|
|
|
QualType type = field->getType();
|
|
|
|
|
|
|
|
// Ignore unnamed fields unless they're anonymous structs/unions.
|
|
|
|
if (name.empty() && !type->isRecordType())
|
|
|
|
return;
|
|
|
|
|
2016-06-30 11:01:59 +08:00
|
|
|
llvm::DIType *FieldType;
|
2013-01-16 09:22:32 +08:00
|
|
|
if (field->isBitField()) {
|
2016-06-30 11:01:59 +08:00
|
|
|
FieldType = createBitFieldType(field, RecordTy, RD);
|
|
|
|
} else {
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getDeclAlignIfRequired(field, CGM.getContext());
|
2016-06-30 11:01:59 +08:00
|
|
|
FieldType =
|
|
|
|
createFieldType(name, type, field->getLocation(), field->getAccess(),
|
2016-10-20 08:13:19 +08:00
|
|
|
OffsetInBits, Align, tunit, RecordTy, RD);
|
2013-01-16 09:22:32 +08:00
|
|
|
}
|
|
|
|
|
2016-06-30 11:01:59 +08:00
|
|
|
elements.push_back(FieldType);
|
2013-01-16 09:22:32 +08:00
|
|
|
}
|
|
|
|
|
2017-08-09 04:30:14 +08:00
|
|
|
void CGDebugInfo::CollectRecordNestedType(
|
|
|
|
const TypeDecl *TD, SmallVectorImpl<llvm::Metadata *> &elements) {
|
|
|
|
QualType Ty = CGM.getContext().getTypeDeclType(TD);
|
2016-08-02 02:56:13 +08:00
|
|
|
// Injected class names are not considered nested records.
|
|
|
|
if (isa<InjectedClassNameType>(Ty))
|
|
|
|
return;
|
2017-08-09 04:30:14 +08:00
|
|
|
SourceLocation Loc = TD->getLocation();
|
2016-07-22 02:43:20 +08:00
|
|
|
llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc));
|
|
|
|
elements.push_back(nestedType);
|
|
|
|
}
|
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
void CGDebugInfo::CollectRecordFields(
|
2015-04-30 00:40:08 +08:00
|
|
|
const RecordDecl *record, llvm::DIFile *tunit,
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVectorImpl<llvm::Metadata *> &elements,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *RecordTy) {
|
2016-07-17 08:39:12 +08:00
|
|
|
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(record);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-16 09:22:32 +08:00
|
|
|
if (CXXDecl && CXXDecl->isLambda())
|
|
|
|
CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
|
|
|
|
else {
|
|
|
|
const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record);
|
|
|
|
|
|
|
|
// Field number for non-static fields.
|
2013-01-05 01:59:07 +08:00
|
|
|
unsigned fieldNo = 0;
|
2013-01-16 09:22:32 +08:00
|
|
|
|
|
|
|
// Static and non-static members should appear in the same order as
|
|
|
|
// the corresponding declarations in the source program.
|
2014-03-08 03:56:05 +08:00
|
|
|
for (const auto *I : record->decls())
|
|
|
|
if (const auto *V = dyn_cast<VarDecl>(I)) {
|
2016-04-28 01:37:12 +08:00
|
|
|
if (V->hasAttr<NoDebugAttr>())
|
|
|
|
continue;
|
2018-07-21 04:55:00 +08:00
|
|
|
|
|
|
|
// Skip variable template specializations when emitting CodeView. MSVC
|
|
|
|
// doesn't emit them.
|
|
|
|
if (CGM.getCodeGenOpts().EmitCodeView &&
|
|
|
|
isa<VarTemplateSpecializationDecl>(V))
|
|
|
|
continue;
|
|
|
|
|
2019-06-18 03:40:52 +08:00
|
|
|
if (isa<VarTemplatePartialSpecializationDecl>(V))
|
|
|
|
continue;
|
|
|
|
|
2013-08-21 05:49:21 +08:00
|
|
|
// Reuse the existing static member declaration if one exists
|
2014-12-10 02:39:32 +08:00
|
|
|
auto MI = StaticDataMemberCache.find(V->getCanonicalDecl());
|
2013-08-21 05:49:21 +08:00
|
|
|
if (MI != StaticDataMemberCache.end()) {
|
|
|
|
assert(MI->second &&
|
|
|
|
"Static data member declaration should still exist");
|
2015-07-25 02:05:58 +08:00
|
|
|
elements.push_back(MI->second);
|
2014-08-30 06:44:27 +08:00
|
|
|
} else {
|
|
|
|
auto Field = CreateRecordStaticField(V, RecordTy, record);
|
|
|
|
elements.push_back(Field);
|
|
|
|
}
|
2014-03-08 03:56:05 +08:00
|
|
|
} else if (const auto *field = dyn_cast<FieldDecl>(I)) {
|
2014-10-27 07:40:33 +08:00
|
|
|
CollectRecordNormalField(field, layout.getFieldOffset(fieldNo), tunit,
|
|
|
|
elements, RecordTy, record);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-16 09:22:32 +08:00
|
|
|
// Bump field number for next field.
|
|
|
|
++fieldNo;
|
2018-07-21 04:55:00 +08:00
|
|
|
} else if (CGM.getCodeGenOpts().EmitCodeView) {
|
|
|
|
// Debug info for nested types is included in the member list only for
|
|
|
|
// CodeView.
|
2017-08-09 04:30:14 +08:00
|
|
|
if (const auto *nestedType = dyn_cast<TypeDecl>(I))
|
|
|
|
if (!nestedType->isImplicit() &&
|
|
|
|
nestedType->getDeclContext() == record)
|
|
|
|
CollectRecordNestedType(nestedType, elements);
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubroutineType *
|
2012-12-18 22:30:41 +08:00
|
|
|
CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit) {
|
2013-01-08 07:06:35 +08:00
|
|
|
const FunctionProtoType *Func = Method->getType()->getAs<FunctionProtoType>();
|
2013-01-08 06:24:59 +08:00
|
|
|
if (Method->isStatic())
|
2015-04-30 00:40:08 +08:00
|
|
|
return cast_or_null<llvm::DISubroutineType>(
|
2015-04-07 07:21:33 +08:00
|
|
|
getOrCreateType(QualType(Func, 0), Unit));
|
2019-01-11 09:54:53 +08:00
|
|
|
return getOrCreateInstanceMethodType(Method->getThisType(), Func, Unit);
|
2013-01-08 07:06:35 +08:00
|
|
|
}
|
2013-01-08 06:24:59 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
|
|
|
|
QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile *Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Add "this" pointer.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DITypeRefArray Args(
|
|
|
|
cast<llvm::DISubroutineType>(getOrCreateType(QualType(Func, 0), Unit))
|
2015-04-07 07:21:33 +08:00
|
|
|
->getTypeArray());
|
2015-04-07 12:14:45 +08:00
|
|
|
assert(Args.size() && "Invalid number of arguments!");
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 16> Elts;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// First element is always return type. For 'void' functions it is NULL.
|
2015-04-08 02:41:26 +08:00
|
|
|
Elts.push_back(Args[0]);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-08 06:24:59 +08:00
|
|
|
// "this" pointer is always first argument.
|
2013-01-08 07:06:35 +08:00
|
|
|
const CXXRecordDecl *RD = ThisPtr->getPointeeCXXRecordDecl();
|
2013-01-08 06:24:59 +08:00
|
|
|
if (isa<ClassTemplateSpecializationDecl>(RD)) {
|
|
|
|
// Create pointer type directly in this case.
|
|
|
|
const PointerType *ThisPtrTy = cast<PointerType>(ThisPtr);
|
|
|
|
QualType PointeeTy = ThisPtrTy->getPointeeType();
|
|
|
|
unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy);
|
2013-04-17 06:48:15 +08:00
|
|
|
uint64_t Size = CGM.getTarget().getPointerWidth(AS);
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getTypeAlignIfRequired(ThisPtrTy, CGM.getContext());
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *PointeeType = getOrCreateType(PointeeTy, Unit);
|
|
|
|
llvm::DIType *ThisPtrType =
|
2014-10-27 07:40:33 +08:00
|
|
|
DBuilder.createPointerType(PointeeType, Size, Align);
|
2014-12-10 02:39:32 +08:00
|
|
|
TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
|
2013-01-08 06:24:59 +08:00
|
|
|
// TODO: This and the artificial type below are misleading, the
|
|
|
|
// types aren't artificial the argument is, but the current
|
|
|
|
// metadata doesn't represent that.
|
|
|
|
ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
|
|
|
|
Elts.push_back(ThisPtrType);
|
|
|
|
} else {
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
|
2014-12-10 02:39:32 +08:00
|
|
|
TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
|
2013-01-08 06:24:59 +08:00
|
|
|
ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
|
|
|
|
Elts.push_back(ThisPtrType);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy rest of the arguments.
|
2015-04-07 12:14:45 +08:00
|
|
|
for (unsigned i = 1, e = Args.size(); i != e; ++i)
|
|
|
|
Elts.push_back(Args[i]);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
|
2013-12-19 05:48:18 +08:00
|
|
|
if (Func->getExtProtoInfo().RefQualifier == RQ_LValue)
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagLValueReference;
|
2013-12-19 05:48:18 +08:00
|
|
|
if (Func->getExtProtoInfo().RefQualifier == RQ_RValue)
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagRValueReference;
|
2013-12-19 05:48:18 +08:00
|
|
|
|
2016-06-09 04:41:54 +08:00
|
|
|
return DBuilder.createSubroutineType(EltTypeArray, Flags,
|
|
|
|
getDwarfCC(Func->getCallConv()));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
/// isFunctionLocalClass - Return true if CXXRecordDecl is defined
|
2012-12-18 22:30:41 +08:00
|
|
|
/// inside a function.
|
|
|
|
static bool isFunctionLocalClass(const CXXRecordDecl *RD) {
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *NRD = dyn_cast<CXXRecordDecl>(RD->getDeclContext()))
|
2012-12-18 22:30:41 +08:00
|
|
|
return isFunctionLocalClass(NRD);
|
|
|
|
if (isa<FunctionDecl>(RD->getDeclContext()))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
|
|
|
|
const CXXMethodDecl *Method, llvm::DIFile *Unit, llvm::DIType *RecordTy) {
|
2013-05-16 08:45:12 +08:00
|
|
|
bool IsCtorOrDtor =
|
2014-10-27 07:40:33 +08:00
|
|
|
isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef MethodName = getFunctionName(Method);
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Since a single ctor/dtor corresponds to multiple functions, it doesn't
|
|
|
|
// make sense to give a single ctor/dtor a linkage name.
|
|
|
|
StringRef MethodLinkageName;
|
2016-04-13 05:22:48 +08:00
|
|
|
// FIXME: 'isFunctionLocalClass' seems like an arbitrary/unintentional
|
|
|
|
// property to use here. It may've been intended to model "is non-external
|
|
|
|
// type" but misses cases of non-function-local but non-external classes such
|
|
|
|
// as those in anonymous namespaces as well as the reverse - external types
|
|
|
|
// that are function local, such as those in (non-local) inline functions.
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!IsCtorOrDtor && !isFunctionLocalClass(Method->getParent()))
|
|
|
|
MethodLinkageName = CGM.getMangledName(Method);
|
|
|
|
|
|
|
|
// Get the location for the method.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *MethodDefUnit = nullptr;
|
2013-08-19 11:37:48 +08:00
|
|
|
unsigned MethodLine = 0;
|
|
|
|
if (!Method->isImplicit()) {
|
|
|
|
MethodDefUnit = getOrCreateFile(Method->getLocation());
|
|
|
|
MethodLine = getLineNumber(Method->getLocation());
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Collect virtual method info.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *ContainingType = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned VIndex = 0;
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
|
2018-11-20 02:29:28 +08:00
|
|
|
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
|
2016-07-01 10:41:25 +08:00
|
|
|
int ThisAdjustment = 0;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Method->isVirtual()) {
|
|
|
|
if (Method->isPure())
|
2018-11-20 02:29:28 +08:00
|
|
|
SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
|
2012-12-18 22:30:41 +08:00
|
|
|
else
|
2018-11-20 02:29:28 +08:00
|
|
|
SPFlags |= llvm::DISubprogram::SPFlagVirtual;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2016-06-17 04:08:51 +08:00
|
|
|
if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
|
|
|
|
// It doesn't make sense to give a virtual destructor a vtable index,
|
|
|
|
// since a single destructor has two entries in the vtable.
|
|
|
|
if (!isa<CXXDestructorDecl>(Method))
|
|
|
|
VIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(Method);
|
|
|
|
} else {
|
|
|
|
// Emit MS ABI vftable information. There is only one entry for the
|
|
|
|
// deleting dtor.
|
|
|
|
const auto *DD = dyn_cast<CXXDestructorDecl>(Method);
|
|
|
|
GlobalDecl GD = DD ? GlobalDecl(DD, Dtor_Deleting) : GlobalDecl(Method);
|
2018-04-03 04:00:39 +08:00
|
|
|
MethodVFTableLocation ML =
|
2016-06-17 04:08:51 +08:00
|
|
|
CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
|
|
|
|
VIndex = ML.Index;
|
2016-06-23 02:34:45 +08:00
|
|
|
|
|
|
|
// CodeView only records the vftable offset in the class that introduces
|
|
|
|
// the virtual method. This is possible because, unlike Itanium, the MS
|
|
|
|
// 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.
|
2017-12-18 07:52:45 +08:00
|
|
|
if (Method->size_overridden_methods() == 0)
|
2016-06-23 02:34:45 +08:00
|
|
|
Flags |= llvm::DINode::FlagIntroducedVirtual;
|
|
|
|
|
2016-07-01 10:41:25 +08:00
|
|
|
// The 'this' adjustment accounts for both the virtual and non-virtual
|
|
|
|
// portions of the adjustment. Presumably the debugger only uses it when
|
|
|
|
// it knows the dynamic type of an object.
|
|
|
|
ThisAdjustment = CGM.getCXXABI()
|
|
|
|
.getVirtualFunctionPrologueThisAdjustment(GD)
|
|
|
|
.getQuantity();
|
2016-06-17 04:08:51 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
ContainingType = RecordTy;
|
|
|
|
}
|
|
|
|
|
2017-09-14 04:53:55 +08:00
|
|
|
if (Method->isStatic())
|
|
|
|
Flags |= llvm::DINode::FlagStaticMember;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Method->isImplicit())
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagArtificial;
|
2014-08-30 06:44:27 +08:00
|
|
|
Flags |= getAccessFlag(Method->getAccess(), Method->getParent());
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *CXXC = dyn_cast<CXXConstructorDecl>(Method)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (CXXC->isExplicit())
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagExplicit;
|
2016-07-17 08:39:12 +08:00
|
|
|
} else if (const auto *CXXC = dyn_cast<CXXConversionDecl>(Method)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (CXXC->isExplicit())
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagExplicit;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
if (Method->hasPrototype())
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagPrototyped;
|
2013-12-19 05:48:18 +08:00
|
|
|
if (Method->getRefQualifier() == RQ_LValue)
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagLValueReference;
|
2013-12-19 05:48:18 +08:00
|
|
|
if (Method->getRefQualifier() == RQ_RValue)
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagRValueReference;
|
2018-11-20 02:29:28 +08:00
|
|
|
if (CGM.getLangOpts().Optimize)
|
|
|
|
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
|
|
|
|
llvm::DISubprogram *SP = DBuilder.createMethod(
|
2014-10-27 07:40:33 +08:00
|
|
|
RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
|
2018-11-20 02:29:28 +08:00
|
|
|
MethodTy, VIndex, ThisAdjustment, ContainingType, Flags, SPFlags,
|
2016-07-01 10:41:25 +08:00
|
|
|
TParamsArray.get());
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
SPCache[Method->getCanonicalDecl()].reset(SP);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
return SP;
|
|
|
|
}
|
|
|
|
|
2014-10-27 07:40:33 +08:00
|
|
|
void CGDebugInfo::CollectCXXMemberFunctions(
|
2015-04-30 00:40:08 +08:00
|
|
|
const CXXRecordDecl *RD, llvm::DIFile *Unit,
|
|
|
|
SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy) {
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Since we want more than just the individual member decls if we
|
|
|
|
// have templated functions iterate over every declaration to gather
|
|
|
|
// the functions.
|
2014-10-27 07:40:33 +08:00
|
|
|
for (const auto *I : RD->decls()) {
|
2014-10-06 13:18:55 +08:00
|
|
|
const auto *Method = dyn_cast<CXXMethodDecl>(I);
|
|
|
|
// If the member is implicit, don't add it to the member list. This avoids
|
|
|
|
// the member being added to type units by LLVM, while still allowing it
|
|
|
|
// to be emitted into the type declaration/reference inside the compile
|
|
|
|
// unit.
|
2015-06-26 01:50:43 +08:00
|
|
|
// Ditto 'nodebug' methods, for consistency with CodeGenFunction.cpp.
|
2014-10-06 13:52:27 +08:00
|
|
|
// FIXME: Handle Using(Shadow?)Decls here to create
|
|
|
|
// DW_TAG_imported_declarations inside the class for base decls brought into
|
|
|
|
// derived classes. GDB doesn't seem to notice/leverage these when I tried
|
|
|
|
// it, so I'm not rushing to fix this. (GCC seems to produce them, if
|
|
|
|
// referenced)
|
2015-06-26 01:50:43 +08:00
|
|
|
if (!Method || Method->isImplicit() || Method->hasAttr<NoDebugAttr>())
|
2014-10-06 13:18:55 +08:00
|
|
|
continue;
|
PR16091 continued: Debug Info for member functions with undeduced return types.
So DWARF5 specs out auto deduced return types as DW_TAG_unspecified_type
with DW_AT_name "auto", and GCC implements this somewhat, but it
presents a few problems to do this with Clang.
GCC's implementation only applies to member functions where the auto
return type isn't deduced immediately (ie: member functions of templates
or member functions defined out of line). In the common case of an
inline deduced return type function, GCC emits the DW_AT_type as the
deduced return type.
Currently GDB doesn't seem to behave too well with this debug info - it
treats the return type as 'void', even though the definition of the
function has the correctly deduced return type (I guess it sees the
return type the declaration has, doesn't understand it, and assumes
void). This means the function's ABI might be broken (non-trivial return
types, etc), etc.
Clang, on the other hand doesn't track this particular case of a
deducable return type that is deduced immediately versus one that is
deduced 'later'. So if we implement the DWARF5 representation, all
deducible return type functions would get adverse GDB behavior
(including deduced return type lambda functions, inline deduced return
type functions, etc).
Also, we can't just do this for auto types that are not deduced -
because Clang marks even the declaration's return type as deduced (&
provides the underlying type) once a definition is seen that allows the
deduction. So we have to ignore even deduced types - but we can't do
that for auto variables (because this representation only applies to
function declarations - variables and function definitions need the real
type so the function can be called, etc) so we'd need to add an extra
flag to the type unwrapping/creation code to indicate when we want to
see through deduced types and when we don't. It's also not as simple as
just checking at the top level when building a function type (for one
thing, we reuse the function type building for building function pointer
types which might also have 'auto' in them - but be the type of a
variable instead) because the auto might be arbitrarily deeply nested
("auto &", "auto (*)()", etc...)
So, with all that said, let's do the simple thing that works in existing
debuggers for now and treat these functions the same way we do function
templates and implicit special members: omit them from the member list,
since they can't be correctly called anyway (without knowing the return
type the ABI isn't know and a function call could put the arguments in
the wrong place) so they're not much use to the user.
At some point in the future, when GDB understands the DWARF5
representation better it might be worth plumbing through the extra type
builder handling to avoid looking through AutoType for some callers,
etc...
llvm-svn: 221704
2014-11-12 04:44:45 +08:00
|
|
|
|
|
|
|
if (Method->getType()->getAs<FunctionProtoType>()->getContainedAutoType())
|
|
|
|
continue;
|
|
|
|
|
2014-10-06 13:18:55 +08:00
|
|
|
// Reuse the existing member function declaration if it exists.
|
|
|
|
// It may be associated with the declaration of the type & should be
|
|
|
|
// reused as we're building the definition.
|
|
|
|
//
|
|
|
|
// This situation can arise in the vtable-based debug info reduction where
|
|
|
|
// implicit members are emitted in a non-vtable TU.
|
|
|
|
auto MI = SPCache.find(Method->getCanonicalDecl());
|
|
|
|
EltTys.push_back(MI == SPCache.end()
|
|
|
|
? CreateCXXMemberFunction(Method, Unit, RecordTy)
|
2014-12-10 02:39:32 +08:00
|
|
|
: static_cast<llvm::Metadata *>(MI->second));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
void CGDebugInfo::CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile *Unit,
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVectorImpl<llvm::Metadata *> &EltTys,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *RecordTy) {
|
2016-10-26 06:19:32 +08:00
|
|
|
llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> SeenTypes;
|
|
|
|
CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->bases(), SeenTypes,
|
|
|
|
llvm::DINode::FlagZero);
|
|
|
|
|
|
|
|
// If we are generating CodeView debug info, we also need to emit records for
|
|
|
|
// indirect virtual base classes.
|
|
|
|
if (CGM.getCodeGenOpts().EmitCodeView) {
|
|
|
|
CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->vbases(), SeenTypes,
|
|
|
|
llvm::DINode::FlagIndirectVirtualBase);
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2016-10-26 06:19:32 +08:00
|
|
|
void CGDebugInfo::CollectCXXBasesAux(
|
|
|
|
const CXXRecordDecl *RD, llvm::DIFile *Unit,
|
|
|
|
SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
|
|
|
|
const CXXRecordDecl::base_class_const_range &Bases,
|
|
|
|
llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
|
|
|
|
llvm::DINode::DIFlags StartingFlags) {
|
|
|
|
const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
|
|
|
|
for (const auto &BI : Bases) {
|
2016-07-17 08:39:12 +08:00
|
|
|
const auto *Base =
|
2014-10-27 07:40:33 +08:00
|
|
|
cast<CXXRecordDecl>(BI.getType()->getAs<RecordType>()->getDecl());
|
2016-10-26 06:19:32 +08:00
|
|
|
if (!SeenTypes.insert(Base).second)
|
|
|
|
continue;
|
|
|
|
auto *BaseTy = getOrCreateType(BI.getType(), Unit);
|
|
|
|
llvm::DINode::DIFlags BFlags = StartingFlags;
|
|
|
|
uint64_t BaseOffset;
|
2018-05-15 05:21:22 +08:00
|
|
|
uint32_t VBPtrOffset = 0;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2014-03-13 23:41:46 +08:00
|
|
|
if (BI.isVirtual()) {
|
2014-08-08 05:29:25 +08:00
|
|
|
if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
|
|
|
|
// virtual base offset offset is -ve. The code generator emits dwarf
|
|
|
|
// expression where it expects +ve number.
|
2014-10-27 07:40:33 +08:00
|
|
|
BaseOffset = 0 - CGM.getItaniumVTableContext()
|
|
|
|
.getVirtualBaseOffsetOffset(RD, Base)
|
|
|
|
.getQuantity();
|
2014-08-08 05:29:25 +08:00
|
|
|
} else {
|
|
|
|
// In the MS ABI, store the vbtable offset, which is analogous to the
|
|
|
|
// vbase offset offset in Itanium.
|
|
|
|
BaseOffset =
|
|
|
|
4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD, Base);
|
2018-06-28 18:56:40 +08:00
|
|
|
VBPtrOffset = CGM.getContext()
|
|
|
|
.getASTRecordLayout(RD)
|
|
|
|
.getVBPtrOffset()
|
|
|
|
.getQuantity();
|
2014-08-08 05:29:25 +08:00
|
|
|
}
|
2016-10-26 06:19:32 +08:00
|
|
|
BFlags |= llvm::DINode::FlagVirtual;
|
2012-12-18 22:30:41 +08:00
|
|
|
} else
|
|
|
|
BaseOffset = CGM.getContext().toBits(RL.getBaseClassOffset(Base));
|
|
|
|
// FIXME: Inconsistent units for BaseOffset. It is in bytes when
|
|
|
|
// BI->isVirtual() and bits when not.
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2014-08-30 06:44:27 +08:00
|
|
|
BFlags |= getAccessFlag(BI.getAccessSpecifier(), RD);
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::DIType *DTy = DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset,
|
|
|
|
VBPtrOffset, BFlags);
|
2012-12-18 22:30:41 +08:00
|
|
|
EltTys.push_back(DTy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray
|
2014-10-27 07:40:33 +08:00
|
|
|
CGDebugInfo::CollectTemplateParams(const TemplateParameterList *TPList,
|
|
|
|
ArrayRef<TemplateArgument> TAList,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit) {
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 16> TemplateParams;
|
2012-12-18 22:30:41 +08:00
|
|
|
for (unsigned i = 0, e = TAList.size(); i != e; ++i) {
|
|
|
|
const TemplateArgument &TA = TAList[i];
|
2013-06-23 02:59:18 +08:00
|
|
|
StringRef Name;
|
|
|
|
if (TPList)
|
|
|
|
Name = TPList->getParam(i)->getName();
|
2013-05-11 05:53:14 +08:00
|
|
|
switch (TA.getKind()) {
|
|
|
|
case TemplateArgument::Type: {
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
|
2015-04-22 02:43:54 +08:00
|
|
|
TemplateParams.push_back(
|
|
|
|
DBuilder.createTemplateTypeParameter(TheCU, Name, TTy));
|
2013-05-11 05:53:14 +08:00
|
|
|
} break;
|
|
|
|
case TemplateArgument::Integral: {
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
|
2015-04-22 02:43:54 +08:00
|
|
|
TemplateParams.push_back(DBuilder.createTemplateValueParameter(
|
|
|
|
TheCU, Name, TTy,
|
|
|
|
llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral())));
|
2013-05-11 05:53:14 +08:00
|
|
|
} break;
|
|
|
|
case TemplateArgument::Declaration: {
|
|
|
|
const ValueDecl *D = TA.getAsDecl();
|
2014-10-18 10:21:26 +08:00
|
|
|
QualType T = TA.getParamTypeForDecl().getDesugaredType(CGM.getContext());
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *TTy = getOrCreateType(T, Unit);
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::Constant *V = nullptr;
|
2019-03-07 05:16:27 +08:00
|
|
|
// Skip retrieve the value if that template parameter has cuda device
|
|
|
|
// attribute, i.e. that value is not available at the host side.
|
|
|
|
if (!CGM.getLangOpts().CUDA || CGM.getLangOpts().CUDAIsDevice ||
|
|
|
|
!D->hasAttr<CUDADeviceAttr>()) {
|
|
|
|
const CXXMethodDecl *MD;
|
|
|
|
// Variable pointer template parameters have a value that is the address
|
|
|
|
// of the variable.
|
|
|
|
if (const auto *VD = dyn_cast<VarDecl>(D))
|
|
|
|
V = CGM.GetAddrOfGlobalVar(VD);
|
|
|
|
// Member function pointers have special support for building them,
|
|
|
|
// though this is currently unsupported in LLVM CodeGen.
|
|
|
|
else if ((MD = dyn_cast<CXXMethodDecl>(D)) && MD->isInstance())
|
|
|
|
V = CGM.getCXXABI().EmitMemberFunctionPointer(MD);
|
|
|
|
else if (const auto *FD = dyn_cast<FunctionDecl>(D))
|
|
|
|
V = CGM.GetAddrOfFunction(FD);
|
|
|
|
// Member data pointers have special handling too to compute the fixed
|
|
|
|
// offset within the object.
|
|
|
|
else if (const auto *MPT =
|
|
|
|
dyn_cast<MemberPointerType>(T.getTypePtr())) {
|
|
|
|
// These five lines (& possibly the above member function pointer
|
|
|
|
// handling) might be able to be refactored to use similar code in
|
|
|
|
// CodeGenModule::getMemberPointerConstant
|
|
|
|
uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
|
|
|
|
CharUnits chars =
|
|
|
|
CGM.getContext().toCharUnitsFromBits((int64_t)fieldOffset);
|
|
|
|
V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
|
|
|
|
}
|
|
|
|
V = V->stripPointerCasts();
|
2013-05-11 05:53:14 +08:00
|
|
|
}
|
2015-04-22 02:43:54 +08:00
|
|
|
TemplateParams.push_back(DBuilder.createTemplateValueParameter(
|
2019-03-07 05:16:27 +08:00
|
|
|
TheCU, Name, TTy, cast_or_null<llvm::Constant>(V)));
|
2013-05-11 05:53:14 +08:00
|
|
|
} break;
|
|
|
|
case TemplateArgument::NullPtr: {
|
|
|
|
QualType T = TA.getNullPtrType();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *TTy = getOrCreateType(T, Unit);
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::Constant *V = nullptr;
|
2013-05-11 05:53:14 +08:00
|
|
|
// Special case member data pointer null values since they're actually -1
|
|
|
|
// instead of zero.
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *MPT = dyn_cast<MemberPointerType>(T.getTypePtr()))
|
2013-05-11 05:53:14 +08:00
|
|
|
// But treat member function pointers as simple zero integers because
|
|
|
|
// it's easier than having a special case in LLVM's CodeGen. If LLVM
|
|
|
|
// CodeGen grows handling for values of non-null member function
|
|
|
|
// pointers then perhaps we could remove this special case and rely on
|
|
|
|
// EmitNullMemberPointer for member function pointers.
|
|
|
|
if (MPT->isMemberDataPointer())
|
|
|
|
V = CGM.getCXXABI().EmitNullMemberPointer(MPT);
|
|
|
|
if (!V)
|
|
|
|
V = llvm::ConstantInt::get(CGM.Int8Ty, 0);
|
2018-06-28 18:56:40 +08:00
|
|
|
TemplateParams.push_back(
|
|
|
|
DBuilder.createTemplateValueParameter(TheCU, Name, TTy, V));
|
2013-06-23 02:59:18 +08:00
|
|
|
} break;
|
2015-04-22 02:43:54 +08:00
|
|
|
case TemplateArgument::Template:
|
|
|
|
TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
|
2015-04-21 02:51:48 +08:00
|
|
|
TheCU, Name, nullptr,
|
2015-04-22 02:43:54 +08:00
|
|
|
TA.getAsTemplate().getAsTemplateDecl()->getQualifiedNameAsString()));
|
|
|
|
break;
|
|
|
|
case TemplateArgument::Pack:
|
|
|
|
TemplateParams.push_back(DBuilder.createTemplateParameterPack(
|
|
|
|
TheCU, Name, nullptr,
|
|
|
|
CollectTemplateParams(nullptr, TA.getPackAsArray(), Unit)));
|
|
|
|
break;
|
2013-08-24 16:21:10 +08:00
|
|
|
case TemplateArgument::Expression: {
|
|
|
|
const Expr *E = TA.getAsExpr();
|
|
|
|
QualType T = E->getType();
|
2014-10-25 03:49:04 +08:00
|
|
|
if (E->isGLValue())
|
|
|
|
T = CGM.getContext().getLValueReferenceType(T);
|
2017-08-16 05:42:52 +08:00
|
|
|
llvm::Constant *V = ConstantEmitter(CGM).emitAbstract(E, T);
|
2013-08-24 16:21:10 +08:00
|
|
|
assert(V && "Expression in template argument isn't constant");
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *TTy = getOrCreateType(T, Unit);
|
2015-04-22 02:43:54 +08:00
|
|
|
TemplateParams.push_back(DBuilder.createTemplateValueParameter(
|
2016-07-17 08:39:12 +08:00
|
|
|
TheCU, Name, TTy, V->stripPointerCasts()));
|
2013-08-24 16:21:10 +08:00
|
|
|
} break;
|
2013-05-11 07:36:06 +08:00
|
|
|
// And the following should never occur:
|
2013-05-11 05:53:14 +08:00
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
llvm_unreachable(
|
|
|
|
"These argument types shouldn't exist in concrete types");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return DBuilder.getOrCreateArray(TemplateParams);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray
|
2015-04-22 04:07:29 +08:00
|
|
|
CGDebugInfo::CollectFunctionTemplateParams(const FunctionDecl *FD,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (FD->getTemplatedKind() ==
|
|
|
|
FunctionDecl::TK_FunctionTemplateSpecialization) {
|
2014-10-27 07:40:33 +08:00
|
|
|
const TemplateParameterList *TList = FD->getTemplateSpecializationInfo()
|
|
|
|
->getTemplate()
|
|
|
|
->getTemplateParameters();
|
2013-06-23 02:59:18 +08:00
|
|
|
return CollectTemplateParams(
|
|
|
|
TList, FD->getTemplateSpecializationArgs()->asArray(), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2015-04-30 00:40:08 +08:00
|
|
|
return llvm::DINodeArray();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2018-10-04 02:45:04 +08:00
|
|
|
llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(const VarDecl *VL,
|
Use primary template parameter names for variable template debug info
Summary:
Fixes PR41677
Consider:
template <typename LHS, typename RHS> constexpr bool is_same_v = false;
template <typename T> constexpr bool is_same_v<T, T> = true;
template constexpr bool is_same_v<int, int>;
Before this change, when emitting debug info for the
`is_same_v<int, int>` global variable, clang would crash because it
would try to use the template parameter list from the partial
specialization to give parameter names to template arguments. This
doesn't work in general, since a partial specialization can have fewer
arguments than the primary template. Therefore, always use the primary
template. Hypothetically we could try to use the parameter names from
the partial specialization when possible, but it's not clear this really
helps debugging in practice.
Reviewers: JDevlieghere, aprantl, ormris, dblaikie
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61408
llvm-svn: 359809
2019-05-03 01:45:54 +08:00
|
|
|
llvm::DIFile *Unit) {
|
|
|
|
// Always get the full list of parameters, not just the ones from the
|
|
|
|
// specialization. A partial specialization may have fewer parameters than
|
|
|
|
// there are arguments.
|
|
|
|
auto *TS = dyn_cast<VarTemplateSpecializationDecl>(VL);
|
|
|
|
if (!TS)
|
|
|
|
return llvm::DINodeArray();
|
|
|
|
VarTemplateDecl *T = TS->getSpecializedTemplate();
|
|
|
|
const TemplateParameterList *TList = T->getTemplateParameters();
|
|
|
|
auto TA = TS->getTemplateArgs().asArray();
|
|
|
|
return CollectTemplateParams(TList, TA, Unit);
|
2018-10-04 02:45:04 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
|
|
|
|
const ClassTemplateSpecializationDecl *TSpecial, llvm::DIFile *Unit) {
|
Use primary template parameter names for variable template debug info
Summary:
Fixes PR41677
Consider:
template <typename LHS, typename RHS> constexpr bool is_same_v = false;
template <typename T> constexpr bool is_same_v<T, T> = true;
template constexpr bool is_same_v<int, int>;
Before this change, when emitting debug info for the
`is_same_v<int, int>` global variable, clang would crash because it
would try to use the template parameter list from the partial
specialization to give parameter names to template arguments. This
doesn't work in general, since a partial specialization can have fewer
arguments than the primary template. Therefore, always use the primary
template. Hypothetically we could try to use the parameter names from
the partial specialization when possible, but it's not clear this really
helps debugging in practice.
Reviewers: JDevlieghere, aprantl, ormris, dblaikie
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61408
llvm-svn: 359809
2019-05-03 01:45:54 +08:00
|
|
|
// Always get the full list of parameters, not just the ones from the
|
|
|
|
// specialization. A partial specialization may have fewer parameters than
|
|
|
|
// there are arguments.
|
2014-04-17 09:04:01 +08:00
|
|
|
TemplateParameterList *TPList =
|
2014-10-27 07:40:33 +08:00
|
|
|
TSpecial->getSpecializedTemplate()->getTemplateParameters();
|
2014-04-17 08:30:48 +08:00
|
|
|
const TemplateArgumentList &TAList = TSpecial->getTemplateArgs();
|
2013-06-23 02:59:18 +08:00
|
|
|
return CollectTemplateParams(TPList, TAList.asArray(), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
|
2015-04-16 07:48:50 +08:00
|
|
|
if (VTablePtrType)
|
2012-12-18 22:30:41 +08:00
|
|
|
return VTablePtrType;
|
|
|
|
|
|
|
|
ASTContext &Context = CGM.getContext();
|
|
|
|
|
|
|
|
/* Function type */
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::Metadata *STy = getOrCreateType(Context.IntTy, Unit);
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DITypeRefArray SElements = DBuilder.getOrCreateTypeArray(STy);
|
2015-10-15 14:56:08 +08:00
|
|
|
llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Size = Context.getTypeSize(Context.VoidPtrTy);
|
2017-03-09 07:56:48 +08:00
|
|
|
unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
|
|
|
|
Optional<unsigned> DWARFAddressSpace =
|
|
|
|
CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
|
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::DIType *vtbl_ptr_type = DBuilder.createPointerType(
|
|
|
|
SubTy, Size, 0, DWARFAddressSpace, "__vtbl_ptr_type");
|
2012-12-18 22:30:41 +08:00
|
|
|
VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
|
|
|
|
return VTablePtrType;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef CGDebugInfo::getVTableName(const CXXRecordDecl *RD) {
|
2013-09-10 00:39:06 +08:00
|
|
|
// Copy the gdb compatible name on the side and use its reference.
|
|
|
|
return internString("_vptr$", RD->getNameAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2019-04-25 06:45:44 +08:00
|
|
|
StringRef CGDebugInfo::getDynamicInitializerName(const VarDecl *VD,
|
|
|
|
DynamicInitKind StubKind,
|
|
|
|
llvm::Function *InitFn) {
|
|
|
|
// If we're not emitting codeview, use the mangled name. For Itanium, this is
|
|
|
|
// arbitrary.
|
|
|
|
if (!CGM.getCodeGenOpts().EmitCodeView)
|
|
|
|
return InitFn->getName();
|
|
|
|
|
|
|
|
// Print the normal qualified name for the variable, then break off the last
|
|
|
|
// NNS, and add the appropriate other text. Clang always prints the global
|
|
|
|
// variable name without template arguments, so we can use rsplit("::") and
|
|
|
|
// then recombine the pieces.
|
|
|
|
SmallString<128> QualifiedGV;
|
|
|
|
StringRef Quals;
|
|
|
|
StringRef GVName;
|
|
|
|
{
|
|
|
|
llvm::raw_svector_ostream OS(QualifiedGV);
|
|
|
|
VD->printQualifiedName(OS, getPrintingPolicy());
|
|
|
|
std::tie(Quals, GVName) = OS.str().rsplit("::");
|
|
|
|
if (GVName.empty())
|
|
|
|
std::swap(Quals, GVName);
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallString<128> InitName;
|
|
|
|
llvm::raw_svector_ostream OS(InitName);
|
|
|
|
if (!Quals.empty())
|
|
|
|
OS << Quals << "::";
|
|
|
|
|
|
|
|
switch (StubKind) {
|
|
|
|
case DynamicInitKind::NoStub:
|
|
|
|
llvm_unreachable("not an initializer");
|
|
|
|
case DynamicInitKind::Initializer:
|
|
|
|
OS << "`dynamic initializer for '";
|
|
|
|
break;
|
|
|
|
case DynamicInitKind::AtExit:
|
|
|
|
OS << "`dynamic atexit destructor for '";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << GVName;
|
|
|
|
|
|
|
|
// Add any template specialization args.
|
|
|
|
if (const auto *VTpl = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
|
|
|
|
printTemplateArgumentList(OS, VTpl->getTemplateArgs().asArray(),
|
|
|
|
getPrintingPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << '\'';
|
|
|
|
|
|
|
|
return internString(OS.str());
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
void CGDebugInfo::CollectVTableInfo(const CXXRecordDecl *RD, llvm::DIFile *Unit,
|
2016-09-01 00:11:43 +08:00
|
|
|
SmallVectorImpl<llvm::Metadata *> &EltTys,
|
|
|
|
llvm::DICompositeType *RecordTy) {
|
|
|
|
// If this class is not dynamic then there is not any vtable info to collect.
|
|
|
|
if (!RD->isDynamicClass())
|
|
|
|
return;
|
|
|
|
|
2016-09-01 04:35:01 +08:00
|
|
|
// Don't emit any vtable shape or vptr info if this class doesn't have an
|
|
|
|
// extendable vfptr. This can happen if the class doesn't have virtual
|
|
|
|
// methods, or in the MS ABI if those virtual methods only come from virtually
|
|
|
|
// inherited bases.
|
|
|
|
const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
|
|
|
|
if (!RL.hasExtendableVFPtr())
|
|
|
|
return;
|
|
|
|
|
2016-09-01 00:11:43 +08:00
|
|
|
// CodeView needs to know how large the vtable of every dynamic class is, so
|
|
|
|
// emit a special named pointer type into the element list. The vptr type
|
|
|
|
// points to this type as well.
|
|
|
|
llvm::DIType *VPtrTy = nullptr;
|
|
|
|
bool NeedVTableShape = CGM.getCodeGenOpts().EmitCodeView &&
|
|
|
|
CGM.getTarget().getCXXABI().isMicrosoft();
|
|
|
|
if (NeedVTableShape) {
|
|
|
|
uint64_t PtrWidth =
|
|
|
|
CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
|
|
|
|
const VTableLayout &VFTLayout =
|
|
|
|
CGM.getMicrosoftVTableContext().getVFTableLayout(RD, CharUnits::Zero());
|
|
|
|
unsigned VSlotCount =
|
2016-09-08 09:14:39 +08:00
|
|
|
VFTLayout.vtable_components().size() - CGM.getLangOpts().RTTIData;
|
2016-09-01 00:11:43 +08:00
|
|
|
unsigned VTableWidth = PtrWidth * VSlotCount;
|
2017-03-09 07:56:48 +08:00
|
|
|
unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
|
|
|
|
Optional<unsigned> DWARFAddressSpace =
|
|
|
|
CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
|
2016-09-01 00:11:43 +08:00
|
|
|
|
|
|
|
// Create a very wide void* type and insert it directly in the element list.
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::DIType *VTableType = DBuilder.createPointerType(
|
|
|
|
nullptr, VTableWidth, 0, DWARFAddressSpace, "__vtbl_ptr_type");
|
2016-09-01 00:11:43 +08:00
|
|
|
EltTys.push_back(VTableType);
|
|
|
|
|
|
|
|
// The vptr is a pointer to this special vtable type.
|
|
|
|
VPtrTy = DBuilder.createPointerType(VTableType, PtrWidth);
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-09-01 00:11:43 +08:00
|
|
|
// If there is a primary base then the artificial vptr member lives there.
|
2012-12-18 22:30:41 +08:00
|
|
|
if (RL.getPrimaryBase())
|
|
|
|
return;
|
|
|
|
|
2016-09-01 00:11:43 +08:00
|
|
|
if (!VPtrTy)
|
|
|
|
VPtrTy = getOrCreateVTablePtrType(Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::DIType *VPtrMember =
|
|
|
|
DBuilder.createMemberType(Unit, getVTableName(RD), Unit, 0, Size, 0, 0,
|
|
|
|
llvm::DINode::FlagArtificial, VPtrTy);
|
2016-09-01 00:11:43 +08:00
|
|
|
EltTys.push_back(VPtrMember);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::getOrCreateRecordType(QualType RTy,
|
2015-04-21 02:51:48 +08:00
|
|
|
SourceLocation Loc) {
|
2016-02-02 19:06:51 +08:00
|
|
|
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *T = getOrCreateType(RTy, getOrCreateFile(Loc));
|
2012-12-18 22:30:41 +08:00
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::getOrCreateInterfaceType(QualType D,
|
2015-04-21 02:51:48 +08:00
|
|
|
SourceLocation Loc) {
|
2015-08-28 05:21:19 +08:00
|
|
|
return getOrCreateStandaloneType(D, Loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType *CGDebugInfo::getOrCreateStandaloneType(QualType D,
|
|
|
|
SourceLocation Loc) {
|
2016-02-02 19:06:51 +08:00
|
|
|
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
|
2015-08-28 05:21:19 +08:00
|
|
|
assert(!D.isNull() && "null type");
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *T = getOrCreateType(D, getOrCreateFile(Loc));
|
2015-08-28 05:21:19 +08:00
|
|
|
assert(T && "could not create debug info for type");
|
2015-08-28 06:56:46 +08:00
|
|
|
|
2013-03-12 02:33:46 +08:00
|
|
|
RetainedTypes.push_back(D.getAsOpaquePtr());
|
2012-12-18 22:30:41 +08:00
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
2019-04-13 04:25:30 +08:00
|
|
|
void CGDebugInfo::addHeapAllocSiteMetadata(llvm::Instruction *CI,
|
|
|
|
QualType D,
|
|
|
|
SourceLocation Loc) {
|
|
|
|
llvm::MDNode *node;
|
|
|
|
if (D.getTypePtr()->isVoidPointerType()) {
|
|
|
|
node = llvm::MDNode::get(CGM.getLLVMContext(), None);
|
|
|
|
} else {
|
|
|
|
QualType PointeeTy = D.getTypePtr()->getPointeeType();
|
|
|
|
node = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
|
|
|
|
}
|
2019-04-24 05:12:58 +08:00
|
|
|
|
2019-04-13 04:25:30 +08:00
|
|
|
CI->setMetadata("heapallocsite", node);
|
|
|
|
}
|
|
|
|
|
2014-05-07 02:35:21 +08:00
|
|
|
void CGDebugInfo::completeType(const EnumDecl *ED) {
|
2016-02-02 19:06:51 +08:00
|
|
|
if (DebugKind <= codegenoptions::DebugLineTablesOnly)
|
2014-05-07 02:35:21 +08:00
|
|
|
return;
|
|
|
|
QualType Ty = CGM.getContext().getEnumType(ED);
|
2014-10-27 07:40:33 +08:00
|
|
|
void *TyPtr = Ty.getAsOpaquePtr();
|
2014-05-07 02:35:21 +08:00
|
|
|
auto I = TypeCache.find(TyPtr);
|
2015-04-30 00:40:08 +08:00
|
|
|
if (I == TypeCache.end() || !cast<llvm::DIType>(I->second)->isForwardDecl())
|
2014-05-07 02:35:21 +08:00
|
|
|
return;
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *Res = CreateTypeDefinition(Ty->castAs<EnumType>());
|
2015-04-16 09:00:56 +08:00
|
|
|
assert(!Res->isForwardDecl());
|
2014-12-10 02:39:32 +08:00
|
|
|
TypeCache[TyPtr].reset(Res);
|
2014-05-07 02:35:21 +08:00
|
|
|
}
|
|
|
|
|
2013-08-16 04:49:17 +08:00
|
|
|
void CGDebugInfo::completeType(const RecordDecl *RD) {
|
2016-02-02 19:06:51 +08:00
|
|
|
if (DebugKind > codegenoptions::LimitedDebugInfo ||
|
2013-08-16 04:49:17 +08:00
|
|
|
!CGM.getLangOpts().CPlusPlus)
|
|
|
|
completeRequiredType(RD);
|
|
|
|
}
|
|
|
|
|
2017-01-30 14:36:08 +08:00
|
|
|
/// Return true if the class or any of its methods are marked dllimport.
|
|
|
|
static bool isClassOrMethodDLLImport(const CXXRecordDecl *RD) {
|
|
|
|
if (RD->hasAttr<DLLImportAttr>())
|
|
|
|
return true;
|
|
|
|
for (const CXXMethodDecl *MD : RD->methods())
|
|
|
|
if (MD->hasAttr<DLLImportAttr>())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-25 07:48:51 +08:00
|
|
|
/// 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;
|
2018-10-24 08:06:02 +08:00
|
|
|
// Check wether RD is a template.
|
2017-07-25 07:48:51 +08:00
|
|
|
auto TemplateKind = CXXDecl->getTemplateSpecializationKind();
|
|
|
|
if (TemplateKind != TSK_Undeclared) {
|
2018-10-24 08:06:02 +08:00
|
|
|
// Unfortunately getOwningModule() isn't accurate enough to find the
|
|
|
|
// owning module of a ClassTemplateSpecializationDecl that is inside a
|
|
|
|
// namespace spanning multiple modules.
|
|
|
|
bool Explicit = false;
|
|
|
|
if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(CXXDecl))
|
|
|
|
Explicit = TD->isExplicitInstantiationOrSpecialization();
|
|
|
|
if (!Explicit && CXXDecl->getEnclosingNamespaceContext())
|
|
|
|
return false;
|
2017-07-25 07:48:51 +08:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2013-08-20 09:28:15 +08:00
|
|
|
void CGDebugInfo::completeClassData(const RecordDecl *RD) {
|
2017-01-30 14:36:08 +08:00
|
|
|
if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
|
|
|
|
if (CXXRD->isDynamicClass() &&
|
|
|
|
CGM.getVTableLinkage(CXXRD) ==
|
|
|
|
llvm::GlobalValue::AvailableExternallyLinkage &&
|
|
|
|
!isClassOrMethodDLLImport(CXXRD))
|
|
|
|
return;
|
2017-07-25 07:48:51 +08:00
|
|
|
|
|
|
|
if (DebugTypeExtRefs && isDefinedInClangModule(RD->getDefinition()))
|
|
|
|
return;
|
|
|
|
|
2017-01-30 14:36:08 +08:00
|
|
|
completeClass(RD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::completeClass(const RecordDecl *RD) {
|
2016-02-02 19:06:51 +08:00
|
|
|
if (DebugKind <= codegenoptions::DebugLineTablesOnly)
|
2013-08-20 02:46:16 +08:00
|
|
|
return;
|
2013-08-20 09:28:15 +08:00
|
|
|
QualType Ty = CGM.getContext().getRecordType(RD);
|
2014-10-27 07:40:33 +08:00
|
|
|
void *TyPtr = Ty.getAsOpaquePtr();
|
2014-05-06 07:23:53 +08:00
|
|
|
auto I = TypeCache.find(TyPtr);
|
2015-04-30 00:40:08 +08:00
|
|
|
if (I != TypeCache.end() && !cast<llvm::DIType>(I->second)->isForwardDecl())
|
2013-08-16 04:49:17 +08:00
|
|
|
return;
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *Res = CreateTypeDefinition(Ty->castAs<RecordType>());
|
2015-04-16 09:00:56 +08:00
|
|
|
assert(!Res->isForwardDecl());
|
2014-12-10 02:39:32 +08:00
|
|
|
TypeCache[TyPtr].reset(Res);
|
2013-08-16 04:49:17 +08:00
|
|
|
}
|
|
|
|
|
2014-03-04 07:48:23 +08:00
|
|
|
static bool hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I,
|
|
|
|
CXXRecordDecl::method_iterator End) {
|
2016-07-17 08:39:12 +08:00
|
|
|
for (CXXMethodDecl *MD : llvm::make_range(I, End))
|
|
|
|
if (FunctionDecl *Tmpl = MD->getInstantiatedFromMemberFunction())
|
2014-03-04 11:08:14 +08:00
|
|
|
if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
|
2016-07-17 08:39:12 +08:00
|
|
|
!MD->getMemberSpecializationInfo()->isExplicitSpecialization())
|
2014-03-04 07:48:23 +08:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-02 19:06:51 +08:00
|
|
|
static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
|
|
|
|
bool DebugTypeExtRefs, const RecordDecl *RD,
|
2014-03-04 07:48:23 +08:00
|
|
|
const LangOptions &LangOpts) {
|
2016-04-27 05:58:18 +08:00
|
|
|
if (DebugTypeExtRefs && isDefinedInClangModule(RD->getDefinition()))
|
2016-01-20 07:42:53 +08:00
|
|
|
return true;
|
2015-09-12 01:23:08 +08:00
|
|
|
|
2017-04-12 05:13:37 +08:00
|
|
|
if (auto *ES = RD->getASTContext().getExternalSource())
|
|
|
|
if (ES->hasExternalDefinitions(RD) == ExternalASTSource::EK_Always)
|
|
|
|
return true;
|
|
|
|
|
2016-02-02 19:06:51 +08:00
|
|
|
if (DebugKind > codegenoptions::LimitedDebugInfo)
|
2014-03-04 07:48:23 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!LangOpts.CPlusPlus)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!RD->isCompleteDefinitionRequired())
|
|
|
|
return true;
|
|
|
|
|
2016-07-17 08:39:12 +08:00
|
|
|
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
|
2014-03-04 07:48:23 +08:00
|
|
|
|
|
|
|
if (!CXXDecl)
|
|
|
|
return false;
|
|
|
|
|
2016-08-17 06:11:18 +08:00
|
|
|
// Only emit complete debug info for a dynamic class when its vtable is
|
|
|
|
// emitted. However, Microsoft debuggers don't resolve type information
|
2016-09-10 00:27:04 +08:00
|
|
|
// across DLL boundaries, so skip this optimization if the class or any of its
|
|
|
|
// methods are marked dllimport. This isn't a complete solution, since objects
|
|
|
|
// without any dllimport methods can be used in one DLL and constructed in
|
|
|
|
// another, but it is the current behavior of LimitedDebugInfo.
|
2016-08-17 06:11:18 +08:00
|
|
|
if (CXXDecl->hasDefinition() && CXXDecl->isDynamicClass() &&
|
2016-09-10 00:27:04 +08:00
|
|
|
!isClassOrMethodDLLImport(CXXDecl))
|
2014-03-04 07:48:23 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
TemplateSpecializationKind Spec = TSK_Undeclared;
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
|
2014-03-04 07:48:23 +08:00
|
|
|
Spec = SD->getSpecializationKind();
|
|
|
|
|
|
|
|
if (Spec == TSK_ExplicitInstantiationDeclaration &&
|
|
|
|
hasExplicitMemberDefinition(CXXDecl->method_begin(),
|
|
|
|
CXXDecl->method_end()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-13 08:01:23 +08:00
|
|
|
void CGDebugInfo::completeRequiredType(const RecordDecl *RD) {
|
|
|
|
if (shouldOmitDefinition(DebugKind, DebugTypeExtRefs, RD, CGM.getLangOpts()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
QualType Ty = CGM.getContext().getRecordType(RD);
|
|
|
|
llvm::DIType *T = getTypeOrNull(Ty);
|
|
|
|
if (T && T->isForwardDecl())
|
|
|
|
completeClassData(RD);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const RecordType *Ty) {
|
2012-12-18 22:30:41 +08:00
|
|
|
RecordDecl *RD = Ty->getDecl();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *T = cast_or_null<llvm::DIType>(getTypeOrNull(QualType(Ty, 0)));
|
2015-09-12 01:23:08 +08:00
|
|
|
if (T || shouldOmitDefinition(DebugKind, DebugTypeExtRefs, RD,
|
|
|
|
CGM.getLangOpts())) {
|
PR17046, PR17092: Debug Info assert-on-valid due to member loss when context creation recreates the item the context is created for
By removing the possibility of strange partial definitions with no
members that older GCC's produced for the otherwise unreferenced outer
types of referenced inner types, we can simplify debug info generation
and correct this bug. Newer (4.8.1 and ToT) GCC's don't produce this
quirky debug info, and instead produce the full definition for the outer
type (except in the case where that type is dynamic and its vtable is
not emitted in this TU).
During the creation of the context for a type, we may revisit that type
(due to the need to visit template parameters, among other things) and
used to end up visiting it first there. Then when we would reach the
original code attempting to define that type, we would lose debug info
by overwriting its members.
By avoiding the possibility of latent "defined with no members" types,
we can be sure than whenever we already have a type in a cache (either a
definition or declaration), we can just return that. In the case of a
full definition, our work is done. In the case of a partial definition,
we must already be in the process of completing it. And in the case of a
declaration, the completed/vtable/etc callbacks can handle converting it
to a definition.
llvm-svn: 190122
2013-09-06 14:45:04 +08:00
|
|
|
if (!T)
|
2015-09-11 02:39:45 +08:00
|
|
|
T = getOrCreateRecordFwdDecl(Ty, getDeclContextDescriptor(RD));
|
PR17046, PR17092: Debug Info assert-on-valid due to member loss when context creation recreates the item the context is created for
By removing the possibility of strange partial definitions with no
members that older GCC's produced for the otherwise unreferenced outer
types of referenced inner types, we can simplify debug info generation
and correct this bug. Newer (4.8.1 and ToT) GCC's don't produce this
quirky debug info, and instead produce the full definition for the outer
type (except in the case where that type is dynamic and its vtable is
not emitted in this TU).
During the creation of the context for a type, we may revisit that type
(due to the need to visit template parameters, among other things) and
used to end up visiting it first there. Then when we would reach the
original code attempting to define that type, we would lose debug info
by overwriting its members.
By avoiding the possibility of latent "defined with no members" types,
we can be sure than whenever we already have a type in a cache (either a
definition or declaration), we can just return that. In the case of a
full definition, our work is done. In the case of a partial definition,
we must already be in the process of completing it. And in the case of a
declaration, the completed/vtable/etc callbacks can handle converting it
to a definition.
llvm-svn: 190122
2013-09-06 14:45:04 +08:00
|
|
|
return T;
|
2013-06-05 13:32:23 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-08-16 04:49:17 +08:00
|
|
|
return CreateTypeDefinition(Ty);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
|
2013-08-16 04:49:17 +08:00
|
|
|
RecordDecl *RD = Ty->getDecl();
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Get overall information about the record type for the debug info.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Records and classes and unions can all be recursive. To handle them, we
|
|
|
|
// first generate a debug descriptor for the struct as a forward declaration.
|
|
|
|
// Then (if it is a definition) we go through and get debug info for all of
|
|
|
|
// 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.
|
2015-07-25 04:34:41 +08:00
|
|
|
llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty, DefUnit);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-02-12 01:45:15 +08:00
|
|
|
const RecordDecl *D = RD->getDefinition();
|
|
|
|
if (!D || !D->isCompleteDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return FwdDecl;
|
|
|
|
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
|
2013-08-19 00:55:33 +08:00
|
|
|
CollectContainingType(CXXDecl, FwdDecl);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Push the struct on region stack.
|
2014-12-10 02:39:32 +08:00
|
|
|
LexicalBlockStack.emplace_back(&*FwdDecl);
|
|
|
|
RegionMap[Ty->getDecl()].reset(FwdDecl);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Convert all the elements.
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 16> EltTys;
|
2013-08-20 09:28:15 +08:00
|
|
|
// what about nested types?
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Note: The split of CXXDecl information here is intentional, the
|
|
|
|
// gdb tests will depend on a certain ordering at printout. The debug
|
|
|
|
// information offsets are still correct if we merge them all together
|
|
|
|
// though.
|
2016-07-17 08:39:12 +08:00
|
|
|
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (CXXDecl) {
|
|
|
|
CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
|
2016-09-01 00:11:43 +08:00
|
|
|
CollectVTableInfo(CXXDecl, DefUnit, EltTys, FwdDecl);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-01-16 09:22:32 +08:00
|
|
|
// Collect data fields (including static variables and any initializers).
|
2012-12-18 22:30:41 +08:00
|
|
|
CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
|
2013-10-12 02:16:51 +08:00
|
|
|
if (CXXDecl)
|
2012-12-18 22:30:41 +08:00
|
|
|
CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
|
|
|
|
|
|
|
|
LexicalBlockStack.pop_back();
|
|
|
|
RegionMap.erase(Ty->getDecl());
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
|
2014-12-18 08:48:56 +08:00
|
|
|
DBuilder.replaceArrays(FwdDecl, Elements);
|
2013-04-02 04:33:18 +08:00
|
|
|
|
2015-02-12 01:45:15 +08:00
|
|
|
if (FwdDecl->isTemporary())
|
2015-04-17 00:36:45 +08:00
|
|
|
FwdDecl =
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
|
2015-02-12 01:45:15 +08:00
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
RegionMap[Ty->getDecl()].reset(FwdDecl);
|
2013-04-03 06:59:11 +08:00
|
|
|
return FwdDecl;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const ObjCObjectType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Ignore protocols.
|
|
|
|
return getOrCreateType(Ty->getBaseType(), Unit);
|
|
|
|
}
|
|
|
|
|
2016-09-14 01:25:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const ObjCTypeParamType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
|
|
|
// Ignore protocols.
|
|
|
|
SourceLocation Loc = Ty->getDecl()->getLocation();
|
|
|
|
|
|
|
|
// Use Typedefs to represent ObjCTypeParamType.
|
|
|
|
return DBuilder.createTypedef(
|
|
|
|
getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit),
|
|
|
|
Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc),
|
|
|
|
getDeclContextDescriptor(Ty->getDecl()));
|
|
|
|
}
|
|
|
|
|
2013-06-07 09:10:45 +08:00
|
|
|
/// \return true if Getter has the default name for the property PD.
|
|
|
|
static bool hasDefaultGetterName(const ObjCPropertyDecl *PD,
|
|
|
|
const ObjCMethodDecl *Getter) {
|
|
|
|
assert(PD);
|
|
|
|
if (!Getter)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
assert(Getter->getDeclName().isObjCZeroArgSelector());
|
|
|
|
return PD->getName() ==
|
2014-10-27 07:40:33 +08:00
|
|
|
Getter->getDeclName().getObjCSelector().getNameForSlot(0);
|
2013-06-07 09:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \return true if Setter has the default name for the property PD.
|
|
|
|
static bool hasDefaultSetterName(const ObjCPropertyDecl *PD,
|
|
|
|
const ObjCMethodDecl *Setter) {
|
|
|
|
assert(PD);
|
|
|
|
if (!Setter)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
assert(Setter->getDeclName().isObjCOneArgSelector());
|
2013-06-08 06:29:12 +08:00
|
|
|
return SelectorTable::constructSetterName(PD->getName()) ==
|
2014-10-27 07:40:33 +08:00
|
|
|
Setter->getDeclName().getObjCSelector().getNameForSlot(0);
|
2013-06-07 09:10:45 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
ObjCInterfaceDecl *ID = Ty->getDecl();
|
|
|
|
if (!ID)
|
2015-04-21 02:51:48 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-04-21 07:59:32 +08:00
|
|
|
// Return a forward declaration if this type was imported from a clang module,
|
|
|
|
// and this is not the compile unit with the implementation of the type (which
|
|
|
|
// may contain hidden ivars).
|
|
|
|
if (DebugTypeExtRefs && ID->isFromASTFile() && ID->getDefinition() &&
|
|
|
|
!ID->getImplementation())
|
2015-09-12 01:23:08 +08:00
|
|
|
return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
|
|
|
|
ID->getName(),
|
|
|
|
getDeclContextDescriptor(ID), Unit, 0);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Get overall information about the record type for the debug info.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *DefUnit = getOrCreateFile(ID->getLocation());
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Line = getLineNumber(ID->getLocation());
|
2015-04-16 07:19:15 +08:00
|
|
|
auto RuntimeLang =
|
|
|
|
static_cast<llvm::dwarf::SourceLanguage>(TheCU->getSourceLanguage());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// If this is just a forward declaration return a special forward-declaration
|
|
|
|
// debug type since we won't be able to lay out the entire type.
|
|
|
|
ObjCInterfaceDecl *Def = ID->getDefinition();
|
2014-05-06 07:23:53 +08:00
|
|
|
if (!Def || !Def->getImplementation()) {
|
2015-10-02 00:57:02 +08:00
|
|
|
llvm::DIScope *Mod = getParentModuleOrNull(ID);
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *FwdDecl = DBuilder.createReplaceableCompositeType(
|
2015-10-02 00:57:02 +08:00
|
|
|
llvm::dwarf::DW_TAG_structure_type, ID->getName(), Mod ? Mod : TheCU,
|
|
|
|
DefUnit, Line, RuntimeLang);
|
2014-05-06 07:23:53 +08:00
|
|
|
ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
|
2012-12-18 22:30:41 +08:00
|
|
|
return FwdDecl;
|
|
|
|
}
|
|
|
|
|
2014-05-06 07:23:53 +08:00
|
|
|
return CreateTypeDefinition(Ty, Unit);
|
|
|
|
}
|
|
|
|
|
2015-07-01 01:39:51 +08:00
|
|
|
llvm::DIModule *
|
2015-09-19 07:01:45 +08:00
|
|
|
CGDebugInfo::getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
|
|
|
|
bool CreateSkeletonCU) {
|
2015-09-25 00:10:04 +08:00
|
|
|
// Use the Module pointer as the key into the cache. This is a
|
|
|
|
// nullptr if the "Module" is a PCH, which is safe because we don't
|
|
|
|
// support chained PCH debug info, so there can only be a single PCH.
|
|
|
|
const Module *M = Mod.getModuleOrNull();
|
2015-09-30 04:44:46 +08:00
|
|
|
auto ModRef = ModuleCache.find(M);
|
|
|
|
if (ModRef != ModuleCache.end())
|
|
|
|
return cast<llvm::DIModule>(ModRef->second);
|
2015-07-01 02:01:05 +08:00
|
|
|
|
|
|
|
// Macro definitions that were defined with "-D" on the command line.
|
|
|
|
SmallString<128> ConfigMacros;
|
|
|
|
{
|
|
|
|
llvm::raw_svector_ostream OS(ConfigMacros);
|
|
|
|
const auto &PPOpts = CGM.getPreprocessorOpts();
|
|
|
|
unsigned I = 0;
|
2018-04-06 23:14:32 +08:00
|
|
|
// Translate the macro definitions back into a command line.
|
2015-07-01 02:01:05 +08:00
|
|
|
for (auto &M : PPOpts.Macros) {
|
|
|
|
if (++I > 1)
|
|
|
|
OS << " ";
|
|
|
|
const std::string &Macro = M.first;
|
|
|
|
bool Undef = M.second;
|
|
|
|
OS << "\"-" << (Undef ? 'U' : 'D');
|
|
|
|
for (char c : Macro)
|
|
|
|
switch (c) {
|
2018-06-28 18:56:40 +08:00
|
|
|
case '\\':
|
|
|
|
OS << "\\\\";
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
OS << "\\\"";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
OS << c;
|
2015-07-01 02:01:05 +08:00
|
|
|
}
|
|
|
|
OS << '\"';
|
2015-07-01 01:39:51 +08:00
|
|
|
}
|
|
|
|
}
|
2015-09-19 07:01:45 +08:00
|
|
|
|
2015-09-25 00:10:10 +08:00
|
|
|
bool IsRootModule = M ? !M->Parent : true;
|
2019-02-09 07:15:42 +08:00
|
|
|
// When a module name is specified as -fmodule-name, that module gets a
|
|
|
|
// clang::Module object, but it won't actually be built or imported; it will
|
|
|
|
// be textual.
|
2019-02-16 04:24:26 +08:00
|
|
|
if (CreateSkeletonCU && IsRootModule && Mod.getASTFile().empty() && M)
|
|
|
|
assert(StringRef(M->Name).startswith(CGM.getLangOpts().ModuleName) &&
|
2019-02-09 07:15:42 +08:00
|
|
|
"clang module without ASTFile must be specified by -fmodule-name");
|
|
|
|
|
|
|
|
if (CreateSkeletonCU && IsRootModule && !Mod.getASTFile().empty()) {
|
2016-01-23 01:43:43 +08:00
|
|
|
// PCH files don't have a signature field in the control block,
|
|
|
|
// but LLVM detects skeleton CUs by looking for a non-zero DWO id.
|
2017-03-14 02:45:08 +08:00
|
|
|
// We use the lower 64 bits for debug info.
|
|
|
|
uint64_t Signature =
|
|
|
|
Mod.getSignature()
|
|
|
|
? (uint64_t)Mod.getSignature()[1] << 32 | Mod.getSignature()[0]
|
|
|
|
: ~1ULL;
|
2015-09-19 07:01:45 +08:00
|
|
|
llvm::DIBuilder DIB(CGM.getModule());
|
2016-12-15 04:24:40 +08:00
|
|
|
DIB.createCompileUnit(TheCU->getSourceLanguage(),
|
2018-02-27 01:32:31 +08:00
|
|
|
// TODO: Support "Source" from external AST providers?
|
2016-12-15 04:24:40 +08:00
|
|
|
DIB.createFile(Mod.getModuleName(), Mod.getPath()),
|
|
|
|
TheCU->getProducer(), true, StringRef(), 0,
|
|
|
|
Mod.getASTFile(), llvm::DICompileUnit::FullDebug,
|
|
|
|
Signature);
|
2015-09-19 07:01:45 +08:00
|
|
|
DIB.finalize();
|
2015-09-19 08:59:22 +08:00
|
|
|
}
|
2019-02-09 07:15:42 +08:00
|
|
|
|
2015-09-25 00:10:10 +08:00
|
|
|
llvm::DIModule *Parent =
|
|
|
|
IsRootModule ? nullptr
|
|
|
|
: getOrCreateModuleRef(
|
|
|
|
ExternalASTSource::ASTSourceDescriptor(*M->Parent),
|
|
|
|
CreateSkeletonCU);
|
2015-09-25 00:10:04 +08:00
|
|
|
llvm::DIModule *DIMod =
|
2015-09-25 00:10:10 +08:00
|
|
|
DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
|
|
|
|
Mod.getPath(), CGM.getHeaderSearchOpts().Sysroot);
|
2015-09-30 04:44:46 +08:00
|
|
|
ModuleCache[M].reset(DIMod);
|
2015-09-25 00:10:04 +08:00
|
|
|
return DIMod;
|
2015-07-01 01:39:51 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateTypeDefinition(const ObjCInterfaceType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2014-05-06 07:23:53 +08:00
|
|
|
ObjCInterfaceDecl *ID = Ty->getDecl();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *DefUnit = getOrCreateFile(ID->getLocation());
|
2014-05-06 07:23:53 +08:00
|
|
|
unsigned Line = getLineNumber(ID->getLocation());
|
2015-04-16 07:19:15 +08:00
|
|
|
unsigned RuntimeLang = TheCU->getSourceLanguage();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Bit size, align and offset of the type.
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getTypeAlignIfRequired(Ty, CGM.getContext());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (ID->getImplementation())
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagObjcClassComplete;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-10-01 08:48:51 +08:00
|
|
|
llvm::DIScope *Mod = getParentModuleOrNull(ID);
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *RealDecl = DBuilder.createStructType(
|
2015-10-01 08:48:51 +08:00
|
|
|
Mod ? Mod : Unit, ID->getName(), DefUnit, Line, Size, Align, Flags,
|
|
|
|
nullptr, llvm::DINodeArray(), RuntimeLang);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-05-06 07:23:53 +08:00
|
|
|
QualType QTy(Ty, 0);
|
2014-12-10 02:39:32 +08:00
|
|
|
TypeCache[QTy.getAsOpaquePtr()].reset(RealDecl);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-07-15 05:00:07 +08:00
|
|
|
// Push the struct on region stack.
|
2015-04-17 00:36:45 +08:00
|
|
|
LexicalBlockStack.emplace_back(RealDecl);
|
2014-12-10 02:39:32 +08:00
|
|
|
RegionMap[Ty->getDecl()].reset(RealDecl);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Convert all the elements.
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 16> EltTys;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
ObjCInterfaceDecl *SClass = ID->getSuperClass();
|
|
|
|
if (SClass) {
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *SClassTy =
|
2014-10-27 07:40:33 +08:00
|
|
|
getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit);
|
2015-04-16 07:48:50 +08:00
|
|
|
if (!SClassTy)
|
2015-04-21 02:51:48 +08:00
|
|
|
return nullptr;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2018-05-15 05:21:22 +08:00
|
|
|
llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0,
|
2016-09-07 01:06:14 +08:00
|
|
|
llvm::DINode::FlagZero);
|
2012-12-18 22:30:41 +08:00
|
|
|
EltTys.push_back(InhTag);
|
|
|
|
}
|
|
|
|
|
2013-07-15 05:00:07 +08:00
|
|
|
// Create entries for all of the properties.
|
2015-12-05 03:14:14 +08:00
|
|
|
auto AddProperty = [&](const ObjCPropertyDecl *PD) {
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceLocation Loc = PD->getLocation();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *PUnit = getOrCreateFile(Loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned PLine = getLineNumber(Loc);
|
|
|
|
ObjCMethodDecl *Getter = PD->getGetterMethodDecl();
|
|
|
|
ObjCMethodDecl *Setter = PD->getSetterMethodDecl();
|
2014-10-27 07:40:33 +08:00
|
|
|
llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(
|
|
|
|
PD->getName(), PUnit, PLine,
|
|
|
|
hasDefaultGetterName(PD, Getter) ? ""
|
|
|
|
: getSelectorName(PD->getGetterName()),
|
|
|
|
hasDefaultSetterName(PD, Setter) ? ""
|
|
|
|
: getSelectorName(PD->getSetterName()),
|
|
|
|
PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit));
|
2012-12-18 22:30:41 +08:00
|
|
|
EltTys.push_back(PropertyNode);
|
2015-12-05 03:14:14 +08:00
|
|
|
};
|
|
|
|
{
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::SmallPtrSet<const IdentifierInfo *, 16> PropertySet;
|
2015-12-05 03:35:45 +08:00
|
|
|
for (const ObjCCategoryDecl *ClassExt : ID->known_extensions())
|
2016-01-28 04:00:32 +08:00
|
|
|
for (auto *PD : ClassExt->properties()) {
|
2015-12-05 03:35:45 +08:00
|
|
|
PropertySet.insert(PD->getIdentifier());
|
|
|
|
AddProperty(PD);
|
|
|
|
}
|
2016-01-28 04:00:32 +08:00
|
|
|
for (const auto *PD : ID->properties()) {
|
2015-12-05 03:14:14 +08:00
|
|
|
// Don't emit duplicate metadata for properties that were already in a
|
|
|
|
// class extension.
|
|
|
|
if (!PropertySet.insert(PD->getIdentifier()).second)
|
|
|
|
continue;
|
|
|
|
AddProperty(PD);
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID);
|
|
|
|
unsigned FieldNo = 0;
|
|
|
|
for (ObjCIvarDecl *Field = ID->all_declared_ivar_begin(); Field;
|
|
|
|
Field = Field->getNextIvar(), ++FieldNo) {
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
|
2015-04-16 07:48:50 +08:00
|
|
|
if (!FieldTy)
|
2015-04-21 02:51:48 +08:00
|
|
|
return nullptr;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef FieldName = Field->getName();
|
|
|
|
|
|
|
|
// Ignore unnamed fields.
|
|
|
|
if (FieldName.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Get the location for the field.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *FieldDefUnit = getOrCreateFile(Field->getLocation());
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned FieldLine = getLineNumber(Field->getLocation());
|
|
|
|
QualType FType = Field->getType();
|
|
|
|
uint64_t FieldSize = 0;
|
2016-10-20 06:11:07 +08:00
|
|
|
uint32_t FieldAlign = 0;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (!FType->isIncompleteArrayType()) {
|
|
|
|
|
|
|
|
// Bit size, align and offset of the type.
|
|
|
|
FieldSize = Field->isBitField()
|
2013-07-15 05:00:07 +08:00
|
|
|
? Field->getBitWidthValue(CGM.getContext())
|
|
|
|
: CGM.getContext().getTypeSize(FType);
|
2016-10-20 08:13:19 +08:00
|
|
|
FieldAlign = getTypeAlignIfRequired(FType, CGM.getContext());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t FieldOffset;
|
|
|
|
if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
|
|
|
|
// We don't know the runtime offset of an ivar if we're using the
|
|
|
|
// non-fragile ABI. For bitfields, use the bit offset into the first
|
|
|
|
// byte of storage of the bitfield. For other fields, use zero.
|
|
|
|
if (Field->isBitField()) {
|
2014-10-27 07:40:33 +08:00
|
|
|
FieldOffset =
|
|
|
|
CGM.getObjCRuntime().ComputeBitfieldBitOffset(CGM, ID, Field);
|
2012-12-18 22:30:41 +08:00
|
|
|
FieldOffset %= CGM.getContext().getCharWidth();
|
|
|
|
} else {
|
|
|
|
FieldOffset = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
FieldOffset = RL.getFieldOffset(FieldNo);
|
|
|
|
}
|
|
|
|
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Field->getAccessControl() == ObjCIvarDecl::Protected)
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags = llvm::DINode::FlagProtected;
|
2012-12-18 22:30:41 +08:00
|
|
|
else if (Field->getAccessControl() == ObjCIvarDecl::Private)
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags = llvm::DINode::FlagPrivate;
|
2014-08-30 06:44:27 +08:00
|
|
|
else if (Field->getAccessControl() == ObjCIvarDecl::Public)
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags = llvm::DINode::FlagPublic;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::MDNode *PropertyNode = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (ObjCImplementationDecl *ImpD = ID->getImplementation()) {
|
2013-05-16 08:45:12 +08:00
|
|
|
if (ObjCPropertyImplDecl *PImpD =
|
2014-10-27 07:40:33 +08:00
|
|
|
ImpD->FindPropertyImplIvarDecl(Field->getIdentifier())) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (ObjCPropertyDecl *PD = PImpD->getPropertyDecl()) {
|
2013-02-22 06:35:08 +08:00
|
|
|
SourceLocation Loc = PD->getLocation();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *PUnit = getOrCreateFile(Loc);
|
2013-02-22 06:35:08 +08:00
|
|
|
unsigned PLine = getLineNumber(Loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
ObjCMethodDecl *Getter = PD->getGetterMethodDecl();
|
|
|
|
ObjCMethodDecl *Setter = PD->getSetterMethodDecl();
|
2014-10-27 07:40:33 +08:00
|
|
|
PropertyNode = DBuilder.createObjCProperty(
|
|
|
|
PD->getName(), PUnit, PLine,
|
2018-06-28 18:56:40 +08:00
|
|
|
hasDefaultGetterName(PD, Getter)
|
|
|
|
? ""
|
|
|
|
: getSelectorName(PD->getGetterName()),
|
|
|
|
hasDefaultSetterName(PD, Setter)
|
|
|
|
? ""
|
|
|
|
: getSelectorName(PD->getSetterName()),
|
2014-10-27 07:40:33 +08:00
|
|
|
PD->getPropertyAttributes(),
|
|
|
|
getOrCreateType(PD->getType(), PUnit));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-27 07:40:33 +08:00
|
|
|
FieldTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit, FieldLine,
|
|
|
|
FieldSize, FieldAlign, FieldOffset, Flags,
|
|
|
|
FieldTy, PropertyNode);
|
2012-12-18 22:30:41 +08:00
|
|
|
EltTys.push_back(FieldTy);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
|
2014-12-18 08:48:56 +08:00
|
|
|
DBuilder.replaceArrays(RealDecl, Elements);
|
2013-03-07 06:03:30 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
LexicalBlockStack.pop_back();
|
2013-04-03 06:59:11 +08:00
|
|
|
return RealDecl;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const VectorType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
|
|
|
llvm::DIType *ElementTy = getOrCreateType(Ty->getElementType(), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
int64_t Count = Ty->getNumElements();
|
|
|
|
|
2018-02-03 21:55:59 +08:00
|
|
|
llvm::Metadata *Subscript;
|
|
|
|
QualType QTy(Ty, 0);
|
|
|
|
auto SizeExpr = SizeExprCache.find(QTy);
|
|
|
|
if (SizeExpr != SizeExprCache.end())
|
|
|
|
Subscript = DBuilder.getOrCreateSubrange(0, SizeExpr->getSecond());
|
|
|
|
else
|
|
|
|
Subscript = DBuilder.getOrCreateSubrange(0, Count ? Count : -1);
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getTypeAlignIfRequired(Ty, CGM.getContext());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const ArrayType *Ty, llvm::DIFile *Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
uint64_t Size;
|
2016-10-20 06:11:07 +08:00
|
|
|
uint32_t Align;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// FIXME: make getTypeAlign() aware of VLAs and incomplete array types
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
Size = 0;
|
2016-10-20 08:13:19 +08:00
|
|
|
Align = getTypeAlignIfRequired(CGM.getContext().getBaseElementType(VAT),
|
|
|
|
CGM.getContext());
|
2012-12-18 22:30:41 +08:00
|
|
|
} else if (Ty->isIncompleteArrayType()) {
|
|
|
|
Size = 0;
|
|
|
|
if (Ty->getElementType()->isIncompleteType())
|
|
|
|
Align = 0;
|
|
|
|
else
|
2016-10-20 08:13:19 +08:00
|
|
|
Align = getTypeAlignIfRequired(Ty->getElementType(), CGM.getContext());
|
2013-05-10 04:48:12 +08:00
|
|
|
} else if (Ty->isIncompleteType()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
Size = 0;
|
|
|
|
Align = 0;
|
|
|
|
} else {
|
|
|
|
// Size and align of the whole array, not the element type.
|
|
|
|
Size = CGM.getContext().getTypeSize(Ty);
|
2016-10-20 08:13:19 +08:00
|
|
|
Align = getTypeAlignIfRequired(Ty, CGM.getContext());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the dimensions of the array. FIXME: This loses CV qualifiers from
|
|
|
|
// interior arrays, do we care? Why aren't nested arrays represented the
|
|
|
|
// obvious/recursive way?
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 8> Subscripts;
|
2012-12-18 22:30:41 +08:00
|
|
|
QualType EltTy(Ty, 0);
|
|
|
|
while ((Ty = dyn_cast<ArrayType>(EltTy))) {
|
|
|
|
// If the number of elements is known, then count is that number. Otherwise,
|
|
|
|
// it's -1. This allows us to represent a subrange with an array of 0
|
|
|
|
// elements, like this:
|
|
|
|
//
|
|
|
|
// struct foo {
|
|
|
|
// int x[0];
|
|
|
|
// };
|
2014-10-27 07:40:33 +08:00
|
|
|
int64_t Count = -1; // Count == -1 is an unbounded array.
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
|
2012-12-18 22:30:41 +08:00
|
|
|
Count = CAT->getSize().getZExtValue();
|
2016-08-23 01:49:56 +08:00
|
|
|
else if (const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
|
2016-10-20 06:16:32 +08:00
|
|
|
if (Expr *Size = VAT->getSizeExpr()) {
|
2018-12-01 07:41:18 +08:00
|
|
|
Expr::EvalResult Result;
|
|
|
|
if (Size->EvaluateAsInt(Result, CGM.getContext()))
|
|
|
|
Count = Result.Val.getInt().getExtValue();
|
2016-10-20 06:16:32 +08:00
|
|
|
}
|
2016-08-23 01:49:56 +08:00
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2018-02-03 21:55:59 +08:00
|
|
|
auto SizeNode = SizeExprCache.find(EltTy);
|
|
|
|
if (SizeNode != SizeExprCache.end())
|
|
|
|
Subscripts.push_back(
|
|
|
|
DBuilder.getOrCreateSubrange(0, SizeNode->getSecond()));
|
|
|
|
else
|
|
|
|
Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
|
2012-12-18 22:30:41 +08:00
|
|
|
EltTy = Ty->getElementType();
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-04-21 02:51:48 +08:00
|
|
|
return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
|
|
|
|
SubscriptArray);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const LValueReferenceType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2014-10-27 07:40:33 +08:00
|
|
|
return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
|
|
|
|
Ty->getPointeeType(), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const RValueReferenceType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2014-10-27 07:40:33 +08:00
|
|
|
return CreatePointerLikeType(llvm::dwarf::DW_TAG_rvalue_reference_type, Ty,
|
|
|
|
Ty->getPointeeType(), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const MemberPointerType *Ty,
|
|
|
|
llvm::DIFile *U) {
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
|
2016-06-18 06:27:59 +08:00
|
|
|
uint64_t Size = 0;
|
|
|
|
|
|
|
|
if (!Ty->isIncompleteType()) {
|
|
|
|
Size = CGM.getContext().getTypeSize(Ty);
|
|
|
|
|
|
|
|
// Set the MS inheritance model. There is no flag for the unspecified model.
|
|
|
|
if (CGM.getTarget().getCXXABI().isMicrosoft()) {
|
|
|
|
switch (Ty->getMostRecentCXXRecordDecl()->getMSInheritanceModel()) {
|
|
|
|
case MSInheritanceAttr::Keyword_single_inheritance:
|
|
|
|
Flags |= llvm::DINode::FlagSingleInheritance;
|
|
|
|
break;
|
|
|
|
case MSInheritanceAttr::Keyword_multiple_inheritance:
|
|
|
|
Flags |= llvm::DINode::FlagMultipleInheritance;
|
|
|
|
break;
|
|
|
|
case MSInheritanceAttr::Keyword_virtual_inheritance:
|
|
|
|
Flags |= llvm::DINode::FlagVirtualInheritance;
|
|
|
|
break;
|
|
|
|
case MSInheritanceAttr::Keyword_unspecified_inheritance:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *ClassType = getOrCreateType(QualType(Ty->getClass(), 0), U);
|
2015-04-24 09:25:08 +08:00
|
|
|
if (Ty->isMemberDataPointerType())
|
2013-01-20 03:20:56 +08:00
|
|
|
return DBuilder.createMemberPointerType(
|
2016-06-18 06:27:59 +08:00
|
|
|
getOrCreateType(Ty->getPointeeType(), U), ClassType, Size, /*Align=*/0,
|
|
|
|
Flags);
|
2013-12-19 09:38:47 +08:00
|
|
|
|
|
|
|
const FunctionProtoType *FPT =
|
2014-10-27 07:40:33 +08:00
|
|
|
Ty->getPointeeType()->getAs<FunctionProtoType>();
|
|
|
|
return DBuilder.createMemberPointerType(
|
2018-12-13 18:15:27 +08:00
|
|
|
getOrCreateInstanceMethodType(
|
|
|
|
CXXMethodDecl::getThisType(FPT, Ty->getMostRecentCXXRecordDecl()),
|
|
|
|
FPT, U),
|
2016-06-18 06:27:59 +08:00
|
|
|
ClassType, Size, /*Align=*/0, Flags);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const AtomicType *Ty, llvm::DIFile *U) {
|
2016-11-01 03:09:47 +08:00
|
|
|
auto *FromTy = getOrCreateType(Ty->getValueType(), U);
|
|
|
|
return DBuilder.createQualifiedType(llvm::dwarf::DW_TAG_atomic_type, FromTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateType(const PipeType *Ty, llvm::DIFile *U) {
|
2016-01-09 20:53:17 +08:00
|
|
|
return getOrCreateType(Ty->getElementType(), U);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateEnumType(const EnumType *Ty) {
|
2013-08-29 05:20:28 +08:00
|
|
|
const EnumDecl *ED = Ty->getDecl();
|
2015-09-12 01:23:08 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
uint64_t Size = 0;
|
2016-10-20 06:11:07 +08:00
|
|
|
uint32_t Align = 0;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!ED->getTypeForDecl()->isIncompleteType()) {
|
|
|
|
Size = CGM.getContext().getTypeSize(ED->getTypeForDecl());
|
2016-10-20 08:13:19 +08:00
|
|
|
Align = getDeclAlignIfRequired(ED, CGM.getContext());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2018-05-22 20:41:19 +08:00
|
|
|
SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
|
2013-08-30 07:19:58 +08:00
|
|
|
|
2015-09-12 01:23:08 +08:00
|
|
|
bool isImportedFromModule =
|
|
|
|
DebugTypeExtRefs && ED->isFromASTFile() && ED->getDefinition();
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// If this is just a forward declaration, construct an appropriately
|
|
|
|
// marked node and just return it.
|
2015-09-12 01:23:08 +08:00
|
|
|
if (isImportedFromModule || !ED->getDefinition()) {
|
2016-02-24 03:30:08 +08:00
|
|
|
// Note that it is possible for enums to be created as part of
|
|
|
|
// their own declcontext. In this case a FwdDecl will be created
|
|
|
|
// twice. This doesn't cause a problem because both FwdDecls are
|
|
|
|
// entered into the ReplaceMap: finalize() will replace the first
|
|
|
|
// FwdDecl with the second and then replace the second with
|
|
|
|
// complete type.
|
2016-04-30 09:44:38 +08:00
|
|
|
llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
|
2016-02-09 01:03:28 +08:00
|
|
|
llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
|
|
|
|
llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0));
|
2016-02-06 09:59:09 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Line = getLineNumber(ED->getLocation());
|
|
|
|
StringRef EDName = ED->getName();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
|
2016-02-24 03:30:08 +08:00
|
|
|
llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line,
|
2018-05-22 20:41:19 +08:00
|
|
|
0, Size, Align, llvm::DINode::FlagFwdDecl, Identifier);
|
2016-02-06 09:59:09 +08:00
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
ReplaceMap.emplace_back(
|
|
|
|
std::piecewise_construct, std::make_tuple(Ty),
|
|
|
|
std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));
|
2014-05-06 11:42:01 +08:00
|
|
|
return RetTy;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-05-07 02:35:21 +08:00
|
|
|
return CreateTypeDefinition(Ty);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
|
2014-05-07 02:35:21 +08:00
|
|
|
const EnumDecl *ED = Ty->getDecl();
|
|
|
|
uint64_t Size = 0;
|
2016-10-20 06:11:07 +08:00
|
|
|
uint32_t Align = 0;
|
2014-05-07 02:35:21 +08:00
|
|
|
if (!ED->getTypeForDecl()->isIncompleteType()) {
|
|
|
|
Size = CGM.getContext().getTypeSize(ED->getTypeForDecl());
|
2016-10-20 08:13:19 +08:00
|
|
|
Align = getDeclAlignIfRequired(ED, CGM.getContext());
|
2014-05-07 02:35:21 +08:00
|
|
|
}
|
|
|
|
|
2018-05-22 20:41:19 +08:00
|
|
|
SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
|
2014-05-07 02:35:21 +08:00
|
|
|
|
2015-04-22 02:43:54 +08:00
|
|
|
// Create elements for each enumerator.
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 16> Enumerators;
|
2012-12-18 22:30:41 +08:00
|
|
|
ED = ED->getDefinition();
|
2018-02-13 00:12:52 +08:00
|
|
|
bool IsSigned = ED->getIntegerType()->isSignedIntegerType();
|
2014-03-09 02:45:14 +08:00
|
|
|
for (const auto *Enum : ED->enumerators()) {
|
2018-02-13 00:12:52 +08:00
|
|
|
const auto &InitVal = Enum->getInitVal();
|
|
|
|
auto Value = IsSigned ? InitVal.getSExtValue() : InitVal.getZExtValue();
|
|
|
|
Enumerators.push_back(
|
|
|
|
DBuilder.createEnumerator(Enum->getName(), Value, !IsSigned));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return a CompositeType for the enum itself.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Line = getLineNumber(ED->getLocation());
|
2016-04-30 09:44:38 +08:00
|
|
|
llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
|
2018-02-13 00:12:52 +08:00
|
|
|
llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
|
2015-04-21 02:51:48 +08:00
|
|
|
return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit,
|
|
|
|
Line, Size, Align, EltArray, ClassTy,
|
2019-01-09 00:28:11 +08:00
|
|
|
Identifier, ED->isScoped());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 06:07:24 +08:00
|
|
|
llvm::DIMacro *CGDebugInfo::CreateMacro(llvm::DIMacroFile *Parent,
|
|
|
|
unsigned MType, SourceLocation LineLoc,
|
|
|
|
StringRef Name, StringRef Value) {
|
|
|
|
unsigned Line = LineLoc.isInvalid() ? 0 : getLineNumber(LineLoc);
|
|
|
|
return DBuilder.createMacro(Parent, Line, MType, Name, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIMacroFile *CGDebugInfo::CreateTempMacroFile(llvm::DIMacroFile *Parent,
|
|
|
|
SourceLocation LineLoc,
|
|
|
|
SourceLocation FileLoc) {
|
|
|
|
llvm::DIFile *FName = getOrCreateFile(FileLoc);
|
|
|
|
unsigned Line = LineLoc.isInvalid() ? 0 : getLineNumber(LineLoc);
|
|
|
|
return DBuilder.createTempMacroFile(Parent, Line, FName);
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:37:12 +08:00
|
|
|
static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C) {
|
|
|
|
Qualifiers Quals;
|
2012-12-18 22:30:41 +08:00
|
|
|
do {
|
2013-09-27 05:35:50 +08:00
|
|
|
Qualifiers InnerQuals = T.getLocalQualifiers();
|
|
|
|
// Qualifiers::operator+() doesn't like it if you add a Qualifier
|
|
|
|
// that is already there.
|
|
|
|
Quals += Qualifiers::removeCommonQualifiers(Quals, InnerQuals);
|
|
|
|
Quals += InnerQuals;
|
2012-12-18 22:30:41 +08:00
|
|
|
QualType LastT = T;
|
|
|
|
switch (T->getTypeClass()) {
|
|
|
|
default:
|
2013-01-21 12:37:12 +08:00
|
|
|
return C.getQualifiedType(T.getTypePtr(), Quals);
|
2014-04-07 01:14:06 +08:00
|
|
|
case Type::TemplateSpecialization: {
|
|
|
|
const auto *Spec = cast<TemplateSpecializationType>(T);
|
|
|
|
if (Spec->isTypeAlias())
|
|
|
|
return C.getQualifiedType(T.getTypePtr(), Quals);
|
|
|
|
T = Spec->desugar();
|
2014-10-27 07:40:33 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::TypeOfExpr:
|
|
|
|
T = cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType();
|
|
|
|
break;
|
|
|
|
case Type::TypeOf:
|
|
|
|
T = cast<TypeOfType>(T)->getUnderlyingType();
|
|
|
|
break;
|
|
|
|
case Type::Decltype:
|
|
|
|
T = cast<DecltypeType>(T)->getUnderlyingType();
|
|
|
|
break;
|
|
|
|
case Type::UnaryTransform:
|
|
|
|
T = cast<UnaryTransformType>(T)->getUnderlyingType();
|
|
|
|
break;
|
|
|
|
case Type::Attributed:
|
|
|
|
T = cast<AttributedType>(T)->getEquivalentType();
|
|
|
|
break;
|
|
|
|
case Type::Elaborated:
|
|
|
|
T = cast<ElaboratedType>(T)->getNamedType();
|
|
|
|
break;
|
|
|
|
case Type::Paren:
|
|
|
|
T = cast<ParenType>(T)->getInnerType();
|
|
|
|
break;
|
2019-05-07 11:20:17 +08:00
|
|
|
case Type::MacroQualified:
|
|
|
|
T = cast<MacroQualifiedType>(T)->getUnderlyingType();
|
|
|
|
break;
|
2013-01-21 12:37:12 +08:00
|
|
|
case Type::SubstTemplateTypeParm:
|
2012-12-18 22:30:41 +08:00
|
|
|
T = cast<SubstTemplateTypeParmType>(T)->getReplacementType();
|
|
|
|
break;
|
2017-02-22 08:13:14 +08:00
|
|
|
case Type::Auto:
|
|
|
|
case Type::DeducedTemplateSpecialization: {
|
|
|
|
QualType DT = cast<DeducedType>(T)->getDeducedType();
|
PR16091 continued: Debug Info for member functions with undeduced return types.
So DWARF5 specs out auto deduced return types as DW_TAG_unspecified_type
with DW_AT_name "auto", and GCC implements this somewhat, but it
presents a few problems to do this with Clang.
GCC's implementation only applies to member functions where the auto
return type isn't deduced immediately (ie: member functions of templates
or member functions defined out of line). In the common case of an
inline deduced return type function, GCC emits the DW_AT_type as the
deduced return type.
Currently GDB doesn't seem to behave too well with this debug info - it
treats the return type as 'void', even though the definition of the
function has the correctly deduced return type (I guess it sees the
return type the declaration has, doesn't understand it, and assumes
void). This means the function's ABI might be broken (non-trivial return
types, etc), etc.
Clang, on the other hand doesn't track this particular case of a
deducable return type that is deduced immediately versus one that is
deduced 'later'. So if we implement the DWARF5 representation, all
deducible return type functions would get adverse GDB behavior
(including deduced return type lambda functions, inline deduced return
type functions, etc).
Also, we can't just do this for auto types that are not deduced -
because Clang marks even the declaration's return type as deduced (&
provides the underlying type) once a definition is seen that allows the
deduction. So we have to ignore even deduced types - but we can't do
that for auto variables (because this representation only applies to
function declarations - variables and function definitions need the real
type so the function can be called, etc) so we'd need to add an extra
flag to the type unwrapping/creation code to indicate when we want to
see through deduced types and when we don't. It's also not as simple as
just checking at the top level when building a function type (for one
thing, we reuse the function type building for building function pointer
types which might also have 'auto' in them - but be the type of a
variable instead) because the auto might be arbitrarily deeply nested
("auto &", "auto (*)()", etc...)
So, with all that said, let's do the simple thing that works in existing
debuggers for now and treat these functions the same way we do function
templates and implicit special members: omit them from the member list,
since they can't be correctly called anyway (without knowing the return
type the ABI isn't know and a function call could put the arguments in
the wrong place) so they're not much use to the user.
At some point in the future, when GDB understands the DWARF5
representation better it might be worth plumbing through the extra type
builder handling to avoid looking through AutoType for some callers,
etc...
llvm-svn: 221704
2014-11-12 04:44:45 +08:00
|
|
|
assert(!DT.isNull() && "Undeduced types shouldn't reach here.");
|
2013-05-25 05:24:35 +08:00
|
|
|
T = DT;
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-11-11 07:28:17 +08:00
|
|
|
case Type::Adjusted:
|
|
|
|
case Type::Decayed:
|
|
|
|
// Decayed and adjusted types use the adjusted type in LLVM and DWARF.
|
|
|
|
T = cast<AdjustedType>(T)->getAdjustedType();
|
|
|
|
break;
|
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(T != LastT && "Type unwrapping failed to unwrap!");
|
2013-01-21 18:51:28 +08:00
|
|
|
(void)LastT;
|
2012-12-18 22:30:41 +08:00
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) {
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Unwrap the type as needed for debug information.
|
2013-01-21 12:37:12 +08:00
|
|
|
Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext());
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
auto It = TypeCache.find(Ty.getAsOpaquePtr());
|
|
|
|
if (It != TypeCache.end()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Verify that the debug info still exists.
|
2018-06-28 18:56:40 +08:00
|
|
|
if (llvm::Metadata *V = It->second)
|
2015-04-30 00:40:08 +08:00
|
|
|
return cast<llvm::DIType>(V);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-07 07:21:33 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-03-04 07:48:23 +08:00
|
|
|
void CGDebugInfo::completeTemplateDefinition(
|
|
|
|
const ClassTemplateSpecializationDecl &SD) {
|
2016-02-02 19:06:51 +08:00
|
|
|
if (DebugKind <= codegenoptions::DebugLineTablesOnly)
|
2014-03-05 06:01:08 +08:00
|
|
|
return;
|
2017-04-12 05:13:37 +08:00
|
|
|
completeUnusedClass(SD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::completeUnusedClass(const CXXRecordDecl &D) {
|
|
|
|
if (DebugKind <= codegenoptions::DebugLineTablesOnly)
|
|
|
|
return;
|
2014-03-05 06:01:08 +08:00
|
|
|
|
2017-04-12 05:13:37 +08:00
|
|
|
completeClassData(&D);
|
2014-03-04 07:48:23 +08:00
|
|
|
// In case this type has no member function definitions being emitted, ensure
|
|
|
|
// it is retained
|
2017-04-12 05:13:37 +08:00
|
|
|
RetainedTypes.push_back(CGM.getContext().getRecordType(&D).getAsOpaquePtr());
|
2014-03-04 07:48:23 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile *Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Ty.isNull())
|
2015-04-21 02:51:48 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Unwrap the type as needed for debug information.
|
2013-01-21 12:37:12 +08:00
|
|
|
Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-04-21 02:51:48 +08:00
|
|
|
if (auto *T = getTypeOrNull(Ty))
|
2012-12-18 22:30:41 +08:00
|
|
|
return T;
|
|
|
|
|
2015-09-12 01:23:03 +08:00
|
|
|
llvm::DIType *Res = CreateTypeNode(Ty, Unit);
|
2018-06-28 18:56:40 +08:00
|
|
|
void *TyPtr = Ty.getAsOpaquePtr();
|
2013-03-12 02:33:46 +08:00
|
|
|
|
|
|
|
// And update the type cache.
|
2014-12-10 02:39:32 +08:00
|
|
|
TypeCache[TyPtr].reset(Res);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
2015-09-12 01:23:08 +08:00
|
|
|
llvm::DIModule *CGDebugInfo::getParentModuleOrNull(const Decl *D) {
|
2015-10-03 01:36:14 +08:00
|
|
|
// A forward declaration inside a module header does not belong to the module.
|
|
|
|
if (isa<RecordDecl>(D) && !cast<RecordDecl>(D)->getDefinition())
|
|
|
|
return nullptr;
|
2015-09-22 01:48:37 +08:00
|
|
|
if (DebugTypeExtRefs && D->isFromASTFile()) {
|
|
|
|
// Record a reference to an imported clang module or precompiled header.
|
|
|
|
auto *Reader = CGM.getContext().getExternalSource();
|
|
|
|
auto Idx = D->getOwningModuleID();
|
|
|
|
auto Info = Reader->getSourceDescriptor(Idx);
|
|
|
|
if (Info)
|
|
|
|
return getOrCreateModuleRef(*Info, /*SkeletonCU=*/true);
|
|
|
|
} else if (ClangModuleMap) {
|
2015-09-21 00:51:35 +08:00
|
|
|
// We are building a clang module or a precompiled header.
|
|
|
|
//
|
|
|
|
// TODO: When D is a CXXRecordDecl or a C++ Enum, the ODR applies
|
|
|
|
// and it wouldn't be necessary to specify the parent scope
|
|
|
|
// because the type is already unique by definition (it would look
|
|
|
|
// like the output of -fno-standalone-debug). On the other hand,
|
|
|
|
// the parent scope helps a consumer to quickly locate the object
|
|
|
|
// file where the type's definition is located, so it might be
|
|
|
|
// best to make this behavior a command line or debugger tuning
|
|
|
|
// option.
|
2017-05-18 10:29:20 +08:00
|
|
|
if (Module *M = D->getOwningModule()) {
|
2016-01-23 05:14:41 +08:00
|
|
|
// This is a (sub-)module.
|
2015-09-21 00:51:35 +08:00
|
|
|
auto Info = ExternalASTSource::ASTSourceDescriptor(*M);
|
|
|
|
return getOrCreateModuleRef(Info, /*SkeletonCU=*/false);
|
2016-01-23 05:14:41 +08:00
|
|
|
} else {
|
|
|
|
// This the precompiled header being built.
|
|
|
|
return getOrCreateModuleRef(PCHDescriptor, /*SkeletonCU=*/false);
|
2015-09-21 00:51:35 +08:00
|
|
|
}
|
|
|
|
}
|
2015-09-12 01:23:08 +08:00
|
|
|
|
2015-09-21 00:51:35 +08:00
|
|
|
return nullptr;
|
2015-09-12 01:23:08 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Handle qualifiers, which recursively handles what they refer to.
|
|
|
|
if (Ty.hasLocalQualifiers())
|
2013-09-05 06:03:57 +08:00
|
|
|
return CreateQualifiedType(Ty, Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Work out details of type.
|
|
|
|
switch (Ty->getTypeClass()) {
|
|
|
|
#define TYPE(Class, Base)
|
|
|
|
#define ABSTRACT_TYPE(Class, Base)
|
|
|
|
#define NON_CANONICAL_TYPE(Class, Base)
|
|
|
|
#define DEPENDENT_TYPE(Class, Base) case Type::Class:
|
|
|
|
#include "clang/AST/TypeNodes.def"
|
|
|
|
llvm_unreachable("Dependent types cannot show up in debug information");
|
|
|
|
|
|
|
|
case Type::ExtVector:
|
|
|
|
case Type::Vector:
|
|
|
|
return CreateType(cast<VectorType>(Ty), Unit);
|
|
|
|
case Type::ObjCObjectPointer:
|
|
|
|
return CreateType(cast<ObjCObjectPointerType>(Ty), Unit);
|
|
|
|
case Type::ObjCObject:
|
|
|
|
return CreateType(cast<ObjCObjectType>(Ty), Unit);
|
2016-09-14 01:25:08 +08:00
|
|
|
case Type::ObjCTypeParam:
|
|
|
|
return CreateType(cast<ObjCTypeParamType>(Ty), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::ObjCInterface:
|
|
|
|
return CreateType(cast<ObjCInterfaceType>(Ty), Unit);
|
|
|
|
case Type::Builtin:
|
|
|
|
return CreateType(cast<BuiltinType>(Ty));
|
|
|
|
case Type::Complex:
|
|
|
|
return CreateType(cast<ComplexType>(Ty));
|
|
|
|
case Type::Pointer:
|
|
|
|
return CreateType(cast<PointerType>(Ty), Unit);
|
|
|
|
case Type::BlockPointer:
|
|
|
|
return CreateType(cast<BlockPointerType>(Ty), Unit);
|
|
|
|
case Type::Typedef:
|
2013-09-05 06:03:57 +08:00
|
|
|
return CreateType(cast<TypedefType>(Ty), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::Record:
|
2013-09-05 06:03:57 +08:00
|
|
|
return CreateType(cast<RecordType>(Ty));
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::Enum:
|
2013-08-29 05:20:28 +08:00
|
|
|
return CreateEnumType(cast<EnumType>(Ty));
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::FunctionProto:
|
|
|
|
case Type::FunctionNoProto:
|
|
|
|
return CreateType(cast<FunctionType>(Ty), Unit);
|
|
|
|
case Type::ConstantArray:
|
|
|
|
case Type::VariableArray:
|
|
|
|
case Type::IncompleteArray:
|
|
|
|
return CreateType(cast<ArrayType>(Ty), Unit);
|
|
|
|
|
|
|
|
case Type::LValueReference:
|
|
|
|
return CreateType(cast<LValueReferenceType>(Ty), Unit);
|
|
|
|
case Type::RValueReference:
|
|
|
|
return CreateType(cast<RValueReferenceType>(Ty), Unit);
|
|
|
|
|
|
|
|
case Type::MemberPointer:
|
|
|
|
return CreateType(cast<MemberPointerType>(Ty), Unit);
|
|
|
|
|
|
|
|
case Type::Atomic:
|
|
|
|
return CreateType(cast<AtomicType>(Ty), Unit);
|
|
|
|
|
2016-01-09 20:53:17 +08:00
|
|
|
case Type::Pipe:
|
|
|
|
return CreateType(cast<PipeType>(Ty), Unit);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::TemplateSpecialization:
|
2014-04-07 01:14:06 +08:00
|
|
|
return CreateType(cast<TemplateSpecializationType>(Ty), Unit);
|
|
|
|
|
PR16091 continued: Debug Info for member functions with undeduced return types.
So DWARF5 specs out auto deduced return types as DW_TAG_unspecified_type
with DW_AT_name "auto", and GCC implements this somewhat, but it
presents a few problems to do this with Clang.
GCC's implementation only applies to member functions where the auto
return type isn't deduced immediately (ie: member functions of templates
or member functions defined out of line). In the common case of an
inline deduced return type function, GCC emits the DW_AT_type as the
deduced return type.
Currently GDB doesn't seem to behave too well with this debug info - it
treats the return type as 'void', even though the definition of the
function has the correctly deduced return type (I guess it sees the
return type the declaration has, doesn't understand it, and assumes
void). This means the function's ABI might be broken (non-trivial return
types, etc), etc.
Clang, on the other hand doesn't track this particular case of a
deducable return type that is deduced immediately versus one that is
deduced 'later'. So if we implement the DWARF5 representation, all
deducible return type functions would get adverse GDB behavior
(including deduced return type lambda functions, inline deduced return
type functions, etc).
Also, we can't just do this for auto types that are not deduced -
because Clang marks even the declaration's return type as deduced (&
provides the underlying type) once a definition is seen that allows the
deduction. So we have to ignore even deduced types - but we can't do
that for auto variables (because this representation only applies to
function declarations - variables and function definitions need the real
type so the function can be called, etc) so we'd need to add an extra
flag to the type unwrapping/creation code to indicate when we want to
see through deduced types and when we don't. It's also not as simple as
just checking at the top level when building a function type (for one
thing, we reuse the function type building for building function pointer
types which might also have 'auto' in them - but be the type of a
variable instead) because the auto might be arbitrarily deeply nested
("auto &", "auto (*)()", etc...)
So, with all that said, let's do the simple thing that works in existing
debuggers for now and treat these functions the same way we do function
templates and implicit special members: omit them from the member list,
since they can't be correctly called anyway (without knowing the return
type the ABI isn't know and a function call could put the arguments in
the wrong place) so they're not much use to the user.
At some point in the future, when GDB understands the DWARF5
representation better it might be worth plumbing through the extra type
builder handling to avoid looking through AutoType for some callers,
etc...
llvm-svn: 221704
2014-11-12 04:44:45 +08:00
|
|
|
case Type::Auto:
|
2014-04-07 01:14:06 +08:00
|
|
|
case Type::Attributed:
|
2016-11-11 07:28:17 +08:00
|
|
|
case Type::Adjusted:
|
|
|
|
case Type::Decayed:
|
2017-01-27 04:40:47 +08:00
|
|
|
case Type::DeducedTemplateSpecialization:
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::Elaborated:
|
|
|
|
case Type::Paren:
|
2019-05-07 11:20:17 +08:00
|
|
|
case Type::MacroQualified:
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::SubstTemplateTypeParm:
|
|
|
|
case Type::TypeOfExpr:
|
|
|
|
case Type::TypeOf:
|
|
|
|
case Type::Decltype:
|
|
|
|
case Type::UnaryTransform:
|
2013-07-14 05:08:08 +08:00
|
|
|
case Type::PackExpansion:
|
2013-05-25 05:24:35 +08:00
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
|
PR16091 continued: Debug Info for member functions with undeduced return types.
So DWARF5 specs out auto deduced return types as DW_TAG_unspecified_type
with DW_AT_name "auto", and GCC implements this somewhat, but it
presents a few problems to do this with Clang.
GCC's implementation only applies to member functions where the auto
return type isn't deduced immediately (ie: member functions of templates
or member functions defined out of line). In the common case of an
inline deduced return type function, GCC emits the DW_AT_type as the
deduced return type.
Currently GDB doesn't seem to behave too well with this debug info - it
treats the return type as 'void', even though the definition of the
function has the correctly deduced return type (I guess it sees the
return type the declaration has, doesn't understand it, and assumes
void). This means the function's ABI might be broken (non-trivial return
types, etc), etc.
Clang, on the other hand doesn't track this particular case of a
deducable return type that is deduced immediately versus one that is
deduced 'later'. So if we implement the DWARF5 representation, all
deducible return type functions would get adverse GDB behavior
(including deduced return type lambda functions, inline deduced return
type functions, etc).
Also, we can't just do this for auto types that are not deduced -
because Clang marks even the declaration's return type as deduced (&
provides the underlying type) once a definition is seen that allows the
deduction. So we have to ignore even deduced types - but we can't do
that for auto variables (because this representation only applies to
function declarations - variables and function definitions need the real
type so the function can be called, etc) so we'd need to add an extra
flag to the type unwrapping/creation code to indicate when we want to
see through deduced types and when we don't. It's also not as simple as
just checking at the top level when building a function type (for one
thing, we reuse the function type building for building function pointer
types which might also have 'auto' in them - but be the type of a
variable instead) because the auto might be arbitrarily deeply nested
("auto &", "auto (*)()", etc...)
So, with all that said, let's do the simple thing that works in existing
debuggers for now and treat these functions the same way we do function
templates and implicit special members: omit them from the member list,
since they can't be correctly called anyway (without knowing the return
type the ABI isn't know and a function call could put the arguments in
the wrong place) so they're not much use to the user.
At some point in the future, when GDB understands the DWARF5
representation better it might be worth plumbing through the extra type
builder handling to avoid looking through AutoType for some callers,
etc...
llvm-svn: 221704
2014-11-12 04:44:45 +08:00
|
|
|
llvm_unreachable("type should have been unwrapped!");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-07-25 04:34:41 +08:00
|
|
|
llvm::DICompositeType *CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty,
|
|
|
|
llvm::DIFile *Unit) {
|
2013-08-13 06:24:20 +08:00
|
|
|
QualType QTy(Ty, 0);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-25 04:34:41 +08:00
|
|
|
auto *T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// We may have cached a forward decl when we could have created
|
|
|
|
// a non-forward decl. Go ahead and create a non-forward decl
|
|
|
|
// now.
|
2015-04-16 09:00:56 +08:00
|
|
|
if (T && !T->isForwardDecl())
|
2014-10-27 07:40:33 +08:00
|
|
|
return T;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Otherwise create the type.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *Res = CreateLimitedType(Ty);
|
2013-08-21 05:03:29 +08:00
|
|
|
|
|
|
|
// Propagate members from the declaration to the definition
|
|
|
|
// CreateType(const RecordType*) will overwrite this with the members in the
|
|
|
|
// correct order if the full type is needed.
|
2015-04-30 00:40:08 +08:00
|
|
|
DBuilder.replaceArrays(Res, T ? T->getElements() : llvm::DINodeArray());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// And update the type cache.
|
2014-12-10 02:39:32 +08:00
|
|
|
TypeCache[QTy.getAsOpaquePtr()].reset(Res);
|
2012-12-18 22:30:41 +08:00
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Currently used for context chains when limiting debug info.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
|
2012-12-18 22:30:41 +08:00
|
|
|
RecordDecl *RD = Ty->getDecl();
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Get overall information about the record type for the debug info.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation());
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Line = getLineNumber(RD->getLocation());
|
|
|
|
StringRef RDName = getClassName(RD);
|
|
|
|
|
2016-04-30 09:44:38 +08:00
|
|
|
llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-08-19 01:36:19 +08:00
|
|
|
// If we ended up creating the type during the context chain construction,
|
|
|
|
// just return that.
|
2015-04-30 00:40:08 +08:00
|
|
|
auto *T = cast_or_null<llvm::DICompositeType>(
|
2015-04-07 07:21:33 +08:00
|
|
|
getTypeOrNull(CGM.getContext().getRecordType(RD)));
|
2015-04-16 09:00:56 +08:00
|
|
|
if (T && (!T->isForwardDecl() || !RD->getDefinition()))
|
2014-10-27 07:40:33 +08:00
|
|
|
return T;
|
2013-08-19 01:36:19 +08:00
|
|
|
|
2014-02-05 05:29:50 +08:00
|
|
|
// If this is just a forward or incomplete declaration, construct an
|
|
|
|
// appropriately marked node and just return it.
|
|
|
|
const RecordDecl *D = RD->getDefinition();
|
|
|
|
if (!D || !D->isCompleteDefinition())
|
2013-08-29 05:20:28 +08:00
|
|
|
return getOrCreateRecordFwdDecl(Ty, RDContext);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getDeclAlignIfRequired(D, CGM.getContext());
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2018-05-22 20:41:19 +08:00
|
|
|
SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
|
2013-08-30 07:19:58 +08:00
|
|
|
|
2018-01-05 09:13:52 +08:00
|
|
|
// Explicitly record the calling convention for C++ records.
|
|
|
|
auto Flags = llvm::DINode::FlagZero;
|
|
|
|
if (auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
|
|
|
|
if (CGM.getCXXABI().getRecordArgABI(CXXRD) == CGCXXABI::RAA_Indirect)
|
|
|
|
Flags |= llvm::DINode::FlagTypePassByReference;
|
|
|
|
else
|
|
|
|
Flags |= llvm::DINode::FlagTypePassByValue;
|
2018-07-24 04:49:07 +08:00
|
|
|
|
2019-04-12 04:24:54 +08:00
|
|
|
// Record if a C++ record is non-trivial type.
|
|
|
|
if (!CXXRD->isTrivial())
|
2019-02-26 11:49:05 +08:00
|
|
|
Flags |= llvm::DINode::FlagNonTrivial;
|
2018-01-05 09:13:52 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
|
2016-09-06 18:48:04 +08:00
|
|
|
getTagForRecord(RD), RDName, RDContext, DefUnit, Line, 0, Size, Align,
|
2018-05-22 20:41:19 +08:00
|
|
|
Flags, Identifier);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-04-17 15:45:08 +08:00
|
|
|
// Elements of composite types usually have back to the type, creating
|
|
|
|
// uniquing cycles. Distinct nodes are more efficient.
|
|
|
|
switch (RealDecl->getTag()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("invalid composite type tag");
|
|
|
|
|
|
|
|
case llvm::dwarf::DW_TAG_array_type:
|
|
|
|
case llvm::dwarf::DW_TAG_enumeration_type:
|
|
|
|
// Array elements and most enumeration elements don't have back references,
|
|
|
|
// so they don't tend to be involved in uniquing cycles and there is some
|
|
|
|
// chance of merging them when linking together two modules. Only make
|
|
|
|
// them distinct if they are ODR-uniqued.
|
2018-05-22 20:41:19 +08:00
|
|
|
if (Identifier.empty())
|
2016-04-17 15:45:08 +08:00
|
|
|
break;
|
2017-06-03 14:30:46 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2016-04-17 15:45:08 +08:00
|
|
|
|
|
|
|
case llvm::dwarf::DW_TAG_structure_type:
|
|
|
|
case llvm::dwarf::DW_TAG_union_type:
|
|
|
|
case llvm::dwarf::DW_TAG_class_type:
|
2018-04-06 23:14:32 +08:00
|
|
|
// Immediately resolve to a distinct node.
|
2016-04-17 15:45:08 +08:00
|
|
|
RealDecl =
|
|
|
|
llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
RegionMap[Ty->getDecl()].reset(RealDecl);
|
|
|
|
TypeCache[QualType(Ty, 0).getAsOpaquePtr()].reset(RealDecl);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
|
2015-04-30 00:40:08 +08:00
|
|
|
DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
|
2014-12-18 08:48:56 +08:00
|
|
|
CollectCXXTemplateParams(TSpecial, DefUnit));
|
2013-08-16 06:42:12 +08:00
|
|
|
return RealDecl;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-08-19 00:55:33 +08:00
|
|
|
void CGDebugInfo::CollectContainingType(const CXXRecordDecl *RD,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *RealDecl) {
|
2013-08-19 00:55:33 +08:00
|
|
|
// A class's primary base or the class itself contains the vtable.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *ContainingType = nullptr;
|
2013-08-19 00:55:33 +08:00
|
|
|
const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
|
|
|
|
if (const CXXRecordDecl *PBase = RL.getPrimaryBase()) {
|
2013-12-05 12:47:09 +08:00
|
|
|
// Seek non-virtual primary base root.
|
2013-08-19 00:55:33 +08:00
|
|
|
while (1) {
|
|
|
|
const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase);
|
|
|
|
const CXXRecordDecl *PBT = BRL.getPrimaryBase();
|
|
|
|
if (PBT && !BRL.isPrimaryBaseVirtual())
|
|
|
|
PBase = PBT;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2015-04-30 00:40:08 +08:00
|
|
|
ContainingType = cast<llvm::DICompositeType>(
|
2013-08-19 00:55:33 +08:00
|
|
|
getOrCreateType(QualType(PBase->getTypeForDecl(), 0),
|
|
|
|
getOrCreateFile(RD->getLocation())));
|
|
|
|
} else if (RD->isDynamicClass())
|
|
|
|
ContainingType = RealDecl;
|
|
|
|
|
2014-12-18 08:48:56 +08:00
|
|
|
DBuilder.replaceVTableHolder(RealDecl, ContainingType);
|
2013-08-19 00:55:33 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit, QualType FType,
|
2015-04-21 02:51:48 +08:00
|
|
|
StringRef Name, uint64_t *Offset) {
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
|
2016-10-20 08:13:19 +08:00
|
|
|
auto FieldAlign = getTypeAlignIfRequired(FType, CGM.getContext());
|
2016-09-07 01:06:14 +08:00
|
|
|
llvm::DIType *Ty =
|
|
|
|
DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign,
|
|
|
|
*Offset, llvm::DINode::FlagZero, FieldTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
*Offset += FieldSize;
|
|
|
|
return Ty;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
|
2015-04-22 04:07:29 +08:00
|
|
|
StringRef &Name,
|
|
|
|
StringRef &LinkageName,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIScope *&FDContext,
|
|
|
|
llvm::DINodeArray &TParamsArray,
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags &Flags) {
|
2016-07-17 08:39:12 +08:00
|
|
|
const auto *FD = cast<FunctionDecl>(GD.getDecl());
|
2014-11-18 11:40:46 +08:00
|
|
|
Name = getFunctionName(FD);
|
|
|
|
// Use mangled name as linkage name for C/C++ functions.
|
|
|
|
if (FD->hasPrototype()) {
|
|
|
|
LinkageName = CGM.getMangledName(GD);
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagPrototyped;
|
2014-11-18 11:40:46 +08:00
|
|
|
}
|
|
|
|
// No need to replicate the linkage name if it isn't different from the
|
|
|
|
// subprogram name, no need to have it at all unless coverage is enabled or
|
Add -fdebug-info-for-profiling to emit more debug info for sample pgo profile collection
Summary:
SamplePGO uses profile with debug info to collect profile. Unlike the traditional debugging purpose, sample pgo needs more accurate debug info to represent the profile. We add -femit-accurate-debug-info for this purpose. It can be combined with all debugging modes (-g, -gmlt, etc). It makes sure that the following pieces of info is always emitted:
* start line of all subprograms
* linkage name of all subprograms
* standalone subprograms (functions that has neither inlined nor been inlined)
The impact on speccpu2006 binary size (size increase comparing with -g0 binary, also includes data for -g binary, which does not change with this patch):
-gmlt(orig) -gmlt(patched) -g
433.milc 4.68% 5.40% 19.73%
444.namd 8.45% 8.93% 45.99%
447.dealII 97.43% 115.21% 374.89%
450.soplex 27.75% 31.88% 126.04%
453.povray 21.81% 26.16% 92.03%
470.lbm 0.60% 0.67% 1.96%
482.sphinx3 5.77% 6.47% 26.17%
400.perlbench 17.81% 19.43% 73.08%
401.bzip2 3.73% 3.92% 12.18%
403.gcc 31.75% 34.48% 122.75%
429.mcf 0.78% 0.88% 3.89%
445.gobmk 6.08% 7.92% 42.27%
456.hmmer 10.36% 11.25% 35.23%
458.sjeng 5.08% 5.42% 14.36%
462.libquantum 1.71% 1.96% 6.36%
464.h264ref 15.61% 16.56% 43.92%
471.omnetpp 11.93% 15.84% 60.09%
473.astar 3.11% 3.69% 14.18%
483.xalancbmk 56.29% 81.63% 353.22%
geomean 15.60% 18.30% 57.81%
Debug info size change for -gmlt binary with this patch:
433.milc 13.46%
444.namd 5.35%
447.dealII 18.21%
450.soplex 14.68%
453.povray 19.65%
470.lbm 6.03%
482.sphinx3 11.21%
400.perlbench 8.91%
401.bzip2 4.41%
403.gcc 8.56%
429.mcf 8.24%
445.gobmk 29.47%
456.hmmer 8.19%
458.sjeng 6.05%
462.libquantum 11.23%
464.h264ref 5.93%
471.omnetpp 31.89%
473.astar 16.20%
483.xalancbmk 44.62%
geomean 16.83%
Reviewers: davidxl, andreadb, rob.lougher, dblaikie, echristo
Reviewed By: dblaikie, echristo
Subscribers: hfinkel, rob.lougher, andreadb, gbedwell, cfe-commits, probinson, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D25435
llvm-svn: 292458
2017-01-19 08:44:21 +08:00
|
|
|
// debug is set to more than just line tables or extra debug info is needed.
|
2016-02-02 19:06:51 +08:00
|
|
|
if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs &&
|
|
|
|
!CGM.getCodeGenOpts().EmitGcovNotes &&
|
Add -fdebug-info-for-profiling to emit more debug info for sample pgo profile collection
Summary:
SamplePGO uses profile with debug info to collect profile. Unlike the traditional debugging purpose, sample pgo needs more accurate debug info to represent the profile. We add -femit-accurate-debug-info for this purpose. It can be combined with all debugging modes (-g, -gmlt, etc). It makes sure that the following pieces of info is always emitted:
* start line of all subprograms
* linkage name of all subprograms
* standalone subprograms (functions that has neither inlined nor been inlined)
The impact on speccpu2006 binary size (size increase comparing with -g0 binary, also includes data for -g binary, which does not change with this patch):
-gmlt(orig) -gmlt(patched) -g
433.milc 4.68% 5.40% 19.73%
444.namd 8.45% 8.93% 45.99%
447.dealII 97.43% 115.21% 374.89%
450.soplex 27.75% 31.88% 126.04%
453.povray 21.81% 26.16% 92.03%
470.lbm 0.60% 0.67% 1.96%
482.sphinx3 5.77% 6.47% 26.17%
400.perlbench 17.81% 19.43% 73.08%
401.bzip2 3.73% 3.92% 12.18%
403.gcc 31.75% 34.48% 122.75%
429.mcf 0.78% 0.88% 3.89%
445.gobmk 6.08% 7.92% 42.27%
456.hmmer 10.36% 11.25% 35.23%
458.sjeng 5.08% 5.42% 14.36%
462.libquantum 1.71% 1.96% 6.36%
464.h264ref 15.61% 16.56% 43.92%
471.omnetpp 11.93% 15.84% 60.09%
473.astar 3.11% 3.69% 14.18%
483.xalancbmk 56.29% 81.63% 353.22%
geomean 15.60% 18.30% 57.81%
Debug info size change for -gmlt binary with this patch:
433.milc 13.46%
444.namd 5.35%
447.dealII 18.21%
450.soplex 14.68%
453.povray 19.65%
470.lbm 6.03%
482.sphinx3 11.21%
400.perlbench 8.91%
401.bzip2 4.41%
403.gcc 8.56%
429.mcf 8.24%
445.gobmk 29.47%
456.hmmer 8.19%
458.sjeng 6.05%
462.libquantum 11.23%
464.h264ref 5.93%
471.omnetpp 31.89%
473.astar 16.20%
483.xalancbmk 44.62%
geomean 16.83%
Reviewers: davidxl, andreadb, rob.lougher, dblaikie, echristo
Reviewed By: dblaikie, echristo
Subscribers: hfinkel, rob.lougher, andreadb, gbedwell, cfe-commits, probinson, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D25435
llvm-svn: 292458
2017-01-19 08:44:21 +08:00
|
|
|
!CGM.getCodeGenOpts().DebugInfoForProfiling &&
|
2016-02-02 19:06:51 +08:00
|
|
|
DebugKind <= codegenoptions::DebugLineTablesOnly))
|
2014-11-18 11:40:46 +08:00
|
|
|
LinkageName = StringRef();
|
|
|
|
|
2016-02-02 19:06:51 +08:00
|
|
|
if (DebugKind >= codegenoptions::LimitedDebugInfo) {
|
2014-11-18 11:40:46 +08:00
|
|
|
if (const NamespaceDecl *NSDecl =
|
2018-06-28 18:56:40 +08:00
|
|
|
dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))
|
2017-05-13 00:23:53 +08:00
|
|
|
FDContext = getOrCreateNamespace(NSDecl);
|
2014-11-18 11:40:46 +08:00
|
|
|
else if (const RecordDecl *RDecl =
|
2018-06-28 18:56:40 +08:00
|
|
|
dyn_cast_or_null<RecordDecl>(FD->getDeclContext())) {
|
2015-09-12 01:23:08 +08:00
|
|
|
llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
|
|
|
|
FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
|
|
|
|
}
|
2016-08-18 00:20:32 +08:00
|
|
|
// Check if it is a noreturn-marked function
|
|
|
|
if (FD->isNoReturn())
|
|
|
|
Flags |= llvm::DINode::FlagNoReturn;
|
2014-11-18 11:40:46 +08:00
|
|
|
// Collect template parameters.
|
|
|
|
TParamsArray = CollectFunctionTemplateParams(FD, Unit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
void CGDebugInfo::collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
|
2014-11-18 11:40:46 +08:00
|
|
|
unsigned &LineNo, QualType &T,
|
|
|
|
StringRef &Name, StringRef &LinkageName,
|
2018-10-04 02:45:04 +08:00
|
|
|
llvm::MDTuple *&TemplateParameters,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIScope *&VDContext) {
|
2014-11-18 11:40:46 +08:00
|
|
|
Unit = getOrCreateFile(VD->getLocation());
|
|
|
|
LineNo = getLineNumber(VD->getLocation());
|
|
|
|
|
|
|
|
setLocation(VD->getLocation());
|
|
|
|
|
|
|
|
T = VD->getType();
|
|
|
|
if (T->isIncompleteArrayType()) {
|
|
|
|
// CodeGen turns int[] into int[1] so we'll do the same here.
|
|
|
|
llvm::APInt ConstVal(32, 1);
|
|
|
|
QualType ET = CGM.getContext().getAsArrayType(T)->getElementType();
|
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
T = CGM.getContext().getConstantArrayType(ET, ConstVal, ArrayType::Normal,
|
|
|
|
0);
|
2014-11-18 11:40:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Name = VD->getName();
|
|
|
|
if (VD->getDeclContext() && !isa<FunctionDecl>(VD->getDeclContext()) &&
|
|
|
|
!isa<ObjCMethodDecl>(VD->getDeclContext()))
|
|
|
|
LinkageName = CGM.getMangledName(VD);
|
|
|
|
if (LinkageName == Name)
|
|
|
|
LinkageName = StringRef();
|
|
|
|
|
2018-10-04 02:45:04 +08:00
|
|
|
if (isa<VarTemplateSpecializationDecl>(VD)) {
|
|
|
|
llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit);
|
|
|
|
TemplateParameters = parameterNodes.get();
|
|
|
|
} else {
|
|
|
|
TemplateParameters = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-11-18 11:40:46 +08:00
|
|
|
// Since we emit declarations (DW_AT_members) for static members, place the
|
|
|
|
// definition of those static members in the namespace they were declared in
|
|
|
|
// in the source code (the lexical decl context).
|
|
|
|
// FIXME: Generalize this for even non-member global variables where the
|
|
|
|
// declaration and definition may have different lexical decl contexts, once
|
|
|
|
// we have support for emitting declarations of (non-member) global variables.
|
2015-02-28 08:13:13 +08:00
|
|
|
const DeclContext *DC = VD->isStaticDataMember() ? VD->getLexicalDeclContext()
|
|
|
|
: VD->getDeclContext();
|
|
|
|
// When a record type contains an in-line initialization of a static data
|
|
|
|
// member, and the record type is marked as __declspec(dllexport), an implicit
|
|
|
|
// definition of the member will be created in the record context. DWARF
|
|
|
|
// doesn't seem to have a nice way to describe this in a form that consumers
|
|
|
|
// are likely to understand, so fake the "normal" situation of a definition
|
|
|
|
// outside the class by putting it in the global scope.
|
|
|
|
if (DC->isRecord())
|
|
|
|
DC = CGM.getContext().getTranslationUnitDecl();
|
2015-09-12 01:23:08 +08:00
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::DIScope *Mod = getParentModuleOrNull(VD);
|
|
|
|
VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU);
|
2014-11-18 11:40:46 +08:00
|
|
|
}
|
|
|
|
|
2017-02-28 05:30:05 +08:00
|
|
|
llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,
|
|
|
|
bool Stub) {
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray TParamsArray;
|
2014-11-18 11:40:51 +08:00
|
|
|
StringRef Name, LinkageName;
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
|
2018-11-20 02:29:28 +08:00
|
|
|
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
|
2017-02-28 05:30:05 +08:00
|
|
|
SourceLocation Loc = GD.getDecl()->getLocation();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit = getOrCreateFile(Loc);
|
|
|
|
llvm::DIScope *DContext = Unit;
|
2014-11-18 11:40:51 +08:00
|
|
|
unsigned Line = getLineNumber(Loc);
|
2018-06-28 18:56:40 +08:00
|
|
|
collectFunctionDeclProps(GD, Unit, Name, LinkageName, DContext, TParamsArray,
|
|
|
|
Flags);
|
2017-02-28 05:30:05 +08:00
|
|
|
auto *FD = dyn_cast<FunctionDecl>(GD.getDecl());
|
|
|
|
|
2014-11-18 11:40:51 +08:00
|
|
|
// Build function type.
|
|
|
|
SmallVector<QualType, 16> ArgTypes;
|
2017-02-28 05:30:05 +08:00
|
|
|
if (FD)
|
|
|
|
for (const ParmVarDecl *Parm : FD->parameters())
|
|
|
|
ArgTypes.push_back(Parm->getType());
|
2016-06-09 04:41:54 +08:00
|
|
|
CallingConv CC = FD->getType()->castAs<FunctionType>()->getCallConv();
|
|
|
|
QualType FnType = CGM.getContext().getFunctionType(
|
|
|
|
FD->getReturnType(), ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
|
2018-11-20 02:29:28 +08:00
|
|
|
if (!FD->isExternallyVisible())
|
|
|
|
SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
|
|
|
|
if (CGM.getLangOpts().Optimize)
|
|
|
|
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
|
|
|
|
|
2017-02-28 05:30:05 +08:00
|
|
|
if (Stub) {
|
2018-10-06 04:37:17 +08:00
|
|
|
Flags |= getCallSiteRelatedAttrs();
|
2018-11-20 02:29:28 +08:00
|
|
|
SPFlags |= llvm::DISubprogram::SPFlagDefinition;
|
2017-02-28 05:30:05 +08:00
|
|
|
return DBuilder.createFunction(
|
|
|
|
DContext, Name, LinkageName, Unit, Line,
|
2018-11-20 02:29:28 +08:00
|
|
|
getOrCreateFunctionType(GD.getDecl(), FnType, Unit), 0, Flags, SPFlags,
|
2017-02-28 05:30:05 +08:00
|
|
|
TParamsArray.get(), getFunctionDeclaration(FD));
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
|
2015-04-08 00:50:49 +08:00
|
|
|
DContext, Name, LinkageName, Unit, Line,
|
2018-11-20 02:29:28 +08:00
|
|
|
getOrCreateFunctionType(GD.getDecl(), FnType, Unit), 0, Flags, SPFlags,
|
2015-04-08 00:50:49 +08:00
|
|
|
TParamsArray.get(), getFunctionDeclaration(FD));
|
2018-03-01 13:43:23 +08:00
|
|
|
const FunctionDecl *CanonDecl = FD->getCanonicalDecl();
|
2015-04-17 00:36:45 +08:00
|
|
|
FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
|
|
|
|
std::make_tuple(CanonDecl),
|
|
|
|
std::make_tuple(SP));
|
2014-11-18 11:40:51 +08:00
|
|
|
return SP;
|
|
|
|
}
|
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::DISubprogram *CGDebugInfo::getFunctionForwardDeclaration(GlobalDecl GD) {
|
2017-02-28 05:30:05 +08:00
|
|
|
return getFunctionFwdDeclOrStub(GD, /* Stub = */ false);
|
|
|
|
}
|
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::DISubprogram *CGDebugInfo::getFunctionStub(GlobalDecl GD) {
|
2017-02-28 05:30:05 +08:00
|
|
|
return getFunctionFwdDeclOrStub(GD, /* Stub = */ true);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIGlobalVariable *
|
2014-11-18 11:40:51 +08:00
|
|
|
CGDebugInfo::getGlobalVariableForwardDeclaration(const VarDecl *VD) {
|
|
|
|
QualType T;
|
|
|
|
StringRef Name, LinkageName;
|
|
|
|
SourceLocation Loc = VD->getLocation();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit = getOrCreateFile(Loc);
|
|
|
|
llvm::DIScope *DContext = Unit;
|
2014-11-18 11:40:51 +08:00
|
|
|
unsigned Line = getLineNumber(Loc);
|
2018-10-04 02:45:04 +08:00
|
|
|
llvm::MDTuple *TemplateParameters = nullptr;
|
2014-11-18 11:40:51 +08:00
|
|
|
|
2018-10-04 02:45:04 +08:00
|
|
|
collectVarDeclProps(VD, Unit, Line, T, Name, LinkageName, TemplateParameters,
|
|
|
|
DContext);
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
|
2015-04-22 02:43:54 +08:00
|
|
|
auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
|
|
|
|
DContext, Name, LinkageName, Unit, Line, getOrCreateType(T, Unit),
|
2018-10-04 02:45:04 +08:00
|
|
|
!VD->isExternallyVisible(), nullptr, TemplateParameters, Align);
|
2014-12-10 02:39:32 +08:00
|
|
|
FwdDeclReplaceMap.emplace_back(
|
|
|
|
std::piecewise_construct,
|
|
|
|
std::make_tuple(cast<VarDecl>(VD->getCanonicalDecl())),
|
|
|
|
std::make_tuple(static_cast<llvm::Metadata *>(GV)));
|
2014-11-18 11:40:51 +08:00
|
|
|
return GV;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(const Decl *D) {
|
2013-05-20 12:58:53 +08:00
|
|
|
// We only need a declaration (not a definition) of the type - so use whatever
|
|
|
|
// we would otherwise do to get a type for a pointee. (forward declarations in
|
|
|
|
// limited debug info, full definitions (if the type definition is available)
|
|
|
|
// in unlimited debug info)
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *TD = dyn_cast<TypeDecl>(D))
|
2013-08-13 07:14:36 +08:00
|
|
|
return getOrCreateType(CGM.getContext().getTypeDeclType(TD),
|
2013-09-05 06:03:57 +08:00
|
|
|
getOrCreateFile(TD->getLocation()));
|
2014-12-10 02:39:32 +08:00
|
|
|
auto I = DeclCache.find(D->getCanonicalDecl());
|
2014-11-18 11:40:51 +08:00
|
|
|
|
2016-12-20 10:10:02 +08:00
|
|
|
if (I != DeclCache.end()) {
|
|
|
|
auto N = I->second;
|
|
|
|
if (auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(N))
|
|
|
|
return GVE->getVariable();
|
|
|
|
return dyn_cast_or_null<llvm::DINode>(N);
|
|
|
|
}
|
2014-11-18 11:40:51 +08:00
|
|
|
|
|
|
|
// No definition for now. Emit a forward definition that might be
|
|
|
|
// merged with a potential upcoming definition.
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *FD = dyn_cast<FunctionDecl>(D))
|
2014-11-18 11:40:51 +08:00
|
|
|
return getFunctionForwardDeclaration(FD);
|
|
|
|
else if (const auto *VD = dyn_cast<VarDecl>(D))
|
|
|
|
return getGlobalVariableForwardDeclaration(VD);
|
|
|
|
|
2015-04-17 00:36:45 +08:00
|
|
|
return nullptr;
|
2013-05-20 12:58:53 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(const Decl *D) {
|
2016-02-02 19:06:51 +08:00
|
|
|
if (!D || DebugKind <= codegenoptions::DebugLineTablesOnly)
|
2015-04-21 06:09:57 +08:00
|
|
|
return nullptr;
|
2013-06-22 08:09:36 +08:00
|
|
|
|
2016-07-17 08:39:12 +08:00
|
|
|
const auto *FD = dyn_cast<FunctionDecl>(D);
|
2014-10-27 07:40:33 +08:00
|
|
|
if (!FD)
|
2015-04-21 06:09:57 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Setup context.
|
2015-09-11 02:39:45 +08:00
|
|
|
auto *S = getDeclContextDescriptor(D);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
auto MI = SPCache.find(FD->getCanonicalDecl());
|
2013-08-10 01:20:05 +08:00
|
|
|
if (MI == SPCache.end()) {
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *MD = dyn_cast<CXXMethodDecl>(FD->getCanonicalDecl())) {
|
2015-04-21 05:17:26 +08:00
|
|
|
return CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()),
|
2015-04-30 00:40:08 +08:00
|
|
|
cast<llvm::DICompositeType>(S));
|
2013-08-10 01:20:05 +08:00
|
|
|
}
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
if (MI != SPCache.end()) {
|
2015-04-30 00:40:08 +08:00
|
|
|
auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
|
2015-04-14 11:24:14 +08:00
|
|
|
if (SP && !SP->isDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return SP;
|
|
|
|
}
|
|
|
|
|
2014-03-07 07:45:36 +08:00
|
|
|
for (auto NextFD : FD->redecls()) {
|
2014-12-10 02:39:32 +08:00
|
|
|
auto MI = SPCache.find(NextFD->getCanonicalDecl());
|
2012-12-18 22:30:41 +08:00
|
|
|
if (MI != SPCache.end()) {
|
2015-04-30 00:40:08 +08:00
|
|
|
auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
|
2015-04-14 11:24:14 +08:00
|
|
|
if (SP && !SP->isDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return SP;
|
|
|
|
}
|
|
|
|
}
|
2015-04-21 06:09:57 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-21 02:51:48 +08:00
|
|
|
// getOrCreateFunctionType - Construct type. If it is a c++ method, include
|
2012-12-18 22:30:41 +08:00
|
|
|
// implicit parameter "this".
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(const Decl *D,
|
2015-04-17 00:36:45 +08:00
|
|
|
QualType FnType,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *F) {
|
2016-02-02 19:06:51 +08:00
|
|
|
if (!D || DebugKind <= codegenoptions::DebugLineTablesOnly)
|
2015-04-21 06:09:57 +08:00
|
|
|
// 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.
|
2015-10-15 14:56:08 +08:00
|
|
|
return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray(None));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *Method = dyn_cast<CXXMethodDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
return getOrCreateMethodType(Method, F);
|
2016-06-09 04:41:54 +08:00
|
|
|
|
|
|
|
const auto *FTy = FnType->getAs<FunctionType>();
|
|
|
|
CallingConv CC = FTy ? FTy->getCallConv() : CallingConv::CC_C;
|
|
|
|
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Add "self" and "_cmd"
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 16> Elts;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// First element is always return type. For 'void' functions it is NULL.
|
2014-01-26 00:55:45 +08:00
|
|
|
QualType ResultTy = OMethod->getReturnType();
|
2013-05-23 05:37:49 +08:00
|
|
|
|
|
|
|
// Replace the instancetype keyword with the actual type.
|
|
|
|
if (ResultTy == CGM.getContext().getObjCInstanceType())
|
|
|
|
ResultTy = CGM.getContext().getPointerType(
|
2014-10-27 07:40:33 +08:00
|
|
|
QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
|
2013-05-23 05:37:49 +08:00
|
|
|
|
2013-05-11 05:08:31 +08:00
|
|
|
Elts.push_back(getOrCreateType(ResultTy, F));
|
2012-12-18 22:30:41 +08:00
|
|
|
// "self" pointer is always first argument.
|
2015-09-09 04:41:52 +08:00
|
|
|
QualType SelfDeclTy;
|
|
|
|
if (auto *SelfDecl = OMethod->getSelfDecl())
|
|
|
|
SelfDeclTy = SelfDecl->getType();
|
|
|
|
else if (auto *FPT = dyn_cast<FunctionProtoType>(FnType))
|
|
|
|
if (FPT->getNumParams() > 1)
|
|
|
|
SelfDeclTy = FPT->getParamType(0);
|
|
|
|
if (!SelfDeclTy.isNull())
|
2018-06-28 18:56:40 +08:00
|
|
|
Elts.push_back(
|
|
|
|
CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
|
2012-12-18 22:30:41 +08:00
|
|
|
// "_cmd" pointer is always second argument.
|
2015-04-21 02:51:48 +08:00
|
|
|
Elts.push_back(DBuilder.createArtificialType(
|
2015-09-09 04:41:52 +08:00
|
|
|
getOrCreateType(CGM.getContext().getObjCSelType(), F)));
|
2012-12-18 22:30:41 +08:00
|
|
|
// Get rest of the arguments.
|
2016-06-24 12:05:48 +08:00
|
|
|
for (const auto *PI : OMethod->parameters())
|
2014-03-08 01:50:17 +08:00
|
|
|
Elts.push_back(getOrCreateType(PI->getType(), F));
|
2014-08-12 12:42:23 +08:00
|
|
|
// Variadic methods need a special marker at the end of the type list.
|
|
|
|
if (OMethod->isVariadic())
|
|
|
|
Elts.push_back(DBuilder.createUnspecifiedParameter());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
|
2016-09-06 18:48:04 +08:00
|
|
|
return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
|
|
|
|
getDwarfCC(CC));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2014-02-26 03:38:11 +08:00
|
|
|
|
2014-02-26 07:42:18 +08:00
|
|
|
// Handle variadic function types; they need an additional
|
|
|
|
// unspecified parameter.
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *FD = dyn_cast<FunctionDecl>(D))
|
2014-02-26 03:38:11 +08:00
|
|
|
if (FD->isVariadic()) {
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 16> EltTys;
|
2014-02-26 03:38:11 +08:00
|
|
|
EltTys.push_back(getOrCreateType(FD->getReturnType(), F));
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *FPT = dyn_cast<FunctionProtoType>(FnType))
|
|
|
|
for (QualType ParamType : FPT->param_types())
|
|
|
|
EltTys.push_back(getOrCreateType(ParamType, F));
|
2014-02-26 03:38:11 +08:00
|
|
|
EltTys.push_back(DBuilder.createUnspecifiedParameter());
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
|
2016-09-06 18:48:04 +08:00
|
|
|
return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
|
|
|
|
getDwarfCC(CC));
|
2014-02-26 03:38:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
return cast<llvm::DISubroutineType>(getOrCreateType(FnType, F));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-10-27 07:40:33 +08:00
|
|
|
void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
|
|
|
|
SourceLocation ScopeLoc, QualType FnType,
|
2018-04-17 00:53:57 +08:00
|
|
|
llvm::Function *Fn, bool CurFuncIsThunk,
|
|
|
|
CGBuilderTy &Builder) {
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
StringRef Name;
|
|
|
|
StringRef LinkageName;
|
|
|
|
|
|
|
|
FnBeginRegionCount.push_back(LexicalBlockStack.size());
|
|
|
|
|
|
|
|
const Decl *D = GD.getDecl();
|
2014-05-21 13:09:00 +08:00
|
|
|
bool HasDecl = (D != nullptr);
|
2014-04-02 06:25:28 +08:00
|
|
|
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
|
2018-11-20 02:29:28 +08:00
|
|
|
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit = getOrCreateFile(Loc);
|
|
|
|
llvm::DIScope *FDContext = Unit;
|
|
|
|
llvm::DINodeArray TParamsArray;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!HasDecl) {
|
|
|
|
// Use llvm function name.
|
2013-08-28 07:57:18 +08:00
|
|
|
LinkageName = Fn->getName();
|
2016-07-17 08:39:12 +08:00
|
|
|
} else if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
|
2015-04-21 06:09:57 +08:00
|
|
|
// If there is a subprogram for this function available then use it.
|
2014-12-10 02:39:32 +08:00
|
|
|
auto FI = SPCache.find(FD->getCanonicalDecl());
|
2012-12-18 22:30:41 +08:00
|
|
|
if (FI != SPCache.end()) {
|
2015-04-30 00:40:08 +08:00
|
|
|
auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
|
2015-04-14 11:24:14 +08:00
|
|
|
if (SP && SP->isDefinition()) {
|
2015-04-18 08:07:30 +08:00
|
|
|
LexicalBlockStack.emplace_back(SP);
|
2014-12-10 02:39:32 +08:00
|
|
|
RegionMap[D].reset(SP);
|
2012-12-18 22:30:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-11-18 11:40:46 +08:00
|
|
|
collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
|
|
|
|
TParamsArray, Flags);
|
2016-07-17 08:39:12 +08:00
|
|
|
} else if (const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
Name = getObjCMethodName(OMD);
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagPrototyped;
|
2019-04-25 06:45:44 +08:00
|
|
|
} else if (isa<VarDecl>(D) &&
|
|
|
|
GD.getDynamicInitKind() != DynamicInitKind::NoStub) {
|
|
|
|
// This is a global initializer or atexit destructor for a global variable.
|
|
|
|
Name = getDynamicInitializerName(cast<VarDecl>(D), GD.getDynamicInitKind(),
|
|
|
|
Fn);
|
2012-12-18 22:30:41 +08:00
|
|
|
} else {
|
|
|
|
// Use llvm function name.
|
|
|
|
Name = Fn->getName();
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagPrototyped;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2016-07-17 08:39:12 +08:00
|
|
|
if (Name.startswith("\01"))
|
2012-12-18 22:30:41 +08:00
|
|
|
Name = Name.substr(1);
|
|
|
|
|
2018-02-14 08:14:07 +08:00
|
|
|
if (!HasDecl || D->isImplicit() || D->hasAttr<ArtificialAttr>()) {
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagArtificial;
|
2016-11-10 05:43:51 +08:00
|
|
|
// Artificial functions should not silently reuse CurLoc.
|
|
|
|
CurLoc = SourceLocation();
|
2014-04-11 07:21:53 +08:00
|
|
|
}
|
2018-04-17 00:53:57 +08:00
|
|
|
|
|
|
|
if (CurFuncIsThunk)
|
|
|
|
Flags |= llvm::DINode::FlagThunk;
|
|
|
|
|
2018-11-20 02:29:28 +08:00
|
|
|
if (Fn->hasLocalLinkage())
|
|
|
|
SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
|
|
|
|
if (CGM.getLangOpts().Optimize)
|
|
|
|
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
|
|
|
|
|
2018-10-06 04:37:17 +08:00
|
|
|
llvm::DINode::DIFlags FlagsForDef = Flags | getCallSiteRelatedAttrs();
|
2018-11-20 02:29:28 +08:00
|
|
|
llvm::DISubprogram::DISPFlags SPFlagsForDef =
|
|
|
|
SPFlags | llvm::DISubprogram::SPFlagDefinition;
|
2018-10-06 04:37:17 +08:00
|
|
|
|
2014-04-11 07:21:53 +08:00
|
|
|
unsigned LineNo = getLineNumber(Loc);
|
|
|
|
unsigned ScopeLine = getLineNumber(ScopeLoc);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-03-28 02:50:35 +08:00
|
|
|
// FIXME: The function declaration we're constructing here is mostly reusing
|
|
|
|
// declarations from CXXMethodDecl and not constructing new ones for arbitrary
|
|
|
|
// FunctionDecls. When/if we fix this we can have FDContext be TheCU/null for
|
|
|
|
// all subprograms instead of the actual context since subprogram definitions
|
|
|
|
// are emitted as CU level entities by the backend.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubprogram *SP = DBuilder.createFunction(
|
2014-10-27 07:40:33 +08:00
|
|
|
FDContext, Name, LinkageName, Unit, LineNo,
|
2018-11-20 02:29:28 +08:00
|
|
|
getOrCreateFunctionType(D, FnType, Unit), ScopeLine, FlagsForDef,
|
|
|
|
SPFlagsForDef, TParamsArray.get(), getFunctionDeclaration(D));
|
2015-11-06 06:04:14 +08:00
|
|
|
Fn->setSubprogram(SP);
|
2014-11-06 03:19:04 +08:00
|
|
|
// We might get here with a VarDecl in the case we're generating
|
|
|
|
// code for the initialization of globals. Do not record these decls
|
|
|
|
// as they will overwrite the actual VarDecl Decl in the cache.
|
|
|
|
if (HasDecl && isa<FunctionDecl>(D))
|
2016-07-17 08:39:12 +08:00
|
|
|
DeclCache[D->getCanonicalDecl()].reset(SP);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2018-06-28 01:31:59 +08:00
|
|
|
if (CGM.getCodeGenOpts().DwarfVersion >= 5) {
|
|
|
|
// Starting with DWARF V5 method declarations are emitted as children of
|
|
|
|
// the interface type.
|
|
|
|
if (const auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
|
|
|
|
const ObjCInterfaceDecl *ID = OMD->getClassInterface();
|
|
|
|
QualType QTy(ID->getTypeForDecl(), 0);
|
|
|
|
auto It = TypeCache.find(QTy.getAsOpaquePtr());
|
|
|
|
if (It != TypeCache.end()) {
|
|
|
|
llvm::DICompositeType *InterfaceDecl =
|
|
|
|
cast<llvm::DICompositeType>(It->second);
|
|
|
|
llvm::DISubprogram *FD = DBuilder.createFunction(
|
|
|
|
InterfaceDecl, Name, LinkageName, Unit, LineNo,
|
2018-11-20 02:29:28 +08:00
|
|
|
getOrCreateFunctionType(D, FnType, Unit), ScopeLine, Flags, SPFlags,
|
2018-06-28 01:31:59 +08:00
|
|
|
TParamsArray.get());
|
|
|
|
DBuilder.finalizeSubprogram(FD);
|
|
|
|
ObjCMethodCache[ID].push_back(FD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-22 05:01:58 +08:00
|
|
|
// Push the function onto the lexical block stack.
|
2015-04-18 08:07:30 +08:00
|
|
|
LexicalBlockStack.emplace_back(SP);
|
2014-03-22 05:01:58 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (HasDecl)
|
2014-12-10 02:39:32 +08:00
|
|
|
RegionMap[D].reset(SP);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-09-09 04:41:52 +08:00
|
|
|
void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
|
|
|
|
QualType FnType) {
|
|
|
|
StringRef Name;
|
|
|
|
StringRef LinkageName;
|
|
|
|
|
|
|
|
const Decl *D = GD.getDecl();
|
|
|
|
if (!D)
|
|
|
|
return;
|
|
|
|
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
|
2015-09-09 04:41:52 +08:00
|
|
|
llvm::DIFile *Unit = getOrCreateFile(Loc);
|
2015-10-05 07:23:04 +08:00
|
|
|
llvm::DIScope *FDContext = getDeclContextDescriptor(D);
|
2015-09-09 04:41:52 +08:00
|
|
|
llvm::DINodeArray TParamsArray;
|
|
|
|
if (isa<FunctionDecl>(D)) {
|
|
|
|
// If there is a DISubprogram for this function available then use it.
|
|
|
|
collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
|
|
|
|
TParamsArray, Flags);
|
2016-07-17 08:39:12 +08:00
|
|
|
} else if (const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
|
2015-09-09 04:41:52 +08:00
|
|
|
Name = getObjCMethodName(OMD);
|
|
|
|
Flags |= llvm::DINode::FlagPrototyped;
|
|
|
|
} else {
|
|
|
|
llvm_unreachable("not a function or ObjC method");
|
|
|
|
}
|
|
|
|
if (!Name.empty() && Name[0] == '\01')
|
|
|
|
Name = Name.substr(1);
|
|
|
|
|
|
|
|
if (D->isImplicit()) {
|
|
|
|
Flags |= llvm::DINode::FlagArtificial;
|
|
|
|
// Artificial functions without a location should not silently reuse CurLoc.
|
|
|
|
if (Loc.isInvalid())
|
|
|
|
CurLoc = SourceLocation();
|
|
|
|
}
|
|
|
|
unsigned LineNo = getLineNumber(Loc);
|
|
|
|
unsigned ScopeLine = 0;
|
2018-11-20 02:29:28 +08:00
|
|
|
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
|
|
|
|
if (CGM.getLangOpts().Optimize)
|
|
|
|
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
|
2015-09-09 04:41:52 +08:00
|
|
|
|
2016-04-15 23:55:45 +08:00
|
|
|
DBuilder.retainType(DBuilder.createFunction(
|
|
|
|
FDContext, Name, LinkageName, Unit, LineNo,
|
2018-11-20 02:29:28 +08:00
|
|
|
getOrCreateFunctionType(D, FnType, Unit), ScopeLine, Flags, SPFlags,
|
2016-04-15 23:55:45 +08:00
|
|
|
TParamsArray.get(), getFunctionDeclaration(D)));
|
2015-09-09 04:41:52 +08:00
|
|
|
}
|
|
|
|
|
2017-02-28 05:30:05 +08:00
|
|
|
void CGDebugInfo::EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD) {
|
|
|
|
const auto *FD = cast<FunctionDecl>(GD.getDecl());
|
|
|
|
// If there is a subprogram for this function available then use it.
|
|
|
|
auto FI = SPCache.find(FD->getCanonicalDecl());
|
|
|
|
llvm::DISubprogram *SP = nullptr;
|
|
|
|
if (FI != SPCache.end())
|
|
|
|
SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
|
2017-08-24 05:24:12 +08:00
|
|
|
if (!SP || !SP->isDefinition())
|
2017-02-28 05:30:05 +08:00
|
|
|
SP = getFunctionStub(GD);
|
|
|
|
FnBeginRegionCount.push_back(LexicalBlockStack.size());
|
|
|
|
LexicalBlockStack.emplace_back(SP);
|
|
|
|
setInlinedAt(Builder.getCurrentDebugLocation());
|
|
|
|
EmitLocation(Builder, FD->getLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::EmitInlineFunctionEnd(CGBuilderTy &Builder) {
|
|
|
|
assert(CurInlinedAt && "unbalanced inline scope stack");
|
2017-06-02 05:14:03 +08:00
|
|
|
EmitFunctionEnd(Builder, nullptr);
|
2017-02-28 05:30:05 +08:00
|
|
|
setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt());
|
|
|
|
}
|
|
|
|
|
2018-09-25 02:24:18 +08:00
|
|
|
void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Update our current location
|
|
|
|
setLocation(Loc);
|
|
|
|
|
2018-11-10 05:17:38 +08:00
|
|
|
if (CurLoc.isInvalid() || CurLoc.isMacroID() || LexicalBlockStack.empty())
|
2014-10-27 07:40:33 +08:00
|
|
|
return;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-01-08 06:05:52 +08:00
|
|
|
llvm::MDNode *Scope = LexicalBlockStack.back();
|
2018-09-25 02:24:18 +08:00
|
|
|
Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
|
|
|
|
getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, CurInlinedAt));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::CreateLexicalBlock(SourceLocation Loc) {
|
2014-12-10 03:22:40 +08:00
|
|
|
llvm::MDNode *Back = nullptr;
|
|
|
|
if (!LexicalBlockStack.empty())
|
|
|
|
Back = LexicalBlockStack.back().get();
|
2015-04-18 08:07:30 +08:00
|
|
|
LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
|
2015-04-30 00:40:08 +08:00
|
|
|
cast<llvm::DIScope>(Back), getOrCreateFile(CurLoc), getLineNumber(CurLoc),
|
2015-04-18 08:07:30 +08:00
|
|
|
getColumnNumber(CurLoc)));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2017-03-10 02:06:23 +08:00
|
|
|
void CGDebugInfo::AppendAddressSpaceXDeref(
|
2018-06-28 18:56:40 +08:00
|
|
|
unsigned AddressSpace, SmallVectorImpl<int64_t> &Expr) const {
|
2017-03-10 02:06:23 +08:00
|
|
|
Optional<unsigned> DWARFAddressSpace =
|
|
|
|
CGM.getTarget().getDWARFAddressSpace(AddressSpace);
|
|
|
|
if (!DWARFAddressSpace)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Expr.push_back(llvm::dwarf::DW_OP_constu);
|
|
|
|
Expr.push_back(DWARFAddressSpace.getValue());
|
|
|
|
Expr.push_back(llvm::dwarf::DW_OP_swap);
|
|
|
|
Expr.push_back(llvm::dwarf::DW_OP_xderef);
|
|
|
|
}
|
|
|
|
|
2013-05-16 08:52:20 +08:00
|
|
|
void CGDebugInfo::EmitLexicalBlockStart(CGBuilderTy &Builder,
|
|
|
|
SourceLocation Loc) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Set our current location.
|
|
|
|
setLocation(Loc);
|
|
|
|
|
|
|
|
// Emit a line table change for the current location inside the new scope.
|
2017-02-28 05:30:05 +08:00
|
|
|
Builder.SetCurrentDebugLocation(
|
|
|
|
llvm::DebugLoc::get(getLineNumber(Loc), getColumnNumber(Loc),
|
|
|
|
LexicalBlockStack.back(), CurInlinedAt));
|
2014-10-23 03:34:33 +08:00
|
|
|
|
2016-02-02 19:06:51 +08:00
|
|
|
if (DebugKind <= codegenoptions::DebugLineTablesOnly)
|
2014-10-23 03:34:33 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Create a new lexical block and push it on the stack.
|
|
|
|
CreateLexicalBlock(Loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-05-16 08:52:20 +08:00
|
|
|
void CGDebugInfo::EmitLexicalBlockEnd(CGBuilderTy &Builder,
|
|
|
|
SourceLocation Loc) {
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
|
|
|
|
|
|
|
|
// Provide an entry in the line table for the end of the block.
|
2018-09-25 02:24:18 +08:00
|
|
|
EmitLocation(Builder, Loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-02-02 19:06:51 +08:00
|
|
|
if (DebugKind <= codegenoptions::DebugLineTablesOnly)
|
2014-10-23 03:34:33 +08:00
|
|
|
return;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
LexicalBlockStack.pop_back();
|
|
|
|
}
|
|
|
|
|
2017-06-02 05:14:03 +08:00
|
|
|
void CGDebugInfo::EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn) {
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
|
|
|
|
unsigned RCount = FnBeginRegionCount.back();
|
|
|
|
assert(RCount <= LexicalBlockStack.size() && "Region stack mismatch");
|
|
|
|
|
|
|
|
// Pop all regions for this function.
|
2014-10-23 03:34:33 +08:00
|
|
|
while (LexicalBlockStack.size() != RCount) {
|
|
|
|
// Provide an entry in the line table for the end of the block.
|
2018-09-25 02:24:18 +08:00
|
|
|
EmitLocation(Builder, CurLoc);
|
2014-10-23 03:34:33 +08:00
|
|
|
LexicalBlockStack.pop_back();
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
FnBeginRegionCount.pop_back();
|
2017-06-02 05:14:03 +08:00
|
|
|
|
|
|
|
if (Fn && Fn->getSubprogram())
|
|
|
|
DBuilder.finalizeSubprogram(Fn->getSubprogram());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2018-09-11 00:14:28 +08:00
|
|
|
CGDebugInfo::BlockByRefType
|
|
|
|
CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
|
|
|
|
uint64_t *XOffset) {
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 5> EltTys;
|
2012-12-18 22:30:41 +08:00
|
|
|
QualType FType;
|
|
|
|
uint64_t FieldSize, FieldOffset;
|
2016-10-20 06:11:07 +08:00
|
|
|
uint32_t FieldAlign;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit = getOrCreateFile(VD->getLocation());
|
2013-05-16 08:45:12 +08:00
|
|
|
QualType Type = VD->getType();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
FieldOffset = 0;
|
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__forwarding", &FieldOffset));
|
|
|
|
FType = CGM.getContext().IntTy;
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
|
|
|
|
|
|
|
|
bool HasCopyAndDispose = CGM.getContext().BlockRequiresCopying(Type, VD);
|
|
|
|
if (HasCopyAndDispose) {
|
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
2014-10-27 07:40:33 +08:00
|
|
|
EltTys.push_back(
|
|
|
|
CreateMemberType(Unit, FType, "__copy_helper", &FieldOffset));
|
|
|
|
EltTys.push_back(
|
|
|
|
CreateMemberType(Unit, FType, "__destroy_helper", &FieldOffset));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
bool HasByrefExtendedLayout;
|
|
|
|
Qualifiers::ObjCLifetime Lifetime;
|
2014-10-27 07:40:33 +08:00
|
|
|
if (CGM.getContext().getByrefLifetime(Type, Lifetime,
|
|
|
|
HasByrefExtendedLayout) &&
|
|
|
|
HasByrefExtendedLayout) {
|
2013-07-23 08:12:14 +08:00
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
2014-10-27 07:40:33 +08:00
|
|
|
EltTys.push_back(
|
|
|
|
CreateMemberType(Unit, FType, "__byref_variable_layout", &FieldOffset));
|
2013-07-23 08:12:14 +08:00
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CharUnits Align = CGM.getContext().getDeclAlign(VD);
|
|
|
|
if (Align > CGM.getContext().toCharUnitsFromBits(
|
2014-10-27 07:40:33 +08:00
|
|
|
CGM.getTarget().getPointerAlign(0))) {
|
|
|
|
CharUnits FieldOffsetInBytes =
|
|
|
|
CGM.getContext().toCharUnitsFromBits(FieldOffset);
|
2016-01-15 05:00:27 +08:00
|
|
|
CharUnits AlignedOffsetInBytes = FieldOffsetInBytes.alignTo(Align);
|
2014-10-27 07:40:33 +08:00
|
|
|
CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (NumPaddingBytes.isPositive()) {
|
|
|
|
llvm::APInt pad(32, NumPaddingBytes.getQuantity());
|
|
|
|
FType = CGM.getContext().getConstantArrayType(CGM.getContext().CharTy,
|
|
|
|
pad, ArrayType::Normal, 0);
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "", &FieldOffset));
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
FType = Type;
|
2018-09-11 00:14:28 +08:00
|
|
|
llvm::DIType *WrappedTy = getOrCreateType(FType, Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
FieldSize = CGM.getContext().getTypeSize(FType);
|
|
|
|
FieldAlign = CGM.getContext().toBits(Align);
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
*XOffset = FieldOffset;
|
2018-09-11 00:14:28 +08:00
|
|
|
llvm::DIType *FieldTy = DBuilder.createMemberType(
|
|
|
|
Unit, VD->getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset,
|
|
|
|
llvm::DINode::FlagZero, WrappedTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
EltTys.push_back(FieldTy);
|
|
|
|
FieldOffset += FieldSize;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
|
2018-09-11 00:14:28 +08:00
|
|
|
return {DBuilder.createStructType(Unit, "", Unit, 0, FieldOffset, 0,
|
|
|
|
llvm::DINode::FlagZero, nullptr, Elements),
|
|
|
|
WrappedTy};
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2018-02-03 21:55:59 +08:00
|
|
|
llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
|
|
|
|
llvm::Value *Storage,
|
|
|
|
llvm::Optional<unsigned> ArgNo,
|
2019-06-21 01:15:21 +08:00
|
|
|
CGBuilderTy &Builder,
|
|
|
|
const bool UsePointerValue) {
|
2016-02-02 19:06:51 +08:00
|
|
|
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
|
2016-06-16 08:42:36 +08:00
|
|
|
if (VD->hasAttr<NoDebugAttr>())
|
2018-02-03 21:55:59 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-08-19 11:37:48 +08:00
|
|
|
bool Unwritten =
|
|
|
|
VD->isImplicit() || (isa<Decl>(VD->getDeclContext()) &&
|
|
|
|
cast<Decl>(VD->getDeclContext())->isImplicit());
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit = nullptr;
|
2013-08-19 11:37:48 +08:00
|
|
|
if (!Unwritten)
|
|
|
|
Unit = getOrCreateFile(VD->getLocation());
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *Ty;
|
2012-12-18 22:30:41 +08:00
|
|
|
uint64_t XOffset = 0;
|
|
|
|
if (VD->hasAttr<BlocksAttr>())
|
2018-09-11 00:14:28 +08:00
|
|
|
Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
|
2013-05-16 08:45:12 +08:00
|
|
|
else
|
2012-12-18 22:30:41 +08:00
|
|
|
Ty = getOrCreateType(VD->getType(), Unit);
|
|
|
|
|
|
|
|
// If there is no debug info for this type then do not emit debug info
|
|
|
|
// for this variable.
|
|
|
|
if (!Ty)
|
2018-02-03 21:55:59 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Get location information.
|
2013-08-19 11:37:48 +08:00
|
|
|
unsigned Line = 0;
|
|
|
|
unsigned Column = 0;
|
|
|
|
if (!Unwritten) {
|
|
|
|
Line = getLineNumber(VD->getLocation());
|
|
|
|
Column = getColumnNumber(VD->getLocation());
|
|
|
|
}
|
2017-03-10 02:06:23 +08:00
|
|
|
SmallVector<int64_t, 13> Expr;
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (VD->isImplicit())
|
2015-04-30 00:40:08 +08:00
|
|
|
Flags |= llvm::DINode::FlagArtificial;
|
2016-10-20 08:13:19 +08:00
|
|
|
|
|
|
|
auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
|
|
|
|
|
2017-03-10 02:06:23 +08:00
|
|
|
unsigned AddressSpace = CGM.getContext().getTargetAddressSpace(VD->getType());
|
|
|
|
AppendAddressSpaceXDeref(AddressSpace, Expr);
|
|
|
|
|
2017-06-09 21:55:08 +08:00
|
|
|
// If this is implicit parameter of CXXThis or ObjCSelf kind, then give it an
|
|
|
|
// object pointer flag.
|
2017-06-09 21:40:18 +08:00
|
|
|
if (const auto *IPD = dyn_cast<ImplicitParamDecl>(VD)) {
|
|
|
|
if (IPD->getParameterKind() == ImplicitParamDecl::CXXThis ||
|
|
|
|
IPD->getParameterKind() == ImplicitParamDecl::ObjCSelf)
|
|
|
|
Flags |= llvm::DINode::FlagObjectPointer;
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2017-04-18 09:22:01 +08:00
|
|
|
// Note: Older versions of clang used to emit byval references with an extra
|
|
|
|
// DW_OP_deref, because they referenced the IR arg directly instead of
|
|
|
|
// referencing an alloca. Newer versions of LLVM don't treat allocas
|
|
|
|
// differently from other function arguments when used in a dbg.declare.
|
2015-04-30 00:40:08 +08:00
|
|
|
auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef Name = VD->getName();
|
|
|
|
if (!Name.empty()) {
|
|
|
|
if (VD->hasAttr<BlocksAttr>()) {
|
2017-04-18 09:22:01 +08:00
|
|
|
// Here, we need an offset *into* the alloca.
|
2012-12-18 22:30:41 +08:00
|
|
|
CharUnits offset = CharUnits::fromQuantity(32);
|
2017-06-14 02:06:15 +08:00
|
|
|
Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
|
2012-12-18 22:30:41 +08:00
|
|
|
// offset of __forwarding field
|
|
|
|
offset = CGM.getContext().toCharUnitsFromBits(
|
2014-10-27 07:40:33 +08:00
|
|
|
CGM.getTarget().getPointerWidth(0));
|
2015-01-20 01:51:58 +08:00
|
|
|
Expr.push_back(offset.getQuantity());
|
|
|
|
Expr.push_back(llvm::dwarf::DW_OP_deref);
|
2017-06-14 02:06:15 +08:00
|
|
|
Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
|
2012-12-18 22:30:41 +08:00
|
|
|
// offset of x field
|
|
|
|
offset = CGM.getContext().toCharUnitsFromBits(XOffset);
|
2015-01-20 01:51:58 +08:00
|
|
|
Expr.push_back(offset.getQuantity());
|
2017-04-18 09:22:01 +08:00
|
|
|
}
|
2016-07-17 08:39:12 +08:00
|
|
|
} else if (const auto *RT = dyn_cast<RecordType>(VD->getType())) {
|
2015-04-29 23:05:50 +08:00
|
|
|
// If VD is an anonymous union then Storage represents value for
|
|
|
|
// all union fields.
|
2018-03-01 13:43:23 +08:00
|
|
|
const RecordDecl *RD = RT->getDecl();
|
2015-04-29 23:05:50 +08:00
|
|
|
if (RD->isUnion() && RD->isAnonymousStructOrUnion()) {
|
2015-04-30 00:52:31 +08:00
|
|
|
// GDB has trouble finding local variables in anonymous unions, so we emit
|
2018-04-06 23:14:32 +08:00
|
|
|
// artificial local variables for each of the members.
|
2015-04-30 00:52:31 +08:00
|
|
|
//
|
|
|
|
// FIXME: Remove this code as soon as GDB supports this.
|
|
|
|
// The debug info verifier in LLVM operates based on the assumption that a
|
2018-06-28 18:56:40 +08:00
|
|
|
// variable has the same size as its storage and we had to disable the
|
|
|
|
// check for artificial variables.
|
2015-04-29 23:05:50 +08:00
|
|
|
for (const auto *Field : RD->fields()) {
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
|
2015-04-29 23:05:50 +08:00
|
|
|
StringRef FieldName = Field->getName();
|
|
|
|
|
|
|
|
// Ignore unnamed fields. Do not ignore unnamed records.
|
|
|
|
if (FieldName.empty() && !isa<RecordType>(Field->getType()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Use VarDecl's Tag, Scope and Line number.
|
2016-10-20 08:13:19 +08:00
|
|
|
auto FieldAlign = getDeclAlignIfRequired(Field, CGM.getContext());
|
2015-08-01 01:56:14 +08:00
|
|
|
auto *D = DBuilder.createAutoVariable(
|
|
|
|
Scope, FieldName, Unit, Line, FieldTy, CGM.getLangOpts().Optimize,
|
2016-10-20 08:13:19 +08:00
|
|
|
Flags | llvm::DINode::FlagArtificial, FieldAlign);
|
2015-04-29 23:05:50 +08:00
|
|
|
|
|
|
|
// Insert an llvm.dbg.declare into the current block.
|
2017-02-28 05:30:05 +08:00
|
|
|
DBuilder.insertDeclare(
|
|
|
|
Storage, D, DBuilder.createExpression(Expr),
|
|
|
|
llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),
|
|
|
|
Builder.GetInsertBlock());
|
2015-04-29 23:05:50 +08:00
|
|
|
}
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-01-05 13:58:35 +08:00
|
|
|
|
2019-06-21 01:15:21 +08:00
|
|
|
// Clang stores the sret pointer provided by the caller in a static alloca.
|
|
|
|
// Use DW_OP_deref to tell the debugger to load the pointer and treat it as
|
|
|
|
// the address of the variable.
|
|
|
|
if (UsePointerValue) {
|
|
|
|
assert(std::find(Expr.begin(), Expr.end(), llvm::dwarf::DW_OP_deref) ==
|
|
|
|
Expr.end() &&
|
|
|
|
"Debug info already contains DW_OP_deref.");
|
|
|
|
Expr.push_back(llvm::dwarf::DW_OP_deref);
|
|
|
|
}
|
|
|
|
|
2013-01-05 13:58:35 +08:00
|
|
|
// Create the descriptor for the variable.
|
2018-06-28 18:56:40 +08:00
|
|
|
auto *D = ArgNo ? DBuilder.createParameterVariable(
|
|
|
|
Scope, Name, *ArgNo, Unit, Line, Ty,
|
|
|
|
CGM.getLangOpts().Optimize, Flags)
|
|
|
|
: DBuilder.createAutoVariable(Scope, Name, Unit, Line, Ty,
|
|
|
|
CGM.getLangOpts().Optimize,
|
|
|
|
Flags, Align);
|
2013-01-05 13:58:35 +08:00
|
|
|
|
|
|
|
// Insert an llvm.dbg.declare into the current block.
|
2015-04-16 05:18:30 +08:00
|
|
|
DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
|
2017-02-28 05:30:05 +08:00
|
|
|
llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),
|
2015-04-16 05:18:30 +08:00
|
|
|
Builder.GetInsertBlock());
|
2018-02-03 21:55:59 +08:00
|
|
|
|
|
|
|
return D;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2018-02-03 21:55:59 +08:00
|
|
|
llvm::DILocalVariable *
|
|
|
|
CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD, llvm::Value *Storage,
|
2019-06-21 01:15:21 +08:00
|
|
|
CGBuilderTy &Builder,
|
|
|
|
const bool UsePointerValue) {
|
2016-02-02 19:06:51 +08:00
|
|
|
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
|
2019-06-21 01:15:21 +08:00
|
|
|
return EmitDeclare(VD, Storage, llvm::None, Builder, UsePointerValue);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2019-01-24 13:34:29 +08:00
|
|
|
void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {
|
|
|
|
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
|
|
|
|
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
|
|
|
|
|
|
|
|
if (D->hasAttr<NoDebugAttr>())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
|
|
|
|
llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
|
|
|
|
|
|
|
|
// Get location information.
|
|
|
|
unsigned Line = getLineNumber(D->getLocation());
|
|
|
|
unsigned Column = getColumnNumber(D->getLocation());
|
|
|
|
|
|
|
|
StringRef Name = D->getName();
|
|
|
|
|
|
|
|
// Create the descriptor for the label.
|
|
|
|
auto *L =
|
|
|
|
DBuilder.createLabel(Scope, Name, Unit, Line, CGM.getLangOpts().Optimize);
|
|
|
|
|
|
|
|
// Insert an llvm.dbg.label into the current block.
|
|
|
|
DBuilder.insertLabel(L,
|
|
|
|
llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),
|
|
|
|
Builder.GetInsertBlock());
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
|
|
|
|
llvm::DIType *Ty) {
|
|
|
|
llvm::DIType *CachedTy = getTypeOrNull(QualTy);
|
2014-10-27 07:40:33 +08:00
|
|
|
if (CachedTy)
|
|
|
|
Ty = CachedTy;
|
2013-03-30 03:20:29 +08:00
|
|
|
return DBuilder.createObjectPointerType(Ty);
|
|
|
|
}
|
|
|
|
|
2014-10-27 07:40:33 +08:00
|
|
|
void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
|
|
|
|
const VarDecl *VD, llvm::Value *Storage, CGBuilderTy &Builder,
|
2014-11-21 08:35:25 +08:00
|
|
|
const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
|
2016-02-02 19:06:51 +08:00
|
|
|
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
if (Builder.GetInsertBlock() == nullptr)
|
2012-12-18 22:30:41 +08:00
|
|
|
return;
|
2016-06-16 08:42:36 +08:00
|
|
|
if (VD->hasAttr<NoDebugAttr>())
|
|
|
|
return;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool isByRef = VD->hasAttr<BlocksAttr>();
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
uint64_t XOffset = 0;
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit = getOrCreateFile(VD->getLocation());
|
|
|
|
llvm::DIType *Ty;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (isByRef)
|
2018-09-11 00:14:28 +08:00
|
|
|
Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
|
2013-05-16 08:45:12 +08:00
|
|
|
else
|
2012-12-18 22:30:41 +08:00
|
|
|
Ty = getOrCreateType(VD->getType(), Unit);
|
|
|
|
|
|
|
|
// Self is passed along as an implicit non-arg variable in a
|
|
|
|
// block. Mark it as the object pointer.
|
2017-06-09 21:40:18 +08:00
|
|
|
if (const auto *IPD = dyn_cast<ImplicitParamDecl>(VD))
|
|
|
|
if (IPD->getParameterKind() == ImplicitParamDecl::ObjCSelf)
|
|
|
|
Ty = CreateSelfType(VD->getType(), Ty);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Get location information.
|
|
|
|
unsigned Line = getLineNumber(VD->getLocation());
|
|
|
|
unsigned Column = getColumnNumber(VD->getLocation());
|
|
|
|
|
|
|
|
const llvm::DataLayout &target = CGM.getDataLayout();
|
|
|
|
|
|
|
|
CharUnits offset = CharUnits::fromQuantity(
|
2014-10-27 07:40:33 +08:00
|
|
|
target.getStructLayout(blockInfo.StructureType)
|
2012-12-18 22:30:41 +08:00
|
|
|
->getElementOffset(blockInfo.getCapture(VD).getIndex()));
|
|
|
|
|
2014-10-02 04:26:18 +08:00
|
|
|
SmallVector<int64_t, 9> addr;
|
2017-04-18 09:22:01 +08:00
|
|
|
addr.push_back(llvm::dwarf::DW_OP_deref);
|
2017-06-14 02:06:15 +08:00
|
|
|
addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
|
2014-10-02 04:26:18 +08:00
|
|
|
addr.push_back(offset.getQuantity());
|
2012-12-18 22:30:41 +08:00
|
|
|
if (isByRef) {
|
2014-10-02 04:26:18 +08:00
|
|
|
addr.push_back(llvm::dwarf::DW_OP_deref);
|
2017-06-14 02:06:15 +08:00
|
|
|
addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
|
2012-12-18 22:30:41 +08:00
|
|
|
// offset of __forwarding field
|
2014-10-27 07:40:33 +08:00
|
|
|
offset =
|
|
|
|
CGM.getContext().toCharUnitsFromBits(target.getPointerSizeInBits(0));
|
2014-10-02 04:26:18 +08:00
|
|
|
addr.push_back(offset.getQuantity());
|
|
|
|
addr.push_back(llvm::dwarf::DW_OP_deref);
|
2017-06-14 02:06:15 +08:00
|
|
|
addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
|
2012-12-18 22:30:41 +08:00
|
|
|
// offset of x field
|
|
|
|
offset = CGM.getContext().toCharUnitsFromBits(XOffset);
|
2014-10-02 04:26:18 +08:00
|
|
|
addr.push_back(offset.getQuantity());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the descriptor for the variable.
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
|
2015-08-01 01:56:14 +08:00
|
|
|
auto *D = DBuilder.createAutoVariable(
|
2015-04-30 00:40:08 +08:00
|
|
|
cast<llvm::DILocalScope>(LexicalBlockStack.back()), VD->getName(), Unit,
|
2016-10-20 08:13:19 +08:00
|
|
|
Line, Ty, false, llvm::DINode::FlagZero, Align);
|
2013-03-30 03:20:35 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Insert an llvm.dbg.declare into the current block.
|
2017-02-28 05:30:05 +08:00
|
|
|
auto DL =
|
|
|
|
llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back(), CurInlinedAt);
|
2017-04-18 09:22:01 +08:00
|
|
|
auto *Expr = DBuilder.createExpression(addr);
|
2015-04-16 05:18:30 +08:00
|
|
|
if (InsertPoint)
|
2017-04-18 09:22:01 +08:00
|
|
|
DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint);
|
2015-04-16 05:18:30 +08:00
|
|
|
else
|
2017-04-18 09:22:01 +08:00
|
|
|
DBuilder.insertDeclare(Storage, D, Expr, DL, Builder.GetInsertBlock());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *VD, llvm::Value *AI,
|
|
|
|
unsigned ArgNo,
|
|
|
|
CGBuilderTy &Builder) {
|
2016-02-02 19:06:51 +08:00
|
|
|
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
|
2015-08-01 01:56:14 +08:00
|
|
|
EmitDeclare(VD, AI, ArgNo, Builder);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2014-10-27 07:40:33 +08:00
|
|
|
struct BlockLayoutChunk {
|
|
|
|
uint64_t OffsetInBits;
|
|
|
|
const BlockDecl::Capture *Capture;
|
|
|
|
};
|
|
|
|
bool operator<(const BlockLayoutChunk &l, const BlockLayoutChunk &r) {
|
|
|
|
return l.OffsetInBits < r.OffsetInBits;
|
|
|
|
}
|
2018-06-28 18:56:40 +08:00
|
|
|
} // namespace
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2018-08-08 23:56:12 +08:00
|
|
|
void CGDebugInfo::collectDefaultFieldsForBlockLiteralDeclare(
|
|
|
|
const CGBlockInfo &Block, const ASTContext &Context, SourceLocation Loc,
|
|
|
|
const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
|
|
|
|
SmallVectorImpl<llvm::Metadata *> &Fields) {
|
|
|
|
// Blocks in OpenCL have unique constraints which make the standard fields
|
|
|
|
// redundant while requiring size and align fields for enqueue_kernel. See
|
|
|
|
// initializeForBlockHeader in CGBlocks.cpp
|
|
|
|
if (CGM.getLangOpts().OpenCL) {
|
|
|
|
Fields.push_back(createFieldType("__size", Context.IntTy, Loc, AS_public,
|
|
|
|
BlockLayout.getElementOffsetInBits(0),
|
|
|
|
Unit, Unit));
|
|
|
|
Fields.push_back(createFieldType("__align", Context.IntTy, Loc, AS_public,
|
|
|
|
BlockLayout.getElementOffsetInBits(1),
|
|
|
|
Unit, Unit));
|
|
|
|
} else {
|
|
|
|
Fields.push_back(createFieldType("__isa", Context.VoidPtrTy, Loc, AS_public,
|
|
|
|
BlockLayout.getElementOffsetInBits(0),
|
|
|
|
Unit, Unit));
|
|
|
|
Fields.push_back(createFieldType("__flags", Context.IntTy, Loc, AS_public,
|
|
|
|
BlockLayout.getElementOffsetInBits(1),
|
|
|
|
Unit, Unit));
|
|
|
|
Fields.push_back(
|
|
|
|
createFieldType("__reserved", Context.IntTy, Loc, AS_public,
|
|
|
|
BlockLayout.getElementOffsetInBits(2), Unit, Unit));
|
|
|
|
auto *FnTy = Block.getBlockExpr()->getFunctionType();
|
|
|
|
auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
|
|
|
|
Fields.push_back(createFieldType("__FuncPtr", FnPtrType, Loc, AS_public,
|
|
|
|
BlockLayout.getElementOffsetInBits(3),
|
|
|
|
Unit, Unit));
|
|
|
|
Fields.push_back(createFieldType(
|
|
|
|
"__descriptor",
|
|
|
|
Context.getPointerType(Block.NeedsCopyDispose
|
|
|
|
? Context.getBlockDescriptorExtendedType()
|
|
|
|
: Context.getBlockDescriptorType()),
|
|
|
|
Loc, AS_public, BlockLayout.getElementOffsetInBits(4), Unit, Unit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
|
2017-10-27 04:08:52 +08:00
|
|
|
StringRef Name,
|
2014-08-09 01:10:14 +08:00
|
|
|
unsigned ArgNo,
|
2017-10-27 04:08:52 +08:00
|
|
|
llvm::AllocaInst *Alloca,
|
2012-12-18 22:30:41 +08:00
|
|
|
CGBuilderTy &Builder) {
|
2016-02-02 19:06:51 +08:00
|
|
|
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
ASTContext &C = CGM.getContext();
|
|
|
|
const BlockDecl *blockDecl = block.getBlockDecl();
|
|
|
|
|
|
|
|
// Collect some general information about the block's location.
|
|
|
|
SourceLocation loc = blockDecl->getCaretLocation();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *tunit = getOrCreateFile(loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned line = getLineNumber(loc);
|
|
|
|
unsigned column = getColumnNumber(loc);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Build the debug-info type for the block literal.
|
2015-09-11 02:39:45 +08:00
|
|
|
getDeclContextDescriptor(blockDecl);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
const llvm::StructLayout *blockLayout =
|
2014-10-27 07:40:33 +08:00
|
|
|
CGM.getDataLayout().getStructLayout(block.StructureType);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 16> fields;
|
2018-08-08 23:56:12 +08:00
|
|
|
collectDefaultFieldsForBlockLiteralDeclare(block, C, loc, *blockLayout, tunit,
|
|
|
|
fields);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// We want to sort the captures by offset, not because DWARF
|
|
|
|
// requires this, but because we're paranoid about debuggers.
|
|
|
|
SmallVector<BlockLayoutChunk, 8> chunks;
|
|
|
|
|
|
|
|
// 'this' capture.
|
|
|
|
if (blockDecl->capturesCXXThis()) {
|
|
|
|
BlockLayoutChunk chunk;
|
|
|
|
chunk.OffsetInBits =
|
2014-10-27 07:40:33 +08:00
|
|
|
blockLayout->getElementOffsetInBits(block.CXXThisIndex);
|
2014-05-21 13:09:00 +08:00
|
|
|
chunk.Capture = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
chunks.push_back(chunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Variable captures.
|
2014-03-15 02:34:04 +08:00
|
|
|
for (const auto &capture : blockDecl->captures()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
const VarDecl *variable = capture.getVariable();
|
|
|
|
const CGBlockInfo::Capture &captureInfo = block.getCapture(variable);
|
|
|
|
|
|
|
|
// Ignore constant captures.
|
|
|
|
if (captureInfo.isConstant())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BlockLayoutChunk chunk;
|
|
|
|
chunk.OffsetInBits =
|
2014-10-27 07:40:33 +08:00
|
|
|
blockLayout->getElementOffsetInBits(captureInfo.getIndex());
|
2012-12-18 22:30:41 +08:00
|
|
|
chunk.Capture = &capture;
|
|
|
|
chunks.push_back(chunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort by offset.
|
|
|
|
llvm::array_pod_sort(chunks.begin(), chunks.end());
|
|
|
|
|
2016-07-17 08:39:12 +08:00
|
|
|
for (const BlockLayoutChunk &Chunk : chunks) {
|
|
|
|
uint64_t offsetInBits = Chunk.OffsetInBits;
|
|
|
|
const BlockDecl::Capture *capture = Chunk.Capture;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// If we have a null capture, this must be the C++ 'this' capture.
|
|
|
|
if (!capture) {
|
2016-04-19 07:48:16 +08:00
|
|
|
QualType type;
|
|
|
|
if (auto *Method =
|
|
|
|
cast_or_null<CXXMethodDecl>(blockDecl->getNonClosureContext()))
|
2019-01-11 09:54:53 +08:00
|
|
|
type = Method->getThisType();
|
2016-04-19 07:48:16 +08:00
|
|
|
else if (auto *RDecl = dyn_cast<CXXRecordDecl>(blockDecl->getParent()))
|
|
|
|
type = QualType(RDecl->getTypeForDecl(), 0);
|
|
|
|
else
|
|
|
|
llvm_unreachable("unexpected block declcontext");
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-06-30 11:01:59 +08:00
|
|
|
fields.push_back(createFieldType("this", type, loc, AS_public,
|
2012-12-18 22:30:41 +08:00
|
|
|
offsetInBits, tunit, tunit));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VarDecl *variable = capture->getVariable();
|
|
|
|
StringRef name = variable->getName();
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *fieldType;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (capture->isByRef()) {
|
2014-07-30 09:30:47 +08:00
|
|
|
TypeInfo PtrInfo = C.getTypeInfo(C.VoidPtrTy);
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = PtrInfo.AlignIsRequired ? PtrInfo.Align : 0;
|
2018-09-11 00:14:28 +08:00
|
|
|
// FIXME: This recomputes the layout of the BlockByRefWrapper.
|
2012-12-18 22:30:41 +08:00
|
|
|
uint64_t xoffset;
|
2018-09-11 00:14:28 +08:00
|
|
|
fieldType =
|
|
|
|
EmitTypeForVarWithBlocksAttr(variable, &xoffset).BlockByRefWrapper;
|
2014-07-30 09:30:47 +08:00
|
|
|
fieldType = DBuilder.createPointerType(fieldType, PtrInfo.Width);
|
2016-10-20 08:13:19 +08:00
|
|
|
fieldType = DBuilder.createMemberType(tunit, name, tunit, line,
|
|
|
|
PtrInfo.Width, Align, offsetInBits,
|
|
|
|
llvm::DINode::FlagZero, fieldType);
|
2012-12-18 22:30:41 +08:00
|
|
|
} else {
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getDeclAlignIfRequired(variable, CGM.getContext());
|
2016-06-30 11:01:59 +08:00
|
|
|
fieldType = createFieldType(name, variable->getType(), loc, AS_public,
|
2016-10-20 08:13:19 +08:00
|
|
|
offsetInBits, Align, tunit, tunit);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
fields.push_back(fieldType);
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallString<36> typeName;
|
2018-06-28 18:56:40 +08:00
|
|
|
llvm::raw_svector_ostream(typeName)
|
|
|
|
<< "__block_literal_" << CGM.getUniqueBlockCount();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-09-07 01:06:14 +08:00
|
|
|
llvm::DIType *type =
|
|
|
|
DBuilder.createStructType(tunit, typeName.str(), tunit, line,
|
2016-10-20 08:13:19 +08:00
|
|
|
CGM.getContext().toBits(block.BlockSize), 0,
|
2016-09-07 01:06:14 +08:00
|
|
|
llvm::DINode::FlagZero, nullptr, fieldsArray);
|
2012-12-18 22:30:41 +08:00
|
|
|
type = DBuilder.createPointerType(type, CGM.PointerWidthInBits);
|
|
|
|
|
|
|
|
// Get overall information about the block.
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags flags = llvm::DINode::FlagArtificial;
|
2015-04-30 00:40:08 +08:00
|
|
|
auto *scope = cast<llvm::DILocalScope>(LexicalBlockStack.back());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Create the descriptor for the parameter.
|
2015-08-01 01:56:14 +08:00
|
|
|
auto *debugVar = DBuilder.createParameterVariable(
|
2018-06-28 18:56:40 +08:00
|
|
|
scope, Name, ArgNo, tunit, line, type, CGM.getLangOpts().Optimize, flags);
|
2013-03-15 01:53:33 +08:00
|
|
|
|
2013-03-15 05:52:59 +08:00
|
|
|
// Insert an llvm.dbg.declare into the current block.
|
2017-10-27 04:08:52 +08:00
|
|
|
DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
|
2017-02-28 05:30:05 +08:00
|
|
|
llvm::DebugLoc::get(line, column, scope, CurInlinedAt),
|
2015-04-16 05:18:30 +08:00
|
|
|
Builder.GetInsertBlock());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIDerivedType *
|
2013-08-20 09:28:15 +08:00
|
|
|
CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) {
|
2019-05-31 06:04:11 +08:00
|
|
|
if (!D || !D->isStaticDataMember())
|
2015-04-21 05:17:26 +08:00
|
|
|
return nullptr;
|
2015-02-28 08:13:13 +08:00
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
auto MI = StaticDataMemberCache.find(D->getCanonicalDecl());
|
2013-08-20 09:28:15 +08:00
|
|
|
if (MI != StaticDataMemberCache.end()) {
|
|
|
|
assert(MI->second && "Static data member declaration should still exist");
|
2015-07-25 02:05:58 +08:00
|
|
|
return MI->second;
|
2013-08-20 09:28:15 +08:00
|
|
|
}
|
2013-08-21 05:49:21 +08:00
|
|
|
|
|
|
|
// If the member wasn't found in the cache, lazily construct and add it to the
|
|
|
|
// type (used when a limited form of the type is emitted).
|
2014-08-30 06:44:27 +08:00
|
|
|
auto DC = D->getDeclContext();
|
2015-09-11 02:39:45 +08:00
|
|
|
auto *Ctxt = cast<llvm::DICompositeType>(getDeclContextDescriptor(D));
|
2014-08-30 06:44:27 +08:00
|
|
|
return CreateRecordStaticField(D, Ctxt, cast<RecordDecl>(DC));
|
2013-08-20 09:28:15 +08:00
|
|
|
}
|
|
|
|
|
2016-12-20 10:10:02 +08:00
|
|
|
llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
|
2015-04-30 00:40:08 +08:00
|
|
|
const RecordDecl *RD, llvm::DIFile *Unit, unsigned LineNo,
|
|
|
|
StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
|
2016-12-20 10:10:02 +08:00
|
|
|
llvm::DIGlobalVariableExpression *GVE = nullptr;
|
2014-04-10 13:20:00 +08:00
|
|
|
|
|
|
|
for (const auto *Field : RD->fields()) {
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
|
2014-04-10 13:20:00 +08:00
|
|
|
StringRef FieldName = Field->getName();
|
|
|
|
|
|
|
|
// Ignore unnamed fields, but recurse into anonymous records.
|
|
|
|
if (FieldName.empty()) {
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *RT = dyn_cast<RecordType>(Field->getType()))
|
2016-12-20 10:10:02 +08:00
|
|
|
GVE = CollectAnonRecordDecls(RT->getDecl(), Unit, LineNo, LinkageName,
|
2018-06-28 18:56:40 +08:00
|
|
|
Var, DContext);
|
2014-04-10 13:20:00 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Use VarDecl's Tag, Scope and Line number.
|
2016-12-20 10:10:02 +08:00
|
|
|
GVE = DBuilder.createGlobalVariableExpression(
|
|
|
|
DContext, FieldName, LinkageName, Unit, LineNo, FieldTy,
|
|
|
|
Var->hasLocalLinkage());
|
|
|
|
Var->addDebugInfo(GVE);
|
2014-04-10 13:20:00 +08:00
|
|
|
}
|
2016-12-20 10:10:02 +08:00
|
|
|
return GVE;
|
2014-04-10 13:20:00 +08:00
|
|
|
}
|
|
|
|
|
2013-08-30 16:53:09 +08:00
|
|
|
void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
|
2012-12-18 22:30:41 +08:00
|
|
|
const VarDecl *D) {
|
2016-02-02 19:06:51 +08:00
|
|
|
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
|
2016-04-28 01:37:12 +08:00
|
|
|
if (D->hasAttr<NoDebugAttr>())
|
|
|
|
return;
|
2016-11-09 08:42:03 +08:00
|
|
|
|
|
|
|
// If we already created a DIGlobalVariable for this declaration, just attach
|
|
|
|
// it to the llvm::GlobalVariable.
|
|
|
|
auto Cached = DeclCache.find(D->getCanonicalDecl());
|
|
|
|
if (Cached != DeclCache.end())
|
2016-12-20 10:10:02 +08:00
|
|
|
return Var->addDebugInfo(
|
|
|
|
cast<llvm::DIGlobalVariableExpression>(Cached->second));
|
2016-11-09 08:42:03 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Create global variable debug descriptor.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit = nullptr;
|
|
|
|
llvm::DIScope *DContext = nullptr;
|
2014-11-18 11:40:46 +08:00
|
|
|
unsigned LineNo;
|
|
|
|
StringRef DeclName, LinkageName;
|
|
|
|
QualType T;
|
2018-10-04 02:45:04 +08:00
|
|
|
llvm::MDTuple *TemplateParameters = nullptr;
|
|
|
|
collectVarDeclProps(D, Unit, LineNo, T, DeclName, LinkageName,
|
|
|
|
TemplateParameters, DContext);
|
2014-04-10 13:20:00 +08:00
|
|
|
|
|
|
|
// Attempt to store one global variable for the declaration - even if we
|
|
|
|
// emit a lot of fields.
|
2016-12-20 10:10:02 +08:00
|
|
|
llvm::DIGlobalVariableExpression *GVE = nullptr;
|
2014-04-10 13:20:00 +08:00
|
|
|
|
|
|
|
// If this is an anonymous union then we'll want to emit a global
|
|
|
|
// variable for each member of the anonymous union so that it's possible
|
|
|
|
// to find the name of any field in the union.
|
|
|
|
if (T->isUnionType() && DeclName.empty()) {
|
2015-11-21 01:41:12 +08:00
|
|
|
const RecordDecl *RD = T->castAs<RecordType>()->getDecl();
|
2014-10-27 07:40:33 +08:00
|
|
|
assert(RD->isAnonymousStructOrUnion() &&
|
|
|
|
"unnamed non-anonymous struct or union?");
|
2016-12-20 10:10:02 +08:00
|
|
|
GVE = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
|
2014-04-10 13:20:00 +08:00
|
|
|
} else {
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getDeclAlignIfRequired(D, CGM.getContext());
|
2017-03-10 02:06:23 +08:00
|
|
|
|
|
|
|
SmallVector<int64_t, 4> Expr;
|
|
|
|
unsigned AddressSpace =
|
|
|
|
CGM.getContext().getTargetAddressSpace(D->getType());
|
[DEBUG_INFO][NVPTX] Generate correct data about variable address class.
Summary:
Added ability to generate correct debug info data about the variable
address class. Currently, for all the locals and globals the default
values are used, ADDR_local_space(6) for locals and ADDR_global_space(5)
for globals. The values are taken from the table in
https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf.
We need to emit correct data for address classes of, at least, shared
and constant globals. Currently, all these variables are treated by
the cuda-gdb debugger as the variables in the global address space
and, thus, it require manual data type casting.
Reviewers: echristo, probinson
Subscribers: jholewinski, aprantl, cfe-commits
Differential Revision: https://reviews.llvm.org/D57162
llvm-svn: 353204
2019-02-06 03:45:57 +08:00
|
|
|
if (CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) {
|
|
|
|
if (D->hasAttr<CUDASharedAttr>())
|
|
|
|
AddressSpace =
|
|
|
|
CGM.getContext().getTargetAddressSpace(LangAS::cuda_shared);
|
|
|
|
else if (D->hasAttr<CUDAConstantAttr>())
|
|
|
|
AddressSpace =
|
|
|
|
CGM.getContext().getTargetAddressSpace(LangAS::cuda_constant);
|
|
|
|
}
|
2017-03-10 02:06:23 +08:00
|
|
|
AppendAddressSpaceXDeref(AddressSpace, Expr);
|
|
|
|
|
2016-12-20 10:10:02 +08:00
|
|
|
GVE = DBuilder.createGlobalVariableExpression(
|
2014-04-10 13:20:00 +08:00
|
|
|
DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
|
2017-03-10 02:06:23 +08:00
|
|
|
Var->hasLocalLinkage(),
|
|
|
|
Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
|
2018-10-04 02:45:04 +08:00
|
|
|
getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
|
|
|
|
Align);
|
2016-12-20 10:10:02 +08:00
|
|
|
Var->addDebugInfo(GVE);
|
2014-04-10 13:20:00 +08:00
|
|
|
}
|
2016-12-20 10:10:02 +08:00
|
|
|
DeclCache[D->getCanonicalDecl()].reset(GVE);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2016-09-13 09:13:19 +08:00
|
|
|
void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
|
2016-02-02 19:06:51 +08:00
|
|
|
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
|
2016-04-28 01:37:12 +08:00
|
|
|
if (VD->hasAttr<NoDebugAttr>())
|
|
|
|
return;
|
2016-10-20 08:13:19 +08:00
|
|
|
auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
|
2013-08-30 16:53:09 +08:00
|
|
|
// Create the descriptor for the variable.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit = getOrCreateFile(VD->getLocation());
|
2013-08-30 16:53:09 +08:00
|
|
|
StringRef Name = VD->getName();
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *Ty = getOrCreateType(VD->getType(), Unit);
|
2019-05-22 23:48:59 +08:00
|
|
|
|
2019-06-14 06:53:43 +08:00
|
|
|
// Do not use global variables for enums, unless in CodeView.
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
|
|
|
|
const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
|
2013-08-30 16:53:09 +08:00
|
|
|
assert(isa<EnumType>(ED->getTypeForDecl()) && "Enum without EnumType?");
|
2019-05-23 01:45:24 +08:00
|
|
|
(void)ED;
|
2019-05-31 06:04:11 +08:00
|
|
|
|
2019-06-14 06:53:43 +08:00
|
|
|
// If CodeView, emit enums as global variables, unless they are defined
|
|
|
|
// inside a class. We do this because MSVC doesn't emit S_CONSTANTs for
|
|
|
|
// enums in classes, and because it is difficult to attach this scope
|
|
|
|
// information to the global variable.
|
|
|
|
if (!CGM.getCodeGenOpts().EmitCodeView ||
|
|
|
|
isa<RecordDecl>(ED->getDeclContext()))
|
2019-05-31 06:04:11 +08:00
|
|
|
return;
|
2019-05-22 23:48:59 +08:00
|
|
|
}
|
|
|
|
|
2019-05-30 05:45:34 +08:00
|
|
|
llvm::DIScope *DContext = nullptr;
|
|
|
|
|
|
|
|
// Do not emit separate definitions for function local consts.
|
2014-04-05 04:56:17 +08:00
|
|
|
if (isa<FunctionDecl>(VD->getDeclContext()))
|
|
|
|
return;
|
2019-05-30 05:45:34 +08:00
|
|
|
|
|
|
|
// Emit definition for static members in CodeView.
|
2014-04-05 15:23:17 +08:00
|
|
|
VD = cast<ValueDecl>(VD->getCanonicalDecl());
|
2019-05-31 06:04:11 +08:00
|
|
|
auto *VarD = dyn_cast<VarDecl>(VD);
|
|
|
|
if (VarD && VarD->isStaticDataMember()) {
|
2014-11-21 08:20:58 +08:00
|
|
|
auto *RD = cast<RecordDecl>(VarD->getDeclContext());
|
2015-09-11 02:39:45 +08:00
|
|
|
getDeclContextDescriptor(VarD);
|
2014-11-20 03:42:40 +08:00
|
|
|
// Ensure that the type is retained even though it's otherwise unreferenced.
|
2016-04-24 05:08:27 +08:00
|
|
|
//
|
|
|
|
// FIXME: This is probably unnecessary, since Ty should reference RD
|
|
|
|
// through its scope.
|
2014-11-20 03:42:40 +08:00
|
|
|
RetainedTypes.push_back(
|
2014-11-21 08:20:58 +08:00
|
|
|
CGM.getContext().getRecordType(RD).getAsOpaquePtr());
|
2014-11-20 03:42:40 +08:00
|
|
|
|
2019-05-30 05:45:34 +08:00
|
|
|
if (!CGM.getCodeGenOpts().EmitCodeView)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Use the global scope for static members.
|
|
|
|
DContext = getContextDescriptor(
|
|
|
|
cast<Decl>(CGM.getContext().getTranslationUnitDecl()), TheCU);
|
|
|
|
} else {
|
|
|
|
DContext = getDeclContextDescriptor(VD);
|
|
|
|
}
|
2014-11-21 08:20:58 +08:00
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
auto &GV = DeclCache[VD];
|
|
|
|
if (GV)
|
2014-04-05 15:23:17 +08:00
|
|
|
return;
|
2016-09-13 09:13:19 +08:00
|
|
|
llvm::DIExpression *InitExpr = nullptr;
|
2016-12-17 06:10:52 +08:00
|
|
|
if (CGM.getContext().getTypeSize(VD->getType()) <= 64) {
|
|
|
|
// FIXME: Add a representation for integer constants wider than 64 bits.
|
|
|
|
if (Init.isInt())
|
|
|
|
InitExpr =
|
|
|
|
DBuilder.createConstantValueExpression(Init.getInt().getExtValue());
|
|
|
|
else if (Init.isFloat())
|
|
|
|
InitExpr = DBuilder.createConstantValueExpression(
|
|
|
|
Init.getFloat().bitcastToAPInt().getZExtValue());
|
|
|
|
}
|
2018-10-04 02:45:04 +08:00
|
|
|
|
|
|
|
llvm::MDTuple *TemplateParameters = nullptr;
|
|
|
|
|
|
|
|
if (isa<VarTemplateSpecializationDecl>(VD))
|
|
|
|
if (VarD) {
|
|
|
|
llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VarD, &*Unit);
|
|
|
|
TemplateParameters = parameterNodes.get();
|
|
|
|
}
|
|
|
|
|
2016-12-20 10:10:02 +08:00
|
|
|
GV.reset(DBuilder.createGlobalVariableExpression(
|
2014-04-05 15:46:57 +08:00
|
|
|
DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
|
2016-10-20 08:13:19 +08:00
|
|
|
true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
|
2018-10-04 02:45:04 +08:00
|
|
|
TemplateParameters, Align));
|
2013-05-20 12:58:53 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
|
2013-05-20 12:58:53 +08:00
|
|
|
if (!LexicalBlockStack.empty())
|
2015-04-21 02:32:15 +08:00
|
|
|
return LexicalBlockStack.back();
|
2015-09-12 01:23:08 +08:00
|
|
|
llvm::DIScope *Mod = getParentModuleOrNull(D);
|
|
|
|
return getContextDescriptor(D, Mod ? Mod : TheCU);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-04-22 14:13:21 +08:00
|
|
|
void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) {
|
2016-02-02 19:06:51 +08:00
|
|
|
if (CGM.getCodeGenOpts().getDebugInfo() < codegenoptions::LimitedDebugInfo)
|
2013-05-20 12:58:53 +08:00
|
|
|
return;
|
2015-12-11 02:52:50 +08:00
|
|
|
const NamespaceDecl *NSDecl = UD.getNominatedNamespace();
|
2016-07-22 02:43:20 +08:00
|
|
|
if (!NSDecl->isAnonymousNamespace() ||
|
|
|
|
CGM.getCodeGenOpts().DebugExplicitImport) {
|
2017-07-19 08:09:58 +08:00
|
|
|
auto Loc = UD.getLocation();
|
2015-12-11 02:52:50 +08:00
|
|
|
DBuilder.createImportedModule(
|
|
|
|
getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())),
|
2017-07-19 08:09:58 +08:00
|
|
|
getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
|
2015-12-11 02:52:50 +08:00
|
|
|
}
|
2013-04-22 14:13:21 +08:00
|
|
|
}
|
|
|
|
|
2013-05-20 12:58:53 +08:00
|
|
|
void CGDebugInfo::EmitUsingDecl(const UsingDecl &UD) {
|
2016-02-02 19:06:51 +08:00
|
|
|
if (CGM.getCodeGenOpts().getDebugInfo() < codegenoptions::LimitedDebugInfo)
|
2013-05-20 12:58:53 +08:00
|
|
|
return;
|
|
|
|
assert(UD.shadow_size() &&
|
|
|
|
"We shouldn't be codegening an invalid UsingDecl containing no decls");
|
|
|
|
// Emitting one decl is sufficient - debuggers can detect that this is an
|
|
|
|
// overloaded name & provide lookup for all the overloads.
|
|
|
|
const UsingShadowDecl &USD = **UD.shadow_begin();
|
2016-08-06 03:03:01 +08:00
|
|
|
|
|
|
|
// FIXME: Skip functions with undeduced auto return type for now since we
|
|
|
|
// don't currently have the plumbing for separate declarations & definitions
|
|
|
|
// of free functions and mismatched types (auto in the declaration, concrete
|
|
|
|
// return type in the definition)
|
|
|
|
if (const auto *FD = dyn_cast<FunctionDecl>(USD.getUnderlyingDecl()))
|
|
|
|
if (const auto *AT =
|
|
|
|
FD->getType()->getAs<FunctionProtoType>()->getContainedAutoType())
|
|
|
|
if (AT->getDeducedType().isNull())
|
|
|
|
return;
|
2015-04-30 00:40:08 +08:00
|
|
|
if (llvm::DINode *Target =
|
2017-07-19 08:09:58 +08:00
|
|
|
getDeclarationOrDefinition(USD.getUnderlyingDecl())) {
|
|
|
|
auto Loc = USD.getLocation();
|
2013-05-20 12:58:53 +08:00
|
|
|
DBuilder.createImportedDeclaration(
|
|
|
|
getCurrentContextDescriptor(cast<Decl>(USD.getDeclContext())), Target,
|
2017-07-19 08:09:58 +08:00
|
|
|
getOrCreateFile(Loc), getLineNumber(Loc));
|
|
|
|
}
|
2013-05-20 12:58:53 +08:00
|
|
|
}
|
|
|
|
|
2015-07-01 01:39:51 +08:00
|
|
|
void CGDebugInfo::EmitImportDecl(const ImportDecl &ID) {
|
2016-05-04 07:06:40 +08:00
|
|
|
if (CGM.getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::LLDB)
|
|
|
|
return;
|
2015-12-19 03:44:31 +08:00
|
|
|
if (Module *M = ID.getImportedModule()) {
|
2015-12-19 04:08:40 +08:00
|
|
|
auto Info = ExternalASTSource::ASTSourceDescriptor(*M);
|
2017-07-19 08:09:58 +08:00
|
|
|
auto Loc = ID.getLocation();
|
2015-12-19 03:44:31 +08:00
|
|
|
DBuilder.createImportedDeclaration(
|
|
|
|
getCurrentContextDescriptor(cast<Decl>(ID.getDeclContext())),
|
2017-07-19 08:09:58 +08:00
|
|
|
getOrCreateModuleRef(Info, DebugTypeExtRefs), getOrCreateFile(Loc),
|
|
|
|
getLineNumber(Loc));
|
2015-12-19 03:44:31 +08:00
|
|
|
}
|
2015-07-01 01:39:51 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIImportedEntity *
|
2013-05-21 06:50:41 +08:00
|
|
|
CGDebugInfo::EmitNamespaceAlias(const NamespaceAliasDecl &NA) {
|
2016-02-02 19:06:51 +08:00
|
|
|
if (CGM.getCodeGenOpts().getDebugInfo() < codegenoptions::LimitedDebugInfo)
|
2015-04-22 02:43:54 +08:00
|
|
|
return nullptr;
|
2014-12-10 02:39:32 +08:00
|
|
|
auto &VH = NamespaceAliasCache[&NA];
|
2013-05-21 06:50:41 +08:00
|
|
|
if (VH)
|
2015-04-30 00:40:08 +08:00
|
|
|
return cast<llvm::DIImportedEntity>(VH);
|
|
|
|
llvm::DIImportedEntity *R;
|
2017-07-19 08:09:58 +08:00
|
|
|
auto Loc = NA.getLocation();
|
2016-07-17 08:39:12 +08:00
|
|
|
if (const auto *Underlying =
|
2013-05-21 06:50:41 +08:00
|
|
|
dyn_cast<NamespaceAliasDecl>(NA.getAliasedNamespace()))
|
|
|
|
// This could cache & dedup here rather than relying on metadata deduping.
|
2014-04-06 14:30:03 +08:00
|
|
|
R = DBuilder.createImportedDeclaration(
|
2013-05-21 06:50:41 +08:00
|
|
|
getCurrentContextDescriptor(cast<Decl>(NA.getDeclContext())),
|
2017-07-19 08:09:58 +08:00
|
|
|
EmitNamespaceAlias(*Underlying), getOrCreateFile(Loc),
|
|
|
|
getLineNumber(Loc), NA.getName());
|
2013-05-21 06:50:41 +08:00
|
|
|
else
|
2014-04-06 14:30:03 +08:00
|
|
|
R = DBuilder.createImportedDeclaration(
|
2013-05-21 06:50:41 +08:00
|
|
|
getCurrentContextDescriptor(cast<Decl>(NA.getDeclContext())),
|
2017-05-13 00:23:53 +08:00
|
|
|
getOrCreateNamespace(cast<NamespaceDecl>(NA.getAliasedNamespace())),
|
2017-07-19 08:09:58 +08:00
|
|
|
getOrCreateFile(Loc), getLineNumber(Loc), NA.getName());
|
2014-12-10 02:39:32 +08:00
|
|
|
VH.reset(R);
|
2013-05-21 06:50:41 +08:00
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINamespace *
|
2017-05-13 00:23:53 +08:00
|
|
|
CGDebugInfo::getOrCreateNamespace(const NamespaceDecl *NSDecl) {
|
|
|
|
// Don't canonicalize the NamespaceDecl here: The DINamespace will be uniqued
|
|
|
|
// if necessary, and this way multiple declarations of the same namespace in
|
|
|
|
// different parent modules stay distinct.
|
|
|
|
auto I = NamespaceCache.find(NSDecl);
|
2017-05-12 06:59:19 +08:00
|
|
|
if (I != NamespaceCache.end())
|
2015-04-30 00:40:08 +08:00
|
|
|
return cast<llvm::DINamespace>(I->second);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2015-09-11 02:39:45 +08:00
|
|
|
llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
|
2017-05-12 06:59:19 +08:00
|
|
|
// Don't trust the context if it is a DIModule (see comment above).
|
2017-05-13 00:23:53 +08:00
|
|
|
llvm::DINamespace *NS =
|
|
|
|
DBuilder.createNameSpace(Context, NSDecl->getName(), NSDecl->isInline());
|
|
|
|
NamespaceCache[NSDecl].reset(NS);
|
2012-12-18 22:30:41 +08:00
|
|
|
return NS;
|
|
|
|
}
|
|
|
|
|
2015-09-23 07:26:43 +08:00
|
|
|
void CGDebugInfo::setDwoId(uint64_t Signature) {
|
|
|
|
assert(TheCU && "no main compile unit");
|
|
|
|
TheCU->setDWOId(Signature);
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void CGDebugInfo::finalize() {
|
2014-05-08 00:56:58 +08:00
|
|
|
// Creating types might create further types - invalidating the current
|
|
|
|
// element and the size(), so don't cache/reference them.
|
|
|
|
for (size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
|
|
|
|
ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *Ty = E.Type->getDecl()->getDefinition()
|
2015-04-12 03:05:04 +08:00
|
|
|
? CreateTypeDefinition(E.Type, E.Unit)
|
|
|
|
: E.Decl;
|
2015-04-30 00:40:08 +08:00
|
|
|
DBuilder.replaceTemporary(llvm::TempDIType(E.Decl), Ty);
|
2014-05-08 00:56:58 +08:00
|
|
|
}
|
|
|
|
|
2018-06-28 01:31:59 +08:00
|
|
|
if (CGM.getCodeGenOpts().DwarfVersion >= 5) {
|
|
|
|
// Add methods to interface.
|
2018-06-28 18:56:40 +08:00
|
|
|
for (const auto &P : ObjCMethodCache) {
|
2018-06-28 01:31:59 +08:00
|
|
|
if (P.second.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QualType QTy(P.first->getTypeForDecl(), 0);
|
|
|
|
auto It = TypeCache.find(QTy.getAsOpaquePtr());
|
|
|
|
assert(It != TypeCache.end());
|
|
|
|
|
|
|
|
llvm::DICompositeType *InterfaceDecl =
|
|
|
|
cast<llvm::DICompositeType>(It->second);
|
|
|
|
|
|
|
|
SmallVector<llvm::Metadata *, 16> EltTys;
|
|
|
|
auto CurrenetElts = InterfaceDecl->getElements();
|
|
|
|
EltTys.append(CurrenetElts.begin(), CurrenetElts.end());
|
|
|
|
for (auto &MD : P.second)
|
|
|
|
EltTys.push_back(MD);
|
|
|
|
llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
|
|
|
|
DBuilder.replaceArrays(InterfaceDecl, Elements);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
for (const auto &P : ReplaceMap) {
|
|
|
|
assert(P.second);
|
|
|
|
auto *Ty = cast<llvm::DIType>(P.second);
|
2015-04-16 09:00:56 +08:00
|
|
|
assert(Ty->isForwardDecl());
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
auto It = TypeCache.find(P.first);
|
|
|
|
assert(It != TypeCache.end());
|
|
|
|
assert(It->second);
|
2013-03-12 02:33:46 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
DBuilder.replaceTemporary(llvm::TempDIType(Ty),
|
2018-06-28 18:56:40 +08:00
|
|
|
cast<llvm::DIType>(It->second));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-03-12 02:33:46 +08:00
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
for (const auto &P : FwdDeclReplaceMap) {
|
|
|
|
assert(P.second);
|
|
|
|
llvm::TempMDNode FwdDecl(cast<llvm::MDNode>(P.second));
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::Metadata *Repl;
|
2014-11-18 11:40:51 +08:00
|
|
|
|
2018-06-28 18:56:40 +08:00
|
|
|
auto It = DeclCache.find(P.first);
|
2014-12-19 09:02:11 +08:00
|
|
|
// If there has been no definition for the declaration, call RAUW
|
2014-11-18 11:40:51 +08:00
|
|
|
// with ourselves, that will destroy the temporary MDNode and
|
|
|
|
// replace it with a standard one, avoiding leaking memory.
|
2018-06-28 18:56:40 +08:00
|
|
|
if (It == DeclCache.end())
|
|
|
|
Repl = P.second;
|
2014-11-18 11:40:51 +08:00
|
|
|
else
|
2018-06-28 18:56:40 +08:00
|
|
|
Repl = It->second;
|
2014-11-20 02:53:46 +08:00
|
|
|
|
2016-12-20 10:10:02 +08:00
|
|
|
if (auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(Repl))
|
|
|
|
Repl = GVE->getVariable();
|
2015-04-18 08:07:30 +08:00
|
|
|
DBuilder.replaceTemporary(std::move(FwdDecl), cast<llvm::MDNode>(Repl));
|
2014-11-18 11:40:51 +08:00
|
|
|
}
|
|
|
|
|
2013-03-12 02:33:46 +08:00
|
|
|
// We keep our own list of retained types, because we need to look
|
|
|
|
// up the final type in the type cache.
|
2015-08-28 06:56:46 +08:00
|
|
|
for (auto &RT : RetainedTypes)
|
2015-08-28 05:21:19 +08:00
|
|
|
if (auto MD = TypeCache[RT])
|
|
|
|
DBuilder.retainType(cast<llvm::DIType>(MD));
|
2013-03-12 02:33:46 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
DBuilder.finalize();
|
|
|
|
}
|
2014-09-25 01:01:27 +08:00
|
|
|
|
|
|
|
void CGDebugInfo::EmitExplicitCastType(QualType Ty) {
|
2016-02-02 19:06:51 +08:00
|
|
|
if (CGM.getCodeGenOpts().getDebugInfo() < codegenoptions::LimitedDebugInfo)
|
2014-09-25 01:01:27 +08:00
|
|
|
return;
|
2015-03-28 06:58:05 +08:00
|
|
|
|
2018-12-12 00:58:46 +08:00
|
|
|
if (auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
|
2015-03-28 06:58:05 +08:00
|
|
|
// Don't ignore in case of explicit cast where it is referenced indirectly.
|
|
|
|
DBuilder.retainType(DieTy);
|
2014-09-25 01:01:27 +08:00
|
|
|
}
|
2016-11-10 22:44:30 +08:00
|
|
|
|
|
|
|
llvm::DebugLoc CGDebugInfo::SourceLocToDebugLoc(SourceLocation Loc) {
|
|
|
|
if (LexicalBlockStack.empty())
|
|
|
|
return llvm::DebugLoc();
|
|
|
|
|
|
|
|
llvm::MDNode *Scope = LexicalBlockStack.back();
|
2018-06-28 18:56:40 +08:00
|
|
|
return llvm::DebugLoc::get(getLineNumber(Loc), getColumnNumber(Loc), Scope);
|
2016-11-10 22:44:30 +08:00
|
|
|
}
|
2018-10-06 04:37:17 +08:00
|
|
|
|
|
|
|
llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const {
|
|
|
|
// Call site-related attributes are only useful in optimized programs, and
|
|
|
|
// when there's a possibility of debugging backtraces.
|
|
|
|
if (!CGM.getLangOpts().Optimize || DebugKind == codegenoptions::NoDebugInfo ||
|
|
|
|
DebugKind == codegenoptions::LocTrackingOnly)
|
|
|
|
return llvm::DINode::FlagZero;
|
|
|
|
|
|
|
|
// Call site-related attributes are available in DWARF v5. Some debuggers,
|
|
|
|
// while not fully DWARF v5-compliant, may accept these attributes as if they
|
|
|
|
// were part of DWARF v4.
|
|
|
|
bool SupportsDWARFv4Ext =
|
|
|
|
CGM.getCodeGenOpts().DwarfVersion == 4 &&
|
|
|
|
CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB;
|
|
|
|
if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5)
|
|
|
|
return llvm::DINode::FlagZero;
|
|
|
|
|
|
|
|
return llvm::DINode::FlagAllCallsDescribed;
|
|
|
|
}
|