[lld] [llvm] [DebugInfo][DwarfDebug] Move emission of globals from beginModule() to endModule() (5/7) (PR #184219)

Vladislav Dzhidzhoev via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 06:57:55 PST 2026


https://github.com/dzhidzhoev updated https://github.com/llvm/llvm-project/pull/184219

>From 67cb13d7ffa2ef6e58c9d858bcdcfd973e1b2e98 Mon Sep 17 00:00:00 2001
From: Kristina Bessonova <kbessonova at accesssoftek.com>
Date: Mon, 13 Mar 2023 13:36:06 +0100
Subject: [PATCH 1/6] [DwarfDebug] Move emission of globals from beginModule()
 to endModule() (5/7)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

This patch moves the emission of global variables from `DwarfDebug::beginModule()`
to `DwarfDebug::endModule()`.

It has the following effects:
1. The order of debug entities in the resulting DWARF changes.
2. Currently, if a DISubprogram requires emission of both concrete
   out-of-line and inlined subprogram DIEs, and such a subprogram contains
   a static local variable, the DIE for the variable is emitted into
   the concrete out-of-line subprogram DIE. As a result, the variable
   is not available in debugger when breaking at the inlined function
   instance.

   It happens because static locals are emitted in `DwarfDebug::beginModule()`,
   but abstract DIEs for functions that are not completely inlined away
   are created only later during `DwarfDebug::endFunctionImpl()` calls.

   With this patch, DIEs for static local variables of subprograms that
   have both inlined and the concrete out-of-line instances are placed
   into abstract subprogram DIEs. They get visible in debugger when
   breaking at concrete out-of-line and inlined function instances.

   llvm/test/DebugInfo/Generic/inlined-static-var.ll illustrates that.
3. It will allow to simplify abstract subprogram DIEs creation by
   reverting https://github.com/llvm/llvm-project/pull/159104 later.

This is needed to simplify DWARF emission in a context of proper support of
function-local static variables (which are globals in terms of LLVM IR)
which comes in the next patch (https://reviews.llvm.org/D144008), making
all function-local entities handled in `DwarfDebug::endModuleImpl()`.

This change has already been reviewed in https://reviews.llvm.org/D144007,
but I’m opening a new PR because it has been a while since it was approved.

Authored-by: Kristina Bessonova <kbessonova at accesssoftek.com>
---
 lld/test/wasm/debuginfo.test                  |  32 ++--
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp    |  70 ++++----
 .../test/CodeGen/X86/dbg-distringtype-uint.ll |  16 +-
 .../AArch64/DW_AT_APPLE_enum_kind.ll          |   6 +-
 .../DebugInfo/AMDGPU/variable-locations.ll    |  31 ++--
 .../Generic/cross-cu-linkonce-distinct.ll     |   3 +
 .../Generic/debug-names-linkage-name.ll       |   2 +-
 .../dwarf5-debug-info-static-member.ll        |   6 +-
 .../DebugInfo/Generic/inlined-static-var.ll   |   9 +-
 llvm/test/DebugInfo/Generic/namespace.ll      |  12 +-
 llvm/test/DebugInfo/MSP430/global-var.ll      |   2 +-
 llvm/test/DebugInfo/NVPTX/debug-addr-class.ll | 156 +++++++++---------
 llvm/test/DebugInfo/PowerPC/strict-dwarf.ll   |   4 +-
 .../DebugInfo/WebAssembly/tls_pic_globals.ll  |  24 +--
 .../X86/2011-09-26-GlobalVarContext.ll        |  12 +-
 .../DebugInfo/X86/DW_AT_calling-convention.ll |   8 +-
 llvm/test/DebugInfo/X86/align_cpp11.ll        |  28 ++--
 llvm/test/DebugInfo/X86/align_objc.ll         |  13 +-
 llvm/test/DebugInfo/X86/arange-and-stub.ll    |   2 +-
 .../X86/containing-type-extension-rust.ll     |   1 +
 llvm/test/DebugInfo/X86/debug-info-access.ll  |   8 +-
 .../DebugInfo/X86/debug-info-static-member.ll |   4 +
 .../test/DebugInfo/X86/debug-names-dwarf64.ll |   8 +-
 llvm/test/DebugInfo/X86/dwarf-aranges.ll      |  12 +-
 .../test/DebugInfo/X86/dwarf-linkage-names.ll |   4 +-
 .../dwarfdump-DIImportedEntity_elements.ll    |  10 +-
 llvm/test/DebugInfo/X86/generate-odr-hash.ll  |  12 +-
 llvm/test/DebugInfo/X86/gnu-public-names.ll   | 126 +++++++-------
 llvm/test/DebugInfo/X86/linkage-name.ll       |   2 +-
 llvm/test/DebugInfo/X86/namelist1.ll          |   5 +-
 llvm/test/DebugInfo/X86/prototyped.ll         |   4 +-
 .../test/DebugInfo/X86/ref_addr_relocation.ll |   6 +-
 .../X86/string-offsets-multiple-cus.ll        |  25 ++-
 .../DebugInfo/X86/string-offsets-table.ll     |   4 +-
 llvm/test/DebugInfo/X86/template.ll           |  33 ++--
 llvm/test/DebugInfo/X86/tls.ll                |  37 +++--
 llvm/test/DebugInfo/X86/tu-to-non-tu.ll       |  37 +++--
 llvm/test/DebugInfo/X86/vla-global.ll         |   3 +
 llvm/test/DebugInfo/attr-btf_tag.ll           |  71 ++++----
 llvm/test/MC/WebAssembly/debug-info.ll        |  22 +--
 llvm/test/MC/WebAssembly/debug-info64.ll      |  22 +--
 llvm/test/MC/WebAssembly/dwarfdump.ll         |  84 +++++-----
 llvm/test/MC/WebAssembly/dwarfdump64.ll       |  40 ++---
 .../DWARF/crash-thread-local-storage.test     |   2 +-
 44 files changed, 534 insertions(+), 484 deletions(-)

diff --git a/lld/test/wasm/debuginfo.test b/lld/test/wasm/debuginfo.test
index 7e6bd51cb35c9..09a998aa3521c 100644
--- a/lld/test/wasm/debuginfo.test
+++ b/lld/test/wasm/debuginfo.test
@@ -44,9 +44,23 @@ CHECK-NEXT:              DW_AT_producer	("clang version 7.0.0 (trunk {{.*}})")
 CHECK-NEXT:              DW_AT_language	(DW_LANG_C99)
 CHECK-NEXT:              DW_AT_name	("hi_foo.c")
 
+CHECK:   DW_TAG_subprogram
+CHECK-NEXT:                DW_AT_low_pc
+CHECK-NEXT:                DW_AT_high_pc
+CHECK-NEXT:                DW_AT_frame_base
+CHECK-NEXT:                DW_AT_name	("foo")
+CHECK-NEXT:                DW_AT_decl_file	("{{.*}}hi_foo.c")
+CHECK-NEXT:                DW_AT_decl_line	(3)
+
+CHECK:     DW_TAG_formal_parameter
+CHECK-NEXT:                  DW_AT_location (DW_OP_WASM_location 0x0 0x0, DW_OP_stack_value)
+CHECK-NEXT:                  DW_AT_name	("p")
+CHECK-NEXT:                  DW_AT_decl_file	("{{.*}}hi_foo.c")
+CHECK-NEXT:                  DW_AT_decl_line	(3)
+
 CHECK:   DW_TAG_variable
 CHECK-NEXT:                DW_AT_name	("y")
-CHECK-NEXT:                DW_AT_type	(0x000000ac "int[2]")
+CHECK-NEXT:                DW_AT_type	(0x000000d4 "int[2]")
 CHECK-NEXT:                DW_AT_external	(true)
 CHECK-NEXT:                DW_AT_decl_file	("{{.*}}hi_foo.c")
 CHECK-NEXT:                DW_AT_decl_line	(1)
@@ -68,23 +82,9 @@ CHECK-NEXT:                DW_AT_encoding	(DW_ATE_unsigned)
 
 CHECK:   DW_TAG_variable
 CHECK-NEXT:                DW_AT_name	("z")
-CHECK-NEXT:                DW_AT_type	(0x000000ac "int[2]")
+CHECK-NEXT:                DW_AT_type	(0x000000d4 "int[2]")
 CHECK-NEXT:                DW_AT_external	(true)
 CHECK-NEXT:                DW_AT_decl_file	("{{.*}}hi_foo.c")
 CHECK-NEXT:                DW_AT_decl_line	(8)
 CHECK-NEXT:                DW_AT_location	(DW_OP_addr 0xffffffff)
 
-CHECK:   DW_TAG_subprogram
-CHECK-NEXT:                DW_AT_low_pc
-CHECK-NEXT:                DW_AT_high_pc
-CHECK-NEXT:                DW_AT_frame_base
-CHECK-NEXT:                DW_AT_name	("foo")
-CHECK-NEXT:                DW_AT_decl_file	("{{.*}}hi_foo.c")
-CHECK-NEXT:                DW_AT_decl_line	(3)
-
-CHECK:     DW_TAG_formal_parameter
-CHECK-NEXT:                  DW_AT_location (DW_OP_WASM_location 0x0 0x0, DW_OP_stack_value)
-CHECK-NEXT:                  DW_AT_name	("p")
-CHECK-NEXT:                  DW_AT_decl_file	("{{.*}}hi_foo.c")
-CHECK-NEXT:                  DW_AT_decl_line	(3)
-
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 042c98fa1c02f..cd91a2a08d536 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1256,14 +1256,6 @@ void DwarfDebug::beginModule(Module *M) {
 
   assert(NumDebugCUs > 0 && "Asm unexpectedly initialized");
   SingleCU = NumDebugCUs == 1;
-  DenseMap<DIGlobalVariable *, SmallVector<DwarfCompileUnit::GlobalExpr, 1>>
-      GVMap;
-  for (const GlobalVariable &Global : M->globals()) {
-    SmallVector<DIGlobalVariableExpression *, 1> GVs;
-    Global.getDebugInfo(GVs);
-    for (auto *GVE : GVs)
-      GVMap[GVE->getVariable()].push_back({&Global, GVE->getExpression()});
-  }
 
   // Create the symbol that designates the start of the unit's contribution
   // to the string offsets table. In a split DWARF scenario, only the skeleton
@@ -1298,24 +1290,6 @@ void DwarfDebug::beginModule(Module *M) {
 
     DwarfCompileUnit &CU = getOrCreateDwarfCompileUnit(CUNode);
 
-    // Global Variables.
-    for (auto *GVE : CUNode->getGlobalVariables()) {
-      // Don't bother adding DIGlobalVariableExpressions listed in the CU if we
-      // already know about the variable and it isn't adding a constant
-      // expression.
-      auto &GVMapEntry = GVMap[GVE->getVariable()];
-      auto *Expr = GVE->getExpression();
-      if (!GVMapEntry.size() || (Expr && Expr->isConstant()))
-        GVMapEntry.push_back({nullptr, Expr});
-    }
-
-    DenseSet<DIGlobalVariable *> Processed;
-    for (auto *GVE : CUNode->getGlobalVariables()) {
-      DIGlobalVariable *GV = GVE->getVariable();
-      if (Processed.insert(GV).second)
-        CU.getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(GVMap[GV]));
-    }
-
     for (auto *Ty : CUNode->getEnumTypes()) {
       assert(!isa_and_nonnull<DILocalScope>(Ty->getScope()) &&
              "Unexpected function-local entity in 'enums' CU field.");
@@ -1513,9 +1487,47 @@ void DwarfDebug::endModule() {
   assert(CurFn == nullptr);
   assert(CurMI == nullptr);
 
-  for (const auto &P : CUMap) {
-    const auto *CUNode = cast<DICompileUnit>(P.first);
-    DwarfCompileUnit *CU = &*P.second;
+  const Module *M = MMI->getModule();
+
+  // Collect global variables info.
+  DenseMap<DIGlobalVariable *, SmallVector<DwarfCompileUnit::GlobalExpr, 1>>
+      GVMap;
+  for (const GlobalVariable &Global : M->globals()) {
+    SmallVector<DIGlobalVariableExpression *, 1> GVs;
+    Global.getDebugInfo(GVs);
+    for (auto *GVE : GVs)
+      GVMap[GVE->getVariable()].push_back({&Global, GVE->getExpression()});
+  }
+
+  for (DICompileUnit *CUNode : M->debug_compile_units()) {
+    DwarfCompileUnit *CU = CUMap.lookup(CUNode);
+
+    // If the CU hasn't been emitted yet, create it here unless it is empty.
+    if (!CU) {
+      if (CUNode->getImportedEntities().empty() &&
+          CUNode->getEnumTypes().empty() &&
+          CUNode->getRetainedTypes().empty() &&
+          CUNode->getGlobalVariables().empty() && CUNode->getMacros().empty())
+        continue;
+      CU = &getOrCreateDwarfCompileUnit(CUNode);
+    }
+
+    // Emit Global Variables.
+    for (auto *GVE : CUNode->getGlobalVariables()) {
+      // Don't bother adding DIGlobalVariableExpressions listed in the CU if we
+      // already know about the variable and it isn't adding a constant
+      // expression.
+      auto &GVMapEntry = GVMap[GVE->getVariable()];
+      auto *Expr = GVE->getExpression();
+      if (!GVMapEntry.size() || (Expr && Expr->isConstant()))
+        GVMapEntry.push_back({nullptr, Expr});
+    }
+    DenseSet<DIGlobalVariable *> Processed;
+    for (auto *GVE : CUNode->getGlobalVariables()) {
+      DIGlobalVariable *GV = GVE->getVariable();
+      if (Processed.insert(GV).second)
+        CU->getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(GVMap[GV]));
+    }
 
     // Emit imported entities.
     for (auto *IE : CUNode->getImportedEntities()) {
diff --git a/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll b/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll
index 7542c1b8db327..9eb7c9c59ebd4 100644
--- a/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll
+++ b/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll
@@ -1,17 +1,19 @@
 ; RUN: llc -mtriple=x86_64 -filetype=obj < %s | llvm-dwarfdump -debug-info - | FileCheck %s
 
-; Ensure that static local variable elemnt is placed in abstract subprogram DIE.
 ; CHECK:                   DW_TAG_subprogram
 ; CHECK-NOT:               DW_TAG
 ; CHECK:                     DW_AT_inline  (DW_INL_inlined)
-; CHECK-EMPTY:
-; CHECK-NEXT:                DW_TAG_variable
+; CHECK-NOT:                 DW_TAG
+; CHECK: [[SYM:[a-z0-9]+]]:  DW_TAG_formal_parameter
+; CHECK:                       DW_AT_name	("esym")
+; CHECK:                       DW_AT_type	([[TYPE:[a-z0-9]+]] "CHARACTER_1")
+; CHECK-NOT:                 DW_TAG
+; CHECK:                     DW_TAG_formal_parameter
+; CHECK-NOT:                 DW_TAG
+; Ensure that static local variable elemnt is placed in abstract subprogram DIE.
+; CHECK:                     DW_TAG_variable
 ; CHECK-NEXT:                  DW_AT_name  ("elemnt")
 
-; CHECK: [[SYM:[a-z0-9]+]]:  DW_TAG_formal_parameter
-; CHECK:                     DW_AT_name	("esym")
-; CHECK:                     DW_AT_type	([[TYPE:[a-z0-9]+]] "CHARACTER_1")
-;
 ; CHECK:                     DW_TAG_formal_parameter
 ; CHECK:                       DW_AT_const_value	(7523094288207667809)
 ; CHECK:                       DW_AT_abstract_origin	([[SYM]] "esym")
diff --git a/llvm/test/DebugInfo/AArch64/DW_AT_APPLE_enum_kind.ll b/llvm/test/DebugInfo/AArch64/DW_AT_APPLE_enum_kind.ll
index 399d80c778072..1183202dfadaf 100644
--- a/llvm/test/DebugInfo/AArch64/DW_AT_APPLE_enum_kind.ll
+++ b/llvm/test/DebugInfo/AArch64/DW_AT_APPLE_enum_kind.ll
@@ -15,16 +15,16 @@
 
 ; CHECK: .debug_abbrev contents:
 
-; CHECK: [3] DW_TAG_enumeration_type DW_CHILDREN_yes
+; CHECK: [2] DW_TAG_enumeration_type DW_CHILDREN_yes
 ; CHECK: DW_AT_APPLE_enum_kind   DW_FORM_data1
 
 ; CHECK: .debug_info contents:
 
-; CHECK: DW_TAG_enumeration_type [3]
+; CHECK: DW_TAG_enumeration_type [2]
 ; CHECK-DAG: DW_AT_name {{.*}} string = "OpenEnum"
 ; CHECK-DAG: DW_AT_APPLE_enum_kind [DW_FORM_data1]  (DW_APPLE_ENUM_KIND_Open)
 
-; CHECK: DW_TAG_enumeration_type [3]
+; CHECK: DW_TAG_enumeration_type [2]
 ; CHECK-DAG: DW_AT_name {{.*}} string = "ClosedEnum"
 ; CHECK-DAG: DW_AT_APPLE_enum_kind [DW_FORM_data1]  (DW_APPLE_ENUM_KIND_Closed)
 
diff --git a/llvm/test/DebugInfo/AMDGPU/variable-locations.ll b/llvm/test/DebugInfo/AMDGPU/variable-locations.ll
index b795ad1b61a9c..ce69180e01539 100644
--- a/llvm/test/DebugInfo/AMDGPU/variable-locations.ll
+++ b/llvm/test/DebugInfo/AMDGPU/variable-locations.ll
@@ -13,22 +13,7 @@
 
 declare void @llvm.dbg.declare(metadata, metadata, metadata)
 
-; CHECK: {{.*}}DW_TAG_variable
-; CHECK-NEXT: DW_AT_name {{.*}}"GlobA"
-; CHECK-NEXT: DW_AT_type
-; CHECK-NEXT: DW_AT_external
-; CHECK-NEXT: DW_AT_decl_file
-; CHECK-NEXT: DW_AT_decl_line
-; CHECK-NEXT: DW_AT_location [DW_FORM_block1] (DW_OP_addr 0x0)
 @GlobA = common addrspace(1) global i32 0, align 4, !dbg !0
-
-; CHECK: {{.*}}DW_TAG_variable
-; CHECK-NEXT: DW_AT_name {{.*}}"GlobB"
-; CHECK-NEXT: DW_AT_type
-; CHECK-NEXT: DW_AT_external
-; CHECK-NEXT: DW_AT_decl_file
-; CHECK-NEXT: DW_AT_decl_line
-; CHECK-NEXT: DW_AT_location [DW_FORM_block1] (DW_OP_addr 0x0)
 @GlobB = common addrspace(1) global i32 0, align 4, !dbg !6
 
 ; CHECK: {{.*}}DW_TAG_subprogram
@@ -78,12 +63,28 @@ entry:
 !llvm.ident = !{!12}
 
 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+
+; CHECK: {{.*}}DW_TAG_variable
+; CHECK-NEXT: DW_AT_name {{.*}}"GlobA"
+; CHECK-NEXT: DW_AT_type
+; CHECK-NEXT: DW_AT_external
+; CHECK-NEXT: DW_AT_decl_file
+; CHECK-NEXT: DW_AT_decl_line
+; CHECK-NEXT: DW_AT_location [DW_FORM_block1] (DW_OP_addr 0x0)
 !1 = distinct !DIGlobalVariable(name: "GlobA", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 5.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
 !3 = !DIFile(filename: "variable-locations.cl", directory: "/some/random/directory")
 !4 = !{}
 !5 = !{!0, !6}
 !6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+
+; CHECK: {{.*}}DW_TAG_variable
+; CHECK-NEXT: DW_AT_name {{.*}}"GlobB"
+; CHECK-NEXT: DW_AT_type
+; CHECK-NEXT: DW_AT_external
+; CHECK-NEXT: DW_AT_decl_file
+; CHECK-NEXT: DW_AT_decl_line
+; CHECK-NEXT: DW_AT_location [DW_FORM_block1] (DW_OP_addr 0x0)
 !7 = distinct !DIGlobalVariable(name: "GlobB", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
 !8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
 !9 = !{i32 2, i32 0}
diff --git a/llvm/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll b/llvm/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll
index 450e38c72ed2e..c9abc29b4bd6d 100644
--- a/llvm/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll
+++ b/llvm/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll
@@ -33,9 +33,12 @@
 ; CHECK: DW_TAG_compile_unit
 ; CHECK-NOT: DW_TAG
 ; CHECK:     DW_AT_name ("a.cpp")
+; CHECK: DW_TAG_subprogram
+; CHECK-NOT: DW_TAG
 ; CHECK:     DW_AT_name ("func")
 
 source_filename = "test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll"
+target triple = "x86_64-unknown-linux-gnu"
 
 @x = global ptr @_Z4funci, align 8, !dbg !0
 @y = global ptr @_Z4funci, align 8, !dbg !7
diff --git a/llvm/test/DebugInfo/Generic/debug-names-linkage-name.ll b/llvm/test/DebugInfo/Generic/debug-names-linkage-name.ll
index 9fa73935cacd5..5f901bf9dba95 100644
--- a/llvm/test/DebugInfo/Generic/debug-names-linkage-name.ll
+++ b/llvm/test/DebugInfo/Generic/debug-names-linkage-name.ll
@@ -11,9 +11,9 @@
 
 ; We should have all three linkage names in the .debug_info and .debug_names
 ; ALL: .debug_info contents:
-; ALL: DW_AT_linkage_name	("_ZN1n1vE")
 ; ALL: DW_AT_linkage_name	("_Z1fi")
 ; ALL: DW_AT_linkage_name	("_Z1gi")
+; ALL: DW_AT_linkage_name	("_ZN1n1vE")
 ; ALL: .debug_names contents:
 ; ALL: String: {{.*}} "_Z1fi"
 ; ALL: String: {{.*}} "_Z1gi"
diff --git a/llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll b/llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll
index 3bbc79bdf03c1..b52d5cc1f18d8 100644
--- a/llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll
+++ b/llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll
@@ -88,8 +88,6 @@ attributes #1 = { nounwind readnone }
 !35 = !DILocation(line: 13, column: 3, scope: !26)
 
 ; CHECK:      .debug_info contents:
-; CHECK:      DW_TAG_variable
-; CHECK-NEXT: DW_AT_specification {{.*}} "a"
 ; CHECK:      DW_TAG_structure_type
 ; CHECK:      DW_AT_name {{.*}} "C"
 ; CHECK:      DW_TAG_variable
@@ -105,6 +103,10 @@ attributes #1 = { nounwind readnone }
 ; CHECK:      DW_AT_external
 ; CHECK:      DW_AT_declaration
 ; CHECK:      NULL
+; CHECK:      DW_TAG_subprogram
+; CHECK:      NULL
+; CHECK:      DW_TAG_variable
+; CHECK-NEXT: DW_AT_specification {{.*}} "a"
 ; CHECK:      DW_TAG_variable
 ; CHECK-NEXT: DW_AT_specification {{.*}} "b"
 ; CHECK-NEXT: DW_AT_const_value
diff --git a/llvm/test/DebugInfo/Generic/inlined-static-var.ll b/llvm/test/DebugInfo/Generic/inlined-static-var.ll
index 1d24646896d80..60c986fc2b648 100644
--- a/llvm/test/DebugInfo/Generic/inlined-static-var.ll
+++ b/llvm/test/DebugInfo/Generic/inlined-static-var.ll
@@ -14,18 +14,17 @@
 ; CHECK: DW_TAG_compile_unit
 ; CHECK:   DW_TAG_subprogram
 ; CHECK:     DW_AT_abstract_origin {{.*}} "_Z11not_removedv"
-; TODO: This variable should be emitted in abstract subprogram DIE.
-; CHECK:     DW_TAG_variable
-; CHECK:       DW_AT_name     ("B")
-; CHECK:     NULL
-; CHECK:   DW_TAG_base_type
 ; CHECK:   DW_TAG_subprogram
 ; CHECK:     DW_AT_name       ("removed")
 ; CHECK:     DW_TAG_variable
 ; CHECK:       DW_AT_name     ("A")
 ; CHECK:     NULL
+; CHECK:   DW_TAG_base_type
 ; CHECK:   DW_TAG_subprogram
 ; CHECK:     DW_AT_name       ("not_removed")
+; CHECK:     DW_TAG_variable
+; CHECK:       DW_AT_name     ("B")
+; CHECK:     NULL
 ; CHECK:   DW_TAG_subprogram
 ; CHECK:     DW_AT_name       ("foo")
 ; CHECK:     DW_TAG_inlined_subroutine
diff --git a/llvm/test/DebugInfo/Generic/namespace.ll b/llvm/test/DebugInfo/Generic/namespace.ll
index da6b156e186c2..1d49ea4b8a000 100644
--- a/llvm/test/DebugInfo/Generic/namespace.ll
+++ b/llvm/test/DebugInfo/Generic/namespace.ll
@@ -13,11 +13,6 @@
 ; CHECK-NOT: DW_AT_decl_file
 ; CHECK-NOT: DW_AT_decl_line
 
-; CHECK: [[I:0x[0-9a-f]*]]:{{ *}}DW_TAG_variable
-; CHECK:   DW_AT_name ("i")
-; CHECK: [[VAR_FWD:0x[0-9a-f]*]]:{{ *}}DW_TAG_variable
-; CHECK:   DW_AT_name ("var_fwd")
-
 ; CHECK: [[FOO:0x[0-9a-f]*]]:{{ *}}DW_TAG_structure_type
 ; CHECK:   DW_AT_name ("foo")
 ; CHECK:   DW_AT_declaration
@@ -37,6 +32,11 @@
 ; CHECK:   DW_AT_name ("func_fwd")
 ; CHECK-NOT: DW_AT_declaration
 
+; CHECK: [[I:0x[0-9a-f]*]]:{{ *}}DW_TAG_variable
+; CHECK:   DW_AT_name ("i")
+; CHECK: [[VAR_FWD:0x[0-9a-f]*]]:{{ *}}DW_TAG_variable
+; CHECK:   DW_AT_name ("var_fwd")
+
 ; CHECK: [[BAZ:0x[0-9a-f]*]]:{{.*}}DW_TAG_typedef
 ; CHECK:   DW_AT_name ("baz")
 
@@ -56,7 +56,6 @@
 ; CHECK: DW_TAG_imported_declaration
 ; CHECK: NULL
 
-; CHECK: DW_TAG_base_type
 ; CHECK: DW_TAG_subprogram
 
 ; CHECK: DW_TAG_subprogram
@@ -122,6 +121,7 @@
 ; CHECK:   NULL
 
 ; CHECK: DW_TAG_subprogram
+; CHECK: DW_TAG_base_type
 ; CHECK: DW_TAG_imported_module
 ; CHECK:   DW_AT_decl_file ([[F2:.*]])
 ; CHECK:   DW_AT_decl_line (18)
diff --git a/llvm/test/DebugInfo/MSP430/global-var.ll b/llvm/test/DebugInfo/MSP430/global-var.ll
index 1941b33846dc1..d09dfd6d46379 100644
--- a/llvm/test/DebugInfo/MSP430/global-var.ll
+++ b/llvm/test/DebugInfo/MSP430/global-var.ll
@@ -4,7 +4,7 @@
 
 ; CHECK:      DW_TAG_variable
 ; CHECK-NEXT:   DW_AT_name      ("global_var")
-; CHECK-NEXT:   DW_AT_type      ({{0x[0-9]+}} "char")
+; CHECK-NEXT:   DW_AT_type      ({{0x[0-9a-f]+}} "char")
 ; CHECK-NEXT:   DW_AT_external  (true)
 ; CHECK-NEXT:   DW_AT_decl_file ("/tmp{{[/\\]}}global-var.c")
 ; CHECK-NEXT:   DW_AT_decl_line (1)
diff --git a/llvm/test/DebugInfo/NVPTX/debug-addr-class.ll b/llvm/test/DebugInfo/NVPTX/debug-addr-class.ll
index 8e3e81bcf1517..19f76b941cadd 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-addr-class.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-addr-class.ll
@@ -100,36 +100,6 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 ; CHECK-NEXT: .b8 0                                   // EOM(1)
 ; CHECK-NEXT: .b8 0                                   // EOM(2)
 ; CHECK-NEXT: .b8 2                                   // Abbreviation Code
-; CHECK-NEXT: .b8 52                                  // DW_TAG_variable
-; CHECK-NEXT: .b8 0                                   // DW_CHILDREN_no
-; CHECK-NEXT: .b8 3                                   // DW_AT_name
-; CHECK-NEXT: .b8 8                                   // DW_FORM_string
-; CHECK-NEXT: .b8 73                                  // DW_AT_type
-; CHECK-NEXT: .b8 19                                  // DW_FORM_ref4
-; CHECK-NEXT: .b8 63                                  // DW_AT_external
-; CHECK-NEXT: .b8 12                                  // DW_FORM_flag
-; CHECK-NEXT: .b8 58                                  // DW_AT_decl_file
-; CHECK-NEXT: .b8 11                                  // DW_FORM_data1
-; CHECK-NEXT: .b8 59                                  // DW_AT_decl_line
-; CHECK-NEXT: .b8 11                                  // DW_FORM_data1
-; CHECK-NEXT: .b8 51                                  // DW_AT_address_class
-; CHECK-NEXT: .b8 11                                  // DW_FORM_data1
-; CHECK-NEXT: .b8 2                                   // DW_AT_location
-; CHECK-NEXT: .b8 10                                  // DW_FORM_block1
-; CHECK-NEXT: .b8 0                                   // EOM(1)
-; CHECK-NEXT: .b8 0                                   // EOM(2)
-; CHECK-NEXT: .b8 3                                   // Abbreviation Code
-; CHECK-NEXT: .b8 36                                  // DW_TAG_base_type
-; CHECK-NEXT: .b8 0                                   // DW_CHILDREN_no
-; CHECK-NEXT: .b8 3                                   // DW_AT_name
-; CHECK-NEXT: .b8 8                                   // DW_FORM_string
-; CHECK-NEXT: .b8 62                                  // DW_AT_encoding
-; CHECK-NEXT: .b8 11                                  // DW_FORM_data1
-; CHECK-NEXT: .b8 11                                  // DW_AT_byte_size
-; CHECK-NEXT: .b8 11                                  // DW_FORM_data1
-; CHECK-NEXT: .b8 0                                   // EOM(1)
-; CHECK-NEXT: .b8 0                                   // EOM(2)
-; CHECK-NEXT: .b8 4                                   // Abbreviation Code
 ; CHECK-NEXT: .b8 46                                  // DW_TAG_subprogram
 ; CHECK-NEXT: .b8 1                                   // DW_CHILDREN_yes
 ; CHECK-NEXT: .b8 17                                  // DW_AT_low_pc
@@ -151,7 +121,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 ; CHECK-NEXT: .b8 12                                  // DW_FORM_flag
 ; CHECK-NEXT: .b8 0                                   // EOM(1)
 ; CHECK-NEXT: .b8 0                                   // EOM(2)
-; CHECK-NEXT: .b8 5                                   // Abbreviation Code
+; CHECK-NEXT: .b8 3                                   // Abbreviation Code
 ; CHECK-NEXT: .b8 5                                   // DW_TAG_formal_parameter
 ; CHECK-NEXT: .b8 0                                   // DW_CHILDREN_no
 ; CHECK-NEXT: .b8 51                                  // DW_AT_address_class
@@ -168,6 +138,36 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 ; CHECK-NEXT: .b8 19                                  // DW_FORM_ref4
 ; CHECK-NEXT: .b8 0                                   // EOM(1)
 ; CHECK-NEXT: .b8 0                                   // EOM(2)
+; CHECK-NEXT: .b8 4                                   // Abbreviation Code
+; CHECK-NEXT: .b8 52                                  // DW_TAG_variable
+; CHECK-NEXT: .b8 0                                   // DW_CHILDREN_no
+; CHECK-NEXT: .b8 3                                   // DW_AT_name
+; CHECK-NEXT: .b8 8                                   // DW_FORM_string
+; CHECK-NEXT: .b8 73                                  // DW_AT_type
+; CHECK-NEXT: .b8 19                                  // DW_FORM_ref4
+; CHECK-NEXT: .b8 63                                  // DW_AT_external
+; CHECK-NEXT: .b8 12                                  // DW_FORM_flag
+; CHECK-NEXT: .b8 58                                  // DW_AT_decl_file
+; CHECK-NEXT: .b8 11                                  // DW_FORM_data1
+; CHECK-NEXT: .b8 59                                  // DW_AT_decl_line
+; CHECK-NEXT: .b8 11                                  // DW_FORM_data1
+; CHECK-NEXT: .b8 51                                  // DW_AT_address_class
+; CHECK-NEXT: .b8 11                                  // DW_FORM_data1
+; CHECK-NEXT: .b8 2                                   // DW_AT_location
+; CHECK-NEXT: .b8 10                                  // DW_FORM_block1
+; CHECK-NEXT: .b8 0                                   // EOM(1)
+; CHECK-NEXT: .b8 0                                   // EOM(2)
+; CHECK-NEXT: .b8 5                                   // Abbreviation Code
+; CHECK-NEXT: .b8 36                                  // DW_TAG_base_type
+; CHECK-NEXT: .b8 0                                   // DW_CHILDREN_no
+; CHECK-NEXT: .b8 3                                   // DW_AT_name
+; CHECK-NEXT: .b8 8                                   // DW_FORM_string
+; CHECK-NEXT: .b8 62                                  // DW_AT_encoding
+; CHECK-NEXT: .b8 11                                  // DW_FORM_data1
+; CHECK-NEXT: .b8 11                                  // DW_AT_byte_size
+; CHECK-NEXT: .b8 11                                  // DW_FORM_data1
+; CHECK-NEXT: .b8 0                                   // EOM(1)
+; CHECK-NEXT: .b8 0                                   // EOM(2)
 ; CHECK-NEXT: .b8 6                                   // Abbreviation Code
 ; CHECK-NEXT: .b8 15                                  // DW_TAG_pointer_type
 ; CHECK-NEXT: .b8 0                                   // DW_CHILDREN_no
@@ -255,46 +255,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 ; CHECK-NEXT: .b8 109
 ; CHECK-NEXT: .b8 112
 ; CHECK-NEXT: .b8 0
-; CHECK-NEXT: .b8 2                                   // Abbrev [2] 0x55:0x1a DW_TAG_variable
-; CHECK-NEXT: .b8 71                                  // DW_AT_name
-; CHECK-NEXT: .b8 76
-; CHECK-NEXT: .b8 79
-; CHECK-NEXT: .b8 66
-; CHECK-NEXT: .b8 65
-; CHECK-NEXT: .b8 76
-; CHECK-NEXT: .b8 0
-; CHECK-NEXT: .b32 111                                // DW_AT_type
-; CHECK-NEXT: .b8 1                                   // DW_AT_external
-; CHECK-NEXT: .b8 1                                   // DW_AT_decl_file
-; CHECK-NEXT: .b8 3                                   // DW_AT_decl_line
-; CHECK-NEXT: .b8 5                                   // DW_AT_address_class
-; CHECK-NEXT: .b8 9                                   // DW_AT_location
-; CHECK-NEXT: .b8 3
-; CHECK-NEXT: .b64 GLOBAL
-; CHECK-NEXT: .b8 3                                   // Abbrev [3] 0x6f:0x7 DW_TAG_base_type
-; CHECK-NEXT: .b8 105                                 // DW_AT_name
-; CHECK-NEXT: .b8 110
-; CHECK-NEXT: .b8 116
-; CHECK-NEXT: .b8 0
-; CHECK-NEXT: .b8 5                                   // DW_AT_encoding
-; CHECK-NEXT: .b8 4                                   // DW_AT_byte_size
-; CHECK-NEXT: .b8 2                                   // Abbrev [2] 0x76:0x1a DW_TAG_variable
-; CHECK-NEXT: .b8 83                                  // DW_AT_name
-; CHECK-NEXT: .b8 72
-; CHECK-NEXT: .b8 65
-; CHECK-NEXT: .b8 82
-; CHECK-NEXT: .b8 69
-; CHECK-NEXT: .b8 68
-; CHECK-NEXT: .b8 0
-; CHECK-NEXT: .b32 111                                // DW_AT_type
-; CHECK-NEXT: .b8 1                                   // DW_AT_external
-; CHECK-NEXT: .b8 1                                   // DW_AT_decl_file
-; CHECK-NEXT: .b8 4                                   // DW_AT_decl_line
-; CHECK-NEXT: .b8 8                                   // DW_AT_address_class
-; CHECK-NEXT: .b8 9                                   // DW_AT_location
-; CHECK-NEXT: .b8 3
-; CHECK-NEXT: .b64 SHARED
-; CHECK-NEXT: .b8 4                                   // Abbrev [4] 0x90:0x63 DW_TAG_subprogram
+; CHECK-NEXT: .b8 2                                   // Abbrev [2] 0x55:0x63 DW_TAG_subprogram
 ; CHECK-NEXT: .b64 $L__func_begin0                    // DW_AT_low_pc
 ; CHECK-NEXT: .b64 $L__func_end0                      // DW_AT_high_pc
 ; CHECK-NEXT: .b8 1                                   // DW_AT_frame_base
@@ -312,7 +273,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 ; CHECK-NEXT: .b8 1                                   // DW_AT_decl_file
 ; CHECK-NEXT: .b8 6                                   // DW_AT_decl_line
 ; CHECK-NEXT: .b8 1                                   // DW_AT_external
-; CHECK-NEXT: .b8 5                                   // Abbrev [5] 0xb0:0x10 DW_TAG_formal_parameter
+; CHECK-NEXT: .b8 3                                   // Abbrev [3] 0x75:0x10 DW_TAG_formal_parameter
 ; CHECK-NEXT: .b8 2                                   // DW_AT_address_class
 ; CHECK-NEXT: .b8 5                                   // DW_AT_location
 ; CHECK-NEXT: .b8 144
@@ -325,21 +286,21 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 ; CHECK-NEXT: .b8 1                                   // DW_AT_decl_file
 ; CHECK-NEXT: .b8 6                                   // DW_AT_decl_line
 ; CHECK-NEXT: .b32 248                                // DW_AT_type
-; CHECK-NEXT: .b8 5                                   // Abbrev [5] 0xc0:0x11 DW_TAG_formal_parameter
+; CHECK-NEXT: .b8 3                                   // Abbrev [3] 0x85:0x11 DW_TAG_formal_parameter
 ; CHECK-NEXT: .b8 2                                   // DW_AT_address_class
 ; CHECK-NEXT: .b8 6                                   // DW_AT_location
 ; CHECK-NEXT: .b8 144
 ; CHECK-NEXT: .b8 177
 ; CHECK-NEXT: .b8 200
 ; CHECK-NEXT: .b8 201
-; CHECK-NEXT: .b8 171
+; CHECK-NEXT: .b8 1
 ; CHECK-NEXT: .b8 2
 ; CHECK-NEXT: .b8 120                                 // DW_AT_name
 ; CHECK-NEXT: .b8 0
 ; CHECK-NEXT: .b8 1                                   // DW_AT_decl_file
 ; CHECK-NEXT: .b8 6                                   // DW_AT_decl_line
 ; CHECK-NEXT: .b32 243                                // DW_AT_type
-; CHECK-NEXT: .b8 5                                   // Abbrev [5] 0xd1:0x11 DW_TAG_formal_parameter
+; CHECK-NEXT: .b8 3                                   // Abbrev [3] 0x96:0x11 DW_TAG_formal_parameter
 ; CHECK-NEXT: .b8 2                                   // DW_AT_address_class
 ; CHECK-NEXT: .b8 6                                   // DW_AT_location
 ; CHECK-NEXT: .b8 144
@@ -353,7 +314,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 ; CHECK-NEXT: .b8 1                                   // DW_AT_decl_file
 ; CHECK-NEXT: .b8 6                                   // DW_AT_decl_line
 ; CHECK-NEXT: .b32 243                                // DW_AT_type
-; CHECK-NEXT: .b8 5                                   // Abbrev [5] 0xe2:0x10 DW_TAG_formal_parameter
+; CHECK-NEXT: .b8 3                                   // Abbrev [3] 0xa7:0x10 DW_TAG_formal_parameter
 ; CHECK-NEXT: .b8 2                                   // DW_AT_address_class
 ; CHECK-NEXT: .b8 5                                   // DW_AT_location
 ; CHECK-NEXT: .b8 144
@@ -365,11 +326,50 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 ; CHECK-NEXT: .b8 0
 ; CHECK-NEXT: .b8 1                                   // DW_AT_decl_file
 ; CHECK-NEXT: .b8 6                                   // DW_AT_decl_line
-; CHECK-NEXT: .b32 111                                // DW_AT_type
+; CHECK-NEXT: .b32 210                                // DW_AT_type
 ; CHECK-NEXT: .b8 0                                   // End Of Children Mark
+; CHECK-NEXT: .b8 4                                   // Abbrev [4] 0xb8:0x1a DW_TAG_variable
+; CHECK-NEXT: .b8 71                                  // DW_AT_name
+; CHECK-NEXT: .b8 76
+; CHECK-NEXT: .b8 79
+; CHECK-NEXT: .b8 66
+; CHECK-NEXT: .b8 65
+; CHECK-NEXT: .b8 76
+; CHECK-NEXT: .b8 0
+; CHECK-NEXT: .b32 210                                // DW_AT_type
+; CHECK-NEXT: .b8 1                                   // DW_AT_external
+; CHECK-NEXT: .b8 1                                   // DW_AT_decl_file
+; CHECK-NEXT: .b8 3                                   // DW_AT_decl_line
+; CHECK-NEXT: .b8 5                                   // DW_AT_address_class
+; CHECK-NEXT: .b8 9                                   // DW_AT_location
+; CHECK-NEXT: .b8 3
+; CHECK-NEXT: .b64 GLOBAL
+; CHECK-NEXT: .b8 5                                   // Abbrev [5] 0xd2:0x7 DW_TAG_base_type
+; CHECK-NEXT: .b8 105                                 // DW_AT_name
+; CHECK-NEXT: .b8 110
+; CHECK-NEXT: .b8 116
+; CHECK-NEXT: .b8 0
+; CHECK-NEXT: .b8 5                                   // DW_AT_encoding
+; CHECK-NEXT: .b8 4                                   // DW_AT_byte_size
+; CHECK-NEXT: .b8 4                                   // Abbrev [4] 0xd9:0x1a DW_TAG_variable
+; CHECK-NEXT: .b8 83                                  // DW_AT_name
+; CHECK-NEXT: .b8 72
+; CHECK-NEXT: .b8 65
+; CHECK-NEXT: .b8 82
+; CHECK-NEXT: .b8 69
+; CHECK-NEXT: .b8 68
+; CHECK-NEXT: .b8 0
+; CHECK-NEXT: .b32 210                                // DW_AT_type
+; CHECK-NEXT: .b8 1                                   // DW_AT_external
+; CHECK-NEXT: .b8 1                                   // DW_AT_decl_file
+; CHECK-NEXT: .b8 4                                   // DW_AT_decl_line
+; CHECK-NEXT: .b8 8                                   // DW_AT_address_class
+; CHECK-NEXT: .b8 9                                   // DW_AT_location
+; CHECK-NEXT: .b8 3
+; CHECK-NEXT: .b64 SHARED
 ; CHECK-NEXT: .b8 6                                   // Abbrev [6] 0xf3:0x5 DW_TAG_pointer_type
 ; CHECK-NEXT: .b32 248                                // DW_AT_type
-; CHECK-NEXT: .b8 3                                   // Abbrev [3] 0xf8:0x9 DW_TAG_base_type
+; CHECK-NEXT: .b8 5                                   // Abbrev [5] 0xf8:0x9 DW_TAG_base_type
 ; CHECK-NEXT: .b8 102                                 // DW_AT_name
 ; CHECK-NEXT: .b8 108
 ; CHECK-NEXT: .b8 111
diff --git a/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll b/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll
index 0651f2e3f3d77..66ecb75d67bd3 100644
--- a/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll
+++ b/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll
@@ -15,17 +15,17 @@
 ; 3: DwarfUnit::addUInt()
 ; 4: addUInt(Block, (dwarf::Attribute)0, Form, Integer);
 
+; CHECK: DW_AT_noreturn
 ; CHECK: DW_AT_name      ("var")
 ; CHECK-NOT: DW_TAG_
 ; CHECK: DW_AT_alignment
 ; CHECK: DW_AT_location  (DW_OP_addr 0x0)
-; CHECK: DW_AT_noreturn
 ;
+; STRICT-NOT: DW_AT_noreturn
 ; STRICT: DW_AT_name      ("var")
 ; STRICT-NOT: DW_AT_alignment
 ; STRICT-NOT: DW_TAG_
 ; STRICT: DW_AT_location  (DW_OP_addr 0x0)
-; STRICT-NOT: DW_AT_noreturn
 
 @_ZL3var = internal global i32 0, align 16, !dbg !0
 
diff --git a/llvm/test/DebugInfo/WebAssembly/tls_pic_globals.ll b/llvm/test/DebugInfo/WebAssembly/tls_pic_globals.ll
index cd837107ecc0b..70a68f9489764 100644
--- a/llvm/test/DebugInfo/WebAssembly/tls_pic_globals.ll
+++ b/llvm/test/DebugInfo/WebAssembly/tls_pic_globals.ll
@@ -128,42 +128,42 @@ attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memo
 ; CHECK:      DW_TAG_variable
 ; CHECK-NEXT:   DW_AT_name  ("external_var0")
 ; CHECK:        DW_AT_external  (true)
-; NOPIC:        DW_AT_location  (DW_OP_addrx 0x0)
-; PIC:          DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x0, DW_OP_plus)
-
-; CHECK:      DW_TAG_variable
-; CHECK-NEXT:   DW_AT_name  ("external_var1")
-; CHECK:        DW_AT_external  (true)
 ; NOPIC:        DW_AT_location  (DW_OP_addrx 0x1)
 ; PIC:          DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x1, DW_OP_plus)
 
 ; CHECK:      DW_TAG_variable
-; CHECK-NEXT:   DW_AT_name  ("internal_var0")
+; CHECK-NEXT:   DW_AT_name  ("external_var1")
+; CHECK:        DW_AT_external  (true)
 ; NOPIC:        DW_AT_location  (DW_OP_addrx 0x2)
 ; PIC:          DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x2, DW_OP_plus)
 
 ; CHECK:      DW_TAG_variable
-; CHECK-NEXT:   DW_AT_name  ("internal_var1")
+; CHECK-NEXT:   DW_AT_name  ("internal_var0")
 ; NOPIC:        DW_AT_location  (DW_OP_addrx 0x3)
 ; PIC:          DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x3, DW_OP_plus)
 
+; CHECK:      DW_TAG_variable
+; CHECK-NEXT:   DW_AT_name  ("internal_var1")
+; NOPIC:        DW_AT_location  (DW_OP_addrx 0x4)
+; PIC:          DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x4, DW_OP_plus)
+
 ; CHECK:      DW_TAG_variable
 ; CHECK-NEXT:   DW_AT_name  ("external_tls_var0")
 ; CHECK:        DW_AT_external  (true)
-; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x4, DW_OP_plus)
+; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x5, DW_OP_plus)
 
 ; CHECK:      DW_TAG_variable
 ; CHECK-NEXT:   DW_AT_name  ("external_tls_var1")
 ; CHECK:        DW_AT_external  (true)
-; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x5, DW_OP_plus)
+; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x6, DW_OP_plus)
 
 ; CHECK:      DW_TAG_variable
 ; CHECK-NEXT:   DW_AT_name  ("internal_tls_var0")
-; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x6, DW_OP_plus)
+; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x7, DW_OP_plus)
 
 ; CHECK:      DW_TAG_variable
 ; CHECK-NEXT:   DW_AT_name  ("internal_tls_var1")
-; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x7, DW_OP_plus)
+; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x8, DW_OP_plus)
 
 ; In non-split DWARF, .debug_info section contains relocations referring to
 ; __stack_pointer, __tls_base, and __memory_base (if used)
diff --git a/llvm/test/DebugInfo/X86/2011-09-26-GlobalVarContext.ll b/llvm/test/DebugInfo/X86/2011-09-26-GlobalVarContext.ll
index 21bf4f79a5c75..da8bd4c30ac29 100644
--- a/llvm/test/DebugInfo/X86/2011-09-26-GlobalVarContext.ll
+++ b/llvm/test/DebugInfo/X86/2011-09-26-GlobalVarContext.ll
@@ -46,17 +46,17 @@ attributes #1 = { nounwind readnone }
 
 ; CHECK: DW_TAG_variable
 ; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_name [DW_FORM_strp]       ( .debug_str[0x{{[0-9a-f]*}}] = "GLB")
+; CHECK: DW_AT_name [DW_FORM_strp]   ( .debug_str[0x{{[0-9a-f]*}}] = "LOC")
 ; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_decl_file [DW_FORM_data1] ("/work/llvm/vanilla/test/DebugInfo{{[/\\]}}test.c")
+; CHECK: DW_AT_decl_file [DW_FORM_data1]     ("/work/llvm/vanilla/test/DebugInfo{{[/\\]}}test.c")
 ; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_decl_line [DW_FORM_data1] (1)
+; CHECK: DW_AT_decl_line [DW_FORM_data1]     (4)
 
 ; CHECK: DW_TAG_variable
 ; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_name [DW_FORM_strp]   ( .debug_str[0x{{[0-9a-f]*}}] = "LOC")
+; CHECK: DW_AT_name [DW_FORM_strp]       ( .debug_str[0x{{[0-9a-f]*}}] = "GLB")
 ; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_decl_file [DW_FORM_data1]     ("/work/llvm/vanilla/test/DebugInfo{{[/\\]}}test.c")
+; CHECK: DW_AT_decl_file [DW_FORM_data1] ("/work/llvm/vanilla/test/DebugInfo{{[/\\]}}test.c")
 ; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_decl_line [DW_FORM_data1]     (4)
+; CHECK: DW_AT_decl_line [DW_FORM_data1] (1)
 
diff --git a/llvm/test/DebugInfo/X86/DW_AT_calling-convention.ll b/llvm/test/DebugInfo/X86/DW_AT_calling-convention.ll
index ebbe3573022a6..43cf1266c0d39 100644
--- a/llvm/test/DebugInfo/X86/DW_AT_calling-convention.ll
+++ b/llvm/test/DebugInfo/X86/DW_AT_calling-convention.ll
@@ -21,10 +21,6 @@
 
 ; CHECK: .debug_info contents:
 
-; CHECK:  DW_TAG_subroutine_type [[subroutine_abbrev]] *
-; CHECK-NEXT:         DW_AT_type [DW_FORM_ref4]       {{.*}}
-; CHECK-NEXT:         DW_AT_calling_convention [DW_FORM_data1]        (DW_CC_BORLAND_msfastcall)
-
 ; CHECK: DW_TAG_subprogram [{{.*}}] *
 ; CHECK:                 DW_AT_low_pc
 ; CHECK:                 DW_AT_high_pc
@@ -37,6 +33,10 @@
 ; CHECK:                 DW_AT_type
 ; CHECK:                 DW_AT_external
 
+; CHECK:  DW_TAG_subroutine_type [[subroutine_abbrev]] *
+; CHECK-NEXT:         DW_AT_type [DW_FORM_ref4]       {{.*}}
+; CHECK-NEXT:         DW_AT_calling_convention [DW_FORM_data1]        (DW_CC_BORLAND_msfastcall)
+
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
diff --git a/llvm/test/DebugInfo/X86/align_cpp11.ll b/llvm/test/DebugInfo/X86/align_cpp11.ll
index 29682d05a2817..9310f41bfbb77 100644
--- a/llvm/test/DebugInfo/X86/align_cpp11.ll
+++ b/llvm/test/DebugInfo/X86/align_cpp11.ll
@@ -33,20 +33,6 @@
 ;     auto Lambda = [i](){};
 ; }
 
-; CHECK:   DW_TAG_class_type
-; CHECK:     DW_AT_name{{.*}}"C0"
-; CHECK:     DW_AT_alignment{{.*}}64
-
-; CHECK:   DW_TAG_variable
-; CHECK:     DW_AT_name{{.*}}"s"
-; CHECK:     DW_AT_alignment{{.*}}2048
-
-; CHECK:   DW_TAG_structure_type
-; CHECK:     DW_TAG_member
-; CHECK:     DW_TAG_member
-; CHECK:       DW_AT_name{{.*}}"xx"
-; CHECK:       DW_AT_alignment{{.*}}128
-
 ; CHECK:   DW_TAG_enumeration_type
 ; CHECK:     DW_AT_alignment{{.*}}16
 ; CHECK:       DW_TAG_enumerator
@@ -68,6 +54,20 @@
 ; CHECK:       DW_TAG_subprogram
 ; CHECK:         DW_TAG_formal_parameter
 
+; CHECK:   DW_TAG_class_type
+; CHECK:     DW_AT_name{{.*}}"C0"
+; CHECK:     DW_AT_alignment{{.*}}64
+
+; CHECK:   DW_TAG_variable
+; CHECK:     DW_AT_name{{.*}}"s"
+; CHECK:     DW_AT_alignment{{.*}}2048
+
+; CHECK:   DW_TAG_structure_type
+; CHECK:     DW_TAG_member
+; CHECK:     DW_TAG_member
+; CHECK:       DW_AT_name{{.*}}"xx"
+; CHECK:       DW_AT_alignment{{.*}}128
+
 ; CHECK:   DW_TAG_class_type
 ; CHECK:     DW_AT_name{{.*}}"C1"
 ; CHECK:     DW_TAG_member
diff --git a/llvm/test/DebugInfo/X86/align_objc.ll b/llvm/test/DebugInfo/X86/align_objc.ll
index 733735fb974ef..5d0c1e0430b6a 100644
--- a/llvm/test/DebugInfo/X86/align_objc.ll
+++ b/llvm/test/DebugInfo/X86/align_objc.ll
@@ -16,7 +16,14 @@
 ; }
 
 ; CHECK: DW_TAG_compile_unit
+
+; CHECK:   DW_TAG_subprogram
+; CHECK:     DW_TAG_variable
+; CHECK:     DW_TAG_variable
+; CHECK:       DW_AT_name{{.*}}"i"
+; CHECK:       DW_AT_alignment{{.*}}32
 ; CHECK:   DW_TAG_variable
+
 ; CHECK:   DW_TAG_typedef
 ; CHECK:     DW_AT_name{{.*}}"S0"
 
@@ -25,12 +32,6 @@
 ; CHECK:     DW_TAG_member
 ; CHECK:   DW_TAG_base_type
 
-; CHECK:   DW_TAG_subprogram
-; CHECK:     DW_TAG_variable
-; CHECK:     DW_TAG_variable
-; CHECK:       DW_AT_name{{.*}}"i"
-; CHECK:       DW_AT_alignment{{.*}}32
-
 ; CHECK:   DW_TAG_typedef
 ; CHECK:     DW_AT_name{{.*}}"S1"
 ; CHECK:   DW_TAG_structure_type
diff --git a/llvm/test/DebugInfo/X86/arange-and-stub.ll b/llvm/test/DebugInfo/X86/arange-and-stub.ll
index 7819f59094347..aea4c910fd34f 100644
--- a/llvm/test/DebugInfo/X86/arange-and-stub.ll
+++ b/llvm/test/DebugInfo/X86/arange-and-stub.ll
@@ -5,7 +5,7 @@
 ; CHECK: .L_ZTId.DW.stub:
 
 ; CHECK:  .data
-; CHECK-NEXT: .Lsec_end0:
+; CHECK-NEXT: .Lsec_end1:
 
 source_filename = "test/DebugInfo/X86/arange-and-stub.ll"
 target triple = "x86_64-linux-gnu"
diff --git a/llvm/test/DebugInfo/X86/containing-type-extension-rust.ll b/llvm/test/DebugInfo/X86/containing-type-extension-rust.ll
index d4a2f903f5a81..935dbf3fc008c 100644
--- a/llvm/test/DebugInfo/X86/containing-type-extension-rust.ll
+++ b/llvm/test/DebugInfo/X86/containing-type-extension-rust.ll
@@ -2,6 +2,7 @@
 ; RUN: llvm-dwarfdump -v -debug-info %t | FileCheck %s
 
 ; Check that any type can have a vtable holder.
+; CHECK: DW_TAG_structure_type
 ; CHECK: [[SP:.*]]: DW_TAG_structure_type
 ; CHECK-NOT: TAG
 ; CHECK: DW_AT_containing_type [DW_FORM_ref4] ({{.*}} "f64")
diff --git a/llvm/test/DebugInfo/X86/debug-info-access.ll b/llvm/test/DebugInfo/X86/debug-info-access.ll
index 31819b4af4975..cad5f2e12c135 100644
--- a/llvm/test/DebugInfo/X86/debug-info-access.ll
+++ b/llvm/test/DebugInfo/X86/debug-info-access.ll
@@ -74,6 +74,10 @@
 ;   F f;
 ;   H h;
 
+; CHECK: DW_TAG_subprogram
+; CHECK:     DW_AT_name {{.*}}"free")
+; CHECK-NOT: DW_AT_accessibility
+
 ; CHECK: DW_TAG_member
 ; CHECK:     DW_AT_name {{.*}}"union_priv")
 ; CHECK-NOT: DW_TAG
@@ -142,10 +146,6 @@
 ; CHECK:     DW_AT_name ("I")
 ; CHECK:     DW_AT_accessibility (DW_ACCESS_private)
 
-; CHECK: DW_TAG_subprogram
-; CHECK:     DW_AT_name {{.*}}"free")
-; CHECK-NOT: DW_AT_accessibility
-
 %union.U = type { i32 }
 %struct.A = type { i8 }
 %class.B = type { i32 }
diff --git a/llvm/test/DebugInfo/X86/debug-info-static-member.ll b/llvm/test/DebugInfo/X86/debug-info-static-member.ll
index 0af67eb017f59..0f10eea73303d 100644
--- a/llvm/test/DebugInfo/X86/debug-info-static-member.ll
+++ b/llvm/test/DebugInfo/X86/debug-info-static-member.ll
@@ -105,6 +105,8 @@ attributes #1 = { nounwind readnone }
 ; (for variables) or DW_AT_const_value (for constants).
 ;
 ; PRESENT:      .debug_info contents:
+; PRESENT:      DW_TAG_subprogram
+; PRESENT:      DW_TAG_variable
 ; PRESENT:      DW_TAG_variable
 ; PRESENT-NEXT: DW_AT_specification {{.*}} "a"
 ; PRESENT-NEXT: DW_AT_location
@@ -155,6 +157,8 @@ attributes #1 = { nounwind readnone }
 
 ; For Darwin gdb:
 ; DARWINP:      .debug_info contents:
+; DARWINP:      DW_TAG_subprogram
+; DARWINP:      DW_TAG_variable
 ; DARWINP:      DW_TAG_variable
 ; DARWINP-NEXT: DW_AT_specification {{.*}} "a"
 ; DARWINP-NEXT: DW_AT_location
diff --git a/llvm/test/DebugInfo/X86/debug-names-dwarf64.ll b/llvm/test/DebugInfo/X86/debug-names-dwarf64.ll
index 9a5fd07335873..32b0dcac77bce 100644
--- a/llvm/test/DebugInfo/X86/debug-names-dwarf64.ll
+++ b/llvm/test/DebugInfo/X86/debug-names-dwarf64.ll
@@ -6,14 +6,14 @@
 
 ; CHECK:     .debug_info contents:
 ; CHECK-NEXT: 0x00000000:     Compile Unit: {{.+}}, format = DWARF64,
-; CHECK:      [[VARDIE:.+]]:  DW_TAG_variable
-; CHECK-NEXT:                   DW_AT_name ("foo")
-; CHECK:      [[TYPEDIE:.+]]: DW_TAG_base_type
-; CHECK-NEXT:                   DW_AT_name ("int")
 ; CHECK:      [[SPDIE:.+]]:   DW_TAG_subprogram
 ; CHECK:                        DW_AT_name ("func")
 ; CHECK:      [[LABELDIE:.+]]: DW_TAG_label
 ; CHECK-NEXT:                   DW_AT_name ("MyLabel")
+; CHECK:      [[VARDIE:.+]]:  DW_TAG_variable
+; CHECK-NEXT:                   DW_AT_name ("foo")
+; CHECK:      [[TYPEDIE:.+]]: DW_TAG_base_type
+; CHECK-NEXT:                   DW_AT_name ("int")
 
 ; CHECK:      .debug_names contents:
 ; CHECK-NEXT: Name Index @ 0x0 {
diff --git a/llvm/test/DebugInfo/X86/dwarf-aranges.ll b/llvm/test/DebugInfo/X86/dwarf-aranges.ll
index 0eeeccaf224dd..ad6ba7971dc8e 100644
--- a/llvm/test/DebugInfo/X86/dwarf-aranges.ll
+++ b/llvm/test/DebugInfo/X86/dwarf-aranges.ll
@@ -8,22 +8,22 @@
 ; -- alignment --
 ; CHECK-NEXT: .zero 4,255
 
+; <text section> - it should have made one span covering all functions in this CU.
+; CHECK-NEXT: .quad .Lfunc_begin0
+; CHECK-NEXT: .quad .Lsec_end0-.Lfunc_begin0
+
 ; <data section> - it should have made one span covering all vars in this CU.
 ; CHECK-NEXT: .quad some_data
-; CHECK-NEXT: .quad .Lsec_end0-some_data
+; CHECK-NEXT: .quad .Lsec_end1-some_data
 
 ; <other sections> - it should have made one span covering all vars in this CU.
 ; CHECK-NEXT: .quad some_other
-; CHECK-NEXT: .quad .Lsec_end1-some_other
+; CHECK-NEXT: .quad .Lsec_end2-some_other
 
 ; <common symbols> - it should have made one span for each symbol.
 ; CHECK-NEXT: .quad some_bss
 ; CHECK-NEXT: .quad 4
 
-; <text section> - it should have made one span covering all functions in this CU.
-; CHECK-NEXT: .quad .Lfunc_begin0
-; CHECK-NEXT: .quad .Lsec_end2-.Lfunc_begin0
-
 ; -- finish --
 ; CHECK-NEXT: # ARange terminator
 
diff --git a/llvm/test/DebugInfo/X86/dwarf-linkage-names.ll b/llvm/test/DebugInfo/X86/dwarf-linkage-names.ll
index 857c1da123cfb..3afe1c66dbe65 100644
--- a/llvm/test/DebugInfo/X86/dwarf-linkage-names.ll
+++ b/llvm/test/DebugInfo/X86/dwarf-linkage-names.ll
@@ -17,10 +17,10 @@
 
 ; This assumes the variable will appear before the function.
 ; LINKAGE1: .section .debug_info
-; LINKAGE1: DW_TAG_variable
+; LINKAGE1: DW_TAG_subprogram
 ; LINKAGE1-NOT: DW_TAG
 ; LINKAGE1: {{DW_AT_(MIPS_)?linkage_name}}
-; LINKAGE1: DW_TAG_subprogram
+; LINKAGE1: DW_TAG_variable
 ; LINKAGE1-NOT: DW_TAG
 ; LINKAGE1: {{DW_AT_(MIPS_)?linkage_name}}
 ; LINKAGE1: .section
diff --git a/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll b/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
index 4f5d61780f0ac..573fbf214df32 100644
--- a/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
+++ b/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
@@ -3,11 +3,6 @@
 
 ; RUN: llc %s -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
 
-; CHECK: [[MYMOD:0x[0-9a-f]+]]: DW_TAG_module
-; CHECK:   DW_AT_name      ("mymod")
-; CHECK:   [[VAR1:0x[0-9a-f]+]]: DW_TAG_variable
-; CHECK:     DW_AT_name    ("var1")
-
 ; CHECK: DW_TAG_subprogram
 ; CHECK:   DW_AT_name      ("main")
 ; CHECK:   DW_TAG_subprogram
@@ -18,6 +13,11 @@
 ; CHECK:         DW_AT_import ([[VAR1]] "var1")
 ; CHECK:         DW_AT_name        ("var4")
 
+; CHECK: [[MYMOD]]: DW_TAG_module
+; CHECK:   DW_AT_name      ("mymod")
+; CHECK:   [[VAR1]]: DW_TAG_variable
+; CHECK:     DW_AT_name    ("var1")
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;This test case is generated from
 ;;module mymod
diff --git a/llvm/test/DebugInfo/X86/generate-odr-hash.ll b/llvm/test/DebugInfo/X86/generate-odr-hash.ll
index ad083abde9b89..9c887c45c6d49 100644
--- a/llvm/test/DebugInfo/X86/generate-odr-hash.ll
+++ b/llvm/test/DebugInfo/X86/generate-odr-hash.ll
@@ -61,6 +61,14 @@
 ; CHECK-NEXT: DW_AT_declaration
 ; CHECK-NEXT: DW_AT_signature {{.*}} (0xb04af47397402e77)
 
+; CHECK: [[WOMBAT:^0x........]]: DW_TAG_structure_type
+; CHECK-NEXT: DW_AT_declaration
+; CHECK-NEXT: DW_AT_signature {{.*}} (0xfd756cee88f8a118)
+
+; CHECK: DW_TAG_structure_type
+
+; CHECK: DW_TAG_structure_type
+
 ; Ensure the CU-local type 'walrus' is not placed in a type unit.
 ; CHECK: [[WALRUS:^0x........]]: DW_TAG_structure_type
 ; CHECK-NEXT: DW_AT_name{{.*}}"walrus"
@@ -68,10 +76,6 @@
 ; CHECK-NEXT: DW_AT_decl_file
 ; CHECK-NEXT: DW_AT_decl_line
 
-; CHECK: [[WOMBAT:^0x........]]: DW_TAG_structure_type
-; CHECK-NEXT: DW_AT_declaration
-; CHECK-NEXT: DW_AT_signature {{.*}} (0xfd756cee88f8a118)
-
 ; SINGLE-LABEL: .debug_types contents:
 ; FISSION: .debug_types.dwo contents:
 
diff --git a/llvm/test/DebugInfo/X86/gnu-public-names.ll b/llvm/test/DebugInfo/X86/gnu-public-names.ll
index 6b1279b87f323..5d81468f55379 100644
--- a/llvm/test/DebugInfo/X86/gnu-public-names.ll
+++ b/llvm/test/DebugInfo/X86/gnu-public-names.ll
@@ -66,13 +66,16 @@
 
 ; ASM: .section        .debug_gnu_pubnames
 ; ASM: .byte   32                      # Attributes: VARIABLE, EXTERNAL
+; ASM-NEXT: .asciz  "ns::global_namespace_variable"       # External Name
+; ASM: .byte   32                      # Attributes: VARIABLE, EXTERNAL
+; ASM-NEXT: .asciz  "ns::d"       # External Name
+; ASM: .byte   32                      # Attributes: VARIABLE, EXTERNAL
 ; ASM-NEXT: .asciz  "C::static_member_variable"           # External Name
 ; ASM: .byte   32                      # Attributes: VARIABLE, EXTERNAL
 ; ASM-NEXT: .asciz  "global_variable"       # External Name
-; ASM: .byte   32                      # Attributes: VARIABLE, EXTERNAL
-; ASM-NEXT: .asciz  "ns::global_namespace_variable"       # External Name
 
 ; ASM: .section        .debug_gnu_pubtypes
+; ASM: .long 109                       # DIE offset
 ; ASM: .byte   16                      # Attributes: TYPE, EXTERNAL
 ; ASM-NEXT: .asciz  "C"                     # External Name
 
@@ -81,8 +84,28 @@
 ; CHECK:   DW_AT_GNU_pubnames (true)
 ; CHECK-NOT: DW_AT_GNU_pubtypes [
 
-; CHECK:   [[STATIC_MEM_VAR:0x[0-9a-f]+]]: DW_TAG_variable
-; CHECK:     DW_AT_specification {{.*}} "static_member_variable"
+; CHECK:   DW_TAG_enumeration
+; CHECK:     [[UNNAMED_ENUM_ENUMERATOR:0x[0-9a-f]+]]:  DW_TAG_enumerator
+; CHECK:       DW_AT_name ("unnamed_enum_enumerator")
+; CHECK:     NULL
+
+; CHECK:   [[UNSIGNED_INT:0x[0-9a-f]+]]: DW_TAG_base_type
+; CHECK:     DW_AT_name ("unsigned int")
+
+; CHECK:   [[NAMED_ENUM:0x[0-9a-f]+]]: DW_TAG_enumeration
+; CHECK:     DW_AT_name ("named_enum")
+; CHECK:     [[NAMED_ENUM_ENUMERATOR:0x[0-9a-f]+]]:  DW_TAG_enumerator
+; CHECK:       DW_AT_name ("named_enum_enumerator")
+; CHECK:     NULL
+
+; CHECK:   [[NAMED_ENUM_CLASS:0x[0-9a-f]+]]: DW_TAG_enumeration
+; CHECK:     DW_AT_name ("named_enum_class")
+; CHECK:     [[NAMED_ENUM_CLASS_ENUMERATOR:0x[0-9a-f]+]]:  DW_TAG_enumerator
+; CHECK:       DW_AT_name ("named_enum_class_enumerator")
+; CHECK:     NULL
+
+; CHECK:   [[INT:0x[0-9a-f]+]]: DW_TAG_base_type
+; CHECK:     DW_AT_name ("int")
 
 ; CHECK:   [[C:0x[0-9a-f]+]]: DW_TAG_structure_type
 ; CHECK:     DW_AT_name ("C")
@@ -98,15 +121,25 @@
 ; CHECK:       DW_AT_name ("static_member_function")
 ; CHECK:     NULL
 
-; CHECK:   [[INT:0x[0-9a-f]+]]: DW_TAG_base_type
-; CHECK:     DW_AT_name ("int")
 ; CHECK:   DW_TAG_pointer_type
 
-; CHECK:   [[GLOB_VAR:0x[0-9a-f]+]]: DW_TAG_variable
-; CHECK:     DW_AT_name ("global_variable")
+; CHECK:   [[MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
+; CHECK:     DW_AT_specification {{.*}} "_ZN1C15member_functionEv"
+; CHECK:     DW_TAG_formal_parameter
+; CHECK:     NULL
+
+; CHECK:   [[STATIC_MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
+; CHECK:     DW_AT_specification {{.*}} "_ZN1C22static_member_functionEv"
+
+; CHECK:   [[GLOBAL_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
+; CHECK:     DW_AT_linkage_name
+; CHECK:     DW_AT_name ("global_function")
 
 ; CHECK:   [[NS:0x[0-9a-f]+]]: DW_TAG_namespace
 ; CHECK:     DW_AT_name ("ns")
+; CHECK:     [[GLOB_NS_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
+; CHECK:       DW_AT_linkage_name
+; CHECK:       DW_AT_name ("global_namespace_function")
 ; CHECK:     [[GLOB_NS_VAR:0x[0-9a-f]+]]: DW_TAG_variable
 ; CHECK:       DW_AT_name ("global_namespace_variable")
 ; CHECK-NOT:   DW_AT_specification
@@ -121,9 +154,6 @@
 ; CHECK:       DW_AT_name ("D")
 ; CHECK:       DW_TAG_member
 ; CHECK:       NULL
-; CHECK:     [[GLOB_NS_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
-; CHECK:       DW_AT_linkage_name
-; CHECK:       DW_AT_name ("global_namespace_function")
 ; CHECK:     DW_TAG_variable
 ; CHECK:     NULL
 
@@ -134,6 +164,16 @@
 ; CHECK:       DW_AT_location
 ; CHECK:     NULL
 
+; CHECK:   [[GLOBAL_F7:0x[0-9a-f]+]]: DW_TAG_subprogram
+; CHECK:     DW_AT_linkage_name
+; CHECK:     DW_AT_name ("f7")
+
+; CHECK:   [[STATIC_MEM_VAR:0x[0-9a-f]+]]: DW_TAG_variable
+; CHECK:     DW_AT_specification {{.*}} "static_member_variable"
+
+; CHECK:   [[GLOB_VAR:0x[0-9a-f]+]]: DW_TAG_variable
+; CHECK:     DW_AT_name ("global_variable")
+
 ; CHECK:   [[ANON:.*]]: DW_TAG_namespace
 ; CHECK-NOT: DW_AT_name
 ; CHECK:     [[ANON_I:.*]]: DW_TAG_variable
@@ -154,86 +194,50 @@
 ; CHECK:       NULL
 ; CHECK:     NULL
 
-; CHECK:   DW_TAG_enumeration
-; CHECK:     [[UNNAMED_ENUM_ENUMERATOR:0x[0-9a-f]+]]:  DW_TAG_enumerator
-; CHECK:       DW_AT_name ("unnamed_enum_enumerator")
-; CHECK:     NULL
-
-; CHECK:   [[UNSIGNED_INT:0x[0-9a-f]+]]: DW_TAG_base_type
-; CHECK:     DW_AT_name ("unsigned int")
-
-; CHECK:   [[NAMED_ENUM:0x[0-9a-f]+]]: DW_TAG_enumeration
-; CHECK:     DW_AT_name ("named_enum")
-; CHECK:     [[NAMED_ENUM_ENUMERATOR:0x[0-9a-f]+]]:  DW_TAG_enumerator
-; CHECK:       DW_AT_name ("named_enum_enumerator")
-; CHECK:     NULL
-
-; CHECK:   [[NAMED_ENUM_CLASS:0x[0-9a-f]+]]: DW_TAG_enumeration
-; CHECK:     DW_AT_name ("named_enum_class")
-; CHECK:     [[NAMED_ENUM_CLASS_ENUMERATOR:0x[0-9a-f]+]]:  DW_TAG_enumerator
-; CHECK:       DW_AT_name ("named_enum_class_enumerator")
-; CHECK:     NULL
-
-; CHECK:   [[MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
-; CHECK:     DW_AT_specification {{.*}} "_ZN1C15member_functionEv"
-; CHECK:     DW_TAG_formal_parameter
-; CHECK:     NULL
-
-; CHECK:   [[STATIC_MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
-; CHECK:     DW_AT_specification {{.*}} "_ZN1C22static_member_functionEv"
-
-; CHECK:   [[GLOBAL_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
-; CHECK:     DW_AT_linkage_name
-; CHECK:     DW_AT_name ("global_function")
-
-; CHECK:   [[GLOBAL_F7:0x[0-9a-f]+]]: DW_TAG_subprogram
-; CHECK:     DW_AT_linkage_name
-; CHECK:     DW_AT_name ("f7")
-
 ; CHECK:   DW_TAG_imported_declaration
 ; CHECK:   DW_TAG_pointer_type
 ; CHECK:   DW_TAG_pointer_type
+
 ; CHECK:   NULL
 
 ; CHECK-LABEL: .debug_gnu_pubnames contents:
 ; CHECK-NEXT: length = {{.*}}, version = 0x0002, unit_offset = 0x00000000, unit_size = {{.*}}
 ; CHECK-NEXT: Offset     Linkage  Kind     Name
-; CHECK-NEXT:  [[STATIC_MEM_VAR]] EXTERNAL VARIABLE "C::static_member_variable"
-; CHECK-NEXT:  [[GLOB_VAR]] EXTERNAL VARIABLE "global_variable"
+; CHECK-NEXT:  [[UNNAMED_ENUM_ENUMERATOR]] STATIC VARIABLE  "unnamed_enum_enumerator"
+; CHECK-NEXT:  [[NAMED_ENUM_ENUMERATOR]] STATIC VARIABLE  "named_enum_enumerator"
+; CHECK-NEXT:  [[NAMED_ENUM_CLASS_ENUMERATOR]] STATIC VARIABLE  "named_enum_class_enumerator"
+; CHECK-NEXT:  [[MEM_FUNC]] EXTERNAL FUNCTION "C::member_function"
+; CHECK-NEXT:  [[STATIC_MEM_FUNC]] EXTERNAL FUNCTION "C::static_member_function"
+; CHECK-NEXT:  [[GLOBAL_FUNC]] EXTERNAL FUNCTION "global_function"
 ; CHECK-NEXT:  [[NS]] EXTERNAL TYPE     "ns"
+; CHECK-NEXT:  [[GLOB_NS_FUNC]] EXTERNAL FUNCTION "ns::global_namespace_function"
 ; CHECK-NEXT:  [[GLOB_NS_VAR]] EXTERNAL VARIABLE "ns::global_namespace_variable"
 ; CHECK-NEXT:  [[D_VAR]] EXTERNAL VARIABLE "ns::d"
-; CHECK-NEXT:  [[GLOB_NS_FUNC]] EXTERNAL FUNCTION "ns::global_namespace_function"
 ; CHECK-NEXT:  [[F3]] EXTERNAL FUNCTION "f3"
 ; GCC Doesn't put local statics in pubnames, but it seems not unreasonable and
 ; comes out naturally from LLVM's implementation, so I'm OK with it for now. If
 ; it's demonstrated that this is a major size concern or degrades debug info
 ; consumer behavior, feel free to change it.
 ; CHECK-NEXT:  [[F3_Z]] STATIC VARIABLE "f3::z"
+; CHECK-NEXT:  [[GLOBAL_F7]] EXTERNAL FUNCTION "f7"
+; CHECK-NEXT:  [[STATIC_MEM_VAR]] EXTERNAL VARIABLE "C::static_member_variable"
+; CHECK-NEXT:  [[GLOB_VAR]] EXTERNAL VARIABLE "global_variable"
 ; CHECK-NEXT:  [[ANON]] EXTERNAL TYPE "(anonymous namespace)"
 ; CHECK-NEXT:  [[ANON_I]] STATIC VARIABLE "(anonymous namespace)::i"
 ; CHECK-NEXT:  [[ANON_INNER]] EXTERNAL TYPE "(anonymous namespace)::inner"
 ; CHECK-NEXT:  [[ANON_INNER_B]] STATIC VARIABLE "(anonymous namespace)::inner::b"
 ; CHECK-NEXT:  [[OUTER]] EXTERNAL TYPE "outer"
 ; CHECK-NEXT:  [[OUTER_ANON]] EXTERNAL TYPE "outer::(anonymous namespace)"
-; CHECK-NEXT:  [[OUTER_ANON_C]] STATIC VARIABLE "outer::(anonymous namespace)::c"
-; CHECK-NEXT:  [[UNNAMED_ENUM_ENUMERATOR]] STATIC VARIABLE  "unnamed_enum_enumerator"
-; CHECK-NEXT:  [[NAMED_ENUM_ENUMERATOR]] STATIC VARIABLE  "named_enum_enumerator"
-; CHECK-NEXT:  [[NAMED_ENUM_CLASS_ENUMERATOR]] STATIC VARIABLE  "named_enum_class_enumerator"
-; CHECK-NEXT:  [[MEM_FUNC]] EXTERNAL FUNCTION "C::member_function"
-; CHECK-NEXT:  [[STATIC_MEM_FUNC]] EXTERNAL FUNCTION "C::static_member_function"
 ; FIXME: GCC produces enumerators as EXTERNAL, not STATIC
-; CHECK-NEXT:  [[GLOBAL_FUNC]] EXTERNAL FUNCTION "global_function"
-; CHECK-NEXT:  [[GLOBAL_F7]] EXTERNAL FUNCTION "f7"
+; CHECK-NEXT:  [[OUTER_ANON_C]] STATIC VARIABLE "outer::(anonymous namespace)::c"
 
 ; CHECK-LABEL: debug_gnu_pubtypes contents:
 ; CHECK: Offset     Linkage  Kind     Name
-; CHECK-NEXT:  [[C]] EXTERNAL TYPE     "C"
-; CHECK-NEXT:  [[INT]] STATIC   TYPE     "int"
-; CHECK-NEXT:  [[D]] EXTERNAL TYPE     "ns::D"
 ; CHECK-NEXT:  [[UNSIGNED_INT]] STATIC   TYPE     "unsigned int"
 ; CHECK-NEXT:  [[NAMED_ENUM]] EXTERNAL TYPE     "named_enum"
 ; CHECK-NEXT:  [[NAMED_ENUM_CLASS]] EXTERNAL TYPE     "named_enum_class"
+; CHECK-NEXT:  [[INT]] STATIC   TYPE     "int"
+; CHECK-NEXT:  [[C]] EXTERNAL TYPE     "C"
 
 %struct.C = type { i8 }
 %"struct.ns::D" = type { i32 }
diff --git a/llvm/test/DebugInfo/X86/linkage-name.ll b/llvm/test/DebugInfo/X86/linkage-name.ll
index 8eafd65de82f4..7544d973e40ac 100644
--- a/llvm/test/DebugInfo/X86/linkage-name.ll
+++ b/llvm/test/DebugInfo/X86/linkage-name.ll
@@ -1,7 +1,7 @@
 ; RUN: llc -mtriple=x86_64-macosx %s -o %t -filetype=obj
 ; RUN: llvm-dwarfdump -v -debug-info %t | FileCheck %s
 
-; CHECK: DW_TAG_subprogram [9] *
+; CHECK: DW_TAG_subprogram [8] *
 ; CHECK-NOT: DW_AT_{{(MIPS_)?}}linkage_name
 ; CHECK: DW_AT_specification
 
diff --git a/llvm/test/DebugInfo/X86/namelist1.ll b/llvm/test/DebugInfo/X86/namelist1.ll
index 92c0777f3422e..5132c894e8138 100644
--- a/llvm/test/DebugInfo/X86/namelist1.ll
+++ b/llvm/test/DebugInfo/X86/namelist1.ll
@@ -4,10 +4,11 @@
 ; RUN: llc -O0 -mtriple=x86_64-unknown-linux-gnu %s -filetype=obj -o %t.o
 ; RUN: llvm-dwarfdump %t.o | FileCheck %s
 ;
-; CHECK: [[ITEM1:0x.+]]:       DW_TAG_variable
-; CHECK:                          DW_AT_name  ("a")
 ; CHECK: [[ITEM2:0x.+]]:       DW_TAG_variable
 ; CHECK:                          DW_AT_name  ("b")
+; CHECK:                       DW_TAG_variable
+; CHECK: [[ITEM1:0x.+]]:       DW_TAG_variable
+; CHECK:                          DW_AT_name  ("a")
 ; CHECK: DW_TAG_namelist
 ; CHECK:    DW_AT_name  ("nml")
 ; CHECK: DW_TAG_namelist_item
diff --git a/llvm/test/DebugInfo/X86/prototyped.ll b/llvm/test/DebugInfo/X86/prototyped.ll
index 532f5d3c8ec16..3897b5dcd80fa 100644
--- a/llvm/test/DebugInfo/X86/prototyped.ll
+++ b/llvm/test/DebugInfo/X86/prototyped.ll
@@ -24,11 +24,11 @@
 ; void (*x)(void);
 ; void y(void) { }
 
-; CHECK: DW_TAG_subroutine_type
+; CHECK: DW_TAG_subprogram
 ; CHECK-NOT: {{DW_TAG|NULL}}
 ; CHECK:   DW_AT_prototyped (true)
 
-; CHECK: DW_TAG_subprogram
+; CHECK: DW_TAG_subroutine_type
 ; CHECK-NOT: {{DW_TAG|NULL}}
 ; CHECK:   DW_AT_prototyped (true)
 
diff --git a/llvm/test/DebugInfo/X86/ref_addr_relocation.ll b/llvm/test/DebugInfo/X86/ref_addr_relocation.ll
index 21e54e73edddb..5bc15b13a1e77 100644
--- a/llvm/test/DebugInfo/X86/ref_addr_relocation.ll
+++ b/llvm/test/DebugInfo/X86/ref_addr_relocation.ll
@@ -33,12 +33,12 @@
 
 ; Make sure we use relocation for ref_addr on non-darwin platforms.
 ; CHECK: DW_TAG_compile_unit
+; CHECK: DW_TAG_structure_type
 ; CHECK: DW_TAG_variable
 ; ELF-ASM: .long [[TYPE:.*]] # DW_AT_type
 ; DARWIN-ASM2: .long [[TYPE:.*]] ## DW_AT_type
 ; DARWIN-ASM4: .long [[TYPE:.*]] ## DW_AT_type
 ; COFF-ASM: .long [[TYPE:.*]] # DW_AT_type
-; CHECK: DW_TAG_structure_type
 ; CHECK: cu_begin1
 ; CHECK: DW_TAG_compile_unit
 ; CHECK-NOT: DW_TAG_structure_type
@@ -60,9 +60,9 @@
 ; CHECK-DWARF: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[ADDR]]
 
 ; CHECK-DWARF2: DW_TAG_compile_unit
+; CHECK-DWARF2: [[ADDR:.*]]: DW_TAG_structure_type
 ; CHECK-DWARF2: DW_TAG_variable
-; CHECK-DWARF2: DW_AT_type [DW_FORM_ref4] {{.*}} => {[[ADDR:.*]]}
-; CHECK-DWARF2: [[ADDR]]: DW_TAG_structure_type
+; CHECK-DWARF2: DW_AT_type [DW_FORM_ref4] {{.*}} => {[[ADDR]]}
 
 source_filename = "test/DebugInfo/X86/ref_addr_relocation.ll"
 
diff --git a/llvm/test/DebugInfo/X86/string-offsets-multiple-cus.ll b/llvm/test/DebugInfo/X86/string-offsets-multiple-cus.ll
index 4e8dfc2ada747..2f989b8b8a05b 100644
--- a/llvm/test/DebugInfo/X86/string-offsets-multiple-cus.ll
+++ b/llvm/test/DebugInfo/X86/string-offsets-multiple-cus.ll
@@ -42,21 +42,21 @@
 ; TYPEUNITS-NOT:  NULL
 ; TYPEUNITS:      DW_TAG_enumerator
 ; TYPEUNITS-NOT:  {{DW_TAG|NULL}}
-; TYPEUNITS:      DW_AT_name [DW_FORM_strx1] (indexed (00000005) string = "b")
+; TYPEUNITS:      DW_AT_name [DW_FORM_strx1] (indexed (00000004) string = "b")
 ; TYPEUNITS-NOT:  contents:
 ; TYPEUNITS:      DW_TAG_type_unit
 ; TYPEUNITS-NOT:  {{DW_TAG|NULL}}
 ; TYPEUNITS:      DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF]])
 ; TYPEUNITS-NOT:  NULL
 ; TYPEUNITS:      DW_TAG_enumeration_type
-; TYPEUNITS:      DW_AT_name [DW_FORM_strx1] (indexed (0000000d) string = "E2")
+; TYPEUNITS:      DW_AT_name [DW_FORM_strx1] (indexed (0000000b) string = "E2")
 ; TYPEUNITS-NOT:  contents:
 ; TYPEUNITS:      DW_TAG_type_unit
 ; TYPEUNITS-NOT:  {{DW_TAG|NULL}}
 ; TYPEUNITS:      DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF]])
 ; TYPEUNITS-NOT:  NULL
 ; TYPEUNITS:      DW_TAG_enumeration_type
-; TYPEUNITS:      DW_AT_name [DW_FORM_strx1] (indexed (00000013) string = "E3")
+; TYPEUNITS:      DW_AT_name [DW_FORM_strx1] (indexed (00000010) string = "E3")
 
 ; CU 1
 ; BOTH-NOT:    .contents:
@@ -70,20 +70,20 @@
 ; BOTH:        DW_TAG_compile_unit
 ; BOTH-NOT:    {{DW_TAG|NULL}}
 ; BOTH:        DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF]])
-; BOTH-NOT:    NULL
+; DEFUALT:     NULL
 ; BOTH:        DW_TAG_variable
 ; BOTH-NOT:    {{DW_TAG|NULL}}
-; BOTH:        DW_AT_name [DW_FORM_strx1] (indexed (00000009) string = "glob2")
+; BOTH:        DW_AT_name [DW_FORM_strx1] (indexed (00000012) string = "glob2")
 ;
 ; CU 3
 ; BOTH-NOT:    contents:
 ; BOTH:        DW_TAG_compile_unit
 ; BOTH-NOT:    {{DW_TAG|NULL}}
 ; BOTH:        DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF]])
-; BOTH-NOT:    NULL
+; DEFAULT:     NULL
 ; BOTH:        DW_TAG_variable
 ; BOTH-NOT:    {{DW_TAG|NULL}}
-; BOTH:        DW_AT_name [DW_FORM_strx1] (indexed (0000000f) string = "glob3")
+; BOTH:        DW_AT_name [DW_FORM_strx1] (indexed (00000013) string = "glob3")
 ;
 ; Extract the offset of a string to verify that it is referenced in the string
 ; offsets section.
@@ -104,7 +104,16 @@
 ; BOTH-NEXT:      {{.*:}}
 ; BOTH-NEXT:      {{.*:}}
 ; BOTH-NEXT:      {{.*:}}
-; The string with index 9 should be "glob2"
+; BOTH-NEXT:      {{.*:}}
+; BOTH-NEXT:      {{.*:}}
+; BOTH-NEXT:      {{.*:}}
+; BOTH-NEXT:      {{.*:}}
+; BOTH-NEXT:      {{.*:}}
+; BOTH-NEXT:      {{.*:}}
+; BOTH-NEXT:      {{.*:}}
+; BOTH-NEXT:      {{.*:}}
+; BOTH-NEXT:      {{.*:}}
+; The string with index 12 should be "glob2"
 ; BOTH-NEXT:      {{.*:}} [[GLOB2OFF]]
 ;
 ; ModuleID = 'test.bc'
diff --git a/llvm/test/DebugInfo/X86/string-offsets-table.ll b/llvm/test/DebugInfo/X86/string-offsets-table.ll
index e1c914a1946b8..76240f2f98f00 100644
--- a/llvm/test/DebugInfo/X86/string-offsets-table.ll
+++ b/llvm/test/DebugInfo/X86/string-offsets-table.ll
@@ -72,11 +72,11 @@
 ; SPLIT-NOT:  contents:
 ; SPLIT:      DW_TAG_enumerator
 ; SPLIT-NOT:  {{DW_TAG|NULL}}
-; SPLIT:      DW_AT_name [DW_FORM_strx1]    (indexed (00000001) string = "a")
+; SPLIT:      DW_AT_name [DW_FORM_strx1]    (indexed (00000000) string = "a")
 ; SPLIT-NOT:  contents:
 ; SPLIT:      DW_TAG_enumerator
 ; SPLIT-NOT:  {{DW_TAG|NULL}}
-; SPLIT:      DW_AT_name [DW_FORM_strx1]    (indexed (00000002) string = "b")
+; SPLIT:      DW_AT_name [DW_FORM_strx1]    (indexed (00000001) string = "b")
 ;
 ; Extract the string offsets referenced in the main file by the skeleton unit.
 ; SPLIT:      .debug_str contents:
diff --git a/llvm/test/DebugInfo/X86/template.ll b/llvm/test/DebugInfo/X86/template.ll
index 227aefd224c2b..5cf659ca5d8de 100644
--- a/llvm/test/DebugInfo/X86/template.ll
+++ b/llvm/test/DebugInfo/X86/template.ll
@@ -15,26 +15,10 @@
 
 ; VERIFY-NOT: error:
 
-; CHECK: [[INT:0x[0-9a-f]*]]:{{ *}}DW_TAG_base_type
-; CHECK-NEXT: DW_AT_name{{.*}} = "int"
-
-; CHECK: DW_TAG_structure_type
-; CHECK: DW_AT_name{{.*}}"y_impl<int>"
-; CHECK-NOT: {{TAG|NULL}}
-; CHECK: DW_TAG_template_type_parameter
-
-; CHECK: DW_TAG_variable
-; CHECK-NEXT: DW_AT_name{{.*}}"var"
-; CHECK-NOT: NULL
-; CHECK: DW_TAG_template_type_parameter
-; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT]]}
-; CHECK-NEXT: DW_AT_name{{.*}}= "T"
-
-
 ; CHECK: DW_AT_name{{.*}}"func<3, &glbl, y_impl, nullptr, E, 1, 2>"
 ; CHECK-NOT: NULL
 ; CHECK: DW_TAG_template_value_parameter
-; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT]]}
+; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT:0x[0-9a-f]*]]}
 ; CHECK-NEXT: DW_AT_name{{.*}}= "x"
 ; CHECK-NEXT: DW_AT_const_value [DW_FORM_sdata]{{.*}}(3)
 
@@ -71,6 +55,21 @@
 ; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT]]}
 ; CHECK-NEXT: DW_AT_const_value  [DW_FORM_sdata]{{.*}}(2)
 
+; CHECK: [[INT]]:{{ *}}DW_TAG_base_type
+; CHECK-NEXT: DW_AT_name{{.*}} = "int"
+
+; CHECK: DW_TAG_structure_type
+; CHECK: DW_AT_name{{.*}}"y_impl<int>"
+; CHECK-NOT: {{TAG|NULL}}
+; CHECK: DW_TAG_template_type_parameter
+
+; CHECK: DW_TAG_variable
+; CHECK-NEXT: DW_AT_name{{.*}}"var"
+; CHECK-NOT: NULL
+; CHECK: DW_TAG_template_type_parameter
+; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT]]}
+; CHECK-NEXT: DW_AT_name{{.*}}= "T"
+
 ; CHECK: [[INTPTR]]:{{ *}}DW_TAG_pointer_type
 ; CHECK-NEXT: DW_AT_type{{.*}} => {[[INT]]}
 
diff --git a/llvm/test/DebugInfo/X86/tls.ll b/llvm/test/DebugInfo/X86/tls.ll
index f6f6b6f5bc3ce..da569fdc5e5a4 100644
--- a/llvm/test/DebugInfo/X86/tls.ll
+++ b/llvm/test/DebugInfo/X86/tls.ll
@@ -30,33 +30,45 @@
 ; that here instead of raw assembly printing
 
 ; FISSION: .section    .debug_info.dwo,
-; 3 bytes of data in this DW_FORM_exprloc representation of the location of 'tls'
-; FISSION: .byte 3{{ *}}# DW_AT_location
-; DW_OP_GNU_const_index (0xfx == 252) to refer to the debug_addr table
-; FISSION-NEXT: .byte 252
-; an index of zero into the debug_addr table
-; FISSION-NEXT: .byte 0
-
 ; SINGLE: .section     .debug_info,
 ; DARWIN: .section     {{.*}}debug_info,
 
+; SINGLE-64: DW_TAG_variable
 ; 10 bytes of data in this DW_FORM_exprloc representation of the location of 'tls'
 ; SINGLE-64: .byte     10 # DW_AT_location
 ; DW_OP_const8u (0x0e == 14) of address
 ; SINGLE-64-NEXT: .byte        14
 ; SINGLE-64-NEXT: .quad tls at DTPOFF
 
+; DARWIN: DW_TAG_variable
 ; DARWIN: .byte     10 ## DW_AT_location
 ; DW_OP_const8u (0x0e == 14) of address
 ; DARWIN-NEXT: .byte        14
 ; DARWIN-NEXT: .quad _tls
 
+; SINGLE-32: DW_TAG_variable
 ; 6 bytes of data in 32-bit mode
 ; SINGLE-32: .byte     6 # DW_AT_location
 ; DW_OP_const4u (0x0e == 12) of address
 ; SINGLE-32-NEXT: .byte        12
 ; SINGLE-32-NEXT: .long tls at DTPOFF
 
+; FISSION: DW_TAG_template_value_parameter
+; FISSION: .byte 3 # DW_AT_location
+; DW_OP_GNU_addr_index
+; FISSION-NEXT: .byte 251
+; FISSION-NEXT: .byte 2
+; DW_OP_stack_value
+; FISSION-NEXT: .byte 159
+
+; FISSION: DW_TAG_variable
+; 3 bytes of data in this DW_FORM_exprloc representation of the location of 'tls'
+; FISSION: .byte 3{{ *}}# DW_AT_location
+; DW_OP_GNU_const_index (0xfx == 252) to refer to the debug_addr table
+; FISSION-NEXT: .byte 252
+; an index of 1 into the debug_addr table
+; FISSION-NEXT: .byte 1
+
 ; DW_OP_GNU_push_tls_address
 ; GNUOP-NEXT: .byte 224
 ; DW_OP_form_tls_address
@@ -66,19 +78,12 @@
 ; FISSION: .byte 2 # DW_AT_location
 ; DW_OP_GNU_addr_index
 ; FISSION-NEXT: .byte 251
-; FISSION-NEXT: .byte 1
-
-; FISSION: DW_TAG_template_value_parameter
-; FISSION: .byte 3 # DW_AT_location
-; DW_OP_GNU_addr_index
-; FISSION-NEXT: .byte 251
-; FISSION-NEXT: .byte 1
-; DW_OP_stack_value
-; FISSION-NEXT: .byte 159
+; FISSION-NEXT: .byte 2
 
 ; check that the expected TLS address description is the first thing in the debug_addr section
 ; FISSION: .section    .debug_addr
 ; FISSION-NEXT: .Laddr_table_base0:
+; FISSION-NEXT: .quad .Lfunc_begin0
 ; FISSION-NEXT: .quad  tls at DTPOFF
 ; FISSION-NEXT: .quad  glbl
 ; FISSION-NOT: .quad  glbl
diff --git a/llvm/test/DebugInfo/X86/tu-to-non-tu.ll b/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
index f80bd8b978963..1b055cb881f56 100644
--- a/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
+++ b/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
@@ -90,11 +90,29 @@
 
 ; CHECK: DW_TAG_structure_type
 ; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_name {{.*}}"tu_ref_non_tu"
+; CHECK: DW_AT_name {{.*}}"non_tu"
 
 ; CHECK: DW_TAG_structure_type
 ; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_name {{.*}}"non_tu"
+; CHECK: DW_AT_name {{.*}}"_STN|templ_non_tu|<int>"
+
+; CHECK: DW_TAG_structure_type
+; CHECK-NOT: DW_TAG
+; CHECK: DW_AT_name      ("templ_non_tu")
+; CHECK-NOT: DW_TAG
+; CHECK: DW_TAG_template_type_parameter
+; CHECK-NEXT: DW_AT_type    {{.*}}"long"
+
+; CHECK: DW_TAG_structure_type
+; CHECK-NOT: DW_TAG
+; CHECK: DW_AT_name      ("_STN|templ_non_tu|<bool>")
+; CHECK-NOT: DW_TAG
+; CHECK: DW_TAG_template_type_parameter
+; CHECK-NEXT: DW_AT_type    {{.*}}"bool"
+
+; CHECK: DW_TAG_structure_type
+; CHECK-NOT: DW_TAG
+; CHECK: DW_AT_name {{.*}}"tu_ref_non_tu"
 
 ; CHECK: DW_TAG_structure_type
 ; CHECK-NOT: DW_TAG
@@ -115,29 +133,14 @@
 ; CHECK: DW_TAG_structure_type
 ; CHECK-NOT: DW_TAG
 ; CHECK: DW_AT_name {{.*}}"ref_templ_non_tu"
-; CHECK: DW_TAG_structure_type
-; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_name {{.*}}"_STN|templ_non_tu|<int>"
 
 ; CHECK: DW_TAG_structure_type
 ; CHECK-NOT: DW_TAG
 ; CHECK: DW_AT_name {{.*}}"ref_templ_non_tu_simple"
-; CHECK: DW_TAG_structure_type
-; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_name      ("templ_non_tu")
-; CHECK-NOT: DW_TAG
-; CHECK: DW_TAG_template_type_parameter
-; CHECK-NEXT: DW_AT_type    {{.*}}"long"
 
 ; CHECK: DW_TAG_structure_type
 ; CHECK-NOT: DW_TAG
 ; CHECK: DW_AT_name {{.*}}"ref_templ_non_tu_mangled"
-; CHECK: DW_TAG_structure_type
-; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_name      ("_STN|templ_non_tu|<bool>")
-; CHECK-NOT: DW_TAG
-; CHECK: DW_TAG_template_type_parameter
-; CHECK-NEXT: DW_AT_type    {{.*}}"bool"
 ; CHECK: DW_TAG_class_type
 ; CHECK-NOT: DW_TAG
 ; CHECK: DW_AT_name {{.*}}"ref_internal_template"
diff --git a/llvm/test/DebugInfo/X86/vla-global.ll b/llvm/test/DebugInfo/X86/vla-global.ll
index 1eecb0d58f859..b3752f909b359 100644
--- a/llvm/test/DebugInfo/X86/vla-global.ll
+++ b/llvm/test/DebugInfo/X86/vla-global.ll
@@ -1,5 +1,8 @@
 ; RUN: llc -mtriple=x86_64-apple-darwin %s -o - -filetype=obj | llvm-dwarfdump - | FileCheck %s
 
+; CHECK: DW_TAG_subprogram
+; CHECK: DW_TAG_variable
+; CHECK: DW_TAG_variable
 ; CHECK: 0x00000[[G:.*]]:     DW_TAG_variable
 ; CHECK-NEXT:                DW_AT_name	("g")
 ; CHECK: DW_TAG_array_type
diff --git a/llvm/test/DebugInfo/attr-btf_tag.ll b/llvm/test/DebugInfo/attr-btf_tag.ll
index 2d57dcdf12de3..ada9c325709e9 100644
--- a/llvm/test/DebugInfo/attr-btf_tag.ll
+++ b/llvm/test/DebugInfo/attr-btf_tag.ll
@@ -42,37 +42,6 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
 !llvm.module.flags = !{!10, !11, !12, !13, !14}
 !llvm.ident = !{!15}
 
-!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
-!1 = distinct !DIGlobalVariable(name: "g1", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true, annotations: !7)
-
-; CHECK:       DW_TAG_variable
-; CHECK-NEXT:     DW_AT_name      ("g1")
-; CHECK:          DW_TAG_LLVM_annotation
-; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
-; CHECK-NEXT:       DW_AT_const_value     ("tag1")
-; CHECK-EMPTY:
-; CHECK-NEXT:     DW_TAG_LLVM_annotation
-; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
-; CHECK-NEXT:       DW_AT_const_value     ("tag2")
-; CHECK-EMPTY:
-; CHECK-NEXT:     NULL
-
-!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
-!3 = !DIFile(filename: "t.c", directory: "/tmp/home/yhs/work/tests/llvm/btf_tag")
-!4 = !{}
-!5 = !{!0}
-!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!7 = !{!8, !9}
-!8 = !{!"btf_decl_tag", !"tag1"}
-!9 = !{!"btf_decl_tag", !"tag2"}
-!10 = !{i32 7, !"Dwarf Version", i32 4}
-!11 = !{i32 2, !"Debug Info Version", i32 3}
-!12 = !{i32 1, !"wchar_size", i32 4}
-!13 = !{i32 7, !"uwtable", i32 1}
-!14 = !{i32 7, !"frame-pointer", i32 2}
-!15 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)"}
-!16 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 10, type: !17, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4, annotations: !7)
-
 ; CHECK:      DW_TAG_subprogram
 ; CHECK:        DW_AT_name      ("foo")
 ; CHECK:        DW_TAG_formal_parameter
@@ -96,12 +65,17 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
 ; CHECK-EMPTY:
 ; CHECK-NEXT:   NULL
 
-!17 = !DISubroutineType(types: !18)
-!18 = !{!6, !19}
-!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
-!20 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !3, line: 4, size: 32, elements: !21, annotations: !7)
-!21 = !{!22}
-!22 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !20, file: !3, line: 5, baseType: !6, size: 32, annotations: !7)
+; CHECK:       DW_TAG_variable
+; CHECK-NEXT:     DW_AT_name      ("g1")
+; CHECK:          DW_TAG_LLVM_annotation
+; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
+; CHECK-NEXT:       DW_AT_const_value     ("tag1")
+; CHECK-EMPTY:
+; CHECK-NEXT:     DW_TAG_LLVM_annotation
+; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
+; CHECK-NEXT:       DW_AT_const_value     ("tag2")
+; CHECK-EMPTY:
+; CHECK-NEXT:     NULL
 
 ; CHECK:      DW_TAG_structure_type
 ; CHECK-NEXT:   DW_AT_name      ("t1")
@@ -127,6 +101,29 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
 ; CHECK-EMPTY:
 ; CHECK-NEXT:   NULL
 
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g1", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true, annotations: !7)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/tmp/home/yhs/work/tests/llvm/btf_tag")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{!8, !9}
+!8 = !{!"btf_decl_tag", !"tag1"}
+!9 = !{!"btf_decl_tag", !"tag2"}
+!10 = !{i32 7, !"Dwarf Version", i32 4}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{i32 1, !"wchar_size", i32 4}
+!13 = !{i32 7, !"uwtable", i32 1}
+!14 = !{i32 7, !"frame-pointer", i32 2}
+!15 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)"}
+!16 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 10, type: !17, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4, annotations: !7)
+!17 = !DISubroutineType(types: !18)
+!18 = !{!6, !19}
+!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
+!20 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !3, line: 4, size: 32, elements: !21, annotations: !7)
+!21 = !{!22}
+!22 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !20, file: !3, line: 5, baseType: !6, size: 32, annotations: !7)
 !23 = !DILocalVariable(name: "arg", arg: 1, scope: !16, file: !3, line: 10, type: !19, annotations: !7)
 !24 = !DILocation(line: 10, column: 48, scope: !16)
 !25 = !DILocation(line: 11, column: 10, scope: !16)
diff --git a/llvm/test/MC/WebAssembly/debug-info.ll b/llvm/test/MC/WebAssembly/debug-info.ll
index a65ce0ee83920..5080a5364242d 100644
--- a/llvm/test/MC/WebAssembly/debug-info.ll
+++ b/llvm/test/MC/WebAssembly/debug-info.ll
@@ -154,20 +154,20 @@
 ; CHECK-NEXT:    0x16 R_WASM_SECTION_OFFSET_I32 .debug_line 0
 ; CHECK-NEXT:    0x1A R_WASM_SECTION_OFFSET_I32 .debug_str 62
 ; CHECK-NEXT:    0x1E R_WASM_FUNCTION_OFFSET_I32 f2 0
-; CHECK-NEXT:    0x27 R_WASM_SECTION_OFFSET_I32 .debug_str 105
-; CHECK-NEXT:    0x33 R_WASM_MEMORY_ADDR_I32 foo 0
-; CHECK-NEXT:    0x3D R_WASM_SECTION_OFFSET_I32 .debug_str 109
-; CHECK-NEXT:    0x44 R_WASM_SECTION_OFFSET_I32 .debug_str 113
-; CHECK-NEXT:    0x50 R_WASM_MEMORY_ADDR_I32 ptr2 0
-; CHECK-NEXT:    0x5B R_WASM_FUNCTION_OFFSET_I32 f2 0
-; CHECK-NEXT:    0x66 R_WASM_GLOBAL_INDEX_I32 __stack_pointer
-; CHECK-NEXT:    0x6B R_WASM_SECTION_OFFSET_I32 .debug_str 118
+; CHECK-NEXT:    0x27 R_WASM_FUNCTION_OFFSET_I32 f2 0
+; CHECK-NEXT:    0x32 R_WASM_GLOBAL_INDEX_I32 __stack_pointer
+; CHECK-NEXT:    0x37 R_WASM_SECTION_OFFSET_I32 .debug_str 118
+; CHECK-NEXT:    0x3E R_WASM_SECTION_OFFSET_I32 .debug_str 105
+; CHECK-NEXT:    0x4A R_WASM_MEMORY_ADDR_I32 foo 0
+; CHECK-NEXT:    0x54 R_WASM_SECTION_OFFSET_I32 .debug_str 109
+; CHECK-NEXT:    0x5B R_WASM_SECTION_OFFSET_I32 .debug_str 113
+; CHECK-NEXT:    0x67 R_WASM_MEMORY_ADDR_I32 ptr2 0
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:  Section (10) .debug_aranges {
 ; CHECK-NEXT:    0x6 R_WASM_SECTION_OFFSET_I32 .debug_info 0
-; CHECK-NEXT:    0x10 R_WASM_MEMORY_ADDR_I32 foo 0
-; CHECK-NEXT:    0x18 R_WASM_MEMORY_ADDR_I32 ptr2 0
-; CHECK-NEXT:    0x20 R_WASM_FUNCTION_OFFSET_I32 f2 0
+; CHECK-NEXT:    0x10 R_WASM_FUNCTION_OFFSET_I32 f2 0
+; CHECK-NEXT:    0x18 R_WASM_MEMORY_ADDR_I32 foo 0
+; CHECK-NEXT:    0x20 R_WASM_MEMORY_ADDR_I32 ptr2 0
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:  Section (12) .debug_pubnames {
 ; CHECK-NEXT:    0x6 R_WASM_SECTION_OFFSET_I32 .debug_info 0
diff --git a/llvm/test/MC/WebAssembly/debug-info64.ll b/llvm/test/MC/WebAssembly/debug-info64.ll
index d0081164d73ee..2091b87e10828 100644
--- a/llvm/test/MC/WebAssembly/debug-info64.ll
+++ b/llvm/test/MC/WebAssembly/debug-info64.ll
@@ -160,20 +160,20 @@
 ; CHECK-NEXT:     0x16 R_WASM_SECTION_OFFSET_I32 .debug_line 0
 ; CHECK-NEXT:     0x1A R_WASM_SECTION_OFFSET_I32 .debug_str 62
 ; CHECK-NEXT:     0x1E R_WASM_FUNCTION_OFFSET_I64 f2 0
-; CHECK-NEXT:     0x2B R_WASM_SECTION_OFFSET_I32 .debug_str 105
-; CHECK-NEXT:     0x37 R_WASM_MEMORY_ADDR_I64 foo 0
-; CHECK-NEXT:     0x45 R_WASM_SECTION_OFFSET_I32 .debug_str 109
-; CHECK-NEXT:     0x4C R_WASM_SECTION_OFFSET_I32 .debug_str 113
-; CHECK-NEXT:     0x58 R_WASM_MEMORY_ADDR_I64 ptr2 0
-; CHECK-NEXT:     0x67 R_WASM_FUNCTION_OFFSET_I64 f2 0
-; CHECK-NEXT:     0x76 R_WASM_GLOBAL_INDEX_I32 __stack_pointer
-; CHECK-NEXT:     0x7B R_WASM_SECTION_OFFSET_I32 .debug_str 118
+; CHECK-NEXT:     0x2B R_WASM_FUNCTION_OFFSET_I64 f2 0
+; CHECK-NEXT:     0x3A R_WASM_GLOBAL_INDEX_I32 __stack_pointer
+; CHECK-NEXT:     0x3F R_WASM_SECTION_OFFSET_I32 .debug_str 118
+; CHECK-NEXT:     0x46 R_WASM_SECTION_OFFSET_I32 .debug_str 105
+; CHECK-NEXT:     0x52 R_WASM_MEMORY_ADDR_I64 foo 0
+; CHECK-NEXT:     0x60 R_WASM_SECTION_OFFSET_I32 .debug_str 109
+; CHECK-NEXT:     0x67 R_WASM_SECTION_OFFSET_I32 .debug_str 113
+; CHECK-NEXT:     0x73 R_WASM_MEMORY_ADDR_I64 ptr2 0
 ; CHECK-NEXT:   }
 ; CHECK-NEXT:   Section (10) .debug_aranges {
 ; CHECK-NEXT:     0x6 R_WASM_SECTION_OFFSET_I32 .debug_info 0
-; CHECK-NEXT:     0x10 R_WASM_MEMORY_ADDR_I64 foo 0
-; CHECK-NEXT:     0x20 R_WASM_MEMORY_ADDR_I64 ptr2 0
-; CHECK-NEXT:     0x30 R_WASM_FUNCTION_OFFSET_I64 f2 0
+; CHECK-NEXT:     0x10 R_WASM_FUNCTION_OFFSET_I64 f2 0
+; CHECK-NEXT:     0x20 R_WASM_MEMORY_ADDR_I64 foo 0
+; CHECK-NEXT:     0x30 R_WASM_MEMORY_ADDR_I64 ptr2 0
 ; CHECK-NEXT:   }
 ; CHECK-NEXT:   Section (12) .debug_pubnames {
 ; CHECK-NEXT:     0x6 R_WASM_SECTION_OFFSET_I32 .debug_info 0
diff --git a/llvm/test/MC/WebAssembly/dwarfdump.ll b/llvm/test/MC/WebAssembly/dwarfdump.ll
index 0f3bc4d86fae8..5f8ecee5c4d56 100644
--- a/llvm/test/MC/WebAssembly/dwarfdump.ll
+++ b/llvm/test/MC/WebAssembly/dwarfdump.ll
@@ -15,46 +15,46 @@
 ; CHECK-NEXT:              DW_AT_low_pc		(0x00000002)
 ; CHECK-NEXT:              DW_AT_high_pc	(0x00000004)
 
-; CHECK: 0x00000026:   DW_TAG_variable
+; CHECK: 0x00000026:   DW_TAG_subprogram
+; CHECK-NEXT:                DW_AT_low_pc	(0x00000002)
+; CHECK-NEXT:                DW_AT_high_pc	(0x00000004)
+; CHECK-NEXT:                DW_AT_frame_base	(DW_OP_WASM_location 0x3 0x0, DW_OP_stack_value)
+; CHECK-NEXT:                DW_AT_name	("f2")
+; CHECK-NEXT:                DW_AT_decl_file	("/usr/local/google/home/sbc/dev/wasm/simple{{[/\\]}}test.c")
+; CHECK-NEXT:                DW_AT_decl_line	(2)
+; CHECK-NEXT:                DW_AT_prototyped	(true)
+; CHECK-NEXT:                DW_AT_external		(true)
+
+; CHECK: 0x0000003d:   DW_TAG_variable
 ; CHECK-NEXT:                DW_AT_name	("foo")
-; CHECK-NEXT:                DW_AT_type	(0x00000037 "int *")
+; CHECK-NEXT:                DW_AT_type	(0x0000004e "int *")
 ; CHECK-NEXT:                DW_AT_external	(true)
 ; CHECK-NEXT:                DW_AT_decl_file	("/usr/local/google/home/sbc/dev/wasm/simple{{[/\\]}}test.c")
 ; CHECK-NEXT:                DW_AT_decl_line	(4)
 ; CHECK-NEXT:                DW_AT_location	(DW_OP_addr 0x0)
 
-; CHECK: 0x00000037:   DW_TAG_pointer_type
-; CHECK-NEXT:                DW_AT_type	(0x0000003c "int")
+; CHECK: 0x0000004e:   DW_TAG_pointer_type
+; CHECK-NEXT:                DW_AT_type	(0x00000053 "int")
 
-; CHECK: 0x0000003c:   DW_TAG_base_type
+; CHECK: 0x00000053:   DW_TAG_base_type
 ; CHECK-NEXT:                DW_AT_name	("int")
 ; CHECK-NEXT:                DW_AT_encoding	(DW_ATE_signed)
 ; CHECK-NEXT:                DW_AT_byte_size	(0x04)
 
-; CHECK: 0x00000043:   DW_TAG_variable
+; CHECK: 0x0000005a:   DW_TAG_variable
 ; CHECK-NEXT:                DW_AT_name	("ptr2")
-; CHECK-NEXT:                DW_AT_type	(0x00000054 "void (*)()")
+; CHECK-NEXT:                DW_AT_type	(0x0000006b "void (*)()")
 ; CHECK-NEXT:                DW_AT_external	(true)
 ; CHECK-NEXT:                DW_AT_decl_file	("/usr/local/google/home/sbc/dev/wasm/simple{{[/\\]}}test.c")
 ; CHECK-NEXT:                DW_AT_decl_line	(5)
 ; CHECK-NEXT:                DW_AT_location	(DW_OP_addr 0x4)
 
-; CHECK: 0x00000054:   DW_TAG_pointer_type
-; CHECK-NEXT:                DW_AT_type	(0x00000059 "void ()")
+; CHECK: 0x0000006b:   DW_TAG_pointer_type
+; CHECK-NEXT:                DW_AT_type	(0x00000070 "void ()")
 
-; CHECK: 0x00000059:   DW_TAG_subroutine_type
+; CHECK: 0x00000070:   DW_TAG_subroutine_type
 ; CHECK-NEXT:                DW_AT_prototyped	(true)
 
-; CHECK: 0x0000005a:   DW_TAG_subprogram
-; CHECK-NEXT:                DW_AT_low_pc	(0x00000002)
-; CHECK-NEXT:                DW_AT_high_pc	(0x00000004)
-; CHECK-NEXT:                DW_AT_frame_base	(DW_OP_WASM_location 0x3 0x0, DW_OP_stack_value)
-; CHECK-NEXT:                DW_AT_name	("f2")
-; CHECK-NEXT:                DW_AT_decl_file	("/usr/local/google/home/sbc/dev/wasm/simple{{[/\\]}}test.c")
-; CHECK-NEXT:                DW_AT_decl_line	(2)
-; CHECK-NEXT:                DW_AT_prototyped	(true)
-; CHECK-NEXT:                DW_AT_external		(true)
-
 ; CHECK: 0x00000071:   NULL
 
 
@@ -68,46 +68,46 @@
 ; SPLIT-NEXT:               DW_AT_GNU_dwo_name        ("{{.*}}dwarfdump.ll.tmp.dwo")
 ; SPLIT-NEXT:               DW_AT_GNU_dwo_id  ({{.*}})
 
-; SPLIT:      0x00000019:   DW_TAG_variable
+; SPLIT:      0x00000019:   DW_TAG_subprogram
+; SPLIT-NEXT:                 DW_AT_low_pc    (indexed (00000000) address = <unresolved>)
+; SPLIT-NEXT:                 DW_AT_high_pc   (0x00000002)
+; SPLIT-NEXT:                 DW_AT_frame_base        (DW_OP_WASM_location 0x3 0x0, DW_OP_stack_value)
+; SPLIT-NEXT:                 DW_AT_name      ("f2")
+; SPLIT-NEXT:                 DW_AT_decl_file (0x01)
+; SPLIT-NEXT:                 DW_AT_decl_line (2)
+; SPLIT-NEXT:                 DW_AT_prototyped        (true)
+; SPLIT-NEXT:                 DW_AT_external  (true)
+
+; SPLIT:      0x0000002a:   DW_TAG_variable
 ; SPLIT-NEXT:                 DW_AT_name      ("foo")
-; SPLIT-NEXT:                 DW_AT_type      (0x00000024 "int *")
+; SPLIT-NEXT:                 DW_AT_type      (0x00000035 "int *")
 ; SPLIT-NEXT:                 DW_AT_external  (true)
 ; SPLIT-NEXT:                 DW_AT_decl_file (0x01)
 ; SPLIT-NEXT:                 DW_AT_decl_line (4)
-; SPLIT-NEXT:                 DW_AT_location  (DW_OP_GNU_addr_index 0x0)
+; SPLIT-NEXT:                 DW_AT_location  (DW_OP_GNU_addr_index 0x1)
 
-; SPLIT:      0x00000024:   DW_TAG_pointer_type
-; SPLIT-NEXT:                 DW_AT_type      (0x00000029 "int")
+; SPLIT:      0x00000035:   DW_TAG_pointer_type
+; SPLIT-NEXT:                 DW_AT_type      (0x0000003a "int")
 
-; SPLIT:      0x00000029:   DW_TAG_base_type
+; SPLIT:      0x0000003a:   DW_TAG_base_type
 ; SPLIT-NEXT:                 DW_AT_name      ("int")
 ; SPLIT-NEXT:                 DW_AT_encoding  (DW_ATE_signed)
 ; SPLIT-NEXT:                 DW_AT_byte_size (0x04)
 
-; SPLIT:      0x0000002d:   DW_TAG_variable
+; SPLIT:      0x0000003e:   DW_TAG_variable
 ; SPLIT-NEXT:                 DW_AT_name      ("ptr2")
-; SPLIT-NEXT:                 DW_AT_type      (0x00000038 "void (*)()")
+; SPLIT-NEXT:                 DW_AT_type      (0x00000049 "void (*)()")
 ; SPLIT-NEXT:                 DW_AT_external  (true)
 ; SPLIT-NEXT:                 DW_AT_decl_file (0x01)
 ; SPLIT-NEXT:                 DW_AT_decl_line (5)
-; SPLIT-NEXT:                 DW_AT_location  (DW_OP_GNU_addr_index 0x1)
+; SPLIT-NEXT:                 DW_AT_location  (DW_OP_GNU_addr_index 0x2)
 
-; SPLIT:      0x00000038:   DW_TAG_pointer_type
-; SPLIT-NEXT:                 DW_AT_type      (0x0000003d "void ()")
+; SPLIT:      0x00000049:   DW_TAG_pointer_type
+; SPLIT-NEXT:                 DW_AT_type      (0x0000004e "void ()")
 
-; SPLIT:      0x0000003d:   DW_TAG_subroutine_type
+; SPLIT:      0x0000004e:   DW_TAG_subroutine_type
 ; SPLIT-NEXT:                 DW_AT_prototyped        (true)
 
-; SPLIT:      0x0000003e:   DW_TAG_subprogram
-; SPLIT-NEXT:                 DW_AT_low_pc    (indexed (00000002) address = <unresolved>)
-; SPLIT-NEXT:                 DW_AT_high_pc   (0x00000002)
-; SPLIT-NEXT:                 DW_AT_frame_base        (DW_OP_WASM_location 0x3 0x0, DW_OP_stack_value)
-; SPLIT-NEXT:                 DW_AT_name      ("f2")
-; SPLIT-NEXT:                 DW_AT_decl_file (0x01)
-; SPLIT-NEXT:                 DW_AT_decl_line (2)
-; SPLIT-NEXT:                 DW_AT_prototyped        (true)
-; SPLIT-NEXT:                 DW_AT_external  (true)
-
 ; SPLIT:      0x0000004f:   NULL
 
 
diff --git a/llvm/test/MC/WebAssembly/dwarfdump64.ll b/llvm/test/MC/WebAssembly/dwarfdump64.ll
index c5c0256560144..ab51820e8a683 100644
--- a/llvm/test/MC/WebAssembly/dwarfdump64.ll
+++ b/llvm/test/MC/WebAssembly/dwarfdump64.ll
@@ -14,46 +14,46 @@
 ; CHECK-NEXT:              DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000002)
 ; CHECK-NEXT:              DW_AT_high_pc [DW_FORM_data4]     (0x00000002)
 
-; CHECK: 0x0000002a:   DW_TAG_variable
+; CHECK: 0x0000002a:   DW_TAG_subprogram
+; CHECK-NEXT:                DW_AT_low_pc [DW_FORM_addr]     (0x0000000000000002)
+; CHECK-NEXT:                DW_AT_high_pc [DW_FORM_data4]   (0x00000002)
+; CHECK-NEXT:                DW_AT_frame_base [DW_FORM_exprloc]      (DW_OP_WASM_location 0x3 0x0, DW_OP_stack_value)
+; CHECK-NEXT:                DW_AT_name [DW_FORM_strp]       ("f2")
+; CHECK-NEXT:                DW_AT_decl_file [DW_FORM_data1] ("/usr/local/google/home/sbc/dev/wasm/simple{{[/\\]}}test.c")
+; CHECK-NEXT:                DW_AT_decl_line [DW_FORM_data1] (2)
+; CHECK-NEXT:                DW_AT_prototyped [DW_FORM_flag_present] (true)
+; CHECK-NEXT:                DW_AT_external [DW_FORM_flag_present]   (true)
+
+; CHECK: 0x00000045:   DW_TAG_variable
 ; CHECK-NEXT:                DW_AT_name [DW_FORM_strp]       ("foo")
-; CHECK-NEXT:                DW_AT_type [DW_FORM_ref4]       (0x0000003f "int *")
+; CHECK-NEXT:                DW_AT_type [DW_FORM_ref4]       (0x0000005a "int *")
 ; CHECK-NEXT:                DW_AT_external [DW_FORM_flag_present]   (true)
 ; CHECK-NEXT:                DW_AT_decl_file [DW_FORM_data1] ("/usr/local/google/home/sbc/dev/wasm/simple{{[/\\]}}test.c")
 ; CHECK-NEXT:                DW_AT_decl_line [DW_FORM_data1] (4)
 ; CHECK-NEXT:                DW_AT_location [DW_FORM_exprloc]        (DW_OP_addr 0x0)
 
-; CHECK: 0x0000003f:   DW_TAG_pointer_type
-; CHECK-NEXT:                DW_AT_type [DW_FORM_ref4]       (0x00000044 "int")
+; CHECK: 0x0000005a:   DW_TAG_pointer_type
+; CHECK-NEXT:                DW_AT_type [DW_FORM_ref4]       (0x0000005f "int")
 
-; CHECK: 0x00000044:   DW_TAG_base_type
+; CHECK: 0x0000005f:   DW_TAG_base_type
 ; CHECK-NEXT:                DW_AT_name [DW_FORM_strp]       ("int")
 ; CHECK-NEXT:                DW_AT_encoding [DW_FORM_data1]  (DW_ATE_signed)
 ; CHECK-NEXT:                DW_AT_byte_size [DW_FORM_data1] (0x04)
 
-; CHECK: 0x0000004b:   DW_TAG_variable
+; CHECK: 0x00000066:   DW_TAG_variable
 ; CHECK-NEXT:                DW_AT_name [DW_FORM_strp]       ("ptr2")
-; CHECK-NEXT:                DW_AT_type [DW_FORM_ref4]       (0x00000060 "void (*)()")
+; CHECK-NEXT:                DW_AT_type [DW_FORM_ref4]       (0x0000007b "void (*)()")
 ; CHECK-NEXT:                DW_AT_external [DW_FORM_flag_present]   (true)
 ; CHECK-NEXT:                DW_AT_decl_file [DW_FORM_data1] ("/usr/local/google/home/sbc/dev/wasm/simple{{[/\\]}}test.c")
 ; CHECK-NEXT:                DW_AT_decl_line [DW_FORM_data1] (5)
 ; CHECK-NEXT:                DW_AT_location [DW_FORM_exprloc]        (DW_OP_addr 0x8)
 
-; CHECK: 0x00000060:   DW_TAG_pointer_type
-; CHECK-NEXT:                DW_AT_type [DW_FORM_ref4]       (0x00000065 "void ()")
+; CHECK: 0x0000007b:   DW_TAG_pointer_type
+; CHECK-NEXT:                DW_AT_type [DW_FORM_ref4]       (0x00000080 "void ()")
 
-; CHECK: 0x00000065:   DW_TAG_subroutine_type
+; CHECK: 0x00000080:   DW_TAG_subroutine_type
 ; CHECK-NEXT:                DW_AT_prototyped [DW_FORM_flag_present] (true)
 
-; CHECK: 0x00000066:   DW_TAG_subprogram
-; CHECK-NEXT:                DW_AT_low_pc [DW_FORM_addr]     (0x0000000000000002)
-; CHECK-NEXT:                DW_AT_high_pc [DW_FORM_data4]   (0x00000002)
-; CHECK-NEXT:                DW_AT_frame_base [DW_FORM_exprloc]      (DW_OP_WASM_location 0x3 0x0, DW_OP_stack_value)
-; CHECK-NEXT:                DW_AT_name [DW_FORM_strp]       ("f2")
-; CHECK-NEXT:                DW_AT_decl_file [DW_FORM_data1] ("/usr/local/google/home/sbc/dev/wasm/simple{{[/\\]}}test.c")
-; CHECK-NEXT:                DW_AT_decl_line [DW_FORM_data1] (2)
-; CHECK-NEXT:                DW_AT_prototyped [DW_FORM_flag_present] (true)
-; CHECK-NEXT:                DW_AT_external [DW_FORM_flag_present]   (true)
-
 ; CHECK: 0x00000081:   NULL
 
 target triple = "wasm64-unknown-unknown"
diff --git a/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/crash-thread-local-storage.test b/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/crash-thread-local-storage.test
index 5f2b3f9e824ab..d5349f9f403c3 100644
--- a/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/crash-thread-local-storage.test
+++ b/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/crash-thread-local-storage.test
@@ -41,7 +41,7 @@
 ; CHECK:                    {Entry} const_u 0, gnu_push_tls_address
 ; CHECK:      2         {Variable} extern 'NGlobal' -> 'int'
 ; CHECK:                  {Location}
-; CHECK:                    {Entry} addrx 0
+; CHECK:                    {Entry} addrx 1
 ; CHECK:      3         {Function} extern not_inlined 'test' -> 'void'
 ; CHECK:      4           {Variable} 'TLocal' -> 'int'
 ; CHECK:                    {Location}

>From 9ed608c8a8289bff1c2075102b981c55a82b1b47 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Mon, 2 Mar 2026 22:31:17 +0100
Subject: [PATCH 2/6] Fix dwarfdump-DIImportedEntity_elements.ll

---
 .../DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll     | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll b/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
index 573fbf214df32..9e80921d3c6b3 100644
--- a/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
+++ b/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
@@ -1,6 +1,5 @@
 ;; This test checks processing of DIImportedEntity with elements field.
 ; REQUIRES: x86_64-linux
-
 ; RUN: llc %s -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
 
 ; CHECK: DW_TAG_subprogram
@@ -8,9 +7,9 @@
 ; CHECK:   DW_TAG_subprogram
 ; CHECK:     DW_AT_name      ("use_renamed")
 ; CHECK:     DW_TAG_imported_module
-; CHECK:       DW_AT_import ([[MYMOD]] "mymod")
+; CHECK:       DW_AT_import ([[MYMOD:0x[0-9a-f]+]] "mymod")
 ; CHECK:       DW_TAG_imported_declaration
-; CHECK:         DW_AT_import ([[VAR1]] "var1")
+; CHECK:         DW_AT_import ([[VAR1:0x[0-9a-f]+]] "var1")
 ; CHECK:         DW_AT_name        ("var4")
 
 ; CHECK: [[MYMOD]]: DW_TAG_module

>From 63ca3d02c24365007443c5a8ec5ce3077cd43d56 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <dzhidzhoev at gmail.com>
Date: Tue, 3 Mar 2026 13:05:06 +0100
Subject: [PATCH 3/6] Update llvm/test/CodeGen/X86/dbg-distringtype-uint.ll

Co-authored-by: David Blaikie <dblaikie at gmail.com>
---
 llvm/test/CodeGen/X86/dbg-distringtype-uint.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll b/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll
index 9eb7c9c59ebd4..47b32967e68f7 100644
--- a/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll
+++ b/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll
@@ -10,7 +10,7 @@
 ; CHECK-NOT:                 DW_TAG
 ; CHECK:                     DW_TAG_formal_parameter
 ; CHECK-NOT:                 DW_TAG
-; Ensure that static local variable elemnt is placed in abstract subprogram DIE.
+; Ensure that the static local variable is in the abstract subprogram DIE.
 ; CHECK:                     DW_TAG_variable
 ; CHECK-NEXT:                  DW_AT_name  ("elemnt")
 

>From 32b7444beb5e119ac877712333c7012bdc85547f Mon Sep 17 00:00:00 2001
From: "vdzhidzhoev at accesssoftek.com" <Vladislav Dzhidzhoev>
Date: Tue, 3 Mar 2026 13:37:38 +0100
Subject: [PATCH 4/6] Address review comments

---
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp    | 37 +++++-----
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h      |  1 +
 .../AArch64/DW_AT_APPLE_enum_kind.ll          |  6 +-
 llvm/test/DebugInfo/attr-btf_tag.ll           | 71 ++++++++++---------
 4 files changed, 61 insertions(+), 54 deletions(-)

diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index cd91a2a08d536..41ccf7201247e 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1170,20 +1170,29 @@ void DwarfDebug::finishUnitAttributes(const DICompileUnit *DIUnit,
     }
   }
 }
-// Create new DwarfCompileUnit for the given metadata node with tag
-// DW_TAG_compile_unit.
-DwarfCompileUnit &
-DwarfDebug::getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit) {
+
+DwarfCompileUnit *DwarfDebug::getDwarfCompileUnit(const DICompileUnit *DIUnit) {
   if (auto *CU = CUMap.lookup(DIUnit))
-    return *CU;
+    return CU;
 
   if (useSplitDwarf() &&
       !shareAcrossDWOCUs() &&
       (!DIUnit->getSplitDebugInlining() ||
        DIUnit->getEmissionKind() == DICompileUnit::FullDebug) &&
       !CUMap.empty()) {
-    return *CUMap.begin()->second;
+    return CUMap.begin()->second;
   }
+
+  return nullptr;
+}
+
+// Create new DwarfCompileUnit for the given metadata node with tag
+// DW_TAG_compile_unit.
+DwarfCompileUnit &
+DwarfDebug::getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit) {
+  if (auto *CU = getDwarfCompileUnit(DIUnit))
+    return *CU;
+
   CompilationDir = DIUnit->getDirectory();
 
   auto OwnedUnit = std::make_unique<DwarfCompileUnit>(
@@ -1500,17 +1509,11 @@ void DwarfDebug::endModule() {
   }
 
   for (DICompileUnit *CUNode : M->debug_compile_units()) {
-    DwarfCompileUnit *CU = CUMap.lookup(CUNode);
-
-    // If the CU hasn't been emitted yet, create it here unless it is empty.
-    if (!CU) {
-      if (CUNode->getImportedEntities().empty() &&
-          CUNode->getEnumTypes().empty() &&
-          CUNode->getRetainedTypes().empty() &&
-          CUNode->getGlobalVariables().empty() && CUNode->getMacros().empty())
-        continue;
-      CU = &getOrCreateDwarfCompileUnit(CUNode);
-    }
+    DwarfCompileUnit *CU = getDwarfCompileUnit(CUNode);
+
+    // If the CU hasn't been emitted yet, it must be empty. Skip it.
+    if (!CU)
+      continue;
 
     // Emit Global Variables.
     for (auto *GVE : CUNode->getGlobalVariables()) {
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index cca8d434a0a58..ae1f29144cce7 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -666,6 +666,7 @@ class DwarfDebug : public DebugHandlerBase {
   /// emit it here if we don't have a skeleton CU for split dwarf.
   void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const;
 
+  DwarfCompileUnit *getDwarfCompileUnit(const DICompileUnit *DIUnit);
   /// Create new DwarfCompileUnit for the given metadata node with tag
   /// DW_TAG_compile_unit.
   DwarfCompileUnit &getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit);
diff --git a/llvm/test/DebugInfo/AArch64/DW_AT_APPLE_enum_kind.ll b/llvm/test/DebugInfo/AArch64/DW_AT_APPLE_enum_kind.ll
index 1183202dfadaf..70b1e98845f89 100644
--- a/llvm/test/DebugInfo/AArch64/DW_AT_APPLE_enum_kind.ll
+++ b/llvm/test/DebugInfo/AArch64/DW_AT_APPLE_enum_kind.ll
@@ -15,16 +15,16 @@
 
 ; CHECK: .debug_abbrev contents:
 
-; CHECK: [2] DW_TAG_enumeration_type DW_CHILDREN_yes
+; CHECK: [[[ABBREV_IDX:[0-9]+]]] DW_TAG_enumeration_type DW_CHILDREN_yes
 ; CHECK: DW_AT_APPLE_enum_kind   DW_FORM_data1
 
 ; CHECK: .debug_info contents:
 
-; CHECK: DW_TAG_enumeration_type [2]
+; CHECK: DW_TAG_enumeration_type [[[ABBREV_IDX]]]
 ; CHECK-DAG: DW_AT_name {{.*}} string = "OpenEnum"
 ; CHECK-DAG: DW_AT_APPLE_enum_kind [DW_FORM_data1]  (DW_APPLE_ENUM_KIND_Open)
 
-; CHECK: DW_TAG_enumeration_type [2]
+; CHECK: DW_TAG_enumeration_type [[[ABBREV_IDX]]]
 ; CHECK-DAG: DW_AT_name {{.*}} string = "ClosedEnum"
 ; CHECK-DAG: DW_AT_APPLE_enum_kind [DW_FORM_data1]  (DW_APPLE_ENUM_KIND_Closed)
 
diff --git a/llvm/test/DebugInfo/attr-btf_tag.ll b/llvm/test/DebugInfo/attr-btf_tag.ll
index ada9c325709e9..2d57dcdf12de3 100644
--- a/llvm/test/DebugInfo/attr-btf_tag.ll
+++ b/llvm/test/DebugInfo/attr-btf_tag.ll
@@ -42,6 +42,37 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
 !llvm.module.flags = !{!10, !11, !12, !13, !14}
 !llvm.ident = !{!15}
 
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g1", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true, annotations: !7)
+
+; CHECK:       DW_TAG_variable
+; CHECK-NEXT:     DW_AT_name      ("g1")
+; CHECK:          DW_TAG_LLVM_annotation
+; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
+; CHECK-NEXT:       DW_AT_const_value     ("tag1")
+; CHECK-EMPTY:
+; CHECK-NEXT:     DW_TAG_LLVM_annotation
+; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
+; CHECK-NEXT:       DW_AT_const_value     ("tag2")
+; CHECK-EMPTY:
+; CHECK-NEXT:     NULL
+
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/tmp/home/yhs/work/tests/llvm/btf_tag")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{!8, !9}
+!8 = !{!"btf_decl_tag", !"tag1"}
+!9 = !{!"btf_decl_tag", !"tag2"}
+!10 = !{i32 7, !"Dwarf Version", i32 4}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{i32 1, !"wchar_size", i32 4}
+!13 = !{i32 7, !"uwtable", i32 1}
+!14 = !{i32 7, !"frame-pointer", i32 2}
+!15 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)"}
+!16 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 10, type: !17, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4, annotations: !7)
+
 ; CHECK:      DW_TAG_subprogram
 ; CHECK:        DW_AT_name      ("foo")
 ; CHECK:        DW_TAG_formal_parameter
@@ -65,17 +96,12 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
 ; CHECK-EMPTY:
 ; CHECK-NEXT:   NULL
 
-; CHECK:       DW_TAG_variable
-; CHECK-NEXT:     DW_AT_name      ("g1")
-; CHECK:          DW_TAG_LLVM_annotation
-; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
-; CHECK-NEXT:       DW_AT_const_value     ("tag1")
-; CHECK-EMPTY:
-; CHECK-NEXT:     DW_TAG_LLVM_annotation
-; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
-; CHECK-NEXT:       DW_AT_const_value     ("tag2")
-; CHECK-EMPTY:
-; CHECK-NEXT:     NULL
+!17 = !DISubroutineType(types: !18)
+!18 = !{!6, !19}
+!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
+!20 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !3, line: 4, size: 32, elements: !21, annotations: !7)
+!21 = !{!22}
+!22 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !20, file: !3, line: 5, baseType: !6, size: 32, annotations: !7)
 
 ; CHECK:      DW_TAG_structure_type
 ; CHECK-NEXT:   DW_AT_name      ("t1")
@@ -101,29 +127,6 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
 ; CHECK-EMPTY:
 ; CHECK-NEXT:   NULL
 
-!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
-!1 = distinct !DIGlobalVariable(name: "g1", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true, annotations: !7)
-!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
-!3 = !DIFile(filename: "t.c", directory: "/tmp/home/yhs/work/tests/llvm/btf_tag")
-!4 = !{}
-!5 = !{!0}
-!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!7 = !{!8, !9}
-!8 = !{!"btf_decl_tag", !"tag1"}
-!9 = !{!"btf_decl_tag", !"tag2"}
-!10 = !{i32 7, !"Dwarf Version", i32 4}
-!11 = !{i32 2, !"Debug Info Version", i32 3}
-!12 = !{i32 1, !"wchar_size", i32 4}
-!13 = !{i32 7, !"uwtable", i32 1}
-!14 = !{i32 7, !"frame-pointer", i32 2}
-!15 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)"}
-!16 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 10, type: !17, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4, annotations: !7)
-!17 = !DISubroutineType(types: !18)
-!18 = !{!6, !19}
-!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
-!20 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !3, line: 4, size: 32, elements: !21, annotations: !7)
-!21 = !{!22}
-!22 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !20, file: !3, line: 5, baseType: !6, size: 32, annotations: !7)
 !23 = !DILocalVariable(name: "arg", arg: 1, scope: !16, file: !3, line: 10, type: !19, annotations: !7)
 !24 = !DILocation(line: 10, column: 48, scope: !16)
 !25 = !DILocation(line: 11, column: 10, scope: !16)

>From dd0c4b2db47c38a1ecf0ae5c8d39f5f80adf13cc Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Tue, 3 Mar 2026 15:48:17 +0100
Subject: [PATCH 5/6] Address review comments

---
 llvm/test/DebugInfo/attr-btf_tag.ll | 71 ++++++++++++++---------------
 1 file changed, 34 insertions(+), 37 deletions(-)

diff --git a/llvm/test/DebugInfo/attr-btf_tag.ll b/llvm/test/DebugInfo/attr-btf_tag.ll
index 2d57dcdf12de3..ada9c325709e9 100644
--- a/llvm/test/DebugInfo/attr-btf_tag.ll
+++ b/llvm/test/DebugInfo/attr-btf_tag.ll
@@ -42,37 +42,6 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
 !llvm.module.flags = !{!10, !11, !12, !13, !14}
 !llvm.ident = !{!15}
 
-!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
-!1 = distinct !DIGlobalVariable(name: "g1", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true, annotations: !7)
-
-; CHECK:       DW_TAG_variable
-; CHECK-NEXT:     DW_AT_name      ("g1")
-; CHECK:          DW_TAG_LLVM_annotation
-; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
-; CHECK-NEXT:       DW_AT_const_value     ("tag1")
-; CHECK-EMPTY:
-; CHECK-NEXT:     DW_TAG_LLVM_annotation
-; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
-; CHECK-NEXT:       DW_AT_const_value     ("tag2")
-; CHECK-EMPTY:
-; CHECK-NEXT:     NULL
-
-!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
-!3 = !DIFile(filename: "t.c", directory: "/tmp/home/yhs/work/tests/llvm/btf_tag")
-!4 = !{}
-!5 = !{!0}
-!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!7 = !{!8, !9}
-!8 = !{!"btf_decl_tag", !"tag1"}
-!9 = !{!"btf_decl_tag", !"tag2"}
-!10 = !{i32 7, !"Dwarf Version", i32 4}
-!11 = !{i32 2, !"Debug Info Version", i32 3}
-!12 = !{i32 1, !"wchar_size", i32 4}
-!13 = !{i32 7, !"uwtable", i32 1}
-!14 = !{i32 7, !"frame-pointer", i32 2}
-!15 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)"}
-!16 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 10, type: !17, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4, annotations: !7)
-
 ; CHECK:      DW_TAG_subprogram
 ; CHECK:        DW_AT_name      ("foo")
 ; CHECK:        DW_TAG_formal_parameter
@@ -96,12 +65,17 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
 ; CHECK-EMPTY:
 ; CHECK-NEXT:   NULL
 
-!17 = !DISubroutineType(types: !18)
-!18 = !{!6, !19}
-!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
-!20 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !3, line: 4, size: 32, elements: !21, annotations: !7)
-!21 = !{!22}
-!22 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !20, file: !3, line: 5, baseType: !6, size: 32, annotations: !7)
+; CHECK:       DW_TAG_variable
+; CHECK-NEXT:     DW_AT_name      ("g1")
+; CHECK:          DW_TAG_LLVM_annotation
+; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
+; CHECK-NEXT:       DW_AT_const_value     ("tag1")
+; CHECK-EMPTY:
+; CHECK-NEXT:     DW_TAG_LLVM_annotation
+; CHECK-NEXT:       DW_AT_name    ("btf_decl_tag")
+; CHECK-NEXT:       DW_AT_const_value     ("tag2")
+; CHECK-EMPTY:
+; CHECK-NEXT:     NULL
 
 ; CHECK:      DW_TAG_structure_type
 ; CHECK-NEXT:   DW_AT_name      ("t1")
@@ -127,6 +101,29 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
 ; CHECK-EMPTY:
 ; CHECK-NEXT:   NULL
 
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g1", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true, annotations: !7)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/tmp/home/yhs/work/tests/llvm/btf_tag")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{!8, !9}
+!8 = !{!"btf_decl_tag", !"tag1"}
+!9 = !{!"btf_decl_tag", !"tag2"}
+!10 = !{i32 7, !"Dwarf Version", i32 4}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{i32 1, !"wchar_size", i32 4}
+!13 = !{i32 7, !"uwtable", i32 1}
+!14 = !{i32 7, !"frame-pointer", i32 2}
+!15 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 305231a4f71b68945b4dd92925c76ff49e377c86)"}
+!16 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 10, type: !17, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4, annotations: !7)
+!17 = !DISubroutineType(types: !18)
+!18 = !{!6, !19}
+!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
+!20 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !3, line: 4, size: 32, elements: !21, annotations: !7)
+!21 = !{!22}
+!22 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !20, file: !3, line: 5, baseType: !6, size: 32, annotations: !7)
 !23 = !DILocalVariable(name: "arg", arg: 1, scope: !16, file: !3, line: 10, type: !19, annotations: !7)
 !24 = !DILocation(line: 10, column: 48, scope: !16)
 !25 = !DILocation(line: 11, column: 10, scope: !16)

>From 2efa306304fd205507739ee571489da599115a0f Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Tue, 3 Mar 2026 15:57:38 +0100
Subject: [PATCH 6/6] Remove extra curly brackets

---
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 41ccf7201247e..aaff5c13050c1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1175,13 +1175,11 @@ DwarfCompileUnit *DwarfDebug::getDwarfCompileUnit(const DICompileUnit *DIUnit) {
   if (auto *CU = CUMap.lookup(DIUnit))
     return CU;
 
-  if (useSplitDwarf() &&
-      !shareAcrossDWOCUs() &&
+  if (useSplitDwarf() && !shareAcrossDWOCUs() &&
       (!DIUnit->getSplitDebugInlining() ||
        DIUnit->getEmissionKind() == DICompileUnit::FullDebug) &&
-      !CUMap.empty()) {
+      !CUMap.empty())
     return CUMap.begin()->second;
-  }
 
   return nullptr;
 }



More information about the llvm-commits mailing list