[Mlir-commits] [mlir] [mlir] [irdl] Fix order of emitted cpp namespace closing comments (PR #172035)

Robert Konicar llvmlistbot at llvm.org
Fri Dec 12 08:14:51 PST 2025


https://github.com/Jezurko created https://github.com/llvm/llvm-project/pull/172035

None

>From ce6aa2c5c224e37575ae44c836765a029adff6a4 Mon Sep 17 00:00:00 2001
From: Robert Konicar <rkonicar at mail.muni.cz>
Date: Fri, 12 Dec 2025 17:12:47 +0100
Subject: [PATCH] [mlir] [irdl] Fix order of emitted cpp namespace closing
 comments

---
 mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp                      | 4 +++-
 .../lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp.irdl.mlir     | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp b/mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp
index 8ecb08456da1a..b87cbb5a9aab1 100644
--- a/mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp
+++ b/mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp
@@ -711,10 +711,12 @@ irdl::translateIRDLDialectToCpp(llvm::ArrayRef<irdl::DialectOp> dialects,
     llvm::raw_string_ostream namespacePathStream(namespacePath);
     for (auto &pathElement : namespaceAbsolutePath) {
       namespaceOpenStream << "namespace " << pathElement << " {\n";
-      namespaceCloseStream << "} // namespace " << pathElement << "\n";
       namespacePathStream << "::" << pathElement;
     }
 
+    for (auto &pathElement : llvm::reverse(namespaceAbsolutePath))
+      namespaceCloseStream << "} // namespace " << pathElement << "\n";
+
     std::string cppShortName =
         llvm::convertToCamelFromSnakeCase(dialectName, true);
     std::string dialectBaseTypeName = llvm::formatv("{0}Type", cppShortName);
diff --git a/mlir/test/lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp.irdl.mlir b/mlir/test/lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp.irdl.mlir
index 85fb8cb15acef..770cd36cdee33 100644
--- a/mlir/test/lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp.irdl.mlir
+++ b/mlir/test/lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp.irdl.mlir
@@ -1,6 +1,11 @@
 // RUN: mlir-irdl-to-cpp %s | FileCheck %s
 
+// CHECK: namespace mlir {
+// CHECK: namespace test_irdl_to_cpp {
+
 // CHECK: class TestIrdlToCpp
+// CHECK: } // namespace test_irdl_to_cpp
+// CHECK: } // namespace mlir
 irdl.dialect @test_irdl_to_cpp {
 
     // CHECK: class FooType



More information about the Mlir-commits mailing list