Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 841400b

Browse files
committed
Remove line and file from DINamespace.
Fixes the issue highlighted in http://lists.llvm.org/pipermail/cfe-dev/2014-June/037500.html. The DW_AT_decl_file and DW_AT_decl_line attributes on namespaces can prevent LLVM from uniquing types that are in the same namespace. They also don't carry any meaningful information. rdar://problem/17484998 Differential Revision: https://reviews.llvm.org/D32648 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301706 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e91b6db commit 841400b

36 files changed

+102
-130
lines changed

include/llvm/IR/DIBuilder.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,9 @@ namespace llvm {
632632
/// parent scope.
633633
/// \param Scope Namespace scope
634634
/// \param Name Name of this namespace
635-
/// \param File Source file
636-
/// \param LineNo Line number
637635
/// \param ExportSymbols True for C++ inline namespaces.
638-
DINamespace *createNameSpace(DIScope *Scope, StringRef Name, DIFile *File,
639-
unsigned LineNo, bool ExportSymbols);
636+
DINamespace *createNameSpace(DIScope *Scope, StringRef Name,
637+
bool ExportSymbols);
640638

641639
/// This creates new descriptor for a module with the specified
642640
/// parent scope.

include/llvm/IR/DebugInfoMetadata.h

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,45 +1853,40 @@ class DINamespace : public DIScope {
18531853
friend class LLVMContextImpl;
18541854
friend class MDNode;
18551855

1856-
unsigned Line;
18571856
unsigned ExportSymbols : 1;
18581857

1859-
DINamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1860-
bool ExportSymbols, ArrayRef<Metadata *> Ops)
1858+
DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
1859+
ArrayRef<Metadata *> Ops)
18611860
: DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace,
18621861
Ops),
1863-
Line(Line), ExportSymbols(ExportSymbols) {}
1862+
ExportSymbols(ExportSymbols) {}
18641863
~DINamespace() = default;
18651864

18661865
static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
1867-
DIFile *File, StringRef Name, unsigned Line,
1868-
bool ExportSymbols, StorageType Storage,
1869-
bool ShouldCreate = true) {
1870-
return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1871-
Line, ExportSymbols, Storage, ShouldCreate);
1866+
StringRef Name, bool ExportSymbols,
1867+
StorageType Storage, bool ShouldCreate = true) {
1868+
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1869+
ExportSymbols, Storage, ShouldCreate);
18721870
}
18731871
static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1874-
Metadata *File, MDString *Name, unsigned Line,
1875-
bool ExportSymbols, StorageType Storage,
1876-
bool ShouldCreate = true);
1872+
MDString *Name, bool ExportSymbols,
1873+
StorageType Storage, bool ShouldCreate = true);
18771874

18781875
TempDINamespace cloneImpl() const {
1879-
return getTemporary(getContext(), getScope(), getFile(), getName(),
1880-
getLine(), getExportSymbols());
1876+
return getTemporary(getContext(), getScope(), getName(),
1877+
getExportSymbols());
18811878
}
18821879

18831880
public:
1884-
DEFINE_MDNODE_GET(DINamespace, (DIScope * Scope, DIFile *File, StringRef Name,
1885-
unsigned Line, bool ExportSymbols),
1886-
(Scope, File, Name, Line, ExportSymbols))
18871881
DEFINE_MDNODE_GET(DINamespace,
1888-
(Metadata * Scope, Metadata *File, MDString *Name,
1889-
unsigned Line, bool ExportSymbols),
1890-
(Scope, File, Name, Line, ExportSymbols))
1882+
(DIScope *Scope, StringRef Name, bool ExportSymbols),
1883+
(Scope, Name, ExportSymbols))
1884+
DEFINE_MDNODE_GET(DINamespace,
1885+
(Metadata *Scope, MDString *Name, bool ExportSymbols),
1886+
(Scope, Name, ExportSymbols))
18911887

18921888
TempDINamespace clone() const { return cloneImpl(); }
18931889

1894-
unsigned getLine() const { return Line; }
18951890
bool getExportSymbols() const { return ExportSymbols; }
18961891
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
18971892
StringRef getName() const { return getStringOperand(2); }

lib/AsmParser/LLParser.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4150,15 +4150,13 @@ bool LLParser::ParseDILexicalBlockFile(MDNode *&Result, bool IsDistinct) {
41504150
bool LLParser::ParseDINamespace(MDNode *&Result, bool IsDistinct) {
41514151
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
41524152
REQUIRED(scope, MDField, ); \
4153-
OPTIONAL(file, MDField, ); \
41544153
OPTIONAL(name, MDStringField, ); \
4155-
OPTIONAL(line, LineField, ); \
41564154
OPTIONAL(exportSymbols, MDBoolField, );
41574155
PARSE_MD_FIELDS();
41584156
#undef VISIT_MD_FIELDS
41594157

41604158
Result = GET_OR_DISTINCT(DINamespace,
4161-
(Context, scope.Val, file.Val, name.Val, line.Val, exportSymbols.Val));
4159+
(Context, scope.Val, name.Val, exportSymbols.Val));
41624160
return false;
41634161
}
41644162

lib/Bitcode/Reader/MetadataLoader.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,16 +1383,20 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
13831383
break;
13841384
}
13851385
case bitc::METADATA_NAMESPACE: {
1386-
if (Record.size() != 5)
1386+
// Newer versions of DINamespace dropped file and line.
1387+
MDString *Name;
1388+
if (Record.size() == 3)
1389+
Name = getMDString(Record[2]);
1390+
else if (Record.size() == 5)
1391+
Name = getMDString(Record[3]);
1392+
else
13871393
return error("Invalid record");
13881394

13891395
IsDistinct = Record[0] & 1;
13901396
bool ExportSymbols = Record[0] & 2;
13911397
MetadataList.assignValue(
13921398
GET_OR_DISTINCT(DINamespace,
1393-
(Context, getMDOrNull(Record[1]),
1394-
getMDOrNull(Record[2]), getMDString(Record[3]),
1395-
Record[4], ExportSymbols)),
1399+
(Context, getMDOrNull(Record[1]), Name, ExportSymbols)),
13961400
NextMetadataNo);
13971401
NextMetadataNo++;
13981402
break;

lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,9 +1646,7 @@ void ModuleBitcodeWriter::writeDINamespace(const DINamespace *N,
16461646
unsigned Abbrev) {
16471647
Record.push_back(N->isDistinct() | N->getExportSymbols() << 1);
16481648
Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1649-
Record.push_back(VE.getMetadataOrNullID(N->getFile()));
16501649
Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1651-
Record.push_back(N->getLine());
16521650

16531651
Stream.EmitRecord(bitc::METADATA_NAMESPACE, Record, Abbrev);
16541652
Record.clear();

lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,6 @@ void DwarfUnit::addSourceLine(DIE &Die, const DIObjCProperty *Ty) {
375375
addSourceLine(Die, Ty->getLine(), Ty->getFilename(), Ty->getDirectory());
376376
}
377377

378-
void DwarfUnit::addSourceLine(DIE &Die, const DINamespace *NS) {
379-
addSourceLine(Die, NS->getLine(), NS->getFilename(), NS->getDirectory());
380-
}
381-
382378
/* Byref variables, in Blocks, are declared by the programmer as "SomeType
383379
VarName;", but the compiler creates a __Block_byref_x_VarName struct, and
384380
gives the variable VarName either the struct, or a pointer to the struct, as
@@ -1085,7 +1081,6 @@ DIE *DwarfUnit::getOrCreateNameSpace(const DINamespace *NS) {
10851081
Name = "(anonymous namespace)";
10861082
DD->addAccelNamespace(Name, NDie);
10871083
addGlobalName(Name, NDie, NS->getScope());
1088-
addSourceLine(NDie, NS);
10891084
if (NS->getExportSymbols())
10901085
addFlag(NDie, dwarf::DW_AT_export_symbols);
10911086
return &NDie;

lib/CodeGen/AsmPrinter/DwarfUnit.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ class RangeSpanList {
210210
void addSourceLine(DIE &Die, const DIGlobalVariable *G);
211211
void addSourceLine(DIE &Die, const DISubprogram *SP);
212212
void addSourceLine(DIE &Die, const DIType *Ty);
213-
void addSourceLine(DIE &Die, const DINamespace *NS);
214213
void addSourceLine(DIE &Die, const DIObjCProperty *Ty);
215214

216215
/// Add constant value entry in variable DIE.

lib/IR/AsmWriter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,8 +1756,6 @@ static void writeDINamespace(raw_ostream &Out, const DINamespace *N,
17561756
MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
17571757
Printer.printString("name", N->getName());
17581758
Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1759-
Printer.printMetadata("file", N->getRawFile());
1760-
Printer.printInt("line", N->getLine());
17611759
Printer.printBool("exportSymbols", N->getExportSymbols(), false);
17621760
Out << ")";
17631761
}

lib/IR/DIBuilder.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,15 @@ DISubprogram *DIBuilder::createMethod(
728728
}
729729

730730
DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name,
731-
DIFile *File, unsigned LineNo,
732731
bool ExportSymbols) {
733-
return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name,
734-
LineNo, ExportSymbols);
732+
733+
// It is okay to *not* make anonymous top-level namespaces distinct, because
734+
// all nodes that have an anonymous namespace as their parent scope are
735+
// guaranteed to be unique and/or are linked to their containing
736+
// DICompileUnit. This decision is an explicit tradeoff of link time versus
737+
// memory usage versus code simplicity and may get revisited in the future.
738+
return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
739+
ExportSymbols);
735740
}
736741

737742
DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name,

lib/IR/DebugInfoMetadata.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,13 @@ DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
507507
}
508508

509509
DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
510-
Metadata *File, MDString *Name, unsigned Line,
511-
bool ExportSymbols, StorageType Storage,
512-
bool ShouldCreate) {
510+
MDString *Name, bool ExportSymbols,
511+
StorageType Storage, bool ShouldCreate) {
513512
assert(isCanonical(Name) && "Expected canonical MDString");
514-
DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, Name, Line, ExportSymbols));
515-
Metadata *Ops[] = {File, Scope, Name};
516-
DEFINE_GETIMPL_STORE(DINamespace, (Line, ExportSymbols), Ops);
513+
DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols));
514+
// The nullptr is for DIScope's File operand. This should be refactored.
515+
Metadata *Ops[] = {nullptr, Scope, Name};
516+
DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops);
517517
}
518518

519519
DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,

0 commit comments

Comments
 (0)