1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

Move the sysroot attribute from DIModule to DICompileUnit

[this re-applies c0176916a4824812d25a5a22c4ff7c95857b0cd6
 with the correct commit message and phabricator link]

This addresses point 1 of PR44213.
https://bugs.llvm.org/show_bug.cgi?id=44213

The DW_AT_LLVM_sysroot attribute is used for Clang module debug info,
to allow LLDB to import a Clang module from source. Currently it is
part of each DW_TAG_module, however, it is the same for all modules in
a compile unit. It is more efficient and less ambiguous to store it
once in the DW_TAG_compile_unit.

This should have no effect on DWARF consumers other than LLDB.

Differential Revision: https://reviews.llvm.org/D71732
This commit is contained in:
Adrian Prantl 2020-01-14 13:37:04 -08:00
parent e3aa322358
commit 3363ed7b0a
24 changed files with 167 additions and 141 deletions

View File

@ -117,6 +117,7 @@ type DICompileUnit struct {
Optimized bool Optimized bool
Flags string Flags string
RuntimeVersion int RuntimeVersion int
SysRoot string
} }
// CreateCompileUnit creates compile unit debug metadata. // CreateCompileUnit creates compile unit debug metadata.
@ -129,6 +130,8 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
defer C.free(unsafe.Pointer(producer)) defer C.free(unsafe.Pointer(producer))
flags := C.CString(cu.Flags) flags := C.CString(cu.Flags)
defer C.free(unsafe.Pointer(flags)) defer C.free(unsafe.Pointer(flags))
sysroot := C.CString(cu.SysRoot)
defer C.free(unsafe.Pointer(sysroot))
result := C.LLVMDIBuilderCreateCompileUnit( result := C.LLVMDIBuilderCreateCompileUnit(
d.ref, d.ref,
C.LLVMDWARFSourceLanguage(cu.Language), C.LLVMDWARFSourceLanguage(cu.Language),
@ -142,6 +145,7 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
/*DWOId=*/ 0, /*DWOId=*/ 0,
/*SplitDebugInlining*/ C.LLVMBool(boolToCInt(true)), /*SplitDebugInlining*/ C.LLVMBool(boolToCInt(true)),
/*DebugInfoForProfiling*/ C.LLVMBool(boolToCInt(false)), /*DebugInfoForProfiling*/ C.LLVMBool(boolToCInt(false)),
sysroot,
) )
return Metadata{C: result} return Metadata{C: result}
} }

View File

@ -250,6 +250,8 @@ void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder);
* \param SplitDebugInlining Whether to emit inline debug info. * \param SplitDebugInlining Whether to emit inline debug info.
* \param DebugInfoForProfiling Whether to emit extra debug info for * \param DebugInfoForProfiling Whether to emit extra debug info for
* profile collection. * profile collection.
* \param SysRoot The Clang system root (value of -isysroot).
* \param SysRootLen The length of the C string passed to \c SysRoot.
*/ */
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit( LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang, LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang,
@ -257,7 +259,7 @@ LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
LLVMBool isOptimized, const char *Flags, size_t FlagsLen, LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen, unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining, LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
LLVMBool DebugInfoForProfiling); LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen);
/** /**
* Create a file descriptor to hold debugging information for a file. * Create a file descriptor to hold debugging information for a file.
@ -283,15 +285,12 @@ LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
* \param ConfigMacrosLen The length of the C string passed to \c ConfigMacros. * \param ConfigMacrosLen The length of the C string passed to \c ConfigMacros.
* \param IncludePath The path to the module map file. * \param IncludePath The path to the module map file.
* \param IncludePathLen The length of the C string passed to \c IncludePath. * \param IncludePathLen The length of the C string passed to \c IncludePath.
* \param SysRoot The Clang system root (value of -isysroot).
* \param SysRootLen The length of the C string passed to \c SysRoot.
*/ */
LLVMMetadataRef LLVMMetadataRef
LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope,
const char *Name, size_t NameLen, const char *Name, size_t NameLen,
const char *ConfigMacros, size_t ConfigMacrosLen, const char *ConfigMacros, size_t ConfigMacrosLen,
const char *IncludePath, size_t IncludePathLen, const char *IncludePath, size_t IncludePathLen);
const char *SysRoot, size_t SysRootLen);
/** /**
* Creates a new descriptor for a namespace with the specified parent scope. * Creates a new descriptor for a namespace with the specified parent scope.

View File

@ -135,6 +135,7 @@ namespace llvm {
/// profile collection. /// profile collection.
/// \param NameTableKind Whether to emit .debug_gnu_pubnames, /// \param NameTableKind Whether to emit .debug_gnu_pubnames,
/// .debug_pubnames, or no pubnames at all. /// .debug_pubnames, or no pubnames at all.
/// \param SysRoot The clang system root (value of -isysroot).
DICompileUnit * DICompileUnit *
createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer, createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
bool isOptimized, StringRef Flags, unsigned RV, bool isOptimized, StringRef Flags, unsigned RV,
@ -145,7 +146,7 @@ namespace llvm {
bool DebugInfoForProfiling = false, bool DebugInfoForProfiling = false,
DICompileUnit::DebugNameTableKind NameTableKind = DICompileUnit::DebugNameTableKind NameTableKind =
DICompileUnit::DebugNameTableKind::Default, DICompileUnit::DebugNameTableKind::Default,
bool RangesBaseAddress = false); bool RangesBaseAddress = false, StringRef SysRoot = {});
/// Create a file descriptor to hold debugging information for a file. /// Create a file descriptor to hold debugging information for a file.
/// \param Filename File name. /// \param Filename File name.
@ -734,11 +735,9 @@ namespace llvm {
/// A space-separated shell-quoted list of -D macro /// A space-separated shell-quoted list of -D macro
/// definitions as they would appear on a command line. /// definitions as they would appear on a command line.
/// \param IncludePath The path to the module map file. /// \param IncludePath The path to the module map file.
/// \param SysRoot The clang system root (value of -isysroot).
DIModule *createModule(DIScope *Scope, StringRef Name, DIModule *createModule(DIScope *Scope, StringRef Name,
StringRef ConfigurationMacros, StringRef ConfigurationMacros,
StringRef IncludePath, StringRef IncludePath);
StringRef SysRoot);
/// This creates a descriptor for a lexical block with a new file /// This creates a descriptor for a lexical block with a new file
/// attached. This merely extends the existing /// attached. This merely extends the existing

View File

@ -1172,16 +1172,16 @@ private:
DIGlobalVariableExpressionArray GlobalVariables, DIGlobalVariableExpressionArray GlobalVariables,
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros, DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage, unsigned NameTableKind, bool RangesBaseAddress, StringRef SysRoot,
bool ShouldCreate = true) { StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, SourceLanguage, File, return getImpl(
getCanonicalMDString(Context, Producer), IsOptimized, Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
getCanonicalMDString(Context, Flags), RuntimeVersion, IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
getCanonicalMDString(Context, SplitDebugFilename), getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
EmissionKind, EnumTypes.get(), RetainedTypes.get(), EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
GlobalVariables.get(), ImportedEntities.get(), Macros.get(), ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
DWOId, SplitDebugInlining, DebugInfoForProfiling, DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
NameTableKind, RangesBaseAddress, Storage, ShouldCreate); getCanonicalMDString(Context, SysRoot), Storage, ShouldCreate);
} }
static DICompileUnit * static DICompileUnit *
getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File, getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
@ -1191,7 +1191,8 @@ private:
Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *GlobalVariables, Metadata *ImportedEntities,
Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining, Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
bool DebugInfoForProfiling, unsigned NameTableKind, bool DebugInfoForProfiling, unsigned NameTableKind,
bool RangesBaseAddress, StorageType Storage, bool ShouldCreate = true); bool RangesBaseAddress, MDString *SysRoot, StorageType Storage,
bool ShouldCreate = true);
TempDICompileUnit cloneImpl() const { TempDICompileUnit cloneImpl() const {
return getTemporary( return getTemporary(
@ -1200,7 +1201,7 @@ private:
getEmissionKind(), getEnumTypes(), getRetainedTypes(), getEmissionKind(), getEnumTypes(), getRetainedTypes(),
getGlobalVariables(), getImportedEntities(), getMacros(), DWOId, getGlobalVariables(), getImportedEntities(), getMacros(), DWOId,
getSplitDebugInlining(), getDebugInfoForProfiling(), getNameTableKind(), getSplitDebugInlining(), getDebugInfoForProfiling(), getNameTableKind(),
getRangesBaseAddress()); getRangesBaseAddress(), getSysRoot());
} }
public: public:
@ -1216,11 +1217,13 @@ public:
DIGlobalVariableExpressionArray GlobalVariables, DIGlobalVariableExpressionArray GlobalVariables,
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros, DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
DebugNameTableKind NameTableKind, bool RangesBaseAddress), DebugNameTableKind NameTableKind, bool RangesBaseAddress,
StringRef SysRoot),
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion, (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining, GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress)) DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
SysRoot))
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY( DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
DICompileUnit, DICompileUnit,
(unsigned SourceLanguage, Metadata *File, MDString *Producer, (unsigned SourceLanguage, Metadata *File, MDString *Producer,
@ -1229,11 +1232,11 @@ public:
Metadata *RetainedTypes, Metadata *GlobalVariables, Metadata *RetainedTypes, Metadata *GlobalVariables,
Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
bool SplitDebugInlining, bool DebugInfoForProfiling, bool SplitDebugInlining, bool DebugInfoForProfiling,
unsigned NameTableKind, bool RangesBaseAddress), unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot),
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion, (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining, GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
DebugInfoForProfiling, NameTableKind, RangesBaseAddress)) DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot))
TempDICompileUnit clone() const { return cloneImpl(); } TempDICompileUnit clone() const { return cloneImpl(); }
@ -1250,14 +1253,10 @@ public:
DebugNameTableKind getNameTableKind() const { DebugNameTableKind getNameTableKind() const {
return (DebugNameTableKind)NameTableKind; return (DebugNameTableKind)NameTableKind;
} }
bool getRangesBaseAddress() const { bool getRangesBaseAddress() const { return RangesBaseAddress; }
return RangesBaseAddress; } StringRef getProducer() const { return getStringOperand(1); }
StringRef getProducer() const { StringRef getFlags() const { return getStringOperand(2); }
return getStringOperand(1); } StringRef getSplitDebugFilename() const { return getStringOperand(3); }
StringRef getFlags() const {
return getStringOperand(2); }
StringRef getSplitDebugFilename() const {
return getStringOperand(3); }
DICompositeTypeArray getEnumTypes() const { DICompositeTypeArray getEnumTypes() const {
return cast_or_null<MDTuple>(getRawEnumTypes()); return cast_or_null<MDTuple>(getRawEnumTypes());
} }
@ -1279,6 +1278,7 @@ public:
void setSplitDebugInlining(bool SplitDebugInlining) { void setSplitDebugInlining(bool SplitDebugInlining) {
this->SplitDebugInlining = SplitDebugInlining; this->SplitDebugInlining = SplitDebugInlining;
} }
StringRef getSysRoot() const { return getStringOperand(9); }
MDString *getRawProducer() const { return getOperandAs<MDString>(1); } MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
MDString *getRawFlags() const { return getOperandAs<MDString>(2); } MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
@ -1290,6 +1290,7 @@ public:
Metadata *getRawGlobalVariables() const { return getOperand(6); } Metadata *getRawGlobalVariables() const { return getOperand(6); }
Metadata *getRawImportedEntities() const { return getOperand(7); } Metadata *getRawImportedEntities() const { return getOperand(7); }
Metadata *getRawMacros() const { return getOperand(8); } Metadata *getRawMacros() const { return getOperand(8); }
MDString *getRawSysRoot() const { return getOperandAs<MDString>(9); }
/// Replace arrays. /// Replace arrays.
/// ///
@ -2082,36 +2083,33 @@ class DIModule : public DIScope {
: DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {} : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
~DIModule() = default; ~DIModule() = default;
static DIModule *getImpl(LLVMContext &Context, DIScope *Scope, static DIModule *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
StringRef Name, StringRef ConfigurationMacros, StringRef ConfigurationMacros, StringRef IncludePath,
StringRef IncludePath, StringRef SysRoot,
StorageType Storage, bool ShouldCreate = true) { StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, Scope, getCanonicalMDString(Context, Name), return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
getCanonicalMDString(Context, ConfigurationMacros), getCanonicalMDString(Context, ConfigurationMacros),
getCanonicalMDString(Context, IncludePath), getCanonicalMDString(Context, IncludePath),
getCanonicalMDString(Context, SysRoot),
Storage, ShouldCreate); Storage, ShouldCreate);
} }
static DIModule *getImpl(LLVMContext &Context, Metadata *Scope, static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
MDString *Name, MDString *ConfigurationMacros, MDString *Name, MDString *ConfigurationMacros,
MDString *IncludePath, MDString *SysRoot, MDString *IncludePath, StorageType Storage,
StorageType Storage, bool ShouldCreate = true); bool ShouldCreate = true);
TempDIModule cloneImpl() const { TempDIModule cloneImpl() const {
return getTemporary(getContext(), getScope(), getName(), return getTemporary(getContext(), getScope(), getName(),
getConfigurationMacros(), getIncludePath(), getConfigurationMacros(), getIncludePath());
getSysRoot());
} }
public: public:
DEFINE_MDNODE_GET(DIModule, (DIScope *Scope, StringRef Name, DEFINE_MDNODE_GET(DIModule,
StringRef ConfigurationMacros, StringRef IncludePath, (DIScope * Scope, StringRef Name,
StringRef SysRoot), StringRef ConfigurationMacros, StringRef IncludePath),
(Scope, Name, ConfigurationMacros, IncludePath, SysRoot)) (Scope, Name, ConfigurationMacros, IncludePath))
DEFINE_MDNODE_GET(DIModule, DEFINE_MDNODE_GET(DIModule,
(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros, (Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
MDString *IncludePath, MDString *SysRoot), MDString *IncludePath),
(Scope, Name, ConfigurationMacros, IncludePath, SysRoot)) (Scope, Name, ConfigurationMacros, IncludePath))
TempDIModule clone() const { return cloneImpl(); } TempDIModule clone() const { return cloneImpl(); }
@ -2119,13 +2117,11 @@ public:
StringRef getName() const { return getStringOperand(1); } StringRef getName() const { return getStringOperand(1); }
StringRef getConfigurationMacros() const { return getStringOperand(2); } StringRef getConfigurationMacros() const { return getStringOperand(2); }
StringRef getIncludePath() const { return getStringOperand(3); } StringRef getIncludePath() const { return getStringOperand(3); }
StringRef getSysRoot() const { return getStringOperand(4); }
Metadata *getRawScope() const { return getOperand(0); } Metadata *getRawScope() const { return getOperand(0); }
MDString *getRawName() const { return getOperandAs<MDString>(1); } MDString *getRawName() const { return getOperandAs<MDString>(1); }
MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); } MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); } MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
MDString *getRawSysRoot() const { return getOperandAs<MDString>(4); }
static bool classof(const Metadata *MD) { static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIModuleKind; return MD->getMetadataID() == DIModuleKind;

View File

@ -4633,7 +4633,8 @@ bool LLParser::ParseDIFile(MDNode *&Result, bool IsDistinct) {
/// isOptimized: true, flags: "-O2", runtimeVersion: 1, /// isOptimized: true, flags: "-O2", runtimeVersion: 1,
/// splitDebugFilename: "abc.debug", /// splitDebugFilename: "abc.debug",
/// emissionKind: FullDebug, enums: !1, retainedTypes: !2, /// emissionKind: FullDebug, enums: !1, retainedTypes: !2,
/// globals: !4, imports: !5, macros: !6, dwoId: 0x0abcd) /// globals: !4, imports: !5, macros: !6, dwoId: 0x0abcd,
/// sysroot: "/")
bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) { bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
if (!IsDistinct) if (!IsDistinct)
return Lex.Error("missing 'distinct', required for !DICompileUnit"); return Lex.Error("missing 'distinct', required for !DICompileUnit");
@ -4656,7 +4657,8 @@ bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
OPTIONAL(splitDebugInlining, MDBoolField, = true); \ OPTIONAL(splitDebugInlining, MDBoolField, = true); \
OPTIONAL(debugInfoForProfiling, MDBoolField, = false); \ OPTIONAL(debugInfoForProfiling, MDBoolField, = false); \
OPTIONAL(nameTableKind, NameTableKindField, ); \ OPTIONAL(nameTableKind, NameTableKindField, ); \
OPTIONAL(debugBaseAddress, MDBoolField, = false); OPTIONAL(debugBaseAddress, MDBoolField, = false); \
OPTIONAL(sysroot, MDStringField, );
PARSE_MD_FIELDS(); PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS #undef VISIT_MD_FIELDS
@ -4665,7 +4667,7 @@ bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val, runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
retainedTypes.Val, globals.Val, imports.Val, macros.Val, dwoId.Val, retainedTypes.Val, globals.Val, imports.Val, macros.Val, dwoId.Val,
splitDebugInlining.Val, debugInfoForProfiling.Val, nameTableKind.Val, splitDebugInlining.Val, debugInfoForProfiling.Val, nameTableKind.Val,
debugBaseAddress.Val); debugBaseAddress.Val, sysroot.Val);
return false; return false;
} }
@ -4821,19 +4823,18 @@ bool LLParser::ParseDIMacroFile(MDNode *&Result, bool IsDistinct) {
/// ParseDIModule: /// ParseDIModule:
/// ::= !DIModule(scope: !0, name: "SomeModule", configMacros: "-DNDEBUG", /// ::= !DIModule(scope: !0, name: "SomeModule", configMacros: "-DNDEBUG",
/// includePath: "/usr/include", sysroot: "/") /// includePath: "/usr/include")
bool LLParser::ParseDIModule(MDNode *&Result, bool IsDistinct) { bool LLParser::ParseDIModule(MDNode *&Result, bool IsDistinct) {
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
REQUIRED(scope, MDField, ); \ REQUIRED(scope, MDField, ); \
REQUIRED(name, MDStringField, ); \ REQUIRED(name, MDStringField, ); \
OPTIONAL(configMacros, MDStringField, ); \ OPTIONAL(configMacros, MDStringField, ); \
OPTIONAL(includePath, MDStringField, ); \ OPTIONAL(includePath, MDStringField, );
OPTIONAL(sysroot, MDStringField, );
PARSE_MD_FIELDS(); PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS #undef VISIT_MD_FIELDS
Result = GET_OR_DISTINCT(DIModule, (Context, scope.Val, name.Val, Result = GET_OR_DISTINCT(DIModule, (Context, scope.Val, name.Val,
configMacros.Val, includePath.Val, sysroot.Val)); configMacros.Val, includePath.Val));
return false; return false;
} }

View File

@ -1418,15 +1418,14 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
} }
case bitc::METADATA_MODULE: { case bitc::METADATA_MODULE: {
if (Record.size() != 6) if (Record.size() < 5 || Record.size() > 6)
return error("Invalid record"); return error("Invalid record");
IsDistinct = Record[0]; IsDistinct = Record[0];
MetadataList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIModule, GET_OR_DISTINCT(
(Context, getMDOrNull(Record[1]), DIModule, (Context, getMDOrNull(Record[1]), getMDString(Record[2]),
getMDString(Record[2]), getMDString(Record[3]), getMDString(Record[3]), getMDString(Record[4]))),
getMDString(Record[4]), getMDString(Record[5]))),
NextMetadataNo); NextMetadataNo);
NextMetadataNo++; NextMetadataNo++;
break; break;
@ -1457,7 +1456,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break; break;
} }
case bitc::METADATA_COMPILE_UNIT: { case bitc::METADATA_COMPILE_UNIT: {
if (Record.size() < 14 || Record.size() > 19) if (Record.size() < 14 || Record.size() > 21)
return error("Invalid record"); return error("Invalid record");
// Ignore Record[0], which indicates whether this compile unit is // Ignore Record[0], which indicates whether this compile unit is
@ -1473,7 +1472,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
Record.size() <= 16 ? true : Record[16], Record.size() <= 16 ? true : Record[16],
Record.size() <= 17 ? false : Record[17], Record.size() <= 17 ? false : Record[17],
Record.size() <= 18 ? 0 : Record[18], Record.size() <= 18 ? 0 : Record[18],
Record.size() <= 19 ? 0 : Record[19]); false, // FIXME: https://reviews.llvm.org/rGc51b45e32ef7f35c11891f60871aa9c2c04cd991
// Record.size() <= 19 ? 0 : Record[19],
Record.size() <= 20 ? nullptr : getMDString(Record[20]));
MetadataList.assignValue(CU, NextMetadataNo); MetadataList.assignValue(CU, NextMetadataNo);
NextMetadataNo++; NextMetadataNo++;

View File

@ -1662,6 +1662,8 @@ void ModuleBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
Record.push_back(N->getSplitDebugInlining()); Record.push_back(N->getSplitDebugInlining());
Record.push_back(N->getDebugInfoForProfiling()); Record.push_back(N->getDebugInfoForProfiling());
Record.push_back((unsigned)N->getNameTableKind()); Record.push_back((unsigned)N->getNameTableKind());
Record.push_back(N->getRangesBaseAddress());
Record.push_back(VE.getMetadataOrNullID(N->getRawSysRoot()));
Stream.EmitRecord(bitc::METADATA_COMPILE_UNIT, Record, Abbrev); Stream.EmitRecord(bitc::METADATA_COMPILE_UNIT, Record, Abbrev);
Record.clear(); Record.clear();

View File

@ -836,6 +836,9 @@ void DwarfDebug::finishUnitAttributes(const DICompileUnit *DIUnit,
NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2, NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
DIUnit->getSourceLanguage()); DIUnit->getSourceLanguage());
NewCU.addString(Die, dwarf::DW_AT_name, FN); NewCU.addString(Die, dwarf::DW_AT_name, FN);
StringRef SysRoot = DIUnit->getSysRoot();
if (!SysRoot.empty())
NewCU.addString(Die, dwarf::DW_AT_LLVM_sysroot, SysRoot);
// Add DW_str_offsets_base to the unit DIE, except for split units. // Add DW_str_offsets_base to the unit DIE, except for split units.
if (useSegmentedStringOffsetsTable() && !useSplitDwarf()) if (useSegmentedStringOffsetsTable() && !useSplitDwarf())
@ -848,7 +851,6 @@ void DwarfDebug::finishUnitAttributes(const DICompileUnit *DIUnit,
// skeleton CU and so we don't need to duplicate it here. // skeleton CU and so we don't need to duplicate it here.
if (!CompilationDir.empty()) if (!CompilationDir.empty())
NewCU.addString(Die, dwarf::DW_AT_comp_dir, CompilationDir); NewCU.addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
addGnuPubAttributes(NewCU, Die); addGnuPubAttributes(NewCU, Die);
} }
@ -2822,7 +2824,6 @@ void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE &Die,
if (!CompilationDir.empty()) if (!CompilationDir.empty())
NewU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir); NewU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
addGnuPubAttributes(*NewU, Die); addGnuPubAttributes(*NewU, Die);
SkeletonHolder.addUnit(std::move(NewU)); SkeletonHolder.addUnit(std::move(NewU));

View File

@ -1122,8 +1122,6 @@ DIE *DwarfUnit::getOrCreateModule(const DIModule *M) {
M->getConfigurationMacros()); M->getConfigurationMacros());
if (!M->getIncludePath().empty()) if (!M->getIncludePath().empty())
addString(MDie, dwarf::DW_AT_LLVM_include_path, M->getIncludePath()); addString(MDie, dwarf::DW_AT_LLVM_include_path, M->getIncludePath());
if (!M->getSysRoot().empty())
addString(MDie, dwarf::DW_AT_LLVM_sysroot, M->getSysRoot());
return &MDie; return &MDie;
} }

View File

@ -1945,6 +1945,7 @@ static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N,
false); false);
Printer.printNameTableKind("nameTableKind", N->getNameTableKind()); Printer.printNameTableKind("nameTableKind", N->getNameTableKind());
Printer.printBool("rangesBaseAddress", N->getRangesBaseAddress(), false); Printer.printBool("rangesBaseAddress", N->getRangesBaseAddress(), false);
Printer.printString("sysroot", N->getSysRoot());
Out << ")"; Out << ")";
} }
@ -2057,7 +2058,6 @@ static void writeDIModule(raw_ostream &Out, const DIModule *N,
Printer.printString("name", N->getName()); Printer.printString("name", N->getName());
Printer.printString("configMacros", N->getConfigurationMacros()); Printer.printString("configMacros", N->getConfigurationMacros());
Printer.printString("includePath", N->getIncludePath()); Printer.printString("includePath", N->getIncludePath());
Printer.printString("sysroot", N->getSysRoot());
Out << ")"; Out << ")";
} }

View File

@ -140,7 +140,8 @@ DICompileUnit *DIBuilder::createCompileUnit(
StringRef Flags, unsigned RunTimeVer, StringRef SplitName, StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId, DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
bool SplitDebugInlining, bool DebugInfoForProfiling, bool SplitDebugInlining, bool DebugInfoForProfiling,
DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress) { DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress,
StringRef SysRoot) {
assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) || assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
(Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
@ -151,7 +152,7 @@ DICompileUnit *DIBuilder::createCompileUnit(
VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer, VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId, SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
SplitDebugInlining, DebugInfoForProfiling, NameTableKind, SplitDebugInlining, DebugInfoForProfiling, NameTableKind,
RangesBaseAddress); RangesBaseAddress, SysRoot);
// Create a named metadata so that it is easier to find cu in a module. // Create a named metadata so that it is easier to find cu in a module.
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
@ -829,10 +830,9 @@ DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name,
DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name, DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name,
StringRef ConfigurationMacros, StringRef ConfigurationMacros,
StringRef IncludePath, StringRef IncludePath) {
StringRef SysRoot) { return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name,
return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name, ConfigurationMacros, IncludePath);
ConfigurationMacros, IncludePath, SysRoot);
} }
DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope, DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope,

View File

@ -514,7 +514,7 @@ private:
RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(), RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
CU->getDWOId(), CU->getSplitDebugInlining(), CU->getDWOId(), CU->getSplitDebugInlining(),
CU->getDebugInfoForProfiling(), CU->getNameTableKind(), CU->getDebugInfoForProfiling(), CU->getNameTableKind(),
CU->getRangesBaseAddress()); CU->getRangesBaseAddress(), CU->getSysRoot());
} }
DILocation *getReplacementMDLocation(DILocation *MLD) { DILocation *getReplacementMDLocation(DILocation *MLD) {
@ -782,16 +782,17 @@ LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
LLVMBool isOptimized, const char *Flags, size_t FlagsLen, LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen, unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining, LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
LLVMBool DebugInfoForProfiling) { LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen) {
auto File = unwrapDI<DIFile>(FileRef); auto File = unwrapDI<DIFile>(FileRef);
return wrap(unwrap(Builder)->createCompileUnit( return wrap(unwrap(Builder)->createCompileUnit(
map_from_llvmDWARFsourcelanguage(Lang), File, map_from_llvmDWARFsourcelanguage(Lang), File,
StringRef(Producer, ProducerLen), isOptimized, StringRef(Producer, ProducerLen), isOptimized, StringRef(Flags, FlagsLen),
StringRef(Flags, FlagsLen), RuntimeVer, RuntimeVer, StringRef(SplitName, SplitNameLen),
StringRef(SplitName, SplitNameLen), static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId,
static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId, SplitDebugInlining, DebugInfoForProfiling,
SplitDebugInlining, DebugInfoForProfiling)); DICompileUnit::DebugNameTableKind::Default, false,
StringRef(SysRoot, SysRootLen)));
} }
LLVMMetadataRef LLVMMetadataRef
@ -806,13 +807,11 @@ LLVMMetadataRef
LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope,
const char *Name, size_t NameLen, const char *Name, size_t NameLen,
const char *ConfigMacros, size_t ConfigMacrosLen, const char *ConfigMacros, size_t ConfigMacrosLen,
const char *IncludePath, size_t IncludePathLen, const char *IncludePath, size_t IncludePathLen) {
const char *SysRoot, size_t SysRootLen) {
return wrap(unwrap(Builder)->createModule( return wrap(unwrap(Builder)->createModule(
unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen),
StringRef(ConfigMacros, ConfigMacrosLen), StringRef(ConfigMacros, ConfigMacrosLen),
StringRef(IncludePath, IncludePathLen), StringRef(IncludePath, IncludePathLen)));
StringRef(SysRoot, SysRootLen)));
} }
LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder, LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder,

View File

@ -520,8 +520,8 @@ DICompileUnit *DICompileUnit::getImpl(
unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage, unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
bool ShouldCreate) { StorageType Storage, bool ShouldCreate) {
assert(Storage != Uniqued && "Cannot unique DICompileUnit"); assert(Storage != Uniqued && "Cannot unique DICompileUnit");
assert(isCanonical(Producer) && "Expected canonical MDString"); assert(isCanonical(Producer) && "Expected canonical MDString");
assert(isCanonical(Flags) && "Expected canonical MDString"); assert(isCanonical(Flags) && "Expected canonical MDString");
@ -530,7 +530,7 @@ DICompileUnit *DICompileUnit::getImpl(
Metadata *Ops[] = { Metadata *Ops[] = {
File, Producer, Flags, SplitDebugFilename, File, Producer, Flags, SplitDebugFilename,
EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
Macros}; Macros, SysRoot};
return storeImpl(new (array_lengthof(Ops)) DICompileUnit( return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
Context, Storage, SourceLanguage, IsOptimized, Context, Storage, SourceLanguage, IsOptimized,
RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining, RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
@ -715,12 +715,12 @@ DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope,
DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope, DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
MDString *Name, MDString *ConfigurationMacros, MDString *Name, MDString *ConfigurationMacros,
MDString *IncludePath, MDString *SysRoot, MDString *IncludePath, StorageType Storage,
StorageType Storage, bool ShouldCreate) { bool ShouldCreate) {
assert(isCanonical(Name) && "Expected canonical MDString"); assert(isCanonical(Name) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP( DEFINE_GETIMPL_LOOKUP(DIModule,
DIModule, (Scope, Name, ConfigurationMacros, IncludePath, SysRoot)); (Scope, Name, ConfigurationMacros, IncludePath));
Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, SysRoot}; Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath};
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops); DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
} }

View File

@ -819,27 +819,24 @@ template <> struct MDNodeKeyImpl<DIModule> {
MDString *Name; MDString *Name;
MDString *ConfigurationMacros; MDString *ConfigurationMacros;
MDString *IncludePath; MDString *IncludePath;
MDString *SysRoot;
MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros, MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
MDString *IncludePath, MDString *SysRoot) MDString *IncludePath)
: Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros), : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
IncludePath(IncludePath), SysRoot(SysRoot) {} IncludePath(IncludePath) {}
MDNodeKeyImpl(const DIModule *N) MDNodeKeyImpl(const DIModule *N)
: Scope(N->getRawScope()), Name(N->getRawName()), : Scope(N->getRawScope()), Name(N->getRawName()),
ConfigurationMacros(N->getRawConfigurationMacros()), ConfigurationMacros(N->getRawConfigurationMacros()),
IncludePath(N->getRawIncludePath()), SysRoot(N->getRawSysRoot()) {} IncludePath(N->getRawIncludePath()) {}
bool isKeyOf(const DIModule *RHS) const { bool isKeyOf(const DIModule *RHS) const {
return Scope == RHS->getRawScope() && Name == RHS->getRawName() && return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
ConfigurationMacros == RHS->getRawConfigurationMacros() && ConfigurationMacros == RHS->getRawConfigurationMacros() &&
IncludePath == RHS->getRawIncludePath() && IncludePath == RHS->getRawIncludePath();
SysRoot == RHS->getRawSysRoot();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(Scope, Name, return hash_combine(Scope, Name, ConfigurationMacros, IncludePath);
ConfigurationMacros, IncludePath, SysRoot);
} }
}; };

View File

@ -16,13 +16,14 @@
!6 = distinct !{} !6 = distinct !{}
!7 = distinct !{} !7 = distinct !{}
; CHECK: !8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, flags: "-O2", runtimeVersion: 2, splitDebugFilename: "abc.debug", emissionKind: FullDebug, enums: !2, retainedTypes: !3, globals: !5, imports: !6, macros: !7, dwoId: 42) ; CHECK: !8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, flags: "-O2", runtimeVersion: 2, splitDebugFilename: "abc.debug", emissionKind: FullDebug, enums: !2, retainedTypes: !3, globals: !5, imports: !6, macros: !7, dwoId: 42, sysroot: "/")
!8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", !8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
isOptimized: true, flags: "-O2", runtimeVersion: 2, isOptimized: true, flags: "-O2", runtimeVersion: 2,
splitDebugFilename: "abc.debug", splitDebugFilename: "abc.debug",
emissionKind: FullDebug, emissionKind: FullDebug,
enums: !2, retainedTypes: !3, enums: !2, retainedTypes: !3,
globals: !5, imports: !6, macros: !7, dwoId: 42, splitDebugInlining: true) globals: !5, imports: !6, macros: !7, dwoId: 42,
splitDebugInlining: true, sysroot: "/")
; CHECK: !9 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug) ; CHECK: !9 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
!9 = distinct !DICompileUnit(language: 12, file: !1, producer: "", !9 = distinct !DICompileUnit(language: 12, file: !1, producer: "",

View File

@ -9,7 +9,7 @@
; CHECK: !1 = !DIModule(scope: !0, name: "Module") ; CHECK: !1 = !DIModule(scope: !0, name: "Module")
!1 = !DIModule(scope: !0, name: "Module") !1 = !DIModule(scope: !0, name: "Module")
; CHECK: !2 = !DIModule(scope: !0, name: "Module", configMacros: "-DNDEBUG", includePath: "/usr/include", sysroot: "/") ; CHECK: !2 = !DIModule(scope: !0, name: "Module", configMacros: "-DNDEBUG", includePath: "/usr/include")
!2 = !DIModule(scope: !0, name: "Module", configMacros: "-DNDEBUG", includePath: "/usr/include", sysroot: "/") !2 = !DIModule(scope: !0, name: "Module", configMacros: "-DNDEBUG", includePath: "/usr/include")
!3 = !DIModule(scope: !0, name: "Module", configMacros: "") !3 = !DIModule(scope: !0, name: "Module", configMacros: "")

View File

@ -24,7 +24,7 @@
; CHECK-NEXT: !FooType = !{!28} ; CHECK-NEXT: !FooType = !{!28}
; CHECK-NEXT: !EnumTest = !{!3} ; CHECK-NEXT: !EnumTest = !{!3}
; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !11, imports: !19, macros: !23, splitDebugInlining: false) ; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !11, imports: !19, macros: !23, splitDebugInlining: false, sysroot: "/")
; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".") ; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
; CHECK-NEXT: !2 = !{!3} ; CHECK-NEXT: !2 = !{!3}
; CHECK-NEXT: !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "EnumTest", scope: !4, file: !1, baseType: !6, size: 64, elements: !7) ; CHECK-NEXT: !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "EnumTest", scope: !4, file: !1, baseType: !6, size: 64, elements: !7)

View File

@ -25,7 +25,7 @@ define i32 @zext_load(i32* %arg) !dbg !30 {
!0 = !{i32 2, !"Debug Info Version", i32 3} !0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !3, isOptimized: false, emissionKind: FullDebug) !1 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !3, isOptimized: false, emissionKind: FullDebug)
!2 = !DIModule(scope: null, name: "test", includePath: "", sysroot: "/") !2 = !DIModule(scope: null, name: "test", includePath: "")
!3 = !DIFile(filename: "main.swift", directory: "/") !3 = !DIFile(filename: "main.swift", directory: "/")
!30 = distinct !DISubprogram(name: "main", scope: !2, file: !3, line: 1, type: !31, isLocal: false, isDefinition: true, isOptimized: false, unit: !1) !30 = distinct !DISubprogram(name: "main", scope: !2, file: !3, line: 1, type: !31, isLocal: false, isDefinition: true, isOptimized: false, unit: !1)

View File

@ -2,11 +2,13 @@
; RUN: llc %s -accel-tables=Dwarf -o %t -filetype=obj ; RUN: llc %s -accel-tables=Dwarf -o %t -filetype=obj
; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s ; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
; RUN: llvm-dwarfdump -verify %t ; RUN: llvm-dwarfdump -verify %t
; CHECK: DW_TAG_module ; CHECK: DW_TAG_compile_unit
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_LLVM_sysroot {{.*}}"/"
; CHECK: DW_TAG_module
; CHECK-NEXT: DW_AT_name {{.*}}"DebugModule" ; CHECK-NEXT: DW_AT_name {{.*}}"DebugModule"
; CHECK-NEXT: DW_AT_LLVM_config_macros {{.*}}"-DMODULES=0" ; CHECK-NEXT: DW_AT_LLVM_config_macros {{.*}}"-DMODULES=0"
; CHECK-NEXT: DW_AT_LLVM_include_path {{.*}}"/llvm/tools/clang/test/Modules/Inputs" ; CHECK-NEXT: DW_AT_LLVM_include_path {{.*}}"/llvm/tools/clang/test/Modules/Inputs"
; CHECK-NEXT: DW_AT_LLVM_sysroot {{.*}}"/"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx" target triple = "x86_64-apple-macosx"
@ -15,12 +17,12 @@ target triple = "x86_64-apple-macosx"
!llvm.module.flags = !{!6, !7} !llvm.module.flags = !{!6, !7}
!llvm.ident = !{!8} !llvm.ident = !{!8}
!0 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !1, producer: "LLVM version 3.7.0", isOptimized: false, runtimeVersion: 2, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !3) !0 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !1, producer: "LLVM version 3.7.0", isOptimized: false, runtimeVersion: 2, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !3, sysroot: "/")
!1 = !DIFile(filename: "/llvm/tools/clang/test/Modules/<stdin>", directory: "/") !1 = !DIFile(filename: "/llvm/tools/clang/test/Modules/<stdin>", directory: "/")
!2 = !{} !2 = !{}
!3 = !{!4} !3 = !{!4}
!4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: !5, file: !1, line: 5) !4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: !5, file: !1, line: 5)
!5 = !DIModule(scope: null, name: "DebugModule", configMacros: "-DMODULES=0", includePath: "/llvm/tools/clang/test/Modules/Inputs", sysroot: "/") !5 = !DIModule(scope: null, name: "DebugModule", configMacros: "-DMODULES=0", includePath: "/llvm/tools/clang/test/Modules/Inputs")
!6 = !{i32 2, !"Dwarf Version", i32 4} !6 = !{i32 2, !"Dwarf Version", i32 4}
!7 = !{i32 2, !"Debug Info Version", i32 3} !7 = !{i32 2, !"Debug Info Version", i32 3}
!8 = !{!"LLVM version 3.7.0"} !8 = !{!"LLVM version 3.7.0"}

View File

@ -25,7 +25,7 @@ target triple = "x86_64-apple-macosx"
!5 = !{!0} !5 = !{!0}
!6 = !{!7} !6 = !{!7}
!7 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !2, entity: !8, file: !3, line: 11) !7 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !2, entity: !8, file: !3, line: 11)
!8 = !DIModule(scope: null, name: "Module", includePath: ".", sysroot: "/") !8 = !DIModule(scope: null, name: "Module", includePath: ".")
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64) !9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64)
!10 = !DICompositeType(tag: DW_TAG_structure_type, name: "s", scope: !8, file: !3, line: 1, flags: DIFlagFwdDecl) !10 = !DICompositeType(tag: DW_TAG_structure_type, name: "s", scope: !8, file: !3, line: 1, flags: DIFlagFwdDecl)
!11 = !{i32 2, !"Dwarf Version", i32 2} !11 = !{i32 2, !"Dwarf Version", i32 2}

View File

@ -20,11 +20,11 @@ target triple = "x86_64-apple-macosx10.12.0"
!llvm.module.flags = !{!15, !16} !llvm.module.flags = !{!15, !16}
!llvm.linker.options = !{} !llvm.linker.options = !{}
!0 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !1, producer: "clang version 5.0.0 (trunk 308357) (llvm/trunk 308379)", emissionKind: FullDebug, imports: !3) !0 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !1, producer: "clang version 5.0.0 (trunk 308357) (llvm/trunk 308379)", emissionKind: FullDebug, imports: !3, sysroot: "/")
!1 = !DIFile(filename: "modules.m", directory: "/") !1 = !DIFile(filename: "modules.m", directory: "/")
!3 = !{!4} !3 = !{!4}
!4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: !5, line: 122) !4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: !5, line: 122)
!5 = !DIModule(scope: null, name: "Foo", includePath: ".", sysroot: "/") !5 = !DIModule(scope: null, name: "Foo", includePath: ".")
!6 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !7, producer: "clang version 5.0.0 (trunk 308357) (llvm/trunk 308379)", isOptimized: true, runtimeVersion: 0, splitDebugFilename: "/Foo.pcm", emissionKind: FullDebug, dwoId: 1234) !6 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !7, producer: "clang version 5.0.0 (trunk 308357) (llvm/trunk 308379)", isOptimized: true, runtimeVersion: 0, splitDebugFilename: "/Foo.pcm", emissionKind: FullDebug, dwoId: 1234)
!7 = !DIFile(filename: "Foo", directory: ".") !7 = !DIFile(filename: "Foo", directory: ".")
!15 = !{i32 2, !"Dwarf Version", i32 4} !15 = !{i32 2, !"Dwarf Version", i32 4}

View File

@ -0,0 +1,34 @@
; RUN: %llc_dwarf -split-dwarf-file=foo.dwo %s -filetype=obj -o - | llvm-dwarfdump -debug-info - | FileCheck %s
; DW_AT_LLVM_sysroot goes into the .dwo, not in the skeleton.
; CHECK: DW_TAG_skeleton_unit
; CHECK-NOT: DW_AT_LLVM_sysroot
; CHECK: DW_TAG_compile_unit
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_LLVM_sysroot ("/opt/clang-root")
target triple = "x86_64-pc-linux"
declare void @_Z2f1v()
; Function Attrs: noinline norecurse uwtable
define i32 @main() !dbg !9 {
entry:
ret i32 0, !dbg !18
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!6, !7, !8}
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, emissionKind: FullDebug, enums: !2, sysroot: "/opt/clang-root")
!1 = !DIFile(filename: "a.c", directory: "/")
!2 = !{}
!6 = !{i32 2, !"Dwarf Version", i32 5}
!7 = !{i32 2, !"Debug Info Version", i32 3}
!8 = !{i32 1, !"wchar_size", i32 4}
!9 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
!10 = !DISubroutineType(types: !11)
!11 = !{!12}
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!18 = !DILocation(line: 4, column: 1, scope: !9)

View File

@ -36,23 +36,21 @@ int llvm_test_dibuilder(void) {
LLVMMetadataRef File = LLVMDIBuilderCreateFile(DIB, Filename, LLVMMetadataRef File = LLVMDIBuilderCreateFile(DIB, Filename,
strlen(Filename), ".", 1); strlen(Filename), ".", 1);
LLVMMetadataRef CompileUnit = LLVMDIBuilderCreateCompileUnit(DIB, LLVMMetadataRef CompileUnit = LLVMDIBuilderCreateCompileUnit(
LLVMDWARFSourceLanguageC, File, "llvm-c-test", 11, 0, NULL, 0, 0, DIB, LLVMDWARFSourceLanguageC, File, "llvm-c-test", 11, 0, NULL, 0, 0,
NULL, 0, LLVMDWARFEmissionFull, 0, 0, 0); NULL, 0, LLVMDWARFEmissionFull, 0, 0, 0, "/", 1);
LLVMMetadataRef Module = LLVMMetadataRef Module =
LLVMDIBuilderCreateModule(DIB, CompileUnit, LLVMDIBuilderCreateModule(DIB, CompileUnit,
"llvm-c-test", 11, "llvm-c-test", 11,
"", 0, "", 0,
"/test/include/llvm-c-test.h", 27, "/test/include/llvm-c-test.h", 27);
"", 0);
LLVMMetadataRef OtherModule = LLVMMetadataRef OtherModule =
LLVMDIBuilderCreateModule(DIB, CompileUnit, LLVMDIBuilderCreateModule(DIB, CompileUnit,
"llvm-c-test-import", 18, "llvm-c-test-import", 18,
"", 0, "", 0,
"/test/include/llvm-c-test-import.h", 34, "/test/include/llvm-c-test-import.h", 34);
"", 0);
LLVMMetadataRef ImportedModule = LLVMMetadataRef ImportedModule =
LLVMDIBuilderCreateImportedModuleFromModule(DIB, Module, OtherModule, LLVMDIBuilderCreateImportedModuleFromModule(DIB, Module, OtherModule,
File, 42); File, 42);

View File

@ -96,7 +96,7 @@ protected:
Context, 1, getFile(), "clang", false, "-g", 2, "", Context, 1, getFile(), "clang", false, "-g", 2, "",
DICompileUnit::FullDebug, getTuple(), getTuple(), getTuple(), DICompileUnit::FullDebug, getTuple(), getTuple(), getTuple(),
getTuple(), getTuple(), 0, true, false, getTuple(), getTuple(), 0, true, false,
DICompileUnit::DebugNameTableKind::Default, false); DICompileUnit::DebugNameTableKind::Default, false, "/");
} }
DIType *getBasicType(StringRef Name) { DIType *getBasicType(StringRef Name) {
return DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name); return DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name);
@ -1709,11 +1709,12 @@ TEST_F(DICompileUnitTest, get) {
MDTuple *ImportedEntities = getTuple(); MDTuple *ImportedEntities = getTuple();
uint64_t DWOId = 0x10000000c0ffee; uint64_t DWOId = 0x10000000c0ffee;
MDTuple *Macros = getTuple(); MDTuple *Macros = getTuple();
StringRef SysRoot = "/";
auto *N = DICompileUnit::getDistinct( auto *N = DICompileUnit::getDistinct(
Context, SourceLanguage, File, Producer, IsOptimized, Flags, Context, SourceLanguage, File, Producer, IsOptimized, Flags,
RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, true, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, true,
false, DICompileUnit::DebugNameTableKind::Default, false); false, DICompileUnit::DebugNameTableKind::Default, false, SysRoot);
EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag()); EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag());
EXPECT_EQ(SourceLanguage, N->getSourceLanguage()); EXPECT_EQ(SourceLanguage, N->getSourceLanguage());
@ -1730,6 +1731,7 @@ TEST_F(DICompileUnitTest, get) {
EXPECT_EQ(ImportedEntities, N->getImportedEntities().get()); EXPECT_EQ(ImportedEntities, N->getImportedEntities().get());
EXPECT_EQ(Macros, N->getMacros().get()); EXPECT_EQ(Macros, N->getMacros().get());
EXPECT_EQ(DWOId, N->getDWOId()); EXPECT_EQ(DWOId, N->getDWOId());
EXPECT_EQ(SysRoot, N->getSysRoot());
TempDICompileUnit Temp = N->clone(); TempDICompileUnit Temp = N->clone();
EXPECT_EQ(dwarf::DW_TAG_compile_unit, Temp->getTag()); EXPECT_EQ(dwarf::DW_TAG_compile_unit, Temp->getTag());
@ -1746,7 +1748,7 @@ TEST_F(DICompileUnitTest, get) {
EXPECT_EQ(GlobalVariables, Temp->getGlobalVariables().get()); EXPECT_EQ(GlobalVariables, Temp->getGlobalVariables().get());
EXPECT_EQ(ImportedEntities, Temp->getImportedEntities().get()); EXPECT_EQ(ImportedEntities, Temp->getImportedEntities().get());
EXPECT_EQ(Macros, Temp->getMacros().get()); EXPECT_EQ(Macros, Temp->getMacros().get());
EXPECT_EQ(DWOId, Temp->getDWOId()); EXPECT_EQ(SysRoot, Temp->getSysRoot());
auto *TempAddress = Temp.get(); auto *TempAddress = Temp.get();
auto *Clone = MDNode::replaceWithPermanent(std::move(Temp)); auto *Clone = MDNode::replaceWithPermanent(std::move(Temp));
@ -1767,11 +1769,12 @@ TEST_F(DICompileUnitTest, replaceArrays) {
MDTuple *RetainedTypes = MDTuple::getDistinct(Context, None); MDTuple *RetainedTypes = MDTuple::getDistinct(Context, None);
MDTuple *ImportedEntities = MDTuple::getDistinct(Context, None); MDTuple *ImportedEntities = MDTuple::getDistinct(Context, None);
uint64_t DWOId = 0xc0ffee; uint64_t DWOId = 0xc0ffee;
StringRef SysRoot = "/";
auto *N = DICompileUnit::getDistinct( auto *N = DICompileUnit::getDistinct(
Context, SourceLanguage, File, Producer, IsOptimized, Flags, Context, SourceLanguage, File, Producer, IsOptimized, Flags,
RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
RetainedTypes, nullptr, ImportedEntities, nullptr, DWOId, true, false, RetainedTypes, nullptr, ImportedEntities, nullptr, DWOId, true, false,
DICompileUnit::DebugNameTableKind::Default, false); DICompileUnit::DebugNameTableKind::Default, false, SysRoot);
auto *GlobalVariables = MDTuple::getDistinct(Context, None); auto *GlobalVariables = MDTuple::getDistinct(Context, None);
EXPECT_EQ(nullptr, N->getGlobalVariables().get()); EXPECT_EQ(nullptr, N->getGlobalVariables().get());
@ -2050,28 +2053,19 @@ TEST_F(DIModuleTest, get) {
StringRef Name = "module"; StringRef Name = "module";
StringRef ConfigMacro = "-DNDEBUG"; StringRef ConfigMacro = "-DNDEBUG";
StringRef Includes = "-I."; StringRef Includes = "-I.";
StringRef Sysroot = "/";
auto *N = DIModule::get(Context, Scope, Name, ConfigMacro, Includes, Sysroot); auto *N = DIModule::get(Context, Scope, Name, ConfigMacro, Includes);
EXPECT_EQ(dwarf::DW_TAG_module, N->getTag()); EXPECT_EQ(dwarf::DW_TAG_module, N->getTag());
EXPECT_EQ(Scope, N->getScope()); EXPECT_EQ(Scope, N->getScope());
EXPECT_EQ(Name, N->getName()); EXPECT_EQ(Name, N->getName());
EXPECT_EQ(ConfigMacro, N->getConfigurationMacros()); EXPECT_EQ(ConfigMacro, N->getConfigurationMacros());
EXPECT_EQ(Includes, N->getIncludePath()); EXPECT_EQ(Includes, N->getIncludePath());
EXPECT_EQ(Sysroot, N->getSysRoot()); EXPECT_EQ(N, DIModule::get(Context, Scope, Name, ConfigMacro, Includes));
EXPECT_EQ(N, DIModule::get(Context, Scope, Name, EXPECT_NE(N, DIModule::get(Context, getFile(), Name, ConfigMacro, Includes));
ConfigMacro, Includes, Sysroot)); EXPECT_NE(N, DIModule::get(Context, Scope, "other", ConfigMacro, Includes));
EXPECT_NE(N, DIModule::get(Context, getFile(), Name, EXPECT_NE(N, DIModule::get(Context, Scope, Name, "other", Includes));
ConfigMacro, Includes, Sysroot)); EXPECT_NE(N, DIModule::get(Context, Scope, Name, ConfigMacro, "other"));
EXPECT_NE(N, DIModule::get(Context, Scope, "other",
ConfigMacro, Includes, Sysroot));
EXPECT_NE(N, DIModule::get(Context, Scope, Name,
"other", Includes, Sysroot));
EXPECT_NE(N, DIModule::get(Context, Scope, Name,
ConfigMacro, "other", Sysroot));
EXPECT_NE(N, DIModule::get(Context, Scope, Name,
ConfigMacro, Includes, "other"));
TempDIModule Temp = N->clone(); TempDIModule Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));