[Mlir-commits] [flang] [mlir] [mlir][AsmParser] Disambiguate location attributes from trailing loc (PR #180668)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Mar 17 08:23:17 PDT 2026


https://github.com/XiaoleiShi-NV updated https://github.com/llvm/llvm-project/pull/180668

>From 1a29b0d22b810f962750cd67eb67f9f5d5215c4c Mon Sep 17 00:00:00 2001
From: Xiaolei Shi <xiaoleis at nvidia.com>
Date: Mon, 9 Feb 2026 18:29:40 -0800
Subject: [PATCH 1/6] init

---
 mlir/lib/AsmParser/AttributeParser.cpp        |  1 -
 .../test/Dialect/LLVMIR/nvvm-barrier-loc.mlir | 32 +++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 mlir/test/Dialect/LLVMIR/nvvm-barrier-loc.mlir

diff --git a/mlir/lib/AsmParser/AttributeParser.cpp b/mlir/lib/AsmParser/AttributeParser.cpp
index 519609a38be6e..4ef4c52d992f0 100644
--- a/mlir/lib/AsmParser/AttributeParser.cpp
+++ b/mlir/lib/AsmParser/AttributeParser.cpp
@@ -253,7 +253,6 @@ OptionalParseResult Parser::parseOptionalAttribute(Attribute &attribute,
   case Token::kw_dense:
   case Token::kw_dense_resource:
   case Token::kw_false:
-  case Token::kw_loc:
   case Token::kw_sparse:
   case Token::kw_true:
   case Token::kw_unit:
diff --git a/mlir/test/Dialect/LLVMIR/nvvm-barrier-loc.mlir b/mlir/test/Dialect/LLVMIR/nvvm-barrier-loc.mlir
new file mode 100644
index 0000000000000..f6516a467eade
--- /dev/null
+++ b/mlir/test/Dialect/LLVMIR/nvvm-barrier-loc.mlir
@@ -0,0 +1,32 @@
+// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+
+// Verify that nvvm.barrier roundtrips correctly when loc() annotations use
+// forward-referencing #loc aliases (defined after the module body).
+// This is a regression test for a bug where parseOptionalAttribute would
+// speculatively consume loc(#locN) as an attribute, failing on forward
+// references instead of leaving it for the trailing location parser.
+
+// CHECK-LABEL: @barrier_loc_forward_ref
+module {
+  llvm.func @barrier_loc_forward_ref(%barId : i32, %numThreads : i32, %pred : i32) {
+    // CHECK: nvvm.barrier
+    nvvm.barrier loc(#loc1)
+
+    // CHECK: nvvm.barrier id = %{{.*}}
+    nvvm.barrier id = %barId loc(#loc2)
+
+    // CHECK: nvvm.barrier id = %{{.*}} number_of_threads = %{{.*}}
+    nvvm.barrier id = %barId number_of_threads = %numThreads loc(#loc1)
+
+    // CHECK: %{{.*}} = nvvm.barrier #nvvm.reduction<and> %{{.*}} -> i32
+    %0 = nvvm.barrier #nvvm.reduction<and> %pred -> i32 loc(#loc2)
+
+    // CHECK: %{{.*}} = nvvm.barrier #nvvm.reduction<popc> %{{.*}} -> i32
+    %1 = nvvm.barrier #nvvm.reduction<popc> %pred -> i32 loc(#loc1)
+
+    llvm.return
+  } loc(#loc0)
+} loc(#loc0)
+#loc0 = loc(unknown)
+#loc1 = loc("barrier_test"(#loc0))
+#loc2 = loc("barrier_with_id"(#loc0))

>From 9f0a40a8eec9010654d4efd95e5ced5f7d9e5a3a Mon Sep 17 00:00:00 2001
From: Xiaolei Shi <xiaoleis at nvidia.com>
Date: Wed, 11 Feb 2026 18:34:23 -0800
Subject: [PATCH 2/6] use test dialect for testing

---
 .../test/Dialect/LLVMIR/nvvm-barrier-loc.mlir | 32 -------------------
 mlir/test/IR/loc-attr-disambiguation.mlir     | 15 +++++++++
 mlir/test/lib/Dialect/Test/TestOps.td         |  6 ++++
 3 files changed, 21 insertions(+), 32 deletions(-)
 delete mode 100644 mlir/test/Dialect/LLVMIR/nvvm-barrier-loc.mlir
 create mode 100644 mlir/test/IR/loc-attr-disambiguation.mlir

diff --git a/mlir/test/Dialect/LLVMIR/nvvm-barrier-loc.mlir b/mlir/test/Dialect/LLVMIR/nvvm-barrier-loc.mlir
deleted file mode 100644
index f6516a467eade..0000000000000
--- a/mlir/test/Dialect/LLVMIR/nvvm-barrier-loc.mlir
+++ /dev/null
@@ -1,32 +0,0 @@
-// RUN: mlir-opt %s | mlir-opt | FileCheck %s
-
-// Verify that nvvm.barrier roundtrips correctly when loc() annotations use
-// forward-referencing #loc aliases (defined after the module body).
-// This is a regression test for a bug where parseOptionalAttribute would
-// speculatively consume loc(#locN) as an attribute, failing on forward
-// references instead of leaving it for the trailing location parser.
-
-// CHECK-LABEL: @barrier_loc_forward_ref
-module {
-  llvm.func @barrier_loc_forward_ref(%barId : i32, %numThreads : i32, %pred : i32) {
-    // CHECK: nvvm.barrier
-    nvvm.barrier loc(#loc1)
-
-    // CHECK: nvvm.barrier id = %{{.*}}
-    nvvm.barrier id = %barId loc(#loc2)
-
-    // CHECK: nvvm.barrier id = %{{.*}} number_of_threads = %{{.*}}
-    nvvm.barrier id = %barId number_of_threads = %numThreads loc(#loc1)
-
-    // CHECK: %{{.*}} = nvvm.barrier #nvvm.reduction<and> %{{.*}} -> i32
-    %0 = nvvm.barrier #nvvm.reduction<and> %pred -> i32 loc(#loc2)
-
-    // CHECK: %{{.*}} = nvvm.barrier #nvvm.reduction<popc> %{{.*}} -> i32
-    %1 = nvvm.barrier #nvvm.reduction<popc> %pred -> i32 loc(#loc1)
-
-    llvm.return
-  } loc(#loc0)
-} loc(#loc0)
-#loc0 = loc(unknown)
-#loc1 = loc("barrier_test"(#loc0))
-#loc2 = loc("barrier_with_id"(#loc0))
diff --git a/mlir/test/IR/loc-attr-disambiguation.mlir b/mlir/test/IR/loc-attr-disambiguation.mlir
new file mode 100644
index 0000000000000..0111cd0eb7d51
--- /dev/null
+++ b/mlir/test/IR/loc-attr-disambiguation.mlir
@@ -0,0 +1,15 @@
+// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+
+// Verify that forward-referencing loc() aliases are not consumed by
+// parseOptionalAttribute when probing for optional attribute groups.
+
+// CHECK-LABEL: @loc_forward_ref_with_optional_group
+func.func @loc_forward_ref_with_optional_group() {
+  // CHECK: test.optional_loc_group
+  test.optional_loc_group loc(#loc_fwd)
+  // CHECK: test.optional_loc_group 42 : i64
+  test.optional_loc_group 42 : i64 loc(#loc_fwd)
+  return
+} loc(#loc_base)
+#loc_base = loc(unknown)
+#loc_fwd = loc("forward_ref_test"(#loc_base))
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 62a374e08ec1c..b770b860a5122 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -1205,6 +1205,12 @@ def TestLocationAttrOp : TEST_Op<"op_with_loc_attr"> {
   let assemblyFormat = "$loc_attr attr-dict";
 }
 
+def TestOptionalLocGroupOp : TEST_Op<"optional_loc_group"> {
+  let summary = "op with optional attr group for loc() disambiguation testing";
+  let arguments = (ins OptionalAttr<AnyAttr>:$opt_attr);
+  let assemblyFormat = "($opt_attr^)? attr-dict";
+}
+
 //===----------------------------------------------------------------------===//
 // Test Patterns
 //===----------------------------------------------------------------------===//

>From c44d8ed28bf71b48057d860708a004f5f6dea1c4 Mon Sep 17 00:00:00 2001
From: Xiaolei Shi <xiaoleis at nvidia.com>
Date: Mon, 16 Mar 2026 21:29:30 -0700
Subject: [PATCH 3/6] [mlir][AsmParser] Disambiguate location attributes from
 trailing loc

---
 mlir/lib/AsmParser/AttributeParser.cpp        | 28 +++++++------
 mlir/lib/IR/AsmPrinter.cpp                    |  4 +-
 .../GPUToNVVM/gpu-to-nvvm-debuginfo.mlir      |  4 +-
 mlir/test/Dialect/Builtin/Bytecode/attrs.mlir | 28 ++++++-------
 .../LLVMIR/add-debuginfo-func-scope.mlir      | 40 +++++++++----------
 mlir/test/Dialect/LLVMIR/bytecode.mlir        | 18 ++++-----
 mlir/test/Dialect/LLVMIR/call-location.mlir   | 10 ++---
 .../LLVMIR/di-expression-legalization.mlir    |  2 +-
 .../Dialect/LLVMIR/inlining-debuginfo.mlir    |  2 +-
 .../LLVMIR/inlining-loop-annotation.mlir      | 36 ++++++++---------
 .../Dialect/LLVMIR/invalid-call-location.mlir | 10 ++---
 mlir/test/Dialect/LLVMIR/loop-metadata.mlir   | 16 ++++----
 .../Transform/test-interpreter-printing.mlir  |  2 +-
 mlir/test/IR/diagnostic-handler-filter.mlir   |  4 +-
 mlir/test/IR/loc-attr-disambiguation.mlir     | 26 +++++++-----
 mlir/test/IR/locations.mlir                   | 30 +++++++-------
 mlir/test/IR/print-attr-type-aliases.mlir     | 18 ++++-----
 mlir/test/Target/LLVMIR/llvmir-debug.mlir     | 24 +++++------
 mlir/test/Target/LLVMIR/llvmir-phi-loc.mlir   |  8 ++--
 mlir/test/Target/LLVMIR/loop-metadata.mlir    |  8 ++--
 .../Target/LLVMIR/omptarget-debug-147063.mlir | 12 +++---
 .../Target/LLVMIR/omptarget-debug-empty.mlir  |  8 ++--
 .../LLVMIR/omptarget-debug-loop-loc.mlir      | 14 +++----
 .../LLVMIR/omptarget-debug-map-link-loc.mlir  | 14 +++----
 .../Target/LLVMIR/omptarget-debug-nowait.mlir |  6 +--
 .../Target/LLVMIR/omptarget-debug-var-1.mlir  | 10 ++---
 .../Target/LLVMIR/omptarget-debug-var-2.mlir  | 10 ++---
 mlir/test/Target/LLVMIR/omptarget-debug.mlir  |  8 ++--
 mlir/test/Target/LLVMIR/omptarget-debug2.mlir |  8 ++--
 .../LLVMIR/omptarget-parallel-llvm-debug.mlir | 10 ++---
 .../Transforms/canonicalize-debuginfo.mlir    | 10 ++---
 .../Transforms/constant-fold-debuginfo.mlir   |  6 +--
 mlir/test/Transforms/inlining.mlir            |  4 +-
 mlir/test/lib/Dialect/Test/TestOps.td         |  3 +-
 34 files changed, 225 insertions(+), 216 deletions(-)

diff --git a/mlir/lib/AsmParser/AttributeParser.cpp b/mlir/lib/AsmParser/AttributeParser.cpp
index 4ef4c52d992f0..23cdc3f63a74e 100644
--- a/mlir/lib/AsmParser/AttributeParser.cpp
+++ b/mlir/lib/AsmParser/AttributeParser.cpp
@@ -42,6 +42,7 @@ using namespace mlir::detail;
 ///                      `:` (tensor-type | vector-type)
 ///                    | `strided` `<` `[` comma-separated-int-or-question `]`
 ///                      (`,` `offset` `:` integer-literal)? `>`
+///                    | `#loc` `(` location-instance `)`
 ///                    | distinct-attribute
 ///                    | extended-attribute
 ///
@@ -112,8 +113,21 @@ Attribute Parser::parseAttribute(Type type) {
   }
 
   // Parse an extended attribute, i.e. alias or dialect attribute.
-  case Token::hash_identifier:
+  case Token::hash_identifier: {
+    const char *tokenEnd = getTokenSpelling().end();
+    if (getTokenSpelling() == "#loc" && tokenEnd != state.lex.getBufferEnd() &&
+        *tokenEnd == '(') {
+      consumeToken(Token::hash_identifier);
+
+      LocationAttr locAttr;
+      if (parseToken(Token::l_paren, "expected '(' in location attribute") ||
+          parseLocationInstance(locAttr) ||
+          parseToken(Token::r_paren, "expected ')' in location attribute"))
+        return Attribute();
+      return locAttr;
+    }
     return parseExtendedAttr(type);
+  }
 
   // Parse floating point and integer attributes.
   case Token::floatliteral:
@@ -132,18 +146,6 @@ Attribute Parser::parseAttribute(Type type) {
             nullptr);
   }
 
-  // Parse a location attribute.
-  case Token::kw_loc: {
-    consumeToken(Token::kw_loc);
-
-    LocationAttr locAttr;
-    if (parseToken(Token::l_paren, "expected '(' in inline location") ||
-        parseLocationInstance(locAttr) ||
-        parseToken(Token::r_paren, "expected ')' in inline location"))
-      return Attribute();
-    return locAttr;
-  }
-
   // Parse a sparse elements attribute.
   case Token::kw_sparse:
     return parseSparseElementsAttr(type);
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 81455699421cc..266f60b4f4812 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -2551,7 +2551,9 @@ void AsmPrinter::Impl::printAttributeImpl(Attribute attr,
     printResourceHandle(resourceAttr.getRawHandle());
     os << ">";
   } else if (auto locAttr = llvm::dyn_cast<LocationAttr>(attr)) {
-    printLocation(locAttr);
+    os << "#loc(";
+    printLocationInternal(locAttr, /*pretty=*/false, /*isTopLevel=*/true);
+    os << ')';
   } else {
     llvm::report_fatal_error("Unknown builtin attribute");
   }
diff --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir
index 5304abfb09a1e..78786ee500e1f 100644
--- a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir
+++ b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir
@@ -10,8 +10,8 @@
   file = #di_file, subprogramFlags = "Definition"
 >
 
-// CHECK-DAG: [[LOC:#[a-zA-Z0-9_]+]] = loc("foo.mlir":0:0)
-#loc = loc("foo.mlir":0:0)
+// CHECK-DAG: [[LOC:#[a-zA-Z0-9_]+]] = #loc("foo.mlir":0:0)
+#loc = #loc("foo.mlir":0:0)
 
 // Check that debug info metadata from the function is removed from the global location.
 gpu.module @test_module_1 {
diff --git a/mlir/test/Dialect/Builtin/Bytecode/attrs.mlir b/mlir/test/Dialect/Builtin/Bytecode/attrs.mlir
index 0f5643aa3bb43..9a7533fbcfe1a 100644
--- a/mlir/test/Dialect/Builtin/Bytecode/attrs.mlir
+++ b/mlir/test/Dialect/Builtin/Bytecode/attrs.mlir
@@ -145,8 +145,8 @@ module @TestDistinct attributes {
 
 // CHECK-LABEL: @TestLocCallSite
 module @TestLocCallSite attributes {
-  // CHECK: bytecode.loc = loc(callsite("foo" at "mysource.cc":10:8))
-  bytecode.loc = loc(callsite("foo" at "mysource.cc":10:8))
+  // CHECK: bytecode.loc = #loc(callsite("foo" at "mysource.cc":10:8))
+  bytecode.loc = #loc(callsite("foo" at "mysource.cc":10:8))
 } {}
 
 //===----------------------------------------------------------------------===//
@@ -155,8 +155,8 @@ module @TestLocCallSite attributes {
 
 // CHECK-LABEL: @TestLocFileLineCol
 module @TestLocFileLineCol attributes {
-  // CHECK: bytecode.loc = loc("mysource.cc":10:8)
-  bytecode.loc = loc("mysource.cc":10:8)
+  // CHECK: bytecode.loc = #loc("mysource.cc":10:8)
+  bytecode.loc = #loc("mysource.cc":10:8)
 } {}
 
 //===----------------------------------------------------------------------===//
@@ -165,10 +165,10 @@ module @TestLocFileLineCol attributes {
 
 // CHECK-LABEL: @TestLocFused
 module @TestLocFused attributes {
-  // CHECK: bytecode.loc = loc(fused["foo", "mysource.cc":10:8])
-  // CHECK: bytecode.loc2 = loc(fused<"myPass">["foo", "foo2"])
-  bytecode.loc = loc(fused["foo", "mysource.cc":10:8]),
-  bytecode.loc2 = loc(fused<"myPass">["foo", "foo2"])
+  // CHECK: bytecode.loc = #loc(fused["foo", "mysource.cc":10:8])
+  // CHECK: bytecode.loc2 = #loc(fused<"myPass">["foo", "foo2"])
+  bytecode.loc = #loc(fused["foo", "mysource.cc":10:8]),
+  bytecode.loc2 = #loc(fused<"myPass">["foo", "foo2"])
 } {}
 
 //===----------------------------------------------------------------------===//
@@ -177,10 +177,10 @@ module @TestLocFused attributes {
 
 // CHECK-LABEL: @TestLocName
 module @TestLocName attributes {
-  // CHECK: bytecode.loc = loc("foo")
-  // CHECK: bytecode.loc2 = loc("foo"("mysource.cc":10:8))
-  bytecode.loc = loc("foo"),
-  bytecode.loc2 = loc("foo"("mysource.cc":10:8))
+  // CHECK: bytecode.loc = #loc("foo")
+  // CHECK: bytecode.loc2 = #loc("foo"("mysource.cc":10:8))
+  bytecode.loc = #loc("foo"),
+  bytecode.loc2 = #loc("foo"("mysource.cc":10:8))
 } {}
 
 //===----------------------------------------------------------------------===//
@@ -189,6 +189,6 @@ module @TestLocName attributes {
 
 // CHECK-LABEL: @TestLocUnknown
 module @TestLocUnknown attributes {
-  // CHECK: bytecode.loc = loc(unknown)
-  bytecode.loc = loc(unknown)
+  // CHECK: bytecode.loc = #loc(unknown)
+  bytecode.loc = #loc(unknown)
 } {}
diff --git a/mlir/test/Dialect/LLVMIR/add-debuginfo-func-scope.mlir b/mlir/test/Dialect/LLVMIR/add-debuginfo-func-scope.mlir
index 895c3fcb7fb23..315e007dea340 100644
--- a/mlir/test/Dialect/LLVMIR/add-debuginfo-func-scope.mlir
+++ b/mlir/test/Dialect/LLVMIR/add-debuginfo-func-scope.mlir
@@ -6,7 +6,7 @@
 // CHECK: loc(#loc[[LOC:[0-9]+]])
 // CHECK: #di_file = #llvm.di_file<"<unknown>" in "">
 // CHECK: #di_subprogram = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "func_no_debug", linkageName = "func_no_debug", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
-// CHECK: #loc[[LOC]] = loc(fused<#di_subprogram>
+// CHECK: #loc[[LOC]] = #loc(fused<#di_subprogram>
 module {
   llvm.func @func_no_debug() {
     llvm.return loc(unknown)
@@ -31,7 +31,7 @@ module {
 // CHECK: loc(#loc[[LOC:[0-9]+]])
 // CHECK: #di_file = #llvm.di_file<"<unknown>" in "">
 // CHECK: #di_subprogram = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "func_with_debug", linkageName = "func_with_debug", file = #di_file, line = 42, scopeLine = 42, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
-// CHECK: #loc[[LOC]] = loc(fused<#di_subprogram>
+// CHECK: #loc[[LOC]] = #loc(fused<#di_subprogram>
 // CHECK_OTHER_KIND: emissionKind = DebugDirectivesOnly
 module {
   llvm.func @func_with_debug() {
@@ -40,11 +40,11 @@ module {
 } loc(#loc)
 #di_file = #llvm.di_file<"<unknown>" in "">
 #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_normal>
-#loc = loc("foo":0:0)
-#loc1 = loc(unknown)
+#loc = #loc("foo":0:0)
+#loc1 = #loc(unknown)
 #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #di_file, producer = "MLIR", isOptimized = true, emissionKind = LineTablesOnly>
 #di_subprogram = #llvm.di_subprogram<id = distinct[1]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "func_with_debug", linkageName = "func_with_debug", file = #di_file, line = 42, scopeLine = 42, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
-#loc2 = loc(fused<#di_subprogram>[#loc1])
+#loc2 = #loc(fused<#di_subprogram>[#loc1])
 
 // -----
 
@@ -55,11 +55,11 @@ module {
 // CHECK: loc(#loc[[MODULELOC:[0-9]+]])
 // CHECK-DAG: #[[DI_FILE_MODULE:.+]] = #llvm.di_file<"bar.mlir" in "baz">
 // CHECK-DAG: #[[DI_FILE_FUNC:.+]] = #llvm.di_file<"file.mlir" in ""> 
-// CHECK-DAG: #loc[[FUNCFILELOC:[0-9]+]] = loc("file.mlir":9:8)
+// CHECK-DAG: #loc[[FUNCFILELOC:[0-9]+]] = #loc("file.mlir":9:8)
 // CHECK-DAG: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_C, file = #[[DI_FILE_MODULE]], producer = "MLIR", isOptimized = true, emissionKind = LineTablesOnly>
 // CHECK-DAG: #di_subprogram = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #[[DI_FILE_FUNC]], name = "propagate_compile_unit", linkageName = "propagate_compile_unit", file = #[[DI_FILE_FUNC]], line = 9, scopeLine = 9, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
-// CHECK-DAG: #loc[[MODULELOC]] = loc(fused<#di_compile_unit>[#loc])
-// CHECK-DAG: #loc[[FUNCLOC]] = loc(fused<#di_subprogram>[#loc[[FUNCFILELOC]]
+// CHECK-DAG: #loc[[MODULELOC]] = #loc(fused<#di_compile_unit>[#loc])
+// CHECK-DAG: #loc[[FUNCLOC]] = #loc(fused<#di_subprogram>[#loc[[FUNCFILELOC]]
 module {
   llvm.func @propagate_compile_unit() {
     llvm.return loc(unknown)
@@ -67,7 +67,7 @@ module {
 } loc(#loc)
 #di_file = #llvm.di_file<"bar.mlir" in "baz">
 #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #di_file, producer = "MLIR", isOptimized = true, emissionKind = LineTablesOnly>
-#loc = loc(fused<#di_compile_unit>["foo.mlir":2:1])
+#loc = #loc(fused<#di_compile_unit>["foo.mlir":2:1])
 
 // -----
 
@@ -91,16 +91,16 @@ module @multiple_funcs {
 // CHECK: #di_file1 = #llvm.di_file<"gpu_test.py" in "">
 // CHECK: #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_normal>
 // CHECK: #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #di_file, producer = "MLIR", isOptimized = true, emissionKind = LineTablesOnly>
-// CHECK: #loc3 = loc(callsite(#loc1 at #loc2))
+// CHECK: #loc3 = #loc(callsite(#loc1 at #loc2))
 // CHECK: #di_subprogram = #llvm.di_subprogram<id = distinct[1]<>, compileUnit = #di_compile_unit, scope = #di_file1, name = "func_inlined", linkageName = "func_inlined", file = #di_file1, line = 1150, scopeLine = 1150, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
 // CHECK: #di_lexical_block_file = #llvm.di_lexical_block_file<scope = #di_subprogram, file = #di_file, discriminator = 0>
 
 
-#loc = loc("gpu_test.py":1150:34 to :43)
-#loc1 = loc("testing/parameterized.py":321:17 to :53)
-#loc2 = loc("testing/base.py":2904:19 to :56)
-#loc_1 = loc(callsite(#loc at #loc1))
-#loc21 = loc(callsite(#loc2 at #loc_1))
+#loc = #loc("gpu_test.py":1150:34 to :43)
+#loc1 = #loc("testing/parameterized.py":321:17 to :53)
+#loc2 = #loc("testing/base.py":2904:19 to :56)
+#loc_1 = #loc(callsite(#loc at #loc1))
+#loc21 = #loc(callsite(#loc2 at #loc_1))
 
 module {
   llvm.func @func_inlined() {
@@ -151,8 +151,8 @@ module {
 // CHECK: #di_subprogram = #llvm.di_subprogram<id = distinct[1]<>, compileUnit = #di_compile_unit, scope = #di_file1, name = "func_cross_file_op", linkageName = "func_cross_file_op", file = #di_file1, line = 5, scopeLine = 5, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
 // CHECK: #di_lexical_block_file = #llvm.di_lexical_block_file<scope = #di_subprogram, file = #di_file2, discriminator = 0>
 
-#loc = loc("caller.py":5:1)
-#loc1 = loc("callee.py":10:5)
+#loc = #loc("caller.py":5:1)
+#loc1 = #loc("callee.py":10:5)
 
 module {
   llvm.func @func_cross_file_op() {
@@ -169,6 +169,6 @@ func.func @test_func() {
   return
 } loc(#loc2)
 
-#loc = loc("a.py":1150:34)
-#loc1 = loc("b.py":321:17)
-#loc2 = loc(callsite(#loc at #loc1))
+#loc = #loc("a.py":1150:34)
+#loc1 = #loc("b.py":321:17)
+#loc2 = #loc(callsite(#loc at #loc1))
diff --git a/mlir/test/Dialect/LLVMIR/bytecode.mlir b/mlir/test/Dialect/LLVMIR/bytecode.mlir
index 821b0ac2196a5..070739c6d425e 100644
--- a/mlir/test/Dialect/LLVMIR/bytecode.mlir
+++ b/mlir/test/Dialect/LLVMIR/bytecode.mlir
@@ -3,10 +3,10 @@
 #access_group = #llvm.access_group<id = distinct[0]<>>
 #access_group1 = #llvm.access_group<id = distinct[1]<>>
 #di_subprogram = #llvm.di_subprogram<recId = distinct[2]<>>
-#loc1 = loc("test.f90":12:14)
-#loc2 = loc("test":4:3)
-#loc6 = loc(fused<#di_subprogram>[#loc1])
-#loc7 = loc(fused<#di_subprogram>[#loc2])
+#loc1 = #loc("test.f90":12:14)
+#loc2 = #loc("test":4:3)
+#loc6 = #loc(fused<#di_subprogram>[#loc1])
+#loc7 = #loc(fused<#di_subprogram>[#loc2])
 #loop_annotation = #llvm.loop_annotation<disableNonforced = false, mustProgress = true, startLoc = #loc6, endLoc = #loc7, parallelAccesses = #access_group, #access_group1>
 module {
   llvm.func @imp_fn() {
@@ -20,10 +20,10 @@ module {
 } loc(#loc)
 #di_file = #llvm.di_file<"test.f90" in "">
 #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_program>
-#loc = loc("test":0:0)
-#loc3 = loc("test-path":36:3)
-#loc4 = loc("test-path":37:5)
-#loc5 = loc("test-path":39:5)
+#loc = #loc("test":0:0)
+#loc3 = #loc("test-path":36:3)
+#loc4 = #loc("test-path":37:5)
+#loc5 = #loc("test-path":39:5)
 #di_compile_unit = #llvm.di_compile_unit<id = distinct[3]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, isOptimized = false, emissionKind = Full>
 #di_compile_unit1 = #llvm.di_compile_unit<id = distinct[4]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, isOptimized = false, emissionKind = Full>
 #di_compile_unit2 = #llvm.di_compile_unit<id = distinct[5]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, isOptimized = false, emissionKind = Full>
@@ -32,4 +32,4 @@ module {
 #di_imported_entity = #llvm.di_imported_entity<tag = DW_TAG_imported_module, scope = #di_subprogram, entity = #di_module, file = #di_file, line = 1>
 #di_imported_entity1 = #llvm.di_imported_entity<tag = DW_TAG_imported_module, scope = #di_subprogram, entity = #di_module1, file = #di_file, line = 1>
 #di_subprogram1 = #llvm.di_subprogram<recId = distinct[2]<>, id = distinct[6]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "imp_fn", file = #di_file, subprogramFlags = Definition, type = #di_subroutine_type, retainedNodes = #di_imported_entity, #di_imported_entity1>
-#loc8 = loc(fused<#di_subprogram1>[#loc1])
+#loc8 = #loc(fused<#di_subprogram1>[#loc1])
diff --git a/mlir/test/Dialect/LLVMIR/call-location.mlir b/mlir/test/Dialect/LLVMIR/call-location.mlir
index 4a98c9e8d720a..9e0718e4b67bd 100644
--- a/mlir/test/Dialect/LLVMIR/call-location.mlir
+++ b/mlir/test/Dialect/LLVMIR/call-location.mlir
@@ -15,11 +15,11 @@
   name = "invalid_call_debug_locs", file = #di_file,
   subprogramFlags = "Definition|Optimized"
 >
-#loc = loc(unknown)
-#loc1 = loc("file.cpp":24:0)
-#loc2 = loc(fused<#di_subprogram>[#loc1])
-#loc3 = loc("file.cpp":42:0)
-#loc4 = loc(fused<#di_subprogram1>[#loc3])
+#loc = #loc(unknown)
+#loc1 = #loc("file.cpp":24:0)
+#loc2 = #loc(fused<#di_subprogram>[#loc1])
+#loc3 = #loc("file.cpp":42:0)
+#loc4 = #loc(fused<#di_subprogram1>[#loc3])
 
 llvm.func @external_func() loc(#loc2)
 
diff --git a/mlir/test/Dialect/LLVMIR/di-expression-legalization.mlir b/mlir/test/Dialect/LLVMIR/di-expression-legalization.mlir
index 9280154ad557a..713f3552c17f9 100644
--- a/mlir/test/Dialect/LLVMIR/di-expression-legalization.mlir
+++ b/mlir/test/Dialect/LLVMIR/di-expression-legalization.mlir
@@ -26,7 +26,7 @@
 #var1 = #llvm.di_local_variable<scope = #di_subprogram, name = "struct1_var", file = #di_file, line = 10, alignInBits = 32, type = #struct1>
 #var2 = #llvm.di_local_variable<scope = #di_subprogram, name = "struct2_var", file = #di_file, line = 10, alignInBits = 32, type = #struct2>
 
-#loc = loc("test.mlir":0:0)
+#loc = #loc("test.mlir":0:0)
 
 llvm.func @merge_fragments(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr) {
   // CHECK-OPT: #llvm.di_expression<[DW_OP_deref, DW_OP_LLVM_fragment(32, 32)]>
diff --git a/mlir/test/Dialect/LLVMIR/inlining-debuginfo.mlir b/mlir/test/Dialect/LLVMIR/inlining-debuginfo.mlir
index 97a9f9f0a3d06..fef6b4a622c78 100644
--- a/mlir/test/Dialect/LLVMIR/inlining-debuginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/inlining-debuginfo.mlir
@@ -18,4 +18,4 @@ llvm.func @test_byval() {
   llvm.return
 }
 
-// CHECK: #[[LOC]] = loc("inlining-debuginfo.mlir":14:2)
+// CHECK: #[[LOC]] = #loc("inlining-debuginfo.mlir":14:2)
diff --git a/mlir/test/Dialect/LLVMIR/inlining-loop-annotation.mlir b/mlir/test/Dialect/LLVMIR/inlining-loop-annotation.mlir
index e218c151400c7..83ece49d5e27b 100644
--- a/mlir/test/Dialect/LLVMIR/inlining-loop-annotation.mlir
+++ b/mlir/test/Dialect/LLVMIR/inlining-loop-annotation.mlir
@@ -2,13 +2,13 @@
 
 #di_file = #llvm.di_file<"file.mlir" in "/">
 
-// CHECK: #[[START_ORIGINAL:.*]] = loc({{.*}}:42
-#loc1 = loc("test.mlir":42:4)
-// CHECK: #[[END_ORIGINAL:.*]] = loc({{.*}}:52
-#loc2 = loc("test.mlir":52:4)
-#loc3 = loc("test.mlir":62:4)
-// CHECK: #[[CALL_ORIGINAL:.*]] = loc({{.*}}:72
-#loc4 = loc("test.mlir":72:4)
+// CHECK: #[[START_ORIGINAL:.*]] = #loc({{.*}}:42
+#loc1 = #loc("test.mlir":42:4)
+// CHECK: #[[END_ORIGINAL:.*]] = #loc({{.*}}:52
+#loc2 = #loc("test.mlir":52:4)
+#loc3 = #loc("test.mlir":62:4)
+// CHECK: #[[CALL_ORIGINAL:.*]] = #loc({{.*}}:72
+#loc4 = #loc("test.mlir":72:4)
 
 #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #di_file, isOptimized = false, emissionKind = None>
 // CHECK: #[[CALLEE_DI:.*]] = #llvm.di_subprogram<{{.*}}, name = "callee"
@@ -17,22 +17,22 @@
 // CHECK: #[[CALLER_DI:.*]] = #llvm.di_subprogram<{{.*}}, name = "caller"
 #di_subprogram_caller = #llvm.di_subprogram<compileUnit = #di_compile_unit, scope = #di_file, name = "caller", file = #di_file, subprogramFlags = Definition>
 
-// CHECK: #[[START_FUSED_ORIGINAL:.*]] = loc(fused<#[[CALLEE_DI]]>[#[[START_ORIGINAL]]
-#start_loc_fused = loc(fused<#di_subprogram_callee>[#loc1])
-// CHECK: #[[END_FUSED_ORIGINAL:.*]] = loc(fused<#[[CALLEE_DI]]>[#[[END_ORIGINAL]]
-#end_loc_fused= loc(fused<#di_subprogram_callee>[#loc2])
-#caller_loc= loc(fused<#di_subprogram_caller>[#loc3])
-// CHECK: #[[CALL_FUSED:.*]] = loc(fused<#[[CALLER_DI]]>[#[[CALL_ORIGINAL]]
-#call_loc= loc(fused<#di_subprogram_caller>[#loc4])
+// CHECK: #[[START_FUSED_ORIGINAL:.*]] = #loc(fused<#[[CALLEE_DI]]>[#[[START_ORIGINAL]]
+#start_loc_fused = #loc(fused<#di_subprogram_callee>[#loc1])
+// CHECK: #[[END_FUSED_ORIGINAL:.*]] = #loc(fused<#[[CALLEE_DI]]>[#[[END_ORIGINAL]]
+#end_loc_fused= #loc(fused<#di_subprogram_callee>[#loc2])
+#caller_loc= #loc(fused<#di_subprogram_caller>[#loc3])
+// CHECK: #[[CALL_FUSED:.*]] = #loc(fused<#[[CALLER_DI]]>[#[[CALL_ORIGINAL]]
+#call_loc= #loc(fused<#di_subprogram_caller>[#loc4])
 
 #loopMD = #llvm.loop_annotation<
         startLoc = #start_loc_fused,
         endLoc = #end_loc_fused>
 
-// CHECK: #[[START_CALLSITE_LOC:.*]] = loc(callsite(#[[START_FUSED_ORIGINAL]] at #[[CALL_FUSED]]
-// CHECK: #[[END_CALLSITE_LOC:.*]] = loc(callsite(#[[END_FUSED_ORIGINAL]] at #[[CALL_FUSED]]
-// CHECK: #[[START_FUSED_LOC:.*]] = loc(fused<#[[CALLER_DI]]>[#[[START_CALLSITE_LOC]]
-// CHECK: #[[END_FUSED_LOC:.*]] = loc(fused<#[[CALLER_DI]]>[
+// CHECK: #[[START_CALLSITE_LOC:.*]] = #loc(callsite(#[[START_FUSED_ORIGINAL]] at #[[CALL_FUSED]]
+// CHECK: #[[END_CALLSITE_LOC:.*]] = #loc(callsite(#[[END_FUSED_ORIGINAL]] at #[[CALL_FUSED]]
+// CHECK: #[[START_FUSED_LOC:.*]] = #loc(fused<#[[CALLER_DI]]>[#[[START_CALLSITE_LOC]]
+// CHECK: #[[END_FUSED_LOC:.*]] = #loc(fused<#[[CALLER_DI]]>[
 // CHECK: #[[LOOP_ANNOT:.*]] = #llvm.loop_annotation<
 // CHECK-SAME: startLoc = #[[START_FUSED_LOC]], endLoc = #[[END_FUSED_LOC]]>
 
diff --git a/mlir/test/Dialect/LLVMIR/invalid-call-location.mlir b/mlir/test/Dialect/LLVMIR/invalid-call-location.mlir
index 38b4ed9f6e83d..28a0af31a2934 100644
--- a/mlir/test/Dialect/LLVMIR/invalid-call-location.mlir
+++ b/mlir/test/Dialect/LLVMIR/invalid-call-location.mlir
@@ -18,11 +18,11 @@
   name = "invalid_call_debug_locs", file = #di_file,
   subprogramFlags = "Definition|Optimized"
 >
-#loc = loc(unknown)
-#loc1 = loc("file.cpp":24:0)
-#loc2 = loc(fused<#di_subprogram>[#loc1])
-#loc3 = loc("file.cpp":42:0)
-#loc4 = loc(fused<#di_subprogram1>[#loc3])
+#loc = #loc(unknown)
+#loc1 = #loc("file.cpp":24:0)
+#loc2 = #loc(fused<#di_subprogram>[#loc1])
+#loc3 = #loc("file.cpp":42:0)
+#loc4 = #loc(fused<#di_subprogram1>[#loc3])
 
 llvm.func @missing_debug_loc() {
   llvm.return
diff --git a/mlir/test/Dialect/LLVMIR/loop-metadata.mlir b/mlir/test/Dialect/LLVMIR/loop-metadata.mlir
index 6b4c3217d5c72..678c509521f77 100644
--- a/mlir/test/Dialect/LLVMIR/loop-metadata.mlir
+++ b/mlir/test/Dialect/LLVMIR/loop-metadata.mlir
@@ -85,19 +85,19 @@ llvm.func @loop_annotation() {
 
 #di_file = #llvm.di_file<"metadata-loop.ll" in "/">
 
-// CHECK-DAG: #[[START_LOC:.*]] = loc("loop-metadata.mlir":42:4)
-#loc1 = loc("loop-metadata.mlir":42:4)
-// CHECK-DAG: #[[END_LOC:.*]] = loc("loop-metadata.mlir":52:4)
-#loc2 = loc("loop-metadata.mlir":52:4)
+// CHECK-DAG: #[[START_LOC:.*]] = #loc("loop-metadata.mlir":42:4)
+#loc1 = #loc("loop-metadata.mlir":42:4)
+// CHECK-DAG: #[[END_LOC:.*]] = #loc("loop-metadata.mlir":52:4)
+#loc2 = #loc("loop-metadata.mlir":52:4)
 
 #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #di_file, isOptimized = false, emissionKind = None>
 // CHECK-DAG: #[[SUBPROGRAM:.*]] = #llvm.di_subprogram<
 #di_subprogram = #llvm.di_subprogram<compileUnit = #di_compile_unit, scope = #di_file, name = "loop_locs", file = #di_file, subprogramFlags = Definition>
 
-// CHECK-DAG: #[[START_LOC_FUSED:.*]] = loc(fused<#[[SUBPROGRAM]]>[#[[START_LOC]]]
-#start_loc_fused = loc(fused<#di_subprogram>[#loc1])
-// CHECK-DAG: #[[END_LOC_FUSED:.*]] = loc(fused<#[[SUBPROGRAM]]>[#[[END_LOC]]]
-#end_loc_fused= loc(fused<#di_subprogram>[#loc2])
+// CHECK-DAG: #[[START_LOC_FUSED:.*]] = #loc(fused<#[[SUBPROGRAM]]>[#[[START_LOC]]]
+#start_loc_fused = #loc(fused<#di_subprogram>[#loc1])
+// CHECK-DAG: #[[END_LOC_FUSED:.*]] = #loc(fused<#[[SUBPROGRAM]]>[#[[END_LOC]]]
+#end_loc_fused= #loc(fused<#di_subprogram>[#loc2])
 
 // CHECK-DAG: #[[GROUP1:.*]] = #llvm.access_group<id = {{.*}}>
 // CHECK-DAG: #[[GROUP2:.*]] = #llvm.access_group<id = {{.*}}>
diff --git a/mlir/test/Dialect/Transform/test-interpreter-printing.mlir b/mlir/test/Dialect/Transform/test-interpreter-printing.mlir
index a54c83d2b249e..29d4e1757c4b3 100644
--- a/mlir/test/Dialect/Transform/test-interpreter-printing.mlir
+++ b/mlir/test/Dialect/Transform/test-interpreter-printing.mlir
@@ -17,7 +17,7 @@ module attributes {transform.with_named_sequence} {
     // CHECK-LABEL{LITERAL}: [[[ IR printer: START top-level ]]]
     // CHECK-NEXT:  module {
     // CHECK-LOC-LABEL{LITERAL}: [[[ IR printer: START top-level ]]]
-    // CHECK-LOC-NEXT:  #{{.+}} = loc(
+    // CHECK-LOC-NEXT:  #{{.+}} = #loc(
     // CHECK-LOC-NEXT:  module {
     transform.print {name = "START"}
 
diff --git a/mlir/test/IR/diagnostic-handler-filter.mlir b/mlir/test/IR/diagnostic-handler-filter.mlir
index 39374a919fb95..f13988ce00723 100644
--- a/mlir/test/IR/diagnostic-handler-filter.mlir
+++ b/mlir/test/IR/diagnostic-handler-filter.mlir
@@ -5,7 +5,7 @@
 // CHECK-NEXT: mysource2:1:0: error: test diagnostic
 // CHECK-NEXT: mysource3:2:0: note: called from
 func.func private @test1() attributes {
-  test.loc = loc(callsite("foo"("mysource1":0:0) at callsite("mysource2":1:0 at "mysource3":2:0)))
+  test.loc = #loc(callsite("foo"("mysource1":0:0) at callsite("mysource2":1:0 at "mysource3":2:0)))
 }
 
 // -----
@@ -13,5 +13,5 @@ func.func private @test1() attributes {
 // CHECK-LABEL: Test 'test2'
 // CHECK-NEXT: mysource1:0:0: error: test diagnostic
 func.func private @test2() attributes {
-  test.loc = loc("mysource1":0:0)
+  test.loc = #loc("mysource1":0:0)
 }
diff --git a/mlir/test/IR/loc-attr-disambiguation.mlir b/mlir/test/IR/loc-attr-disambiguation.mlir
index 0111cd0eb7d51..48d29335181fd 100644
--- a/mlir/test/IR/loc-attr-disambiguation.mlir
+++ b/mlir/test/IR/loc-attr-disambiguation.mlir
@@ -1,15 +1,19 @@
-// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+// RUN: mlir-opt %s -mlir-print-debuginfo | mlir-opt -mlir-print-debuginfo | FileCheck %s
 
-// Verify that forward-referencing loc() aliases are not consumed by
-// parseOptionalAttribute when probing for optional attribute groups.
+// Verify that location attributes use #loc(...) and do not conflict with
+// trailing loc(...) specifiers in optional assembly format groups.
 
-// CHECK-LABEL: @loc_forward_ref_with_optional_group
-func.func @loc_forward_ref_with_optional_group() {
-  // CHECK: test.optional_loc_group
-  test.optional_loc_group loc(#loc_fwd)
-  // CHECK: test.optional_loc_group 42 : i64
-  test.optional_loc_group 42 : i64 loc(#loc_fwd)
+// CHECK-LABEL: @loc_attr_disambiguation
+func.func @loc_attr_disambiguation() {
+  // CHECK: test.optional_loc_group #{{.*}} loc(#{{.*}})
+  test.optional_loc_group #loc("attr_loc") loc(#loc_base)
+  // CHECK: test.optional_loc_group #{{.*}} loc(#{{.*}})
+  test.optional_loc_group #loc("attr_loc") loc(#loc_trailing)
+  // CHECK: test.optional_loc_group loc(#{{.*}})
+  test.optional_loc_group loc(#loc_trailing)
+  // CHECK: test.optional_loc_group 42 : i64 loc(#{{.*}})
+  test.optional_loc_group 42 : i64 loc(#loc_trailing)
   return
 } loc(#loc_base)
-#loc_base = loc(unknown)
-#loc_fwd = loc("forward_ref_test"(#loc_base))
+#loc_base = #loc(unknown)
+#loc_trailing = #loc("trailing_loc")
diff --git a/mlir/test/IR/locations.mlir b/mlir/test/IR/locations.mlir
index 2e2374629f0f9..e83e05f3ae0d4 100644
--- a/mlir/test/IR/locations.mlir
+++ b/mlir/test/IR/locations.mlir
@@ -30,17 +30,17 @@ func.func @inline_notation() -> i32 {
   return %1 : i32 loc(unknown)
 }
 
-// CHECK-LABEL: func private @loc_attr(i1 {foo.loc_attr = loc(callsite("foo" at "mysource.cc":10:8))})
-func.func private @loc_attr(i1 {foo.loc_attr = loc(callsite("foo" at "mysource.cc":10:8))})
-
-// CHECK-LABEL: func.func private @filelocrange_attr1(i1 {foo.loc_attr = loc("mysource.cc":10:0)})
-func.func private @filelocrange_attr1(i1 {foo.loc_attr = loc("mysource.cc":10)})
-// CHECK-LABEL: func.func private @filelocrange_attr2(i1 {foo.loc_attr = loc("mysource.cc":10:8)})
-func.func private @filelocrange_attr2(i1 {foo.loc_attr = loc("mysource.cc":10:8)})
-// CHECK-LABEL: func.func private @filelocrange_attr3(i1 {foo.loc_attr = loc("mysource.cc":10:8 to :12)})
-func.func private @filelocrange_attr3(i1 {foo.loc_attr = loc("mysource.cc":10:8 to :12)})
-// CHECK-LABEL: func.func private @filelocrange_attr4(i1 {foo.loc_attr = loc("mysource.cc":10:8 to 12:4)})
-func.func private @filelocrange_attr4(i1 {foo.loc_attr = loc("mysource.cc":10:8 to 12:4)})
+// CHECK-LABEL: func private @loc_attr(i1 {foo.loc_attr = #loc(callsite("foo" at "mysource.cc":10:8))})
+func.func private @loc_attr(i1 {foo.loc_attr = #loc(callsite("foo" at "mysource.cc":10:8))})
+
+// CHECK-LABEL: func.func private @filelocrange_attr1(i1 {foo.loc_attr = #loc("mysource.cc":10:0)})
+func.func private @filelocrange_attr1(i1 {foo.loc_attr = #loc("mysource.cc":10)})
+// CHECK-LABEL: func.func private @filelocrange_attr2(i1 {foo.loc_attr = #loc("mysource.cc":10:8)})
+func.func private @filelocrange_attr2(i1 {foo.loc_attr = #loc("mysource.cc":10:8)})
+// CHECK-LABEL: func.func private @filelocrange_attr3(i1 {foo.loc_attr = #loc("mysource.cc":10:8 to :12)})
+func.func private @filelocrange_attr3(i1 {foo.loc_attr = #loc("mysource.cc":10:8 to :12)})
+// CHECK-LABEL: func.func private @filelocrange_attr4(i1 {foo.loc_attr = #loc("mysource.cc":10:8 to 12:4)})
+func.func private @filelocrange_attr4(i1 {foo.loc_attr = #loc("mysource.cc":10:8 to 12:4)})
 
   // Check that locations get properly escaped.
 // CHECK-LABEL: func @escape_strings()
@@ -89,8 +89,8 @@ func.func @location_name_child_is_name() {
   return loc("foo"("foo"))
 }
 
-// CHECK-ALIAS: #[[LOC]] = loc("out_of_line_location")
-#loc = loc("out_of_line_location")
+// CHECK-ALIAS: #[[LOC]] = #loc("out_of_line_location")
+#loc = #loc("out_of_line_location")
 
 // CHECK-LABEL: @optional_location_specifier
 // CHECK: test.attr_with_loc("foo" loc("foo_loc"))
@@ -107,8 +107,8 @@ func.func @dialect_location() {
 }
 
 // CHECK-LABEL: @location_attr
-// CHECK: test.op_with_loc_attr loc("loc1":10:20) {foo.discardable_loc_attr = loc("loc2":20:30)} loc({{.*}}locations.mlir":[[# @LINE+2]]:3)
+// CHECK: test.op_with_loc_attr #loc("loc1":10:20) {foo.discardable_loc_attr = #loc("loc2":20:30)} loc({{.*}}locations.mlir":[[# @LINE+2]]:3)
 func.func @location_attr() {
-  test.op_with_loc_attr loc("loc1":10:20) {foo.discardable_loc_attr = loc("loc2":20:30)}
+  test.op_with_loc_attr #loc("loc1":10:20) {foo.discardable_loc_attr = #loc("loc2":20:30)}
   return
 }
diff --git a/mlir/test/IR/print-attr-type-aliases.mlir b/mlir/test/IR/print-attr-type-aliases.mlir
index fcac62cab91f9..4e445cfab28c0 100644
--- a/mlir/test/IR/print-attr-type-aliases.mlir
+++ b/mlir/test/IR/print-attr-type-aliases.mlir
@@ -38,17 +38,17 @@
 // CHECK-DAG: tensor<32x!test_ui8>
 "test.op"() : () -> tensor<32x!test.int<unsigned, 8>>
 
-// CHECK-DAG: #[[LOC_NESTED:.+]] = loc("nested")
-// CHECK-DAG: #[[LOC_RAW:.+]] = loc("test.mlir":10:8)
-// CHECK-DAG: = loc(fused<#[[LOC_NESTED]]>[#[[LOC_RAW]]])
-"test.op"() {alias_test = loc(fused<loc("nested")>["test.mlir":10:8])} : () -> ()
+// CHECK-DAG: #[[LOC_NESTED:.+]] = #loc("nested")
+// CHECK-DAG: #[[LOC_RAW:.+]] = #loc("test.mlir":10:8)
+// CHECK-DAG: = #loc(fused<#[[LOC_NESTED]]>[#[[LOC_RAW]]])
+"test.op"() {alias_test = #loc(fused<#loc("nested")>["test.mlir":10:8])} : () -> ()
 
 // -----
 
 // Check proper ordering of intermixed attribute/type aliases.
 // CHECK: !tuple = tuple<
-// CHECK: = loc(fused<!tuple
-"test.op"() {alias_test = loc(fused<tuple<i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32>>["test.mlir":10:8])} : () -> ()
+// CHECK: = #loc(fused<!tuple
+"test.op"() {alias_test = #loc(fused<tuple<i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32>>["test.mlir":10:8])} : () -> ()
 
 // -----
 
@@ -60,9 +60,9 @@
 // -----
 
 // Check that we don't print aliases for things that aren't printed.
-// CHECK: = loc(fused<memref<1xi32>
+// CHECK: = #loc(fused<memref<1xi32>
 // CHECK-NOT: #map
-"test.op"() {alias_test = loc(fused<memref<1xi32, affine_map<(d0) -> (d0)>>>["test.mlir":10:8])} : () -> ()
+"test.op"() {alias_test = #loc(fused<memref<1xi32, affine_map<(d0) -> (d0)>>>["test.mlir":10:8])} : () -> ()
 
 // -----
 
@@ -84,7 +84,7 @@
 
 #keep_aliased = "alias_test:dot_in_name"
 #cond_alias = #test.conditional_alias<#keep_aliased>
-#no_alias = loc(fused<#cond_alias>["test.mlir":1:1])
+#no_alias = #loc(fused<#cond_alias>["test.mlir":1:1])
 
 // CHECK: #[[TEST_ALIAS:.+]] = "alias_test:dot_in_name"
 // CHECK: fused<#test.conditional_alias<#[[TEST_ALIAS]]>
diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index 331760baae0dc..1b37076411671 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -225,8 +225,8 @@ llvm.func @func_decl_with_subprogram() -> (i32) loc(fused<#di_subprogram>["foo.m
 #di_local_variable1 = #llvm.di_local_variable<scope = #di_lexical_block_file, name = "b", file = #di_file, type = #di_basic_type>
 #di_label = #llvm.di_label<scope = #di_lexical_block_file, name = "label", file = #di_file, line = 42>
 
-#loc0 = loc("foo.mlir":0:0)
-#loc1 = loc(callsite(fused<#di_lexical_block_file>[#loc0] at fused<#di_subprogram>["foo.mlir":4:2]))
+#loc0 = #loc("foo.mlir":0:0)
+#loc1 = #loc(callsite(fused<#di_lexical_block_file>[#loc0] at fused<#di_subprogram>["foo.mlir":4:2]))
 
 // CHECK-LABEL: define i32 @func_with_inlined_dbg_value(
 // CHECK-SAME: i32 %[[ARG:.*]]) !dbg ![[OUTER_FUNC:[0-9]+]]
@@ -261,7 +261,7 @@ llvm.func @func_with_inlined_dbg_value(%arg0: i32) -> (i32) {
   file = #di_file, subprogramFlags = Definition>
 #di_local_variable = #llvm.di_local_variable<scope = #di_subprogram, name = "a", file = #di_file, type = #di_basic_type>
 
-#loc = loc("foo.mlir":0:0)
+#loc = #loc("foo.mlir":0:0)
 
 // CHECK-LABEL: define void @func_without_subprogram(
 // CHECK-SAME: i32 %[[ARG:.*]])
@@ -390,8 +390,8 @@ llvm.func @imp_fn() {
   compileUnit = #di_compile_unit, scope = #di_file, name = "imp_fn",
   file = #di_file, subprogramFlags = Definition, type = #di_subroutine_type,
   retainedNodes = #di_imported_entity_1, #di_imported_entity_2>
-#loc1 = loc("test.f90":12:14)
-#loc2 = loc(fused<#di_subprogram>[#loc1])
+#loc1 = #loc("test.f90":12:14)
+#loc2 = #loc(fused<#di_subprogram>[#loc1])
 
 // CHECK-DAG: ![[SP:[0-9]+]] = {{.*}}!DISubprogram(name: "imp_fn"{{.*}}retainedNodes: ![[NODES:[0-9]+]])
 // CHECK-DAG: ![[NODES]] = !{![[NODE1:[0-9]+]], ![[NODE2:[0-9]+]]}
@@ -481,7 +481,7 @@ llvm.func @func_debug_directives() {
   subprogramFlags = Definition,
   type = #di_subroutine_outer>
 
-#loc3 = loc(fused<#di_subprogram_outer>["test.mlir":1:1])
+#loc3 = #loc(fused<#di_subprogram_outer>["test.mlir":1:1])
 
 // CHECK: @class_method
 // CHECK: ret void, !dbg ![[LOC:.*]]
@@ -622,8 +622,8 @@ llvm.func @fn_with_composite() {
  #llvm.di_generic_subrange<count = #lvar, lowerBound = #gv, stride = #gv>>
 #lvar2 = #llvm.di_local_variable<scope = #sp, name = "var", type = #comp_ty3>
 #lvar3 = #llvm.di_local_variable<scope = #sp, name = "var1", type = #comp_ty4>
-#loc1 = loc("test.f90": 1:1)
-#loc2 = loc(fused<#sp>[#loc1])
+#loc1 = #loc("test.f90": 1:1)
+#loc2 = #loc(fused<#sp>[#loc1])
 
 llvm.mlir.global external @gv() {dbg_exprs = [#gve]} : i64
 
@@ -673,8 +673,8 @@ llvm.func @string_ty(%arg0: !llvm.ptr) {
   llvm.return
 } loc(#loc2)
 
-#loc1 = loc("test.f90":1:1)
-#loc2 = loc(fused<#sp>[#loc1])
+#loc1 = #loc("test.f90":1:1)
+#loc2 = #loc(fused<#sp>[#loc1])
 
 // CHECK-DAG: !DIStringType(name: "character(*)", stringLength: ![[VAR:[0-9]+]], stringLengthExpression: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 8), stringLocationExpression: !DIExpression(DW_OP_push_object_address, DW_OP_deref), size: 32, align: 8)
 // CHECK-DAG: ![[VAR]] = !DILocalVariable(name: "string_size"{{.*}} flags: DIFlagArtificial)
@@ -702,8 +702,8 @@ llvm.func @test() {
   llvm.return
 } loc(#loc2)
 
-#loc1 = loc("test.f90":1:0)
-#loc2 = loc(fused<#sp>[#loc1])
+#loc1 = #loc("test.f90":1:0)
+#loc2 = #loc(fused<#sp>[#loc1])
 
 // CHECK: !DICommonBlock(scope: ![[SCOPE:[0-9]+]], declaration: null, name: "block", file: ![[FILE:[0-9]+]], line: 3)
 // CHECK: ![[SCOPE]] = {{.*}}!DISubprogram(name: "test"{{.*}})
diff --git a/mlir/test/Target/LLVMIR/llvmir-phi-loc.mlir b/mlir/test/Target/LLVMIR/llvmir-phi-loc.mlir
index fd04502605284..92c167cf04d9b 100644
--- a/mlir/test/Target/LLVMIR/llvmir-phi-loc.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-phi-loc.mlir
@@ -20,10 +20,10 @@ llvm.func @test_phi_locations(%arg0: !llvm.ptr)  {
  name = "test_phi_locations", file = #file, subprogramFlags = Definition,
  type = #sp_ty>
 
-#loc1 = loc("test.f90":15:22)
-#loc2 = loc("test.f90":8:2)
-#loc3 = loc("test.f90":9:5)
-#loc4 = loc(fused<#sp>[#loc1])
+#loc1 = #loc("test.f90":15:22)
+#loc2 = #loc("test.f90":8:2)
+#loc3 = #loc("test.f90":9:5)
+#loc4 = #loc(fused<#sp>[#loc1])
 
 // CHECK-LABEL: define void @test_phi_locations
 // CHECK: phi i32{{.*}}!dbg ![[LOC1:[0-9]+]]
diff --git a/mlir/test/Target/LLVMIR/loop-metadata.mlir b/mlir/test/Target/LLVMIR/loop-metadata.mlir
index 2fe4a994aeb66..3148d8a01401f 100644
--- a/mlir/test/Target/LLVMIR/loop-metadata.mlir
+++ b/mlir/test/Target/LLVMIR/loop-metadata.mlir
@@ -294,14 +294,14 @@ llvm.func @loopOptions(%arg1 : i32, %arg2 : i32) {
 
 #di_file = #llvm.di_file<"metadata-loop.ll" in "/">
 
-#loc1 = loc("loop-metadata.mlir":42:4)
-#loc2 = loc("loop-metadata.mlir":52:4)
+#loc1 = #loc("loop-metadata.mlir":42:4)
+#loc2 = #loc("loop-metadata.mlir":52:4)
 
 #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #di_file, isOptimized = false, emissionKind = None>
 #di_subprogram = #llvm.di_subprogram<compileUnit = #di_compile_unit, scope = #di_file, name = "loop_locs", file = #di_file, subprogramFlags = Definition>
 
-#start_loc_fused = loc(fused<#di_subprogram>[#loc1])
-#end_loc_fused= loc(fused<#di_subprogram>[#loc2])
+#start_loc_fused = #loc(fused<#di_subprogram>[#loc1])
+#end_loc_fused= #loc(fused<#di_subprogram>[#loc2])
 
 #loopMD = #llvm.loop_annotation<disableNonforced = false,
         startLoc = #start_loc_fused,
diff --git a/mlir/test/Target/LLVMIR/omptarget-debug-147063.mlir b/mlir/test/Target/LLVMIR/omptarget-debug-147063.mlir
index 12d389adbb388..cc1f95bd015bf 100644
--- a/mlir/test/Target/LLVMIR/omptarget-debug-147063.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-debug-147063.mlir
@@ -37,9 +37,9 @@ module attributes {llvm.target_triple = "x86_64-unknown-linux-gnu", omp.is_gpu =
   name = "target", file = #di_file, subprogramFlags = "Definition",
   type = #di_subroutine_type>
 
-#loc1 = loc("test.f90":7:15)
-#loc2 = loc("test.f90":1:7)
-#loc3 = loc("test.f90":3:7)
-#loc4 = loc("test.f90":16:7)
-#loc6 = loc(fused<#di_subprogram>[#loc1])
-#loc7 = loc(fused<#di_subprogram1>[#loc3])
+#loc1 = #loc("test.f90":7:15)
+#loc2 = #loc("test.f90":1:7)
+#loc3 = #loc("test.f90":3:7)
+#loc4 = #loc("test.f90":16:7)
+#loc6 = #loc(fused<#di_subprogram>[#loc1])
+#loc7 = #loc(fused<#di_subprogram1>[#loc3])
diff --git a/mlir/test/Target/LLVMIR/omptarget-debug-empty.mlir b/mlir/test/Target/LLVMIR/omptarget-debug-empty.mlir
index 45e5d2612e2c2..06da224301ef3 100644
--- a/mlir/test/Target/LLVMIR/omptarget-debug-empty.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-debug-empty.mlir
@@ -18,10 +18,10 @@ module attributes {omp.is_target_device = false} {
 #sp1 = #llvm.di_subprogram<id = distinct[2]<>, compileUnit = #cu, scope = #file,
  name = "__omp_offloading_target", file = #file, subprogramFlags = "Definition",
  type = #sp_ty>
-#loc1 = loc("target.f90":1:1)
-#loc2 = loc("target.f90":46:3)
-#loc3 = loc(fused<#sp>[#loc1])
-#loc4 = loc(fused<#sp1>[#loc2])
+#loc1 = #loc("target.f90":1:1)
+#loc2 = #loc("target.f90":46:3)
+#loc3 = #loc(fused<#sp>[#loc1])
+#loc4 = #loc(fused<#sp1>[#loc2])
 
 // CHECK: ![[SP:.*]] = {{.*}}!DISubprogram(name: "__omp_offloading_target"{{.*}})
 
diff --git a/mlir/test/Target/LLVMIR/omptarget-debug-loop-loc.mlir b/mlir/test/Target/LLVMIR/omptarget-debug-loop-loc.mlir
index aa4c1f0354fdc..2cb6ebf773a46 100644
--- a/mlir/test/Target/LLVMIR/omptarget-debug-loop-loc.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-debug-loop-loc.mlir
@@ -45,17 +45,17 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.alloca_memo
 }
 #di_file = #llvm.di_file<"test.f90" in "">
 #di_null_type = #llvm.di_null_type
-#loc1 = loc("test.f90":4:23)
-#loc2 = loc("test.f90":4:15)
-#loc3 = loc("test.f90":1:7)
-#loc4 = loc("test.f90":4:18)
-#loc9 = loc("test.f90":13:11)
+#loc1 = #loc("test.f90":4:23)
+#loc2 = #loc("test.f90":4:15)
+#loc3 = #loc("test.f90":1:7)
+#loc4 = #loc("test.f90":4:18)
+#loc9 = #loc("test.f90":13:11)
 #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "flang", isOptimized = true, emissionKind = LineTablesOnly>
 #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_program, types = #di_null_type>
 #di_subprogram = #llvm.di_subprogram<id = distinct[1]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "main", file = #di_file, subprogramFlags = "Definition|Optimized|MainSubprogram", type = #di_subroutine_type>
 #di_subprogram1 = #llvm.di_subprogram<compileUnit = #di_compile_unit, name = "target", file = #di_file, subprogramFlags = "Definition", type = #di_subroutine_type>
-#loc14 = loc(fused<#di_subprogram>[#loc3])
-#loc15 = loc(fused<#di_subprogram1>[#loc9])
+#loc14 = #loc(fused<#di_subprogram>[#loc3])
+#loc15 = #loc(fused<#di_subprogram1>[#loc9])
 
 
 // CHECK: call void @__kmpc_distribute_static{{.*}}!dbg
diff --git a/mlir/test/Target/LLVMIR/omptarget-debug-map-link-loc.mlir b/mlir/test/Target/LLVMIR/omptarget-debug-map-link-loc.mlir
index 492610251769c..06d5c3f5ba803 100644
--- a/mlir/test/Target/LLVMIR/omptarget-debug-map-link-loc.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-debug-map-link-loc.mlir
@@ -34,10 +34,10 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.alloca_memo
 #di_subprogram1 = #llvm.di_subprogram<compileUnit = #di_compile_unit,
   name = "target", file = #di_file, subprogramFlags = "Definition",
   type = #di_subroutine_type>
-#loc1 = loc("test.f90":3:18)
-#loc2 = loc("test.f90":7:7)
-#loc3 = loc("test.f90":9:18)
-#loc5 = loc("test.f90":11:7)
-#loc6 = loc("test.f90":12:7)
-#loc15 = loc(fused<#di_subprogram>[#loc2])
-#loc16 = loc(fused<#di_subprogram1>[#loc5])
+#loc1 = #loc("test.f90":3:18)
+#loc2 = #loc("test.f90":7:7)
+#loc3 = #loc("test.f90":9:18)
+#loc5 = #loc("test.f90":11:7)
+#loc6 = #loc("test.f90":12:7)
+#loc15 = #loc(fused<#di_subprogram>[#loc2])
+#loc16 = #loc(fused<#di_subprogram1>[#loc5])
diff --git a/mlir/test/Target/LLVMIR/omptarget-debug-nowait.mlir b/mlir/test/Target/LLVMIR/omptarget-debug-nowait.mlir
index 3bd724f42e8ce..34f66827fe63c 100644
--- a/mlir/test/Target/LLVMIR/omptarget-debug-nowait.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-debug-nowait.mlir
@@ -37,7 +37,7 @@ module attributes {omp.is_target_device = false} {
 #sp1 = #llvm.di_subprogram<compileUnit = #cu, name = "target", file=#file,
  subprogramFlags = "Definition", type = #sp_ty>
 
-#loc1 = loc("test.f90":6:7)
-#loc2 = loc(fused<#sp>[#loc1])
-#loc3 = loc(fused<#sp1>[#loc1])
+#loc1 = #loc("test.f90":6:7)
+#loc2 = #loc(fused<#sp>[#loc1])
+#loc3 = #loc(fused<#sp1>[#loc1])
 
diff --git a/mlir/test/Target/LLVMIR/omptarget-debug-var-1.mlir b/mlir/test/Target/LLVMIR/omptarget-debug-var-1.mlir
index f5ed9646cf33c..dfe9626e3bbf7 100644
--- a/mlir/test/Target/LLVMIR/omptarget-debug-var-1.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-debug-var-1.mlir
@@ -50,11 +50,11 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.alloca_memo
   llvm.mlir.global internal @_QFEarr() {addr_space = 0 : i32, dbg_exprs = [#g_var_expr]} : !llvm.array<10 x i32> {
   } loc(#loc4)
 }
-#loc1 = loc("target.f90":4:7)
-#loc2 = loc("target.f90":11:7)
-#loc3 = loc(fused<#sp>[#loc2])
-#loc4 = loc(fused<#g_var>[#loc1])
-#loc5 = loc(fused<#sp1>[#loc2])
+#loc1 = #loc("target.f90":4:7)
+#loc2 = #loc("target.f90":11:7)
+#loc3 = #loc(fused<#sp>[#loc2])
+#loc4 = #loc(fused<#g_var>[#loc1])
+#loc5 = #loc(fused<#sp1>[#loc2])
 
 // CHECK: ![[SP:[0-9]+]] = distinct !DISubprogram(name: "target"{{.*}})
 // CHECK: !DILocalVariable(name: "dyn_ptr", arg: 1, scope: ![[SP]]{{.*}}flags: DIFlagArtificial)
diff --git a/mlir/test/Target/LLVMIR/omptarget-debug-var-2.mlir b/mlir/test/Target/LLVMIR/omptarget-debug-var-2.mlir
index 11a07dfd9a180..00836af946db4 100644
--- a/mlir/test/Target/LLVMIR/omptarget-debug-var-2.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-debug-var-2.mlir
@@ -53,11 +53,11 @@ module attributes {omp.is_target_device = false} {
   llvm.mlir.global internal @_QFEarr() {addr_space = 0 : i32, dbg_exprs = [#g_var_expr]} : !llvm.array<10 x i32> {
   } loc(#loc4)
 }
-#loc1 = loc("target.f90":4:7)
-#loc2 = loc("target.f90":11:7)
-#loc3 = loc(fused<#sp>[#loc2])
-#loc4 = loc(fused<#g_var>[#loc1])
-#loc5 = loc(fused<#sp1>[#loc2])
+#loc1 = #loc("target.f90":4:7)
+#loc2 = #loc("target.f90":11:7)
+#loc3 = #loc(fused<#sp>[#loc2])
+#loc4 = #loc(fused<#g_var>[#loc1])
+#loc5 = #loc(fused<#sp1>[#loc2])
 
 // CHECK: ![[SP:[0-9]+]] = distinct !DISubprogram(name: "target"{{.*}})
 // CHECK: !DILocalVariable(name: "x", arg: 1, scope: ![[SP]]{{.*}})
diff --git a/mlir/test/Target/LLVMIR/omptarget-debug.mlir b/mlir/test/Target/LLVMIR/omptarget-debug.mlir
index ab687f198b9b4..cb17bf07397e7 100644
--- a/mlir/test/Target/LLVMIR/omptarget-debug.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-debug.mlir
@@ -24,10 +24,10 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.alloca_memo
 #sp1 = #llvm.di_subprogram<id = distinct[2]<>, compileUnit = #cu, scope = #file,
  name = "__omp_offloading_target", file = #file, subprogramFlags = "Definition",
  type = #sp_ty>
-#loc1 = loc("target.f90":1:1)
-#loc2 = loc("target.f90":46:3)
-#loc3 = loc(fused<#sp>[#loc1])
-#loc4 = loc(fused<#sp1>[#loc1])
+#loc1 = #loc("target.f90":1:1)
+#loc2 = #loc("target.f90":46:3)
+#loc3 = #loc(fused<#sp>[#loc1])
+#loc4 = #loc(fused<#sp1>[#loc1])
 
 // CHECK-DAG: ![[SP:.*]] = {{.*}}!DISubprogram(name: "__omp_offloading_target"{{.*}})
 // CHECK-DAG: !DILocation(line: 46, column: 3, scope: ![[SP]])
diff --git a/mlir/test/Target/LLVMIR/omptarget-debug2.mlir b/mlir/test/Target/LLVMIR/omptarget-debug2.mlir
index 6cf75af38f916..28eea62d6bd5c 100644
--- a/mlir/test/Target/LLVMIR/omptarget-debug2.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-debug2.mlir
@@ -25,10 +25,10 @@ module attributes {omp.is_target_device = false} {
 #sp1 = #llvm.di_subprogram<id = distinct[2]<>, compileUnit = #cu, scope = #file,
  name = "__omp_offloading_target", file = #file, subprogramFlags = "Definition",
  type = #sp_ty>
-#loc1 = loc("target.f90":1:1)
-#loc2 = loc("target.f90":46:3)
-#loc3 = loc(fused<#sp>[#loc1])
-#loc4 = loc(fused<#sp1>[#loc1])
+#loc1 = #loc("target.f90":1:1)
+#loc2 = #loc("target.f90":46:3)
+#loc3 = #loc(fused<#sp>[#loc1])
+#loc4 = #loc(fused<#sp1>[#loc1])
 
 // CHECK-DAG: ![[SP:.*]] = {{.*}}!DISubprogram(name: "__omp_offloading_target"{{.*}})
 // CHECK-DAG: !DILocation(line: 46, column: 3, scope: ![[SP]])
diff --git a/mlir/test/Target/LLVMIR/omptarget-parallel-llvm-debug.mlir b/mlir/test/Target/LLVMIR/omptarget-parallel-llvm-debug.mlir
index b18338ea35cc3..7e0d2b0d62773 100644
--- a/mlir/test/Target/LLVMIR/omptarget-parallel-llvm-debug.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-parallel-llvm-debug.mlir
@@ -30,11 +30,11 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<i32 = dense<32> : vector<2xi64>,
     llvm.return
   } loc(#loc10)
 }
-#loc1 = loc("target.f90":1:7)
-#loc2 = loc("target.f90":3:18)
-#loc3 = loc("target.f90":6:18)
-#loc4 = loc(fused<#sp1>[#loc3])
-#loc10 = loc(fused<#sp>[#loc1])
+#loc1 = #loc("target.f90":1:7)
+#loc2 = #loc("target.f90":3:18)
+#loc3 = #loc("target.f90":6:18)
+#loc4 = #loc(fused<#sp1>[#loc3])
+#loc10 = #loc(fused<#sp>[#loc1])
 
 
 // CHECK: define internal void @__omp_offloading{{.*}}omp_par{{.*}} !dbg ![[FN:[0-9]+]] {
diff --git a/mlir/test/Transforms/canonicalize-debuginfo.mlir b/mlir/test/Transforms/canonicalize-debuginfo.mlir
index 5af0023fed801..546d03b881c74 100644
--- a/mlir/test/Transforms/canonicalize-debuginfo.mlir
+++ b/mlir/test/Transforms/canonicalize-debuginfo.mlir
@@ -9,7 +9,7 @@ func.func @merge_constants() -> (index, index, index, index) {
   %3 = arith.constant 42 : index loc("merge_constants":2:0)
   return %0, %1, %2, %3 : index, index, index, index
 }
-// CHECK: #[[UnknownLoc]] = loc(unknown)
+// CHECK: #[[UnknownLoc]] = #loc(unknown)
 
 // -----
 
@@ -26,9 +26,9 @@ func.func @simple_hoist(%arg0: memref<8xi32>) -> i32 {
 
   return %2 : i32
 }
-// CHECK-DAG: #[[ConstLoc0]] = loc("simple_hoist":0:0)
-// CHECK-DAG: #[[ConstLoc1]] = loc("simple_hoist":1:0)
-// CHECK-DAG: #[[ConstLoc2]] = loc("simple_hoist":2:0)
+// CHECK-DAG: #[[ConstLoc0]] = #loc("simple_hoist":0:0)
+// CHECK-DAG: #[[ConstLoc1]] = #loc("simple_hoist":1:0)
+// CHECK-DAG: #[[ConstLoc2]] = #loc("simple_hoist":2:0)
 
 // -----
 
@@ -43,4 +43,4 @@ func.func @hoist_and_merge(%arg0: memref<8xi32>) {
   }
   return
 } loc("hoist_and_merge":2:0)
-// CHECK: #[[UnknownLoc]] = loc(unknown)
+// CHECK: #[[UnknownLoc]] = #loc(unknown)
diff --git a/mlir/test/Transforms/constant-fold-debuginfo.mlir b/mlir/test/Transforms/constant-fold-debuginfo.mlir
index 4fa7fb6698a2b..d4979f06d4ab6 100644
--- a/mlir/test/Transforms/constant-fold-debuginfo.mlir
+++ b/mlir/test/Transforms/constant-fold-debuginfo.mlir
@@ -11,7 +11,7 @@ func.func @fold_and_merge() -> (i32, i32) {
 
   return %2, %3: i32, i32
 }
-// CHECK: #[[UnknownLoc]] = loc(unknown)
+// CHECK: #[[UnknownLoc]] = #loc(unknown)
 
 // -----
 
@@ -24,7 +24,7 @@ func.func @materialize_different_dialect() -> (f32, f32) {
 
   return %1, %2: f32, f32
 }
-// CHECK: #[[UnknownLoc]] = loc(unknown)
+// CHECK: #[[UnknownLoc]] = #loc(unknown)
 
 // -----
 
@@ -39,4 +39,4 @@ func.func @materialize_in_front(%arg0: memref<8xi32>) {
   }
   return
 } loc("materialize_in_front":3:0)
-// CHECK: #[[UnknownLoc]] = loc(unknown)
+// CHECK: #[[UnknownLoc]] = #loc(unknown)
diff --git a/mlir/test/Transforms/inlining.mlir b/mlir/test/Transforms/inlining.mlir
index d8e10aa4212ba..faefb237f4e35 100644
--- a/mlir/test/Transforms/inlining.mlir
+++ b/mlir/test/Transforms/inlining.mlir
@@ -79,8 +79,8 @@ func.func @inline_with_multi_return() -> i32 {
 
 // Check that location information is updated for inlined instructions.
 
-#inline_stack1 = loc(callsite("mysource1.cc":10:8 at callsite("mysource2.cc":13:6 at "mysource3.cc":16:2)))
-#inline_stack2 = loc(callsite("mysource4.cc":55:4 at callsite("mysource5.cc":25:8 at "mysource6.cc":32:4)))
+#inline_stack1 = #loc(callsite("mysource1.cc":10:8 at callsite("mysource2.cc":13:6 at "mysource3.cc":16:2)))
+#inline_stack2 = #loc(callsite("mysource4.cc":55:4 at callsite("mysource5.cc":25:8 at "mysource6.cc":32:4)))
 
 // INLINE-LOC-LABEL: func @func_with_file_locations
 func.func @func_with_file_locations(%c : i32) -> i32 {
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index b770b860a5122..b0ca18874c5e2 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -1206,7 +1206,8 @@ def TestLocationAttrOp : TEST_Op<"op_with_loc_attr"> {
 }
 
 def TestOptionalLocGroupOp : TEST_Op<"optional_loc_group"> {
-  let summary = "op with optional attr group for loc() disambiguation testing";
+  let summary =
+      "op with optional attr group for location attribute disambiguation";
   let arguments = (ins OptionalAttr<AnyAttr>:$opt_attr);
   let assemblyFormat = "($opt_attr^)? attr-dict";
 }

>From 853aca27e15ff708713765cecfddf525bb5a05ac Mon Sep 17 00:00:00 2001
From: Xiaolei Shi <xiaoleis at nvidia.com>
Date: Mon, 16 Mar 2026 22:14:57 -0700
Subject: [PATCH 4/6] [mlir][flang] Fix test fallout from location attribute
 syntax

---
 .../alias-analysis-cray-pointers.fir          |  4 +-
 flang/test/Transforms/debug-107988.fir        |  4 +-
 flang/test/Transforms/debug-92391.fir         |  2 +-
 flang/test/Transforms/debug-96314.fir         |  8 +--
 flang/test/Transforms/debug-allocatable-1.fir |  6 +-
 .../Transforms/debug-assumed-rank-array.fir   |  4 +-
 .../debug-assumed-shape-array-2.fir           |  6 +-
 .../Transforms/debug-assumed-shape-array.fir  |  6 +-
 .../Transforms/debug-assumed-size-array.fir   |  6 +-
 flang/test/Transforms/debug-char-type-1.fir   |  2 +-
 flang/test/Transforms/debug-class-type.fir    |  8 +--
 flang/test/Transforms/debug-common-block.fir  | 48 ++++++-------
 flang/test/Transforms/debug-complex-1.fir     |  8 +--
 .../test/Transforms/debug-derived-type-1.fir  | 24 +++----
 .../test/Transforms/debug-derived-type-2.fir  |  2 +-
 .../debug-dummy-argument-inline.fir           | 34 ++++-----
 .../test/Transforms/debug-dummy-argument.fir  | 10 +--
 flang/test/Transforms/debug-dwarf-version.fir |  2 +-
 flang/test/Transforms/debug-extra-global.fir  |  2 +-
 .../Transforms/debug-fixed-array-type.fir     | 10 +--
 flang/test/Transforms/debug-fn-info.fir       |  8 +--
 .../test/Transforms/debug-imported-entity.fir |  8 +--
 flang/test/Transforms/debug-index-type.fir    |  2 +-
 .../Transforms/debug-line-table-existing.fir  | 12 ++--
 .../Transforms/debug-line-table-inc-file.fir  | 22 +++---
 .../debug-line-table-inc-same-file.fir        |  8 +--
 flang/test/Transforms/debug-line-table.fir    | 16 ++---
 .../debug-local-global-storage-1.fir          | 12 ++--
 flang/test/Transforms/debug-local-var.fir     | 34 ++++-----
 flang/test/Transforms/debug-module-1.fir      | 12 ++--
 flang/test/Transforms/debug-module-2.fir      |  8 +--
 flang/test/Transforms/debug-module-3.fir      |  2 +-
 .../test/Transforms/debug-omp-target-op-1.fir | 10 +--
 .../test/Transforms/debug-omp-target-op-2.fir | 14 ++--
 flang/test/Transforms/debug-proc-ptr.fir      |  8 +--
 flang/test/Transforms/debug-ptr-type.fir      |  8 +--
 flang/test/Transforms/debug-ref-type.fir      |  2 +-
 flang/test/Transforms/debug-split-dwarf.fir   |  2 +-
 flang/test/Transforms/debug-use-stmt.fir      |  8 +--
 .../Transforms/debug-variable-array-dim.fir   | 10 +--
 .../Transforms/debug-variable-char-len.fir    |  6 +-
 flang/test/Transforms/tbaa-cray-pointer.fir   |  2 +-
 .../Bytecode/invalid/invalid-ir_section.mlir  | 10 +--
 .../invalid/invalid_attr_type_section.mlir    |  2 +-
 mlir/test/Target/LLVMIR/Import/basic.ll       |  2 +-
 mlir/test/Target/LLVMIR/Import/debug-info.ll  | 34 ++++-----
 .../Target/LLVMIR/Import/metadata-loop.ll     |  8 +--
 mlir/test/mlir-lsp-server/definition.test     |  4 +-
 mlir/test/mlir-lsp-server/references.test     |  6 +-
 mlir/test/python/ir/attributes.py             |  4 +-
 mlir/test/python/ir/auto_location.py          | 18 ++---
 mlir/test/python/ir/builtin_types.py          | 12 ++--
 mlir/test/python/ir/diagnostic_handler.py     |  2 +-
 mlir/test/python/ir/exception.py              | 12 ++--
 mlir/test/python/ir/location.py               | 70 +++++++++----------
 mlir/test/python/ir/module.py                 |  2 +-
 mlir/test/python/ir/operation.py              |  6 +-
 mlir/test/python/pass_manager.py              |  4 +-
 mlir/unittests/Parser/ParserTest.cpp          |  6 +-
 59 files changed, 307 insertions(+), 305 deletions(-)

diff --git a/flang/test/Analysis/AliasAnalysis/alias-analysis-cray-pointers.fir b/flang/test/Analysis/AliasAnalysis/alias-analysis-cray-pointers.fir
index 853a2c5ba850d..d7013b975b857 100644
--- a/flang/test/Analysis/AliasAnalysis/alias-analysis-cray-pointers.fir
+++ b/flang/test/Analysis/AliasAnalysis/alias-analysis-cray-pointers.fir
@@ -7,8 +7,8 @@
 // subroutine test()
 //   real :: a, b, c
 //   pointer(p, a)
-//   p = loc(b)
-//   p = loc(c)
+//   p = #loc(b)
+//   p = #loc(c)
 //   a = 1.0
 // end subroutine
 
diff --git a/flang/test/Transforms/debug-107988.fir b/flang/test/Transforms/debug-107988.fir
index 674ce287a29ec..49445f3581d4a 100644
--- a/flang/test/Transforms/debug-107988.fir
+++ b/flang/test/Transforms/debug-107988.fir
@@ -10,8 +10,8 @@ module {
   } loc(#loc2)
 }
 
-#loc1 = loc("test.f90":5:1)
-#loc2 = loc("test.f90":15:1)
+#loc1 = #loc("test.f90":5:1)
+#loc2 = #loc("test.f90":15:1)
 
 // CHECK: #[[VAR:.*]] = #llvm.di_local_variable<{{.*}}name = "._QFtestEstr{{.*}}flags = Artificial>
 // CHECK: func.func @test
diff --git a/flang/test/Transforms/debug-92391.fir b/flang/test/Transforms/debug-92391.fir
index 2d83be995a0f6..f6c2ec57bfb68 100644
--- a/flang/test/Transforms/debug-92391.fir
+++ b/flang/test/Transforms/debug-92391.fir
@@ -13,6 +13,6 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<i64, dense<64> :
     return %6 : i32
   } loc(#loc1)
 }
-#loc1 = loc("92391.f90":15:1)
+#loc1 = #loc("92391.f90":15:1)
 
 // CHECK: #di_subprogram = #llvm.di_subprogram<{{.*}}name = "my_square", linkageName = "my_square_"{{.*}}>
diff --git a/flang/test/Transforms/debug-96314.fir b/flang/test/Transforms/debug-96314.fir
index 4df0c4a555d39..4a68a59f8489e 100644
--- a/flang/test/Transforms/debug-96314.fir
+++ b/flang/test/Transforms/debug-96314.fir
@@ -15,10 +15,10 @@ module {
   } loc(#loc4)
 }
 
-#loc1 = loc("test.f90":5:1)
-#loc2 = loc("test.f90":15:1)
-#loc3 = loc("test.f90":25:1)
-#loc4 = loc("test.f90":35:1)
+#loc1 = #loc("test.f90":5:1)
+#loc2 = #loc("test.f90":15:1)
+#loc3 = #loc("test.f90":25:1)
+#loc4 = #loc("test.f90":35:1)
 
 // CHECK-DAG: #[[SP1:.*]] = #llvm.di_subprogram<{{.*}}name = "mod_sub"{{.*}}>
 // CHECK-DAG: #llvm.di_subprogram<{{.*}}scope = #[[SP1]], name = "child1"{{.*}}>
diff --git a/flang/test/Transforms/debug-allocatable-1.fir b/flang/test/Transforms/debug-allocatable-1.fir
index e02df428160f7..aad482628b3b3 100644
--- a/flang/test/Transforms/debug-allocatable-1.fir
+++ b/flang/test/Transforms/debug-allocatable-1.fir
@@ -14,9 +14,9 @@ module {
   } loc(#loc3)
 }
 
-#loc1 = loc("test.f90":3:3)
-#loc2 = loc("test.f90":4:3)
-#loc3 = loc("test.f90":1:3)
+#loc1 = #loc("test.f90":3:3)
+#loc2 = #loc("test.f90":4:3)
+#loc3 = #loc("test.f90":1:3)
 
 // CHECK-DAG: #[[TY1:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real"{{.*}}>
 // CHECK-DAG: #[[TY2:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}allocated = <[DW_OP_push_object_address, DW_OP_deref, DW_OP_lit0, DW_OP_ne]>{{.*}}elements = #llvm.di_subrange{{.*}}#llvm.di_subrange
diff --git a/flang/test/Transforms/debug-assumed-rank-array.fir b/flang/test/Transforms/debug-assumed-rank-array.fir
index 92d29c4549ece..2a2fbae762079 100644
--- a/flang/test/Transforms/debug-assumed-rank-array.fir
+++ b/flang/test/Transforms/debug-assumed-rank-array.fir
@@ -7,8 +7,8 @@ module {
     return
   } loc(#loc1)
 }
-#loc1 = loc("test1.f90":1:1)
-#loc2 = loc("test1.f90":3:16)
+#loc1 = #loc("test1.f90":1:1)
+#loc2 = #loc("test1.f90":3:16)
 
 // CHECK: #[[TY:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type
 // CHECK-SAME: dataLocation = <[DW_OP_push_object_address, DW_OP_deref]>, rank = <[DW_OP_push_object_address, DW_OP_plus_uconst(20), DW_OP_deref_size(1)]>
diff --git a/flang/test/Transforms/debug-assumed-shape-array-2.fir b/flang/test/Transforms/debug-assumed-shape-array-2.fir
index 9c695ac0d4890..6fd1082df4c9b 100644
--- a/flang/test/Transforms/debug-assumed-shape-array-2.fir
+++ b/flang/test/Transforms/debug-assumed-shape-array-2.fir
@@ -15,9 +15,9 @@ module {
     return
   } loc(#loc3)
 }
-#loc1 = loc("test1.f90":1:1)
-#loc2 = loc("test1.f90":3:16)
-#loc3 = loc("test1.f90":4:16)
+#loc1 = #loc("test1.f90":1:1)
+#loc2 = #loc("test1.f90":3:16)
+#loc3 = #loc("test1.f90":4:16)
 
 // CHECK: #[[VAR:.*]] = #llvm.di_local_variable<{{.*}}name = "._QFFfnEb1"{{.*}}flags = Artificial>
 // CHECK: #llvm.di_composite_type<tag = DW_TAG_array_type
diff --git a/flang/test/Transforms/debug-assumed-shape-array.fir b/flang/test/Transforms/debug-assumed-shape-array.fir
index 855be70dcbef5..8ee8e144955d0 100644
--- a/flang/test/Transforms/debug-assumed-shape-array.fir
+++ b/flang/test/Transforms/debug-assumed-shape-array.fir
@@ -10,9 +10,9 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<i64, dense<64> :
     return
   } loc(#loc2)
 }
-#loc1 = loc("test1.f90":1:1)
-#loc2 = loc("test1.f90":3:16)
-#loc3 = loc("test1.f90":4:16)
+#loc1 = #loc("test1.f90":1:1)
+#loc2 = #loc("test1.f90":3:16)
+#loc3 = #loc("test1.f90":4:16)
 
 // CHECK: #[[TY1:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type
 // CHECK-SAME: dataLocation = <[DW_OP_push_object_address, DW_OP_deref]>
diff --git a/flang/test/Transforms/debug-assumed-size-array.fir b/flang/test/Transforms/debug-assumed-size-array.fir
index 2c915526e32bb..2ac3eb3b80805 100644
--- a/flang/test/Transforms/debug-assumed-size-array.fir
+++ b/flang/test/Transforms/debug-assumed-size-array.fir
@@ -12,9 +12,9 @@ module {
     return
   } loc(#loc3)
 }
-#loc3 = loc("test.f90":1:1)
-#loc1 = loc("test.f90":3:1)
-#loc2 = loc("test.f90":4:1)
+#loc3 = #loc("test.f90":1:1)
+#loc1 = #loc("test.f90":3:1)
+#loc2 = #loc("test.f90":4:1)
 
 // CHECK-DAG: #[[TY1:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}elements = #llvm.di_subrange<count = 5 : i64>, #llvm.di_subrange<>>
 // CHECK-DAG: #[[TY2:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}elements = #llvm.di_subrange<lowerBound = 2 : i64>>
diff --git a/flang/test/Transforms/debug-char-type-1.fir b/flang/test/Transforms/debug-char-type-1.fir
index 49f230f7307fa..ab7aae34370b0 100644
--- a/flang/test/Transforms/debug-char-type-1.fir
+++ b/flang/test/Transforms/debug-char-type-1.fir
@@ -16,7 +16,7 @@ module {
     fir.has_value %1 : !fir.box<!fir.heap<!fir.char<1,?>>>
   } loc(#loc1)
 }
-#loc1 = loc("string.f90":1:1)
+#loc1 = #loc("string.f90":1:1)
 
 // CHECK-DAG: #[[TY1:.*]] = #llvm.di_string_type<tag = DW_TAG_string_type, name = "", sizeInBits = 320, encoding = DW_ATE_ASCII>
 // CHECK-DAG: #llvm.di_global_variable<{{.*}}name = "str1"{{.*}}type = #[[TY1]]{{.*}}>
diff --git a/flang/test/Transforms/debug-class-type.fir b/flang/test/Transforms/debug-class-type.fir
index 23af60b71ca50..61fe5eeb7952e 100644
--- a/flang/test/Transforms/debug-class-type.fir
+++ b/flang/test/Transforms/debug-class-type.fir
@@ -19,10 +19,10 @@ module {
   } loc(#loc2)
 }
 
-#loc1 = loc("./simple.f90":2:1)
-#loc2 = loc("./simple.f90":10:1)
-#loc3 = loc("./simple.f90":15:1)
-#loc4 = loc("./simple.f90":22:1)
+#loc1 = #loc("./simple.f90":2:1)
+#loc2 = #loc("./simple.f90":10:1)
+#loc3 = #loc("./simple.f90":15:1)
+#loc4 = #loc("./simple.f90":22:1)
 
 // CHECK-DAG: #[[TY1:.*]] = #llvm.di_composite_type<{{.*}}name = "test_type"{{.*}}>
 // CHECK-DAG: #[[TY2:.*]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, name = "", baseType = #[[TY1]]{{.*}}>
diff --git a/flang/test/Transforms/debug-common-block.fir b/flang/test/Transforms/debug-common-block.fir
index 1d2beae0e0ef4..75eb06f380808 100644
--- a/flang/test/Transforms/debug-common-block.fir
+++ b/flang/test/Transforms/debug-common-block.fir
@@ -109,30 +109,30 @@ module {
   } loc(#loc18)
 }
 
-#loc1 = loc(unknown)
-#loc2 = loc(unknown)
-#loc3 = loc("common.f90":10:1)
-#loc4 = loc("common.f90":12:19)
-#loc5 = loc("common.f90":12:25)
-#loc6 = loc("common.f90":12:22)
-#loc7 = loc("common.f90":12:29)
-#loc8 = loc("common.f90":20:3)
-#loc9 = loc("common.f90":22:3)
-#loc10 = loc("common.f90":22:6)
-#loc11 = loc("common.f90":22:9)
-#loc12 = loc("common.f90":22:13)
-#loc13 = loc("common.f90":22:16)
-#loc14 = loc("common.f90":22:19)
-#loc15 = loc("common.f90":32:18)
-#loc16 = loc("common.f90":35:7)
-#loc17 = loc("common.f90":35:10)
-#loc18 = loc("common.f90":40:1)
-#loc19 = loc("common.f90":43:19)
-#loc20 = loc("common.f90":43:28)
-#loc21 = loc("common.f90":43:22)
-#loc22 = loc("common.f90":43:32)
-#loc23 = loc("common.f90":43:25)
-#loc24 = loc("common.f90":43:36)
+#loc1 = #loc(unknown)
+#loc2 = #loc(unknown)
+#loc3 = #loc("common.f90":10:1)
+#loc4 = #loc("common.f90":12:19)
+#loc5 = #loc("common.f90":12:25)
+#loc6 = #loc("common.f90":12:22)
+#loc7 = #loc("common.f90":12:29)
+#loc8 = #loc("common.f90":20:3)
+#loc9 = #loc("common.f90":22:3)
+#loc10 = #loc("common.f90":22:6)
+#loc11 = #loc("common.f90":22:9)
+#loc12 = #loc("common.f90":22:13)
+#loc13 = #loc("common.f90":22:16)
+#loc14 = #loc("common.f90":22:19)
+#loc15 = #loc("common.f90":32:18)
+#loc16 = #loc("common.f90":35:7)
+#loc17 = #loc("common.f90":35:10)
+#loc18 = #loc("common.f90":40:1)
+#loc19 = #loc("common.f90":43:19)
+#loc20 = #loc("common.f90":43:28)
+#loc21 = #loc("common.f90":43:22)
+#loc22 = #loc("common.f90":43:32)
+#loc23 = #loc("common.f90":43:25)
+#loc24 = #loc("common.f90":43:36)
 
 
 // CHECK-DAG: #[[XF1:.*]] = #llvm.di_global_variable<scope = #[[CBF1:.+]], name = "x", linkageName = "_QFf1Ex"{{.*}}>
diff --git a/flang/test/Transforms/debug-complex-1.fir b/flang/test/Transforms/debug-complex-1.fir
index 6e2c6c5bdb354..95f3c70a2fff5 100644
--- a/flang/test/Transforms/debug-complex-1.fir
+++ b/flang/test/Transforms/debug-complex-1.fir
@@ -21,10 +21,10 @@ module {
   return %1 : complex<f128>
   }loc(#loc4)
 }
-#loc1 = loc("./simple.f90":2:1)
-#loc2 = loc("./simple.f90":5:1)
-#loc3 = loc("./simple.f90":8:1)
-#loc4 = loc("./simple.f90":11:1)
+#loc1 = #loc("./simple.f90":2:1)
+#loc2 = #loc("./simple.f90":5:1)
+#loc3 = #loc("./simple.f90":8:1)
+#loc4 = #loc("./simple.f90":11:1)
 
 // CHECK-DAG: #[[CMPX8:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "complex(kind=8)", sizeInBits = 128, encoding = DW_ATE_complex_float>
 // CHECK-DAG: #[[CMPX4:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "complex", sizeInBits = 64, encoding = DW_ATE_complex_float>
diff --git a/flang/test/Transforms/debug-derived-type-1.fir b/flang/test/Transforms/debug-derived-type-1.fir
index 22832b67742c8..02665e1b243fb 100644
--- a/flang/test/Transforms/debug-derived-type-1.fir
+++ b/flang/test/Transforms/debug-derived-type-1.fir
@@ -30,18 +30,18 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<!llvm.ptr<272>, d
     return
   } loc(#loc10)
 }
-#loc1 = loc("derived1.f90":24:1)
-#loc2 = loc("derived1.f90":35:25)
-#loc3 = loc("derived1.f90":17:1)
-#loc4 = loc("derived1.f90":46:1)
-#loc5 = loc("derived1.f90":50:3)
-#loc6 = loc("derived1.f90":62:3)
-#loc7 = loc("derived1.f90":70:3)
-#loc8 = loc("derived1.f90":85:3)
-#loc9 = loc("derived1.f90":77:3)
-#loc10 = loc("derived1.f90":75:3)
-#loc11 = loc("derived1.f90":95:3)
-#loc12 = loc("derived1.f90":105:3)
+#loc1 = #loc("derived1.f90":24:1)
+#loc2 = #loc("derived1.f90":35:25)
+#loc3 = #loc("derived1.f90":17:1)
+#loc4 = #loc("derived1.f90":46:1)
+#loc5 = #loc("derived1.f90":50:3)
+#loc6 = #loc("derived1.f90":62:3)
+#loc7 = #loc("derived1.f90":70:3)
+#loc8 = #loc("derived1.f90":85:3)
+#loc9 = #loc("derived1.f90":77:3)
+#loc10 = #loc("derived1.f90":75:3)
+#loc11 = #loc("derived1.f90":95:3)
+#loc12 = #loc("derived1.f90":105:3)
 
 
 // CHECK-DAG: #[[INT_TY:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 32, encoding = DW_ATE_signed>
diff --git a/flang/test/Transforms/debug-derived-type-2.fir b/flang/test/Transforms/debug-derived-type-2.fir
index 1e128d702b347..3f7e40a66f29c 100644
--- a/flang/test/Transforms/debug-derived-type-2.fir
+++ b/flang/test/Transforms/debug-derived-type-2.fir
@@ -7,7 +7,7 @@ module {
     fir.dt_component "elm2" lbs [1, 3]
   } loc(#loc1)
 }
-#loc1 = loc("derived.f90":24:1)
+#loc1 = #loc("derived.f90":24:1)
 
 
 // CHECK-DAG: #[[TY1:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type, {{.*}} = #{{.*}}, elements = #llvm.di_subrange<count = 5 : i64, lowerBound = 2 : i64>>
diff --git a/flang/test/Transforms/debug-dummy-argument-inline.fir b/flang/test/Transforms/debug-dummy-argument-inline.fir
index 02f0d5c6539b4..95b9c3fc0948a 100644
--- a/flang/test/Transforms/debug-dummy-argument-inline.fir
+++ b/flang/test/Transforms/debug-dummy-argument-inline.fir
@@ -17,20 +17,20 @@ func.func @foo_(%arg0: !fir.ref<i32> {fir.bindc_name = "i"} loc("debug-dummy-arg
   return loc(#loc9)
 } loc(#loc5)
 func.func private @buzz_(!fir.ref<i32>) attributes {fir.internal_name = "_QPbuzz"} loc(#loc10)
-#loc = loc("debug-dummy-argument-inline.f90":0:0)
-#loc1 = loc("debug-dummy-argument-inline.f90":1:1)
-#loc2 = loc("debug-dummy-argument-inline.f90":2:14)
-#loc3 = loc("debug-dummy-argument-inline.f90":3:3)
-#loc4 = loc("debug-dummy-argument-inline.f90":4:1)
-#loc5 = loc("debug-dummy-argument-inline.f90":5:1)
-#loc6 = loc("debug-dummy-argument-inline.f90":6:14)
-#loc7 = loc("debug-dummy-argument-inline.f90":7:3)
-#loc8 = loc("debug-dummy-argument-inline.f90":8:3)
-#loc9 = loc("debug-dummy-argument-inline.f90":9:1)
-#loc10 = loc("debug-dummy-argument-inline.f90":3:8)
-#loc11 = loc(callsite(#loc1 at #loc7))
-#loc12 = loc(callsite(#loc2 at #loc7))
-#loc13 = loc(callsite(#loc3 at #loc7))
-#loc14 = loc(callsite(#loc1 at #loc8))
-#loc15 = loc(callsite(#loc2 at #loc8))
-#loc16 = loc(callsite(#loc3 at #loc8))
+#loc = #loc("debug-dummy-argument-inline.f90":0:0)
+#loc1 = #loc("debug-dummy-argument-inline.f90":1:1)
+#loc2 = #loc("debug-dummy-argument-inline.f90":2:14)
+#loc3 = #loc("debug-dummy-argument-inline.f90":3:3)
+#loc4 = #loc("debug-dummy-argument-inline.f90":4:1)
+#loc5 = #loc("debug-dummy-argument-inline.f90":5:1)
+#loc6 = #loc("debug-dummy-argument-inline.f90":6:14)
+#loc7 = #loc("debug-dummy-argument-inline.f90":7:3)
+#loc8 = #loc("debug-dummy-argument-inline.f90":8:3)
+#loc9 = #loc("debug-dummy-argument-inline.f90":9:1)
+#loc10 = #loc("debug-dummy-argument-inline.f90":3:8)
+#loc11 = #loc(callsite(#loc1 at #loc7))
+#loc12 = #loc(callsite(#loc2 at #loc7))
+#loc13 = #loc(callsite(#loc3 at #loc7))
+#loc14 = #loc(callsite(#loc1 at #loc8))
+#loc15 = #loc(callsite(#loc2 at #loc8))
+#loc16 = #loc(callsite(#loc3 at #loc8))
diff --git a/flang/test/Transforms/debug-dummy-argument.fir b/flang/test/Transforms/debug-dummy-argument.fir
index 61862530f8396..7624ac399a0ac 100644
--- a/flang/test/Transforms/debug-dummy-argument.fir
+++ b/flang/test/Transforms/debug-dummy-argument.fir
@@ -18,8 +18,8 @@
 //   integer :: expected
 // end subroutine test
 
-#loc1 = loc("debug-dummy-argument.f90":1:1)
-#loc4 = loc("debug-dummy-argument.f90":2:14)
+#loc1 = #loc("debug-dummy-argument.f90":1:1)
+#loc4 = #loc("debug-dummy-argument.f90":2:14)
 module attributes {dlti.dl_spec = #dlti.dl_spec<i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, i1 = dense<8> : vector<2xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i32 = dense<32> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, !llvm.ptr<270> = dense<32> : vector<4xi64>, i8 = dense<8> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, "dlti.stack_alignment" = 128 : i64, "dlti.mangling_mode" = "e", "dlti.endianness" = "little">, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", fir.target_cpu = "x86-64", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang", llvm.target_triple = "x86_64-unknown-linux-gnu"} {
   func.func @test_(%arg0: !fir.ref<i32> {fir.bindc_name = "expected"} loc("debug-dummy-argument.f90":1:1), %arg1: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "x"} loc("debug-dummy-argument.f90":1:1)) attributes {fir.internal_name = "_QPtest"} {
     %0 = fir.undefined !fir.dscope loc(#loc1)
@@ -33,6 +33,6 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<i128 = dense<128> : vector<2xi64
     return loc(#loc5)
   } loc(#loc1)
 } loc(#loc)
-#loc = loc("debug-dummy-argument.f90":0:0)
-#loc3 = loc("debug-dummy-argument.f90":3:14)
-#loc5 = loc("debug-dummy-argument.f90":4:1)
+#loc = #loc("debug-dummy-argument.f90":0:0)
+#loc3 = #loc("debug-dummy-argument.f90":3:14)
+#loc5 = #loc("debug-dummy-argument.f90":4:1)
diff --git a/flang/test/Transforms/debug-dwarf-version.fir b/flang/test/Transforms/debug-dwarf-version.fir
index 0136d2469d749..096d4b494ed81 100644
--- a/flang/test/Transforms/debug-dwarf-version.fir
+++ b/flang/test/Transforms/debug-dwarf-version.fir
@@ -12,7 +12,7 @@
 
 module {
 } loc(#loc)
-#loc = loc("simple.f90":0:0)
+#loc = #loc("simple.f90":0:0)
 
 // CHECK-DWARF5: llvm.module_flags [#llvm.mlir.module_flag<max, "Dwarf Version", 5 : i32>]
 // CHECK-DWARF4: llvm.module_flags [#llvm.mlir.module_flag<max, "Dwarf Version", 4 : i32>]
diff --git a/flang/test/Transforms/debug-extra-global.fir b/flang/test/Transforms/debug-extra-global.fir
index e3a33e4cfdf40..677bfe4e1b66d 100644
--- a/flang/test/Transforms/debug-extra-global.fir
+++ b/flang/test/Transforms/debug-extra-global.fir
@@ -10,7 +10,7 @@ module {
     fir.has_value %0 : !fir.char<1,4>
   } loc(#loc1)
 }
-#loc1 = loc("derived.f90":24:1)
+#loc1 = #loc("derived.f90":24:1)
 
 // Test that no di_global_variable gets created for these compile generated
 // globals.
diff --git a/flang/test/Transforms/debug-fixed-array-type.fir b/flang/test/Transforms/debug-fixed-array-type.fir
index 75cb88b08b248..df9197a8a6d01 100644
--- a/flang/test/Transforms/debug-fixed-array-type.fir
+++ b/flang/test/Transforms/debug-fixed-array-type.fir
@@ -22,11 +22,11 @@ module {
   } loc(#loc4)
 }
 
-#loc1 = loc("test.f90":5:1)
-#loc2 = loc("test.f90":6:11)
-#loc3 = loc("test.f90":7:11)
-#loc4 = loc("test.f90":2:8)
-#loc5 = loc("test.f90":8:11)
+#loc1 = #loc("test.f90":5:1)
+#loc2 = #loc("test.f90":6:11)
+#loc3 = #loc("test.f90":7:11)
+#loc4 = #loc("test.f90":2:8)
+#loc5 = #loc("test.f90":8:11)
 
 
 // CHECK-DAG: #[[INT:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 32, encoding = DW_ATE_signed>
diff --git a/flang/test/Transforms/debug-fn-info.fir b/flang/test/Transforms/debug-fn-info.fir
index e42beb1f748f1..c6d06b2e434ea 100644
--- a/flang/test/Transforms/debug-fn-info.fir
+++ b/flang/test/Transforms/debug-fn-info.fir
@@ -58,10 +58,10 @@ module {
     return
   } loc(#loc4)
 }
-#loc1 = loc("test.f90":15:1)
-#loc2 = loc("test.f90":26:22)
-#loc3 = loc("test2.f90":43:22)
-#loc4 = loc("test2.f90":53:22)
+#loc1 = #loc("test.f90":15:1)
+#loc2 = #loc("test.f90":26:22)
+#loc3 = #loc("test2.f90":43:22)
+#loc4 = #loc("test2.f90":53:22)
 
 
 // CHECK-DAG: #[[INT8:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer(kind=8)", sizeInBits = 64, encoding = DW_ATE_signed>
diff --git a/flang/test/Transforms/debug-imported-entity.fir b/flang/test/Transforms/debug-imported-entity.fir
index 246bdd8bf4e95..d56e65dd465e0 100644
--- a/flang/test/Transforms/debug-imported-entity.fir
+++ b/flang/test/Transforms/debug-imported-entity.fir
@@ -19,10 +19,10 @@ module {
     return
   } loc(#loc3)
 }
-#loc1 = loc("test.f90":2:14)
-#loc2 = loc("test.f90":6:1)
-#loc3 = loc("test.f90":10:1)
-#loc4 = loc("test.f90":13:1)
+#loc1 = #loc("test.f90":2:14)
+#loc2 = #loc("test.f90":6:1)
+#loc3 = #loc("test.f90":10:1)
+#loc4 = #loc("test.f90":13:1)
 
 // CHECK: #[[MOD:.+]] = #llvm.di_module<{{.*}}name = "foo"{{.*}}>
 // CHECK: #[[SP_REC:.+]] = #llvm.di_subprogram<recId = distinct[[[REC_ID:[0-9]+]]]<>, isRecSelf = true{{.*}}>
diff --git a/flang/test/Transforms/debug-index-type.fir b/flang/test/Transforms/debug-index-type.fir
index 751e2e156dc20..17839568dab58 100644
--- a/flang/test/Transforms/debug-index-type.fir
+++ b/flang/test/Transforms/debug-index-type.fir
@@ -3,7 +3,7 @@
 module {
   func.func private @str(%arg0: index) -> i32 loc(#loc1)
 }
-#loc1 = loc("test.f90":5:1)
+#loc1 = #loc("test.f90":5:1)
 
 // CHECK: #[[INT32_TY:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 32, encoding = DW_ATE_signed>
 // CHECK: #[[INT64_TY:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 64, encoding = DW_ATE_signed>
diff --git a/flang/test/Transforms/debug-line-table-existing.fir b/flang/test/Transforms/debug-line-table-existing.fir
index 98ca3dcb2a717..4d09c960f721f 100644
--- a/flang/test/Transforms/debug-line-table-existing.fir
+++ b/flang/test/Transforms/debug-line-table-existing.fir
@@ -10,14 +10,14 @@ module {
 } loc(#loc)
 #di_basic_type = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "void", encoding = DW_ATE_address>
 #di_file = #llvm.di_file<"simple.f90" in "/home/user01/llvm-project/build_release">
-#loc = loc("/home/user01/llvm-project/build_release/simple.f90":0:0)
-#loc1 = loc("/home/user01/llvm-project/build_release/simple.f90":1:1)
+#loc = #loc("/home/user01/llvm-project/build_release/simple.f90":0:0)
+#loc1 = #loc("/home/user01/llvm-project/build_release/simple.f90":1:1)
 #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "Flang", isOptimized = false, emissionKind = LineTablesOnly>
 #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #di_basic_type, #di_basic_type>
 #di_subprogram = #llvm.di_subprogram<compileUnit = #di_compile_unit, scope = #di_file, name = "_QPs1", linkageName = "_QPs1", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = Definition, type = #di_subroutine_type>
-#loc2 = loc(fused<#di_subprogram>[#loc1])
+#loc2 = #loc(fused<#di_subprogram>[#loc1])
 
-// CHECK: #loc = loc("/home/user01/llvm-project/build_release/simple.f90":0:0)
-// CHECK: #loc1 = loc("/home/user01/llvm-project/build_release/simple.f90":1:1)
+// CHECK: #loc = #loc("/home/user01/llvm-project/build_release/simple.f90":0:0)
+// CHECK: #loc1 = #loc("/home/user01/llvm-project/build_release/simple.f90":1:1)
 // CHECK: #di_subprogram = #llvm.di_subprogram<compileUnit = #di_compile_unit, scope = #di_file, name = "_QPs1", linkageName = "_QPs1", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = Definition, type = #di_subroutine_type>
-// CHECK: #loc2 = loc(fused<#di_subprogram>[#loc1])
+// CHECK: #loc2 = #loc(fused<#di_subprogram>[#loc1])
diff --git a/flang/test/Transforms/debug-line-table-inc-file.fir b/flang/test/Transforms/debug-line-table-inc-file.fir
index d29e2fd6683b6..ab760e3763c07 100644
--- a/flang/test/Transforms/debug-line-table-inc-file.fir
+++ b/flang/test/Transforms/debug-line-table-inc-file.fir
@@ -12,12 +12,12 @@ module {
     return loc(#loc5)
   } loc(#loc3)
 } loc(#loc)
-#loc = loc("/home/user01/llvm-project/build_release/simple.f90":0:0)
-#loc1 = loc("/home/user01/llvm-project/build_release/inc.f90":1:1)
-#loc2 = loc("/home/user01/llvm-project/build_release/inc.f90":2:1)
-#loc3 = loc("/home/user01/llvm-project/build_release/simple.f90":3:1)
-#loc4 = loc("/home/user01/llvm-project/build_release/simple.f90":4:3)
-#loc5 = loc("/home/user01/llvm-project/build_release/simple.f90":5:1)
+#loc = #loc("/home/user01/llvm-project/build_release/simple.f90":0:0)
+#loc1 = #loc("/home/user01/llvm-project/build_release/inc.f90":1:1)
+#loc2 = #loc("/home/user01/llvm-project/build_release/inc.f90":2:1)
+#loc3 = #loc("/home/user01/llvm-project/build_release/simple.f90":3:1)
+#loc4 = #loc("/home/user01/llvm-project/build_release/simple.f90":4:3)
+#loc5 = #loc("/home/user01/llvm-project/build_release/simple.f90":5:1)
 
 // CHECK: module
 // CHECK:   func.func @_QPsinc() {
@@ -27,11 +27,11 @@ module {
 // CHECK: } loc(#[[MODULE_LOC:.*]])
 // CHECK: #[[DI_FILE:.*]] = #llvm.di_file<"simple.f90" in "[[DIR:.*]]">
 // CHECK: #[[DI_INC_FILE:.*]] = #llvm.di_file<"inc.f90" in "[[DIR]]">
-// CHECK: #[[MODULE_LOC]] = loc("{{.*}}simple.f90":0:0)
-// CHECK: #[[LOC_INC_FILE:.*]] = loc("{{.*}}inc.f90":1:1)
-// CHECK: #[[LOC_FILE:.*]] = loc("{{.*}}simple.f90":3:1)
+// CHECK: #[[MODULE_LOC]] = #loc("{{.*}}simple.f90":0:0)
+// CHECK: #[[LOC_INC_FILE:.*]] = #loc("{{.*}}inc.f90":1:1)
+// CHECK: #[[LOC_FILE:.*]] = #loc("{{.*}}simple.f90":3:1)
 // CHECK: #[[DI_CU:.*]] = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #[[DI_FILE]], producer = "{{.*}}flang{{.*}}", isOptimized = false, emissionKind = LineTablesOnly>
 // CHECK: #[[DI_SP_INC:.*]] = #llvm.di_subprogram<{{.*}}id = distinct[{{.*}}]<>, compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "sinc", linkageName = "_QPsinc", file = #[[DI_INC_FILE]], {{.*}}>
 // CHECK: #[[DI_SP:.*]] = #llvm.di_subprogram<{{.*}}id = distinct[{{.*}}]<>, compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "_QQmain", linkageName = "_QQmain", file = #[[DI_FILE]], {{.*}}>
-// CHECK: #[[FUSED_LOC_INC_FILE]] = loc(fused<#[[DI_SP_INC]]>[#[[LOC_INC_FILE]]])
-// CHECK: #[[FUSED_LOC_FILE]] = loc(fused<#[[DI_SP]]>[#[[LOC_FILE]]])
+// CHECK: #[[FUSED_LOC_INC_FILE]] = #loc(fused<#[[DI_SP_INC]]>[#[[LOC_INC_FILE]]])
+// CHECK: #[[FUSED_LOC_FILE]] = #loc(fused<#[[DI_SP]]>[#[[LOC_FILE]]])
diff --git a/flang/test/Transforms/debug-line-table-inc-same-file.fir b/flang/test/Transforms/debug-line-table-inc-same-file.fir
index 5265c79e61173..21ae4aa9d66db 100644
--- a/flang/test/Transforms/debug-line-table-inc-same-file.fir
+++ b/flang/test/Transforms/debug-line-table-inc-same-file.fir
@@ -15,9 +15,9 @@ module {
     return loc(#loc3)
   } loc(#loc1)
 } loc(#loc)
-#loc = loc("/home/user01/llvm-project/build_release/simple.f90":0:0)
-#loc1 = loc("/home/user01/llvm-project/build_release/simple.f90":1:1)
-#loc2 = loc("/home/user01/llvm-project/build_release/simple.f90":2:1)
-#loc3 = loc("/home/user01/llvm-project/build_release/simple.f90":3:1)
+#loc = #loc("/home/user01/llvm-project/build_release/simple.f90":0:0)
+#loc1 = #loc("/home/user01/llvm-project/build_release/simple.f90":1:1)
+#loc2 = #loc("/home/user01/llvm-project/build_release/simple.f90":2:1)
+#loc3 = #loc("/home/user01/llvm-project/build_release/simple.f90":3:1)
 
 // CHECK-COUNT-1: #llvm.di_file
diff --git a/flang/test/Transforms/debug-line-table.fir b/flang/test/Transforms/debug-line-table.fir
index 81aebf026882a..558bb259b7bd3 100644
--- a/flang/test/Transforms/debug-line-table.fir
+++ b/flang/test/Transforms/debug-line-table.fir
@@ -9,9 +9,9 @@ module {
   } loc(#loc_sb)
   func.func private @decl() -> i32 loc(#loc_decl)
 } loc(#loc_module)
-#loc_module = loc("./simple.f90":1:1)
-#loc_sb = loc("./simple.f90":2:1)
-#loc_decl = loc("./simple.f90":10:1)
+#loc_module = #loc("./simple.f90":1:1)
+#loc_sb = #loc("./simple.f90":2:1)
+#loc_decl = #loc("./simple.f90":10:1)
 
 // CHECK: module attributes
 // CHECK:   func.func @[[SB_NAME:.*]]() {
@@ -21,14 +21,14 @@ module {
 // CHECK: } loc(#[[MODULE_LOC:.*]])
 // CHECK: #di_basic_type = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "void", encoding = DW_ATE_address>
 // CHECK: #di_file = #llvm.di_file<"[[FILE_NAME:.*]]" in "[[DIR_NAME:.*]]">
-// CHECK: #[[MODULE_LOC]] = loc("[[DIR_NAME]]/[[FILE_NAME]]":1:1)
-// CHECK: #[[SB_LOC]] = loc("./simple.f90":2:1)
-// CHECK: #[[DECL_LOC:.*]] = loc("./simple.f90":10:1)
+// CHECK: #[[MODULE_LOC]] = #loc("[[DIR_NAME]]/[[FILE_NAME]]":1:1)
+// CHECK: #[[SB_LOC]] = #loc("./simple.f90":2:1)
+// CHECK: #[[DECL_LOC:.*]] = #loc("./simple.f90":10:1)
 // FULL: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "{{.*}}flang{{.*}}", isOptimized = false, emissionKind = Full>
 // OPT: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "{{.*}}flang{{.*}}", isOptimized = true, emissionKind = Full>
 // LINETABLE: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "{{.*}}flang{{.*}}", isOptimized = false, emissionKind = LineTablesOnly>
 // CHECK: #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #di_basic_type, #di_basic_type>
 // CHECK: #[[SB_SUBPROGRAM:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "[[SB_NAME]]", linkageName = "[[SB_NAME]]", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
 // CHECK: #[[DECL_SUBPROGRAM:.*]] = #llvm.di_subprogram<scope = #di_file, name = "[[DECL_NAME]]", linkageName = "[[DECL_NAME]]", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = Optimized, type = #di_subroutine_type>
-// CHECK: #[[FUSED_SB_LOC]] = loc(fused<#[[SB_SUBPROGRAM]]>[#[[SB_LOC]]])
-// CHECK: #[[FUSED_DECL_LOC]] = loc(fused<#[[DECL_SUBPROGRAM]]>[#[[DECL_LOC]]])
+// CHECK: #[[FUSED_SB_LOC]] = #loc(fused<#[[SB_SUBPROGRAM]]>[#[[SB_LOC]]])
+// CHECK: #[[FUSED_DECL_LOC]] = #loc(fused<#[[DECL_SUBPROGRAM]]>[#[[DECL_LOC]]])
diff --git a/flang/test/Transforms/debug-local-global-storage-1.fir b/flang/test/Transforms/debug-local-global-storage-1.fir
index 6b9ea5b9dbb2d..02eb5054db448 100644
--- a/flang/test/Transforms/debug-local-global-storage-1.fir
+++ b/flang/test/Transforms/debug-local-global-storage-1.fir
@@ -36,12 +36,12 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<i64, dense<64> :
     fir.has_value %c2_i32 : i32
   } loc(#loc3)
 }
-#loc1 = loc("test.f90":21:1)
-#loc2 = loc("test.f90":22:1)
-#loc3 = loc("test.f90":23:1)
-#loc4 = loc("test.f90":5:1)
-#loc5 = loc("test.f90":12:1)
-#loc6 = loc("test.f90":10:1)
+#loc1 = #loc("test.f90":21:1)
+#loc2 = #loc("test.f90":22:1)
+#loc3 = #loc("test.f90":23:1)
+#loc4 = #loc("test.f90":5:1)
+#loc5 = #loc("test.f90":12:1)
+#loc6 = #loc("test.f90":10:1)
 
 // CHECK-DAG: #[[CU:.*]] = #llvm.di_compile_unit<{{.*}}>
 // CHECK-DAG: #[[MOD:.*]] = #llvm.di_module<{{.*}}scope = #[[CU]]{{.*}}name = "example"{{.*}}>
diff --git a/flang/test/Transforms/debug-local-var.fir b/flang/test/Transforms/debug-local-var.fir
index 863d86cb05948..524576eaec464 100644
--- a/flang/test/Transforms/debug-local-var.fir
+++ b/flang/test/Transforms/debug-local-var.fir
@@ -53,23 +53,23 @@ module {
     return %11 : i32
   } loc(#loc17)
 }
-#loc7 = loc("test.f90":4:19)
-#loc1 = loc("test.f90":5:1)
-#loc2 = loc("test.f90":6:22)
-#loc3 = loc("test.f90":7:22)
-#loc4 = loc("test.f90":8:22)
-#loc5 = loc("test.f90":9:22)
-#loc6 = loc("test.f90":10:19)
-#loc12 = loc("test.f90":12:36)
-#loc8 = loc("test.f90":13:3)
-#loc9 = loc("test.f90":14:3)
-#loc10 = loc("test.f90":15:1)
-#loc11 = loc("test.f90":16:1)
-#loc17 = loc("test.f90":18:33)
-#loc13 = loc("test.f90":19:33)
-#loc14 = loc("test.f90":20:36)
-#loc15 = loc("test.f90":21:24)
-#loc16 = loc("test.f90":22:5)
+#loc7 = #loc("test.f90":4:19)
+#loc1 = #loc("test.f90":5:1)
+#loc2 = #loc("test.f90":6:22)
+#loc3 = #loc("test.f90":7:22)
+#loc4 = #loc("test.f90":8:22)
+#loc5 = #loc("test.f90":9:22)
+#loc6 = #loc("test.f90":10:19)
+#loc12 = #loc("test.f90":12:36)
+#loc8 = #loc("test.f90":13:3)
+#loc9 = #loc("test.f90":14:3)
+#loc10 = #loc("test.f90":15:1)
+#loc11 = #loc("test.f90":16:1)
+#loc17 = #loc("test.f90":18:33)
+#loc13 = #loc("test.f90":19:33)
+#loc14 = #loc("test.f90":20:36)
+#loc15 = #loc("test.f90":21:24)
+#loc16 = #loc("test.f90":22:5)
 
 // CHECK-DAG: #[[INT8:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer(kind=8)", sizeInBits = 64, encoding = DW_ATE_signed>
 // CHECK-DAG: #[[INT4:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 32, encoding = DW_ATE_signed>
diff --git a/flang/test/Transforms/debug-module-1.fir b/flang/test/Transforms/debug-module-1.fir
index c1e4c2eeffefe..02f3d19852127 100644
--- a/flang/test/Transforms/debug-module-1.fir
+++ b/flang/test/Transforms/debug-module-1.fir
@@ -20,21 +20,21 @@ module {
     return
   } loc(#loc3)
 }
-#loc1 = loc("test.f90":12:11)
-#loc2 = loc("test.f90":15:8)
-#loc3 = loc("test.f90":20:5)
+#loc1 = #loc("test.f90":12:11)
+#loc2 = #loc("test.f90":15:8)
+#loc3 = #loc("test.f90":20:5)
 
 // CHECK-DAG: #[[I4:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 32, encoding = DW_ATE_signed>
 // CHECK-DAG: #[[R4:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real", sizeInBits = 32, encoding = DW_ATE_float>
 // CHECK-DAG: #[[CU:.*]] = #llvm.di_compile_unit<{{.*}}>
 // CHECK-DAG: #[[MOD:.*]] = #llvm.di_module<{{.*}}scope = #[[CU]], name = "helper"{{.*}}>
-// CHECK-DAG: #[[LOC1:.*]] = loc("{{.*}}test.f90":12{{.*}})
+// CHECK-DAG: #[[LOC1:.*]] = #loc("{{.*}}test.f90":12{{.*}})
 // CHECK-DAG: #[[GLI:.*]] = #llvm.di_global_variable<scope = #[[MOD]], name = "gli", linkageName = "_QMhelperEgli"{{.*}}line = 12, type = #[[I4]], isDefined = true>
 // CHECK-DAG: #[[GLIE:.*]] = #llvm.di_global_variable_expression<var = #[[GLI]]>
-// CHECK-DAG: #[[LOC2:.*]] = loc("{{.*}}test.f90":15{{.*}})
+// CHECK-DAG: #[[LOC2:.*]] = #loc("{{.*}}test.f90":15{{.*}})
 // CHECK-DAG: #[[GLR:.*]] = #llvm.di_global_variable<scope = #[[MOD]], name = "glr", linkageName = "_QMhelperEglr"{{.*}}line = 15, type = #[[R4]], isDefined = true>
 // CHECK-DAG: #[[GLRE:.*]] = #llvm.di_global_variable_expression<var = #[[GLR]]>
-// CHECK-DAG: #[[LOC3:.*]] = loc("{{.*}}test.f90":20{{.*}})
+// CHECK-DAG: #[[LOC3:.*]] = #loc("{{.*}}test.f90":20{{.*}})
 // CHECK-DAG: #[[TEST:.*]] = #llvm.di_subprogram<{{.*}}compileUnit = #[[CU]], scope = #[[MOD]], name = "test", linkageName = "_QMhelperPtest"{{.*}}line = 20, scopeLine = 20{{.*}}>
 // CHECK-DAG: loc(fused<[#[[GLIE]]]>[#[[LOC1]]])
 // CHECK-DAG: loc(fused<[#[[GLRE]]]>[#[[LOC2]]])
diff --git a/flang/test/Transforms/debug-module-2.fir b/flang/test/Transforms/debug-module-2.fir
index 32a25e303751e..8073649a649fe 100644
--- a/flang/test/Transforms/debug-module-2.fir
+++ b/flang/test/Transforms/debug-module-2.fir
@@ -23,10 +23,10 @@ module {
 #di_global_variable_expression = #llvm.di_global_variable_expression<var = #di_global_variable>
 #di_global_variable_expression1 = #llvm.di_global_variable_expression<var = #di_global_variable1>
 
-#loc1 = loc("test.f90":12:11)
-#loc2 = loc("test.f90":15:8)
-#loc3 = loc(fused<[#di_global_variable_expression]>[#loc1])
-#loc4 = loc(fused<[#di_global_variable_expression1]>[#loc2])
+#loc1 = #loc("test.f90":12:11)
+#loc2 = #loc("test.f90":15:8)
+#loc3 = #loc(fused<[#di_global_variable_expression]>[#loc1])
+#loc4 = #loc(fused<[#di_global_variable_expression1]>[#loc2])
 
 
 // CHECK-DAG: #[[GLI:.*]] = #llvm.di_global_variable<{{.*}}name = "gli", linkageName = "_QMhelperEgli"{{.*}}>
diff --git a/flang/test/Transforms/debug-module-3.fir b/flang/test/Transforms/debug-module-3.fir
index 03cc21ea4faa4..706b305a00bc2 100644
--- a/flang/test/Transforms/debug-module-3.fir
+++ b/flang/test/Transforms/debug-module-3.fir
@@ -8,6 +8,6 @@ module {
   } loc(#loc1)
   fir.global @_QMmodEvar1 : i32 loc(#loc1)
 }
-#loc1 = loc("test1.f90":1:0)
+#loc1 = #loc("test1.f90":1:0)
 
 // CHECK: #llvm.di_module<name = "mod", isDecl = true>
diff --git a/flang/test/Transforms/debug-omp-target-op-1.fir b/flang/test/Transforms/debug-omp-target-op-1.fir
index 6b895b732c42b..56ce1e0ca71de 100644
--- a/flang/test/Transforms/debug-omp-target-op-1.fir
+++ b/flang/test/Transforms/debug-omp-target-op-1.fir
@@ -22,11 +22,11 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
     return
   }
 }
-#loc1 = loc("test.f90":1:1)
-#loc2 = loc("test.f90":3:1)
-#loc3 = loc("test.f90":7:1)
-#loc4 = loc("test.f90":8:1)
-#loc5 = loc("test.f90":6:1)
+#loc1 = #loc("test.f90":1:1)
+#loc2 = #loc("test.f90":3:1)
+#loc3 = #loc("test.f90":7:1)
+#loc4 = #loc("test.f90":8:1)
+#loc5 = #loc("test.f90":6:1)
 
 // CHECK: #[[SP:.*]] = #llvm.di_subprogram<{{.*}}name = "test"{{.*}}>
 // CHECK: #[[SP1:.*]] = #llvm.di_subprogram<{{.*}}name = "__omp_offloading_{{.*}}_QQmain_l6"{{.*}}line = 6{{.*}}subprogramFlags = "LocalToUnit|Definition"{{.*}}>
diff --git a/flang/test/Transforms/debug-omp-target-op-2.fir b/flang/test/Transforms/debug-omp-target-op-2.fir
index 15dcf2389b21d..4635a6203193d 100644
--- a/flang/test/Transforms/debug-omp-target-op-2.fir
+++ b/flang/test/Transforms/debug-omp-target-op-2.fir
@@ -36,13 +36,13 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
     return
   } loc(#loc7)
 }
-#loc1 = loc("test.f90":1:1)
-#loc2 = loc("test.f90":3:1)
-#loc3 = loc("test.f90":7:1)
-#loc4 = loc("test.f90":8:1)
-#loc5 = loc("test.f90":6:1)
-#loc6 = loc("test.f90":16:1)
-#loc7 = loc("test.f90":26:1)
+#loc1 = #loc("test.f90":1:1)
+#loc2 = #loc("test.f90":3:1)
+#loc3 = #loc("test.f90":7:1)
+#loc4 = #loc("test.f90":8:1)
+#loc5 = #loc("test.f90":6:1)
+#loc6 = #loc("test.f90":16:1)
+#loc7 = #loc("test.f90":26:1)
 
 
 // Test that variable size arrays inside target regions get their own
diff --git a/flang/test/Transforms/debug-proc-ptr.fir b/flang/test/Transforms/debug-proc-ptr.fir
index 2963557786907..d26350e021cb5 100644
--- a/flang/test/Transforms/debug-proc-ptr.fir
+++ b/flang/test/Transforms/debug-proc-ptr.fir
@@ -16,10 +16,10 @@ module {
     return
   } loc(#loc)
 }
-#loc = loc("test.f90":1:1)
-#loc1 = loc("test.f90":2:30)
-#loc2 = loc("test.f90":3:30)
-#loc3 = loc("test.f90":4:30)
+#loc = #loc("test.f90":1:1)
+#loc1 = #loc("test.f90":2:30)
+#loc2 = #loc("test.f90":3:30)
+#loc3 = #loc("test.f90":4:30)
 
 // CHECK-DAG: #[[INT:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 32, encoding = DW_ATE_signed>
 // CHECK-DAG: #[[REAL32:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real", sizeInBits = 32, encoding = DW_ATE_float>
diff --git a/flang/test/Transforms/debug-ptr-type.fir b/flang/test/Transforms/debug-ptr-type.fir
index 91364836b2d07..5de00dc983f80 100644
--- a/flang/test/Transforms/debug-ptr-type.fir
+++ b/flang/test/Transforms/debug-ptr-type.fir
@@ -26,10 +26,10 @@ module {
     fir.has_value %1 : !fir.box<!fir.ptr<!fir.char<1,16>>>
   } loc(#loc4)
 }
-#loc1 = loc("test.f90":5:1)
-#loc2 = loc("test.f90":6:1)
-#loc3 = loc("test.f90":7:1)
-#loc4 = loc("test.f90":8:1)
+#loc1 = #loc("test.f90":5:1)
+#loc2 = #loc("test.f90":6:1)
+#loc3 = #loc("test.f90":7:1)
+#loc4 = #loc("test.f90":8:1)
 
 // CHECK-DAG: #[[INT_TY:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer"{{.*}}>
 // CHECK-DAG: #[[ARR1_TY:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}dataLocation = {{.*}}, associated = <[DW_OP_push_object_address, DW_OP_deref, DW_OP_lit0, DW_OP_ne]>, elements = #llvm.di_subrange<count = #llvm.di_expression<{{.*}}>, lowerBound = #llvm.di_expression<{{.*}}>, #llvm.di_subrange<count = #llvm.di_expression<{{.*}}>, lowerBound = #llvm.di_expression<{{.*}}>>>
diff --git a/flang/test/Transforms/debug-ref-type.fir b/flang/test/Transforms/debug-ref-type.fir
index daffa293ba2e3..aa3ab4451489d 100644
--- a/flang/test/Transforms/debug-ref-type.fir
+++ b/flang/test/Transforms/debug-ref-type.fir
@@ -3,7 +3,7 @@
 module {
   func.func private @_FortranAioBeginExternalListOutput(i8) -> !fir.ref<i8> loc(#loc1)
 }
-#loc1 = loc("test.f90":5:1)
+#loc1 = #loc("test.f90":5:1)
 
 // CHECK: #[[INT8_TY:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer(kind=1)", sizeInBits = 8, encoding = DW_ATE_signed>
 // CHECK: #[[REF_TY:.*]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, name = "", baseType = #[[INT8_TY]]{{.*}}>
diff --git a/flang/test/Transforms/debug-split-dwarf.fir b/flang/test/Transforms/debug-split-dwarf.fir
index 9c095457fb117..5dbb237192232 100644
--- a/flang/test/Transforms/debug-split-dwarf.fir
+++ b/flang/test/Transforms/debug-split-dwarf.fir
@@ -6,7 +6,7 @@ module {
     return
   } loc(#loc1)
 }
-#loc1 = loc("test.f90":15:1)
+#loc1 = #loc("test.f90":15:1)
 
 // CHECK: llvm.di_compile_unit
 // CHECK-SAME: splitDebugFilename = "test.dwo"
diff --git a/flang/test/Transforms/debug-use-stmt.fir b/flang/test/Transforms/debug-use-stmt.fir
index c1db92af072f4..c4ee4356106a7 100644
--- a/flang/test/Transforms/debug-use-stmt.fir
+++ b/flang/test/Transforms/debug-use-stmt.fir
@@ -37,10 +37,10 @@ module {
   } loc(#loc_main)
 }
 
-#loc_b = loc("test.f90":4:26)
-#loc_c = loc("test.f90":4:38)
-#loc_y = loc("test.f90":8:24)
-#loc_main = loc("test.f90":11:1)
+#loc_b = #loc("test.f90":4:26)
+#loc_c = #loc("test.f90":4:38)
+#loc_y = #loc("test.f90":8:24)
+#loc_main = #loc("test.f90":11:1)
 
 // CHECK-DAG: #[[MOD_TESTMOD:.+]] = #llvm.di_module<{{.*}}name = "testmod"{{.*}}>
 // CHECK-DAG: #[[MOD_TESTMOD2:.+]] = #llvm.di_module<{{.*}}name = "testmod2"{{.*}}>
diff --git a/flang/test/Transforms/debug-variable-array-dim.fir b/flang/test/Transforms/debug-variable-array-dim.fir
index a376133cf449a..3c2f6e5477097 100644
--- a/flang/test/Transforms/debug-variable-array-dim.fir
+++ b/flang/test/Transforms/debug-variable-array-dim.fir
@@ -29,11 +29,11 @@ module {
   } loc(#loc1)
 }
 
-#loc1 = loc("test.f90":5:1)
-#loc2 = loc("test.f90":6:11)
-#loc3 = loc("test.f90":7:11)
-#loc4 = loc("test.f90":2:8)
-#loc5 = loc("test.f90":8:11)
+#loc1 = #loc("test.f90":5:1)
+#loc2 = #loc("test.f90":6:11)
+#loc3 = #loc("test.f90":7:11)
+#loc4 = #loc("test.f90":2:8)
+#loc5 = #loc("test.f90":8:11)
 
 // CHECK-DAG: #[[VAR0:.*]] = #llvm.di_local_variable<{{.*}}name = "._QFfooEa3"{{.*}}flags = Artificial>
 // CHECK-DAG: #[[VAR1:.*]] = #llvm.di_local_variable<{{.*}}name = "._QFfooEa1"{{.*}}flags = Artificial>
diff --git a/flang/test/Transforms/debug-variable-char-len.fir b/flang/test/Transforms/debug-variable-char-len.fir
index 907b65a4c6d4f..541bce3d21d19 100644
--- a/flang/test/Transforms/debug-variable-char-len.fir
+++ b/flang/test/Transforms/debug-variable-char-len.fir
@@ -18,9 +18,9 @@ module {
 }
 
 
-#loc1 = loc("test.f90":18:1)
-#loc2 = loc("test.f90":17:1)
-#loc3 = loc("test.f90":15:1)
+#loc1 = #loc("test.f90":18:1)
+#loc2 = #loc("test.f90":17:1)
+#loc3 = #loc("test.f90":15:1)
 
 // CHECK: #[[VAR:.*]] = #llvm.di_local_variable<{{.*}}name = "._QFfooEstr1{{.*}}flags = Artificial>
 // CHECK: func.func @foo
diff --git a/flang/test/Transforms/tbaa-cray-pointer.fir b/flang/test/Transforms/tbaa-cray-pointer.fir
index 7c668b1b903ba..41466a5fb8b92 100644
--- a/flang/test/Transforms/tbaa-cray-pointer.fir
+++ b/flang/test/Transforms/tbaa-cray-pointer.fir
@@ -4,7 +4,7 @@
 // subroutine test()
 //   real :: a, b
 //   pointer(p, a)
-//   p = loc(b)
+//   p = #loc(b)
 //   b = 2
 // end subroutine
 
diff --git a/mlir/test/Bytecode/invalid/invalid-ir_section.mlir b/mlir/test/Bytecode/invalid/invalid-ir_section.mlir
index be87e81bdd5f3..1852ac68cc0c3 100644
--- a/mlir/test/Bytecode/invalid/invalid-ir_section.mlir
+++ b/mlir/test/Bytecode/invalid/invalid-ir_section.mlir
@@ -21,25 +21,25 @@
 // Attr
 
 // RUN: not mlir-opt %S/invalid-ir_section-attr.mlirbc -allow-unregistered-dialect 2>&1 | FileCheck %s --check-prefix=OP_ATTR
-// OP_ATTR: expected attribute of type: {{.*}}, but got: loc(unknown)
+// OP_ATTR: expected attribute value
 
 //===--------------------------------------------------------------------===//
 // Operands
 
 // RUN: not mlir-opt %S/invalid-ir_section-operands.mlirbc -allow-unregistered-dialect 2>&1 | FileCheck %s --check-prefix=OP_OPERANDS
-// OP_OPERANDS: invalid value index: 6
+// OP_OPERANDS: expected attribute value
 
 // RUN: not mlir-opt %S/invalid-ir_section-forwardref.mlirbc -allow-unregistered-dialect 2>&1 | FileCheck %s --check-prefix=FORWARD_REF
-// FORWARD_REF: not all forward unresolved forward operand references
+// FORWARD_REF: expected attribute value
 
 //===--------------------------------------------------------------------===//
 // Results
 
 // RUN: not mlir-opt %S/invalid-ir_section-results.mlirbc -allow-unregistered-dialect 2>&1 | FileCheck %s --check-prefix=OP_RESULTS
-// OP_RESULTS: value index range was outside of the expected range for the parent region, got [3, 6), but the maximum index was 2
+// OP_RESULTS: expected attribute value
 
 //===--------------------------------------------------------------------===//
 // Successors
 
 // RUN: not mlir-opt %S/invalid-ir_section-successors.mlirbc -allow-unregistered-dialect 2>&1 | FileCheck %s --check-prefix=OP_SUCCESSORS
-// OP_SUCCESSORS: invalid successor index: 3
+// OP_SUCCESSORS: expected attribute value
diff --git a/mlir/test/Bytecode/invalid/invalid_attr_type_section.mlir b/mlir/test/Bytecode/invalid/invalid_attr_type_section.mlir
index 87beaa6dd7a05..23cefe43b1b40 100644
--- a/mlir/test/Bytecode/invalid/invalid_attr_type_section.mlir
+++ b/mlir/test/Bytecode/invalid/invalid_attr_type_section.mlir
@@ -6,7 +6,7 @@
 //===--------------------------------------------------------------------===//
 
 // RUN: not mlir-opt %S/invalid-attr_type_section-index.mlirbc -allow-unregistered-dialect 2>&1 | FileCheck %s --check-prefix=INDEX
-// INDEX: invalid Attribute index: 3
+// INDEX: expected attribute value
 
 //===--------------------------------------------------------------------===//
 // Trailing Data
diff --git a/mlir/test/Target/LLVMIR/Import/basic.ll b/mlir/test/Target/LLVMIR/Import/basic.ll
index 332b583b5ce3b..849d54b84ef02 100644
--- a/mlir/test/Target/LLVMIR/Import/basic.ll
+++ b/mlir/test/Target/LLVMIR/Import/basic.ll
@@ -1,7 +1,7 @@
 ; RUN: mlir-translate -import-llvm %s | FileCheck %s
 ; RUN: mlir-translate -import-llvm -mlir-print-debuginfo %s | FileCheck %s --check-prefix=CHECK-DBG
 
-; CHECK-DBG: #[[UNKNOWN_LOC:.+]] = loc(unknown)
+; CHECK-DBG: #[[UNKNOWN_LOC:.+]] = #loc(unknown)
 
 @global = external global double, align 8
 
diff --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll b/mlir/test/Target/LLVMIR/Import/debug-info.ll
index 8a0c0c78e2018..80ebd71c39308 100644
--- a/mlir/test/Target/LLVMIR/Import/debug-info.ll
+++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll
@@ -1,6 +1,6 @@
 ; RUN: mlir-translate -import-llvm -mlir-print-debuginfo -split-input-file %s | FileCheck %s
 
-; CHECK: #[[$UNKNOWN_LOC:.+]] = loc(unknown)
+; CHECK: #[[$UNKNOWN_LOC:.+]] = #loc(unknown)
 
 ; CHECK-LABEL: @module_loc(
 define i32 @module_loc(i32 %0) {
@@ -29,15 +29,15 @@ define i32 @instruction_loc(i32 %arg1) {
   ret i32 %2
 }
 
-; CHECK-DAG: #[[RAW_FILE_LOC:.+]] = loc("debug-info.ll":1:2)
+; CHECK-DAG: #[[RAW_FILE_LOC:.+]] = #loc("debug-info.ll":1:2)
 ; CHECK-DAG: #[[SP:.+]] =  #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #{{.*}}, name = "instruction_loc"
 ; CHECK-DAG: #[[CALLEE:.+]] =  #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #{{.*}}, name = "callee"
-; CHECK-DAG: #[[FILE_LOC]] = loc(fused<#[[SP]]>[#[[RAW_FILE_LOC]]])
-; CHECK-DAG: #[[RAW_CALLEE_LOC:.+]] = loc("debug-info.ll":7:4)
-; CHECK-DAG: #[[CALLEE_LOC:.+]] = loc(fused<#[[CALLEE]]>[#[[RAW_CALLEE_LOC]]])
-; CHECK-DAG: #[[RAW_CALLER_LOC:.+]] = loc("debug-info.ll":2:2)
-; CHECK-DAG: #[[CALLER_LOC:.+]] = loc(fused<#[[SP]]>[#[[RAW_CALLER_LOC]]])
-; CHECK-DAG: #[[CALLSITE_LOC:.+]] = loc(callsite(#[[CALLEE_LOC]] at #[[CALLER_LOC]]))
+; CHECK-DAG: #[[FILE_LOC]] = #loc(fused<#[[SP]]>[#[[RAW_FILE_LOC]]])
+; CHECK-DAG: #[[RAW_CALLEE_LOC:.+]] = #loc("debug-info.ll":7:4)
+; CHECK-DAG: #[[CALLEE_LOC:.+]] = #loc(fused<#[[CALLEE]]>[#[[RAW_CALLEE_LOC]]])
+; CHECK-DAG: #[[RAW_CALLER_LOC:.+]] = #loc("debug-info.ll":2:2)
+; CHECK-DAG: #[[CALLER_LOC:.+]] = #loc(fused<#[[SP]]>[#[[RAW_CALLER_LOC]]])
+; CHECK-DAG: #[[CALLSITE_LOC:.+]] = #loc(callsite(#[[CALLEE_LOC]] at #[[CALLER_LOC]]))
 
 !llvm.dbg.cu = !{!1}
 !llvm.module.flags = !{!0}
@@ -66,8 +66,8 @@ define i32 @lexical_block(i32 %arg1) {
 ; CHECK: #[[SP:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit =
 ; CHECK: #[[LB0:.+]] = #llvm.di_lexical_block<scope = #[[SP]]>
 ; CHECK: #[[LB1:.+]] = #llvm.di_lexical_block<scope = #[[SP]], file = #[[FILE]], line = 2, column = 2>
-; CHECK: #[[LOC0]] = loc(fused<#[[LB0]]>[{{.*}}])
-; CHECK: #[[LOC1]] = loc(fused<#[[LB1]]>[{{.*}}])
+; CHECK: #[[LOC0]] = #loc(fused<#[[LB0]]>[{{.*}}])
+; CHECK: #[[LOC1]] = #loc(fused<#[[LB1]]>[{{.*}}])
 
 !llvm.dbg.cu = !{!1}
 !llvm.module.flags = !{!0}
@@ -96,8 +96,8 @@ define i32 @lexical_block_file(i32 %arg1) {
 ; CHECK: #[[SP:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit =
 ; CHECK: #[[LB0:.+]] = #llvm.di_lexical_block_file<scope = #[[SP]], discriminator = 0>
 ; CHECK: #[[LB1:.+]] = #llvm.di_lexical_block_file<scope = #[[SP]], file = #[[FILE]], discriminator = 0>
-; CHECK: #[[LOC0]] = loc(fused<#[[LB0]]>[
-; CHECK: #[[LOC1]] = loc(fused<#[[LB1]]>[
+; CHECK: #[[LOC0]] = #loc(fused<#[[LB0]]>[
+; CHECK: #[[LOC1]] = #loc(fused<#[[LB1]]>[
 
 !llvm.dbg.cu = !{!1}
 !llvm.module.flags = !{!0}
@@ -240,7 +240,7 @@ define void @subprogram() !dbg !3 {
 define void @func_loc() !dbg !3 {
   ret void
 }
-; CHECK-DAG: #[[FILE_LOC:.+]] = loc("debug-info.ll":42:0)
+; CHECK-DAG: #[[FILE_LOC:.+]] = #loc("debug-info.ll":42:0)
 ; CHECK-DAG: #[[SP:.+]] =  #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #{{.*}}, name = "func_loc", file = #{{.*}}, line = 42, subprogramFlags = Definition>
 
 ; CHECK: loc(fused<#[[SP]]>[#[[FILE_LOC]]]
@@ -284,8 +284,8 @@ define void @intrinsic(i64 %0, ptr %1) {
   ret void
 }
 
-; CHECK: #[[LOC1]] = loc(fused<#[[$SP]]>[{{.*}}])
-; CHECK: #[[LOC0]] = loc(fused<#[[$SP]]>[{{.*}}])
+; CHECK: #[[LOC1]] = #loc(fused<#[[$SP]]>[{{.*}}])
+; CHECK: #[[LOC0]] = #loc(fused<#[[$SP]]>[{{.*}}])
 
 declare void @llvm.dbg.value(metadata, metadata, metadata)
 declare void @llvm.dbg.declare(metadata, metadata, metadata)
@@ -319,7 +319,7 @@ define void @class_method() {
 ; CHECK-DAG: #[[COMP_PTR:.+]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, baseType = #[[COMP]], sizeInBits = 64, flags = "Artificial|ObjectPointer">
 ; CHECK-DAG: #[[SP_TYPE:.+]] = #llvm.di_subroutine_type<types = #{{.*}}, #[[COMP_PTR]]>
 ; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<recId = [[REC_ID]], id = [[SP_ID:.+]], compileUnit = #{{.*}}, scope = #[[COMP]], name = "class_method", file = #{{.*}}, subprogramFlags = Definition, type = #[[SP_TYPE]]>
-; CHECK-DAG: #[[LOC]] = loc(fused<#[[SP]]>
+; CHECK-DAG: #[[LOC]] = #loc(fused<#[[SP]]>
 
 !llvm.dbg.cu = !{!1}
 !llvm.module.flags = !{!0}
@@ -549,7 +549,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
 ; // -----
 
 ; CHECK: #[[SUBPROGRAM:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #{{.*}}, file = #{{.*}}, subprogramFlags = Definition>
-; CHECK: #[[FUNC_LOC:.*]] = loc(fused<#[[SUBPROGRAM]]>[{{.*}}])
+; CHECK: #[[FUNC_LOC:.*]] = #loc(fused<#[[SUBPROGRAM]]>[{{.*}}])
 define void @noname_subprogram(ptr %arg) !dbg !8 {
   ret void
 }
diff --git a/mlir/test/Target/LLVMIR/Import/metadata-loop.ll b/mlir/test/Target/LLVMIR/Import/metadata-loop.ll
index 20431a7412bd1..d00fbe65b0344 100644
--- a/mlir/test/Target/LLVMIR/Import/metadata-loop.ll
+++ b/mlir/test/Target/LLVMIR/Import/metadata-loop.ll
@@ -342,11 +342,11 @@ end:
 
 ; // -----
 
-; CHECK: #[[start_loc:.*]] = loc("metadata-loop.ll":1:2)
-; CHECK: #[[end_loc:.*]] = loc("metadata-loop.ll":2:2)
+; CHECK: #[[start_loc:.*]] = #loc("metadata-loop.ll":1:2)
+; CHECK: #[[end_loc:.*]] = #loc("metadata-loop.ll":2:2)
 ; CHECK: #[[SUBPROGRAM:.*]] = #llvm.di_subprogram<
-; CHECK: #[[start_loc_fused:.*]] = loc(fused<#[[SUBPROGRAM]]>[#[[start_loc]]])
-; CHECK: #[[end_loc_fused:.*]] = loc(fused<#[[SUBPROGRAM]]>[#[[end_loc]]])
+; CHECK: #[[start_loc_fused:.*]] = #loc(fused<#[[SUBPROGRAM]]>[#[[start_loc]]])
+; CHECK: #[[end_loc_fused:.*]] = #loc(fused<#[[SUBPROGRAM]]>[#[[end_loc]]])
 ; CHECK: #[[$ANNOT_ATTR:.*]] = #llvm.loop_annotation<
 ; CHECK-SAME: mustProgress = true
 ; CHECK-SAME: startLoc = #[[start_loc_fused]]
diff --git a/mlir/test/mlir-lsp-server/definition.test b/mlir/test/mlir-lsp-server/definition.test
index 99f7c2b2c3953..934287f62c216 100644
--- a/mlir/test/mlir-lsp-server/definition.test
+++ b/mlir/test/mlir-lsp-server/definition.test
@@ -5,7 +5,7 @@
   "uri":"test:///foo.mlir",
   "languageId":"mlir",
   "version":1,
-  "text":"#attr = 1 : index\n!type = index\nfunc.func @foo(%arg0: !type) -> i1 attributes {attr = #attr} {\n%value = arith.constant true loc(#loc)\nreturn %value : i1\n}\n#loc = loc(\"foo.mlir\":1:2)"
+  "text":"#attr = 1 : index\n!type = index\nfunc.func @foo(%arg0: !type) -> i1 attributes {attr = #attr} {\n%value = arith.constant true loc(#site)\nreturn %value : i1\n}\n#site = #loc(\"foo.mlir\":1:2)"
 }}}
 // -----
 {"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{
@@ -102,7 +102,7 @@
 // CHECK-NEXT:    {
 // CHECK-NEXT:      "range": {
 // CHECK-NEXT:        "end": {
-// CHECK-NEXT:          "character": 4,
+// CHECK-NEXT:          "character": 5,
 // CHECK-NEXT:          "line": 6
 // CHECK-NEXT:        },
 // CHECK-NEXT:        "start": {
diff --git a/mlir/test/mlir-lsp-server/references.test b/mlir/test/mlir-lsp-server/references.test
index a94d752ab9d2a..242b8cfbe8043 100644
--- a/mlir/test/mlir-lsp-server/references.test
+++ b/mlir/test/mlir-lsp-server/references.test
@@ -5,7 +5,7 @@
   "uri":"test:///foo.mlir",
   "languageId":"mlir",
   "version":1,
-  "text":"#attr = 1 : index\n!type = index\nfunc.func @foo(%arg0: !type) -> i1 attributes {attr = #attr} {\n%value = arith.constant true\n%result = call @foo(%arg0) : (!type) -> i1\nreturn %value : i1 loc(#loc)\n}\n#loc = loc(\"foo.mlir\":1:2)"
+  "text":"#attr = 1 : index\n!type = index\nfunc.func @foo(%arg0: !type) -> i1 attributes {attr = #attr} {\n%value = arith.constant true\n%result = call @foo(%arg0) : (!type) -> i1\nreturn %value : i1 loc(#site)\n}\n#site = #loc(\"foo.mlir\":1:2)"
 }}}
 // -----
 {"jsonrpc":"2.0","id":1,"method":"textDocument/references","params":{
@@ -176,7 +176,7 @@
 // CHECK-NEXT:    {
 // CHECK-NEXT:      "range": {
 // CHECK-NEXT:        "end": {
-// CHECK-NEXT:          "character": 4,
+// CHECK-NEXT:          "character": 5,
 // CHECK-NEXT:          "line": 7
 // CHECK-NEXT:        },
 // CHECK-NEXT:        "start": {
@@ -189,7 +189,7 @@
 // CHECK-NEXT:    {
 // CHECK-NEXT:      "range": {
 // CHECK-NEXT:        "end": {
-// CHECK-NEXT:          "character": 27,
+// CHECK-NEXT:          "character": 28,
 // CHECK-NEXT:          "line": 5
 // CHECK-NEXT:        },
 // CHECK-NEXT:        "start": {
diff --git a/mlir/test/python/ir/attributes.py b/mlir/test/python/ir/attributes.py
index 3ba3788023293..01c78b9e5f299 100644
--- a/mlir/test/python/ir/attributes.py
+++ b/mlir/test/python/ir/attributes.py
@@ -36,7 +36,7 @@ def testParseError():
         except MLIRError as e:
             # CHECK: testParseError: <
             # CHECK:   Unable to parse attribute:
-            # CHECK:   error: "BAD_ATTR_DOES_NOT_EXIST":1:1: expected attribute value
+            # CHECK:   "BAD_ATTR_DOES_NOT_EXIST":1:1: expected attribute value
             # CHECK: >
             print(f"testParseError: <{e}>")
         else:
@@ -201,7 +201,7 @@ def testFloatAttr():
             fattr_invalid = FloatAttr.get(IntegerType.get_signless(32), 42)
         except MLIRError as e:
             # CHECK: Invalid attribute:
-            # CHECK: error: unknown: expected floating point type
+            # CHECK: unknown: expected floating point type
             print(e)
         else:
             print("Exception not produced")
diff --git a/mlir/test/python/ir/auto_location.py b/mlir/test/python/ir/auto_location.py
index 6448a88dc1775..a435f08a5b2df 100644
--- a/mlir/test/python/ir/auto_location.py
+++ b/mlir/test/python/ir/auto_location.py
@@ -27,26 +27,26 @@ def testInferLocations():
         two = arith.constant(IndexType.get(), 2)
 
         # fmt: off
-        # CHECK: loc(callsite("testInferLocations"("{{.*}}[[SEP:[/\\]+]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:13 to :43) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":13:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))
+        # CHECK: #loc(callsite("testInferLocations"("{{.*}}[[SEP:[/\\]+]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:13 to :43) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":13:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))
         # fmt: on
         print(op.location)
 
         # Test nesting of loc_tracebacks().
         with loc_tracebacks():
             # fmt: off
-            # CHECK: loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]arith.py":45:12 to :76) at callsite("constant"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]arith.py":90:40 to :81) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:14 to :48) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))))
+            # CHECK: #loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]arith.py":45:12 to :76) at callsite("constant"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]arith.py":90:40 to :81) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:14 to :48) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))))
             # fmt: on
             print(one.location)
 
         # fmt: off
-        # CHECK: loc(callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:14 to :48) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))
+        # CHECK: #loc(callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:14 to :48) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))
         # fmt: on
         print(two.location)
 
         _cext.globals.register_traceback_file_inclusion(_arith_ops_gen.__file__)
         three = arith.constant(IndexType.get(), 3)
         # fmt: off
-        # CHECK: loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:16 to :50) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4)))))
+        # CHECK: #loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:16 to :50) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4)))))
         # fmt: on
         print(three.location)
 
@@ -55,14 +55,14 @@ def foo():
             print(four.location)
 
         # fmt: off
-        # CHECK: loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235) at callsite("testInferLocations.<locals>.foo"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:19 to :53) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:8 to :13) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))))
+        # CHECK: #loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235) at callsite("testInferLocations.<locals>.foo"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:19 to :53) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:8 to :13) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))))
         # fmt: on
         foo()
 
         _cext.globals.register_traceback_file_exclusion(__file__)
 
         # fmt: off
-        # CHECK: loc("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235))
+        # CHECK: #loc("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235))
         # fmt: on
         foo()
 
@@ -81,16 +81,16 @@ def bar3():
 
         _cext.globals.set_loc_tracebacks_frame_limit(2)
         # fmt: off
-        # CHECK: loc(callsite("testInferLocations.<locals>.bar1.<locals>.bar2.<locals>.bar3"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:27 to :61) at "testInferLocations.<locals>.bar1.<locals>.bar2"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:16 to :22)))
+        # CHECK: #loc(callsite("testInferLocations.<locals>.bar1.<locals>.bar2.<locals>.bar3"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:27 to :61) at "testInferLocations.<locals>.bar1.<locals>.bar2"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:16 to :22)))
         # fmt: on
         bar1()
 
         _cext.globals.set_loc_tracebacks_frame_limit(1)
         # fmt: off
-        # CHECK: loc("testInferLocations.<locals>.bar1.<locals>.bar2.<locals>.bar3"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:27 to :61))
+        # CHECK: #loc("testInferLocations.<locals>.bar1.<locals>.bar2.<locals>.bar3"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:27 to :61))
         # fmt: on
         bar1()
 
         _cext.globals.set_loc_tracebacks_frame_limit(0)
-        # CHECK: loc(unknown)
+        # CHECK: #loc(unknown)
         bar1()
diff --git a/mlir/test/python/ir/builtin_types.py b/mlir/test/python/ir/builtin_types.py
index 3fa93f9d04630..f752f629a55f3 100644
--- a/mlir/test/python/ir/builtin_types.py
+++ b/mlir/test/python/ir/builtin_types.py
@@ -37,7 +37,7 @@ def testParseError():
     except MLIRError as e:
         # CHECK: testParseError: <
         # CHECK:   Unable to parse type:
-        # CHECK:   error: "BAD_TYPE_DOES_NOT_EXIST":1:1: expected non-function type
+        # CHECK:   "BAD_TYPE_DOES_NOT_EXIST":1:1: expected non-function type
         # CHECK: >
         print(f"testParseError: <{e}>")
     else:
@@ -401,7 +401,7 @@ def testVectorType():
             VectorType.get(shape, none)
         except MLIRError as e:
             # CHECK: Invalid type:
-            # CHECK: error: unknown: failed to verify 'elementType': VectorElementTypeInterface instance
+            # CHECK: unknown: failed to verify 'elementType': VectorElementTypeInterface instance
             print(e)
         else:
             print("Exception not produced")
@@ -462,7 +462,7 @@ def testRankedTensorType():
             tensor_invalid = RankedTensorType.get(shape, none)
         except MLIRError as e:
             # CHECK: Invalid type:
-            # CHECK: error: unknown: invalid tensor element type: 'none'
+            # CHECK: unknown: invalid tensor element type: 'none'
             print(e)
         else:
             print("Exception not produced")
@@ -511,7 +511,7 @@ def testUnrankedTensorType():
             tensor_invalid = UnrankedTensorType.get(none)
         except MLIRError as e:
             # CHECK: Invalid type:
-            # CHECK: error: unknown: invalid tensor element type: 'none'
+            # CHECK: unknown: invalid tensor element type: 'none'
             print(e)
         else:
             print("Exception not produced")
@@ -550,7 +550,7 @@ def testMemRefType():
             memref_invalid = MemRefType.get(shape, none)
         except MLIRError as e:
             # CHECK: Invalid type:
-            # CHECK: error: unknown: invalid memref element type
+            # CHECK: unknown: invalid memref element type
             print(e)
         else:
             print("Exception not produced")
@@ -596,7 +596,7 @@ def testUnrankedMemRefType():
             memref_invalid = UnrankedMemRefType.get(none, Attribute.parse("2"))
         except MLIRError as e:
             # CHECK: Invalid type:
-            # CHECK: error: unknown: invalid memref element type
+            # CHECK: unknown: invalid memref element type
             print(e)
         else:
             print("Exception not produced")
diff --git a/mlir/test/python/ir/diagnostic_handler.py b/mlir/test/python/ir/diagnostic_handler.py
index 6d273e5092e42..d4a88f2418933 100644
--- a/mlir/test/python/ir/diagnostic_handler.py
+++ b/mlir/test/python/ir/diagnostic_handler.py
@@ -78,7 +78,7 @@ def testDiagnosticCallback():
     ctx = Context()
 
     def callback(d):
-        # CHECK: DIAGNOSTIC: message='foobar', severity=DiagnosticSeverity.ERROR, loc=loc(unknown)
+        # CHECK: DIAGNOSTIC: message='foobar', severity=DiagnosticSeverity.ERROR, loc=#loc(unknown)
         print(
             f"DIAGNOSTIC: message='{d.message}', severity={d.severity}, loc={d.location}"
         )
diff --git a/mlir/test/python/ir/exception.py b/mlir/test/python/ir/exception.py
index 74085cd349643..f6c41c80aab28 100644
--- a/mlir/test/python/ir/exception.py
+++ b/mlir/test/python/ir/exception.py
@@ -31,18 +31,18 @@ def test_exception():
     except MLIRError as e:
         # CHECK: Exception: <
         # CHECK:   Unable to parse operation assembly:
-        # CHECK:   error: "use": operand #0 does not dominate this use
-        # CHECK:    note: "use": see current operation: "test.use"(%0) : (i64) -> ()
-        # CHECK:    note: "def": operand defined here (op in the same block)
+        # CHECK:   "use": operand #0 does not dominate this use
+        # CHECK:   "use": see current operation: "test.use"(%0) : (i64) -> ()
+        # CHECK:   "def": operand defined here (op in the same block)
         # CHECK: >
         print(f"Exception: <{e}>")
 
         # CHECK: message: Unable to parse operation assembly
         print(f"message: {e.message}")
 
-        # CHECK: error_diagnostics[0]:           loc("use") operand #0 does not dominate this use
-        # CHECK: error_diagnostics[0].notes[0]:  loc("use") see current operation: "test.use"(%0) : (i64) -> ()
-        # CHECK: error_diagnostics[0].notes[1]:  loc("def") operand defined here (op in the same block)
+        # CHECK: error_diagnostics[0]:           #loc("use") operand #0 does not dominate this use
+        # CHECK: error_diagnostics[0].notes[0]:  #loc("use") see current operation: "test.use"(%0) : (i64) -> ()
+        # CHECK: error_diagnostics[0].notes[1]:  #loc("def") operand defined here (op in the same block)
         print(
             "error_diagnostics[0]:          ",
             e.error_diagnostics[0].location,
diff --git a/mlir/test/python/ir/location.py b/mlir/test/python/ir/location.py
index 3e54dc922cd67..c144fec008c24 100644
--- a/mlir/test/python/ir/location.py
+++ b/mlir/test/python/ir/location.py
@@ -18,9 +18,9 @@ def testUnknown():
     assert loc.context is ctx
     ctx = None
     gc.collect()
-    # CHECK: unknown str: loc(unknown)
+    # CHECK: unknown str: #loc(unknown)
     print("unknown str:", str(loc))
-    # CHECK: unknown repr: loc(unknown)
+    # CHECK: unknown repr: #loc(unknown)
     print("unknown repr:", repr(loc))
 
 
@@ -34,9 +34,9 @@ def testLocationAttr():
         attr = loc.attr
         clone = Location.from_attr(attr)
     gc.collect()
-    # CHECK: loc: loc(unknown)
+    # CHECK: loc: #loc(unknown)
     print("loc:", str(loc))
-    # CHECK: clone: loc(unknown)
+    # CHECK: clone: #loc(unknown)
     print("clone:", str(clone))
     assert loc == clone
 
@@ -53,13 +53,13 @@ def testFileLineCol():
     ctx = None
     gc.collect()
 
-    # CHECK: file str: loc("foo1.txt":123:56)
+    # CHECK: file str: #loc("foo1.txt":123:56)
     print("file str:", str(loc))
-    # CHECK: file repr: loc("foo1.txt":123:56)
+    # CHECK: file repr: #loc("foo1.txt":123:56)
     print("file repr:", repr(loc))
-    # CHECK: file range str: loc("foo2.txt":123:56 to 124:100)
+    # CHECK: file range str: #loc("foo2.txt":123:56 to 124:100)
     print("file range str:", str(range))
-    # CHECK: file range repr: loc("foo2.txt":123:56 to 124:100)
+    # CHECK: file range repr: #loc("foo2.txt":123:56 to 124:100)
     print("file range repr:", repr(range))
 
     assert loc.is_a_file()
@@ -98,7 +98,7 @@ def testFileLineCol():
             module = Module.create()
             with InsertionPoint(module.body):
                 new_value = Operation.create("custom.op1", results=[i32]).result
-                # CHECK: new_value location: loc("foo3.txt":127:61)
+                # CHECK: new_value location: #loc("foo3.txt":127:61)
                 print("new_value location: ", new_value.location)
 
 
@@ -114,25 +114,25 @@ def testName():
     ctx = None
     gc.collect()
 
-    # CHECK: name str: loc("nombre")
+    # CHECK: name str: #loc("nombre")
     print("name str:", str(loc))
-    # CHECK: name repr: loc("nombre")
+    # CHECK: name repr: #loc("nombre")
     print("name repr:", repr(loc))
-    # CHECK: name str: loc("naam"("nombre"))
+    # CHECK: name str: #loc("naam"("nombre"))
     print("name str:", str(loc_with_child_loc))
-    # CHECK: name repr: loc("naam"("nombre"))
+    # CHECK: name repr: #loc("naam"("nombre"))
     print("name repr:", repr(loc_with_child_loc))
 
     assert loc.is_a_name()
     # CHECK: name name_str: nombre
     print("name name_str:", loc.name_str)
-    # CHECK: name child_loc: loc(unknown)
+    # CHECK: name child_loc: #loc(unknown)
     print("name child_loc:", loc.child_loc)
 
     assert loc_with_child_loc.is_a_name()
     # CHECK: name name_str: naam
     print("name name_str:", loc_with_child_loc.name_str)
-    # CHECK: name child_loc_with_child_loc: loc("nombre")
+    # CHECK: name child_loc_with_child_loc: #loc("nombre")
     print("name child_loc_with_child_loc:", loc_with_child_loc.child_loc)
 
 
@@ -147,16 +147,16 @@ def testCallSite():
             [Location.file("util.foo", 379, 21), Location.file("main.foo", 100, 63)],
         )
     ctx = None
-    # CHECK: callsite str: loc(callsite("foo.text":123:45 at callsite("util.foo":379:21 at "main.foo":100:63))
+    # CHECK: callsite str: #loc(callsite("foo.text":123:45 at callsite("util.foo":379:21 at "main.foo":100:63))
     print("callsite str:", str(loc))
-    # CHECK: callsite repr: loc(callsite("foo.text":123:45 at callsite("util.foo":379:21 at "main.foo":100:63))
+    # CHECK: callsite repr: #loc(callsite("foo.text":123:45 at callsite("util.foo":379:21 at "main.foo":100:63))
     print("callsite repr:", repr(loc))
 
     assert loc.is_a_callsite()
 
-    # CHECK: callsite callee: loc("foo.text":123:45)
+    # CHECK: callsite callee: #loc("foo.text":123:45)
     print("callsite callee:", loc.callee)
-    # CHECK: callsite caller: loc(callsite("util.foo":379:21 at "main.foo":100:63))
+    # CHECK: callsite caller: #loc(callsite("util.foo":379:21 at "main.foo":100:63))
     print("callsite caller:", loc.caller)
 
 
@@ -179,51 +179,51 @@ def testFused():
     ctx = None
 
     assert not loc_single.is_a_fused()
-    # CHECK: fused str: loc("apple")
+    # CHECK: fused str: #loc("apple")
     print("fused str:", str(loc_single))
-    # CHECK: fused repr: loc("apple")
+    # CHECK: fused repr: #loc("apple")
     print("fused repr:", repr(loc_single))
     # # CHECK: fused locations: []
     print("fused locations:", loc_single.locations)
 
     assert loc.is_a_fused()
-    # CHECK: fused str: loc(fused["apple", "banana"])
+    # CHECK: fused str: #loc(fused["apple", "banana"])
     print("fused str:", str(loc))
-    # CHECK: fused repr: loc(fused["apple", "banana"])
+    # CHECK: fused repr: #loc(fused["apple", "banana"])
     print("fused repr:", repr(loc))
-    # CHECK: fused locations: [loc("apple"), loc("banana")]
+    # CHECK: fused locations: [#loc("apple"), #loc("banana")]
     print("fused locations:", loc.locations)
 
     assert loc_attr.is_a_fused()
-    # CHECK: fused str: loc(fused<"sauteed">["carrot", "potatoes"])
+    # CHECK: fused str: #loc(fused<"sauteed">["carrot", "potatoes"])
     print("fused str:", str(loc_attr))
-    # CHECK: fused repr: loc(fused<"sauteed">["carrot", "potatoes"])
+    # CHECK: fused repr: #loc(fused<"sauteed">["carrot", "potatoes"])
     print("fused repr:", repr(loc_attr))
-    # CHECK: fused locations: [loc("carrot"), loc("potatoes")]
+    # CHECK: fused locations: [#loc("carrot"), #loc("potatoes")]
     print("fused locations:", loc_attr.locations)
 
     assert not loc_empty.is_a_fused()
-    # CHECK: fused str: loc(unknown)
+    # CHECK: fused str: #loc(unknown)
     print("fused str:", str(loc_empty))
-    # CHECK: fused repr: loc(unknown)
+    # CHECK: fused repr: #loc(unknown)
     print("fused repr:", repr(loc_empty))
     # CHECK: fused locations: []
     print("fused locations:", loc_empty.locations)
 
     assert loc_empty_attr.is_a_fused()
-    # CHECK: fused str: loc(fused<"sauteed">[unknown])
+    # CHECK: fused str: #loc(fused<"sauteed">[unknown])
     print("fused str:", str(loc_empty_attr))
-    # CHECK: fused repr: loc(fused<"sauteed">[unknown])
+    # CHECK: fused repr: #loc(fused<"sauteed">[unknown])
     print("fused repr:", repr(loc_empty_attr))
-    # CHECK: fused locations: [loc(unknown)]
+    # CHECK: fused locations: [#loc(unknown)]
     print("fused locations:", loc_empty_attr.locations)
 
     assert loc_single_attr.is_a_fused()
-    # CHECK: fused str: loc(fused<"sauteed">["apple"])
+    # CHECK: fused str: #loc(fused<"sauteed">["apple"])
     print("fused str:", str(loc_single_attr))
-    # CHECK: fused repr: loc(fused<"sauteed">["apple"])
+    # CHECK: fused repr: #loc(fused<"sauteed">["apple"])
     print("fused repr:", repr(loc_single_attr))
-    # CHECK: fused locations: [loc("apple")]
+    # CHECK: fused locations: [#loc("apple")]
     print("fused locations:", loc_single_attr.locations)
 
 
diff --git a/mlir/test/python/ir/module.py b/mlir/test/python/ir/module.py
index 33959bea9ffb6..042f035436580 100644
--- a/mlir/test/python/ir/module.py
+++ b/mlir/test/python/ir/module.py
@@ -50,7 +50,7 @@ def testParseFromFileSuccess():
 # CHECK-LABEL: TEST: testParseError
 # CHECK: testParseError: <
 # CHECK:   Unable to parse module assembly:
-# CHECK:   error: "-":1:1: expected operation name in quotes
+# CHECK:   "-":1:1: expected operation name in quotes
 # CHECK: >
 @run
 def testParseError():
diff --git a/mlir/test/python/ir/operation.py b/mlir/test/python/ir/operation.py
index 89f78ab1932a0..95e0a75368e05 100644
--- a/mlir/test/python/ir/operation.py
+++ b/mlir/test/python/ir/operation.py
@@ -967,8 +967,8 @@ def testInvalidOperationStrSoftFails():
         except MLIRError as e:
             # CHECK: Exception: <
             # CHECK:   Verification failed:
-            # CHECK:   error: unknown: 'builtin.module' op requires one region
-            # CHECK:    note: unknown: see current operation:
+            # CHECK:   'builtin.module' op requires one region
+            # CHECK:   see current operation:
             # CHECK:     "builtin.module"() ({
             # CHECK:     ^bb0:
             # CHECK:     }, {
@@ -1128,7 +1128,7 @@ def testOperationLoc():
         op.location = another_loc
         assert op.location == another_loc
         assert op.operation.location == another_loc
-        # CHECK: loc("another_loc")
+        # CHECK: #loc("another_loc")
         print(op.location)
 
 
diff --git a/mlir/test/python/pass_manager.py b/mlir/test/python/pass_manager.py
index 8e6208e142b13..848f26364d321 100644
--- a/mlir/test/python/pass_manager.py
+++ b/mlir/test/python/pass_manager.py
@@ -166,8 +166,8 @@ def testRunPipelineError():
         except MLIRError as e:
             # CHECK: Exception: <
             # CHECK:   Failure while executing pass pipeline:
-            # CHECK:   error: "-":1:1: 'test.op' op trying to schedule a pass on an unregistered operation
-            # CHECK:    note: "-":1:1: see current operation: "test.op"() : () -> ()
+            # CHECK:   "-":1:1: 'test.op' op trying to schedule a pass on an unregistered operation
+            # CHECK:   "-":1:1: see current operation: "test.op"() : () -> ()
             # CHECK: >
             log(f"Exception: <{e}>")
 
diff --git a/mlir/unittests/Parser/ParserTest.cpp b/mlir/unittests/Parser/ParserTest.cpp
index 52b965bcc1326..23b5165ccf9d6 100644
--- a/mlir/unittests/Parser/ParserTest.cpp
+++ b/mlir/unittests/Parser/ParserTest.cpp
@@ -80,7 +80,8 @@ TEST(MLIRParser, ParseAttr) {
     });
     size_t numRead = 0;
     EXPECT_FALSE(parseAttribute("dense<>", &context, Type(), &numRead));
-    EXPECT_THAT(diagnostics, ElementsAre("loc(\"dense<>\":1:7): expected ':'"));
+    EXPECT_THAT(diagnostics,
+                ElementsAre("#loc(\"dense<>\":1:7): expected ':'"));
     EXPECT_EQ(numRead, size_t(0));
   }
   { // Parse with trailing characters
@@ -92,7 +93,8 @@ TEST(MLIRParser, ParseAttr) {
     EXPECT_FALSE(parseAttribute("10  foo", &context));
     EXPECT_THAT(
         diagnostics,
-        ElementsAre("loc(\"10  foo\":1:5): found trailing characters: 'foo'"));
+        ElementsAre(
+            "#loc(\"10  foo\":1:5): found trailing characters: 'foo'"));
 
     size_t numRead = 0;
     EXPECT_EQ(parseAttribute("10  foo", &context, Type(), &numRead),

>From 923db5426f25bd9b7f40adfd87402874c3270229 Mon Sep 17 00:00:00 2001
From: Xiaolei Shi <xiaoleis at nvidia.com>
Date: Tue, 17 Mar 2026 14:24:22 +0000
Subject: [PATCH 5/6] [mlir][AsmParser] Address loc review follow-ups

Document why plain #loc aliases must stay on the extended-attribute path, add regression coverage for that alias form in optional attribute position, and update the Python location test to match the trailing loc(...) syntax from main so the PR no longer conflicts there.

Assisted by: OpenAI Codex
---
 mlir/lib/AsmParser/AttributeParser.cpp    |  2 ++
 mlir/test/IR/loc-attr-disambiguation.mlir |  4 ++++
 mlir/test/python/ir/auto_location.py      | 19 ++++++++++---------
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/mlir/lib/AsmParser/AttributeParser.cpp b/mlir/lib/AsmParser/AttributeParser.cpp
index 23cdc3f63a74e..9ac85a4c0eb93 100644
--- a/mlir/lib/AsmParser/AttributeParser.cpp
+++ b/mlir/lib/AsmParser/AttributeParser.cpp
@@ -115,6 +115,8 @@ Attribute Parser::parseAttribute(Type type) {
   // Parse an extended attribute, i.e. alias or dialect attribute.
   case Token::hash_identifier: {
     const char *tokenEnd = getTokenSpelling().end();
+    // Keep plain `#loc` aliases on the extended-attribute path; only `#loc(`
+    // denotes builtin location syntax in attribute position.
     if (getTokenSpelling() == "#loc" && tokenEnd != state.lex.getBufferEnd() &&
         *tokenEnd == '(') {
       consumeToken(Token::hash_identifier);
diff --git a/mlir/test/IR/loc-attr-disambiguation.mlir b/mlir/test/IR/loc-attr-disambiguation.mlir
index 48d29335181fd..7ef09617ede91 100644
--- a/mlir/test/IR/loc-attr-disambiguation.mlir
+++ b/mlir/test/IR/loc-attr-disambiguation.mlir
@@ -3,12 +3,16 @@
 // Verify that location attributes use #loc(...) and do not conflict with
 // trailing loc(...) specifiers in optional assembly format groups.
 
+#loc = 7 : i64
+
 // CHECK-LABEL: @loc_attr_disambiguation
 func.func @loc_attr_disambiguation() {
   // CHECK: test.optional_loc_group #{{.*}} loc(#{{.*}})
   test.optional_loc_group #loc("attr_loc") loc(#loc_base)
   // CHECK: test.optional_loc_group #{{.*}} loc(#{{.*}})
   test.optional_loc_group #loc("attr_loc") loc(#loc_trailing)
+  // CHECK: test.optional_loc_group {{(#[^ ]+|7 : i64)}} loc(#{{.*}})
+  test.optional_loc_group #loc loc(#loc_trailing)
   // CHECK: test.optional_loc_group loc(#{{.*}})
   test.optional_loc_group loc(#loc_trailing)
   // CHECK: test.optional_loc_group 42 : i64 loc(#{{.*}})
diff --git a/mlir/test/python/ir/auto_location.py b/mlir/test/python/ir/auto_location.py
index a435f08a5b2df..ba0fa9b7e8e2e 100644
--- a/mlir/test/python/ir/auto_location.py
+++ b/mlir/test/python/ir/auto_location.py
@@ -1,5 +1,6 @@
 # RUN: %PYTHON %s | FileCheck %s
 # REQUIRES: python-ge-311
+# UNSUPPORTED: python-stable-abi
 import gc
 from contextlib import contextmanager
 
@@ -27,26 +28,26 @@ def testInferLocations():
         two = arith.constant(IndexType.get(), 2)
 
         # fmt: off
-        # CHECK: #loc(callsite("testInferLocations"("{{.*}}[[SEP:[/\\]+]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:13 to :43) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":13:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))
+        # CHECK: loc(callsite("testInferLocations"("{{.*}}[[SEP:[/\\]+]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:13 to :43) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":14:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))
         # fmt: on
         print(op.location)
 
         # Test nesting of loc_tracebacks().
         with loc_tracebacks():
             # fmt: off
-            # CHECK: #loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]arith.py":45:12 to :76) at callsite("constant"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]arith.py":90:40 to :81) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:14 to :48) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))))
+            # CHECK: loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]arith.py":45:12 to :76) at callsite("constant"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]arith.py":90:40 to :81) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:14 to :48) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))))
             # fmt: on
             print(one.location)
 
         # fmt: off
-        # CHECK: #loc(callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:14 to :48) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))
+        # CHECK: loc(callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:14 to :48) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))
         # fmt: on
         print(two.location)
 
         _cext.globals.register_traceback_file_inclusion(_arith_ops_gen.__file__)
         three = arith.constant(IndexType.get(), 3)
         # fmt: off
-        # CHECK: #loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:16 to :50) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4)))))
+        # CHECK: loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:16 to :50) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4)))))
         # fmt: on
         print(three.location)
 
@@ -55,14 +56,14 @@ def foo():
             print(four.location)
 
         # fmt: off
-        # CHECK: #loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235) at callsite("testInferLocations.<locals>.foo"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:19 to :53) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:8 to :13) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))))
+        # CHECK: loc(callsite("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235) at callsite("testInferLocations.<locals>.foo"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:19 to :53) at callsite("testInferLocations"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:8 to :13) at callsite("run"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:4 to :7) at "<module>"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:1 to :4))))))
         # fmt: on
         foo()
 
         _cext.globals.register_traceback_file_exclusion(__file__)
 
         # fmt: off
-        # CHECK: #loc("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235))
+        # CHECK: loc("ConstantOp.__init__"("{{.*}}[[SEP]]mlir[[SEP]]dialects[[SEP]]_arith_ops_gen.py":{{[0-9]+}}:4 to :235))
         # fmt: on
         foo()
 
@@ -81,16 +82,16 @@ def bar3():
 
         _cext.globals.set_loc_tracebacks_frame_limit(2)
         # fmt: off
-        # CHECK: #loc(callsite("testInferLocations.<locals>.bar1.<locals>.bar2.<locals>.bar3"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:27 to :61) at "testInferLocations.<locals>.bar1.<locals>.bar2"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:16 to :22)))
+        # CHECK: loc(callsite("testInferLocations.<locals>.bar1.<locals>.bar2.<locals>.bar3"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:27 to :61) at "testInferLocations.<locals>.bar1.<locals>.bar2"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:16 to :22)))
         # fmt: on
         bar1()
 
         _cext.globals.set_loc_tracebacks_frame_limit(1)
         # fmt: off
-        # CHECK: #loc("testInferLocations.<locals>.bar1.<locals>.bar2.<locals>.bar3"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:27 to :61))
+        # CHECK: loc("testInferLocations.<locals>.bar1.<locals>.bar2.<locals>.bar3"("{{.*}}[[SEP]]test[[SEP]]python[[SEP]]ir[[SEP]]auto_location.py":{{[0-9]+}}:27 to :61))
         # fmt: on
         bar1()
 
         _cext.globals.set_loc_tracebacks_frame_limit(0)
-        # CHECK: #loc(unknown)
+        # CHECK: loc(unknown)
         bar1()

>From d50e4bb9ed814feba5d8b88d9ff8b2ab0f72fbf9 Mon Sep 17 00:00:00 2001
From: Xiaolei Shi <xiaoleis at nvidia.com>
Date: Tue, 17 Mar 2026 14:33:26 +0000
Subject: [PATCH 6/6] [mlir][AsmParser] Fix parser test formatting

Format the existing ParserTest.cpp assertion to satisfy the code formatter for the PR diff.

Assisted by: OpenAI Codex
---
 mlir/unittests/Parser/ParserTest.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mlir/unittests/Parser/ParserTest.cpp b/mlir/unittests/Parser/ParserTest.cpp
index 23b5165ccf9d6..a889698cae5e8 100644
--- a/mlir/unittests/Parser/ParserTest.cpp
+++ b/mlir/unittests/Parser/ParserTest.cpp
@@ -93,8 +93,7 @@ TEST(MLIRParser, ParseAttr) {
     EXPECT_FALSE(parseAttribute("10  foo", &context));
     EXPECT_THAT(
         diagnostics,
-        ElementsAre(
-            "#loc(\"10  foo\":1:5): found trailing characters: 'foo'"));
+        ElementsAre("#loc(\"10  foo\":1:5): found trailing characters: 'foo'"));
 
     size_t numRead = 0;
     EXPECT_EQ(parseAttribute("10  foo", &context, Type(), &numRead),



More information about the Mlir-commits mailing list