https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/174365


Close https://github.com/llvm/llvm-project/issues/158321

The root cause of the problem is a mismatch in an initializer.

>From 58f3add86b4857b6831d841b9af37a0be1446a8d Mon Sep 17 00:00:00 2001
From: Chuanqi Xu <[email protected]>
Date: Mon, 5 Jan 2026 14:42:43 +0800
Subject: [PATCH] [C++20] [Modules] Fix incorrect read of TULocalOffset for
 delayed namespace

Close https://github.com/llvm/llvm-project/issues/158321

The root cause of the problem is a mismatch in an initializer.
---
 clang/lib/Serialization/ASTReader.cpp |  2 +-
 clang/test/Modules/pr158321.cppm      | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Modules/pr158321.cppm

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index e518c5cca32bb..540373cebdfc6 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4223,7 +4223,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
             TULocalLocalOffset ? BaseOffset + TULocalLocalOffset : 0;
 
         DelayedNamespaceOffsetMap[ID] = {
-            {VisibleOffset, TULocalOffset, ModuleLocalOffset}, LexicalOffset};
+            {VisibleOffset, ModuleLocalOffset, TULocalOffset}, LexicalOffset};
 
         assert(!GetExistingDecl(ID) &&
                "We shouldn't load the namespace in the front of delayed "
diff --git a/clang/test/Modules/pr158321.cppm b/clang/test/Modules/pr158321.cppm
new file mode 100644
index 0000000000000..e5be1769c04a6
--- /dev/null
+++ b/clang/test/Modules/pr158321.cppm
@@ -0,0 +1,27 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/m.cppm -emit-reduced-module-interface -o 
%t/m.pcm
+// RUN: %clang_cc1 -std=c++20 %t/consumer.cpp -fprebuilt-module-path=%t 
-fsyntax-only -verify
+
+//--- repro_header.h
+namespace n
+{
+}
+
+//--- m.cppm
+module;
+#include "repro_header.h"
+export module m;
+namespace n
+{
+    int x;
+}
+
+//--- consumer.cpp
+// expected-no-diagnostics
+import m;
+namespace n
+{
+}
\ No newline at end of file

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to