Index: include/llvm/IR/DIBuilder.h =================================================================== --- include/llvm/IR/DIBuilder.h +++ include/llvm/IR/DIBuilder.h @@ -575,9 +575,8 @@ /// \param Scope Namespace scope /// \param Name Name of this namespace /// \param File Source file - /// \param LineNo Line number - DINamespace *createNameSpace(DIScope *Scope, StringRef Name, DIFile *File, - unsigned LineNo); + DINamespace *createNamespace(DIScope *Scope, StringRef Name, + DIFile *File = nullptr); /// This creates new descriptor for a module with the specified /// parent scope. Index: include/llvm/IR/DebugInfoMetadata.h =================================================================== --- include/llvm/IR/DebugInfoMetadata.h +++ include/llvm/IR/DebugInfoMetadata.h @@ -1532,41 +1532,36 @@ friend class LLVMContextImpl; friend class MDNode; - unsigned Line; - - DINamespace(LLVMContext &Context, StorageType Storage, unsigned Line, + DINamespace(LLVMContext &Context, StorageType Storage, ArrayRef Ops) : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, - Ops), - Line(Line) {} + Ops) {} ~DINamespace() = default; static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope, - DIFile *File, StringRef Name, unsigned Line, - StorageType Storage, bool ShouldCreate = true) { + DIFile *File, StringRef Name, StorageType Storage, + bool ShouldCreate = true) { return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name), - Line, Storage, ShouldCreate); + Storage, ShouldCreate); } static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope, - Metadata *File, MDString *Name, unsigned Line, + Metadata *File, MDString *Name, StorageType Storage, bool ShouldCreate = true); TempDINamespace cloneImpl() const { - return getTemporary(getContext(), getScope(), getFile(), getName(), - getLine()); + return getTemporary(getContext(), getScope(), getFile(), getName()); } public: - DEFINE_MDNODE_GET(DINamespace, (DIScope * Scope, DIFile *File, StringRef Name, - unsigned Line), - (Scope, File, Name, Line)) - DEFINE_MDNODE_GET(DINamespace, (Metadata * Scope, Metadata *File, - MDString *Name, unsigned Line), - (Scope, File, Name, Line)) + DEFINE_MDNODE_GET(DINamespace, + (DIScope * Scope, DIFile *File, StringRef Name), + (Scope, File, Name)) + DEFINE_MDNODE_GET(DINamespace, + (Metadata * Scope, Metadata *File, MDString *Name), + (Scope, File, Name)) TempDINamespace clone() const { return cloneImpl(); } - unsigned getLine() const { return Line; } DIScope *getScope() const { return cast_or_null(getRawScope()); } StringRef getName() const { return getStringOperand(2); } Index: lib/AsmParser/LLParser.cpp =================================================================== --- lib/AsmParser/LLParser.cpp +++ lib/AsmParser/LLParser.cpp @@ -3890,7 +3890,7 @@ #undef VISIT_MD_FIELDS Result = GET_OR_DISTINCT(DINamespace, - (Context, scope.Val, file.Val, name.Val, line.Val)); + (Context, scope.Val, file.Val, name.Val)); return false; } Index: lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- lib/Bitcode/Reader/BitcodeReader.cpp +++ lib/Bitcode/Reader/BitcodeReader.cpp @@ -2218,14 +2218,13 @@ break; } case bitc::METADATA_NAMESPACE: { - if (Record.size() != 5) + if (Record.size() != 4 && Record.size() != 5) return error("Invalid record"); MDValueList.assignValue( GET_OR_DISTINCT(DINamespace, Record[0], (Context, getMDOrNull(Record[1]), - getMDOrNull(Record[2]), getMDString(Record[3]), - Record[4])), + getMDOrNull(Record[2]), getMDString(Record[3]))), NextMDValueNo++); break; } Index: lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitcodeWriter.cpp +++ lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1069,7 +1069,6 @@ Record.push_back(VE.getMetadataOrNullID(N->getScope())); Record.push_back(VE.getMetadataOrNullID(N->getFile())); Record.push_back(VE.getMetadataOrNullID(N->getRawName())); - Record.push_back(N->getLine()); Stream.EmitRecord(bitc::METADATA_NAMESPACE, Record, Abbrev); Record.clear(); Index: lib/CodeGen/AsmPrinter/DwarfUnit.h =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.h +++ lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -239,7 +239,6 @@ void addSourceLine(DIE &Die, const DIGlobalVariable *G); void addSourceLine(DIE &Die, const DISubprogram *SP); void addSourceLine(DIE &Die, const DIType *Ty); - void addSourceLine(DIE &Die, const DINamespace *NS); void addSourceLine(DIE &Die, const DIObjCProperty *Ty); /// Add constant value entry in variable DIE. Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -363,10 +363,6 @@ addSourceLine(Die, Ty->getLine(), Ty->getFilename(), Ty->getDirectory()); } -void DwarfUnit::addSourceLine(DIE &Die, const DINamespace *NS) { - addSourceLine(Die, NS->getLine(), NS->getFilename(), NS->getDirectory()); -} - bool DwarfUnit::addRegisterOpPiece(DIELoc &TheDie, unsigned Reg, unsigned SizeInBits, unsigned OffsetInBits) { DIEDwarfExpression Expr(*Asm, *this, TheDie); @@ -1082,7 +1078,6 @@ Name = "(anonymous namespace)"; DD->addAccelNamespace(Name, NDie); addGlobalName(Name, NDie, NS->getScope()); - addSourceLine(NDie, NS); return &NDie; } Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -3445,11 +3445,14 @@ if (I != NameSpaceCache.end()) return cast(I->second); - unsigned LineNo = getLineNumber(NSDecl->getLocation()); - llvm::DIFile *FileD = getOrCreateFile(NSDecl->getLocation()); llvm::DIScope *Context = getDeclContextDescriptor(NSDecl); - llvm::DINamespace *NS = - DBuilder.createNameSpace(Context, NSDecl->getName(), FileD, LineNo); + StringRef Name = NSDecl->getName(); + llvm::DINamespace *NS; + if (Name.empty()) { + auto *File = getOrCreateFile(NSDecl->getLocation()); + NS = DBuilder.createNamespace(Context, "", File); + } else + NS = DBuilder.createNamespace(Context, Name); NameSpaceCache[NSDecl].reset(NS); return NS; } Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -1733,7 +1733,6 @@ Printer.printString("name", N->getName()); Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); Printer.printMetadata("file", N->getRawFile()); - Printer.printInt("line", N->getLine()); Out << ")"; } Index: lib/IR/DIBuilder.cpp =================================================================== --- lib/IR/DIBuilder.cpp +++ lib/IR/DIBuilder.cpp @@ -739,10 +739,9 @@ return SP; } -DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name, - DIFile *File, unsigned LineNo) { - return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name, - LineNo); +DINamespace *DIBuilder::createNamespace(DIScope *Scope, StringRef Name, + DIFile *File) { + return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name); } DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name, Index: lib/IR/DebugInfoMetadata.cpp =================================================================== --- lib/IR/DebugInfoMetadata.cpp +++ lib/IR/DebugInfoMetadata.cpp @@ -407,12 +407,12 @@ } DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope, - Metadata *File, MDString *Name, unsigned Line, + Metadata *File, MDString *Name, StorageType Storage, bool ShouldCreate) { assert(isCanonical(Name) && "Expected canonical MDString"); - DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, getString(Name), Line)); + DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, getString(Name))); Metadata *Ops[] = {File, Scope, Name}; - DEFINE_GETIMPL_STORE(DINamespace, (Line), Ops); + DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DINamespace, Ops); } DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope, Index: lib/IR/LLVMContextImpl.h =================================================================== --- lib/IR/LLVMContextImpl.h +++ lib/IR/LLVMContextImpl.h @@ -573,21 +573,17 @@ Metadata *Scope; Metadata *File; StringRef Name; - unsigned Line; - MDNodeKeyImpl(Metadata *Scope, Metadata *File, StringRef Name, unsigned Line) - : Scope(Scope), File(File), Name(Name), Line(Line) {} + MDNodeKeyImpl(Metadata *Scope, Metadata *File, StringRef Name) + : Scope(Scope), File(File), Name(Name) {} MDNodeKeyImpl(const DINamespace *N) - : Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getName()), - Line(N->getLine()) {} + : Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getName()) {} bool isKeyOf(const DINamespace *RHS) const { return Scope == RHS->getRawScope() && File == RHS->getRawFile() && - Name == RHS->getName() && Line == RHS->getLine(); - } - unsigned getHashValue() const { - return hash_combine(Scope, File, Name, Line); + Name == RHS->getName(); } + unsigned getHashValue() const { return hash_combine(Scope, File, Name); } }; template <> struct MDNodeKeyImpl { Index: test/Assembler/dinamespace.ll =================================================================== --- test/Assembler/dinamespace.ll +++ test/Assembler/dinamespace.ll @@ -8,9 +8,9 @@ !1 = distinct !{} !2 = !DIFile(filename: "path/to/file", directory: "/path/to/dir") -; CHECK: !3 = !DINamespace(name: "Namespace", scope: !0, file: !2, line: 7) -!3 = !DINamespace(name: "Namespace", scope: !0, file: !2, line: 7) +; CHECK: !3 = !DINamespace(name: "Namespace", scope: !0, file: !2) +!3 = !DINamespace(name: "Namespace", scope: !0, file: !2) -; CHECK: !4 = !DINamespace(scope: !0) -!4 = !DINamespace(name: "", scope: !0, file: null, line: 0) -!5 = !DINamespace(scope: !0) +; CHECK: !4 = !DINamespace(scope: !0, file: !2) +!4 = !DINamespace(name: "", scope: !0, file: !2) +!5 = !DINamespace(scope: !0, file: !2) Index: test/CodeGenCXX/debug-info-namespace.cpp =================================================================== --- test/CodeGenCXX/debug-info-namespace.cpp +++ test/CodeGenCXX/debug-info-namespace.cpp @@ -61,9 +61,8 @@ // CHECK-SAME: line: 5 // CHECK-SAME: DIFlagFwdDecl // CHECK: [[FOOCPP:![0-9]+]] = !DIFile(filename: "foo.cpp" -// CHECK: [[NS:![0-9]+]] = !DINamespace(name: "B", scope: [[CTXT:![0-9]+]], file: [[FOOCPP]], line: 1) -// CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null, file: [[FILE:![0-9]+]], line: 5) -// CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-namespace.cpp", +// CHECK: [[NS:![0-9]+]] = !DINamespace(name: "B", scope: [[CTXT:![0-9]+]]) +// CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null) // CHECK: [[BAR:![0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "bar", // CHECK-SAME: line: 6 // CHECK-SAME: DIFlagFwdDecl Index: test/DebugInfo/Generic/namespace.ll =================================================================== --- test/DebugInfo/Generic/namespace.ll +++ test/DebugInfo/Generic/namespace.ll @@ -4,13 +4,9 @@ ; CHECK: debug_info contents ; CHECK: [[NS1:0x[0-9a-f]*]]:{{ *}}DW_TAG_namespace ; CHECK-NEXT: DW_AT_name{{.*}} = "A" -; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F1:".*debug-info-namespace.cpp"]]) -; CHECK-NEXT: DW_AT_decl_line{{.*}}(5) ; CHECK-NOT: NULL ; CHECK: [[NS2:0x[0-9a-f]*]]:{{ *}}DW_TAG_namespace ; CHECK-NEXT: DW_AT_name{{.*}} = "B" -; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2:".*foo.cpp"]]) -; CHECK-NEXT: DW_AT_decl_line{{.*}}(1) ; CHECK-NOT: NULL ; CHECK: [[I:0x[0-9a-f]*]]:{{ *}}DW_TAG_variable ; CHECK-NEXT: DW_AT_name{{.*}}= "i" @@ -56,7 +52,7 @@ ; CHECK: DW_TAG_imported_module ; This is a bug, it should be in F2 but it inherits the file from its ; enclosing scope -; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F1]]) +; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F1:".*debug-info-namespace.cpp"]]) ; CHECK-NEXT: DW_AT_decl_line{{.*}}(15) ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS2]]}) ; CHECK: NULL @@ -76,7 +72,7 @@ ; CHECK: DW_AT_name{{.*}}= "func" ; CHECK-NOT: NULL ; CHECK: DW_TAG_imported_module -; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) +; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2:".*foo.cpp"]]) ; CHECK-NEXT: DW_AT_decl_line{{.*}}(26) ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]}) ; CHECK-NOT: NULL Index: test/DebugInfo/X86/dwarf-public-names.ll =================================================================== --- test/DebugInfo/X86/dwarf-public-names.ll +++ test/DebugInfo/X86/dwarf-public-names.ll @@ -43,7 +43,7 @@ ; Skip the output to the header of the pubnames section. ; LINUX: debug_pubnames -; LINUX-NEXT: unit_size = 0x0000012a +; LINUX-NEXT: unit_size = 0x00000128 ; Check for each name in the output. ; LINUX-DAG: "ns" Index: test/Modules/ExtDebugInfo.cpp =================================================================== --- test/Modules/ExtDebugInfo.cpp +++ test/Modules/ExtDebugInfo.cpp @@ -35,7 +35,7 @@ auto anon_enum = DebugCXX::e2; char _anchor = anon_enum + conflicting_uid; -// CHECK: ![[NS:.*]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]], +// CHECK: ![[NS:.*]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]]) // CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Struct", Index: unittests/IR/MetadataTest.cpp =================================================================== --- unittests/IR/MetadataTest.cpp +++ unittests/IR/MetadataTest.cpp @@ -1649,21 +1649,18 @@ DIScope *Scope = getFile(); DIFile *File = getFile(); StringRef Name = "namespace"; - unsigned Line = 5; - auto *N = DINamespace::get(Context, Scope, File, Name, Line); + auto *N = DINamespace::get(Context, Scope, File, Name); EXPECT_EQ(dwarf::DW_TAG_namespace, N->getTag()); EXPECT_EQ(Scope, N->getScope()); EXPECT_EQ(File, N->getFile()); EXPECT_EQ(Name, N->getName()); - EXPECT_EQ(Line, N->getLine()); - EXPECT_EQ(N, DINamespace::get(Context, Scope, File, Name, Line)); + EXPECT_EQ(N, DINamespace::get(Context, Scope, File, Name)); - EXPECT_NE(N, DINamespace::get(Context, getFile(), File, Name, Line)); - EXPECT_NE(N, DINamespace::get(Context, Scope, getFile(), Name, Line)); - EXPECT_NE(N, DINamespace::get(Context, Scope, File, "other", Line)); - EXPECT_NE(N, DINamespace::get(Context, Scope, File, Name, Line + 1)); + EXPECT_NE(N, DINamespace::get(Context, getFile(), File, Name)); + EXPECT_NE(N, DINamespace::get(Context, Scope, getFile(), Name)); + EXPECT_NE(N, DINamespace::get(Context, Scope, File, "other")); TempDINamespace Temp = N->clone(); EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));