https://github.com/mpark updated 
https://github.com/llvm/llvm-project/pull/155948

>From 63519ed11294db85a9896e33a6a34bbc8b067dde Mon Sep 17 00:00:00 2001
From: Michael Park <mcyp...@gmail.com>
Date: Thu, 28 Aug 2025 14:38:21 -0700
Subject: [PATCH 1/3] [C++20][Modules] Add tests related to anonymous members
 in class templates.

---
 .../test/Modules/merge-anon-in-template-2.cpp | 47 +++++++++++++++++++
 .../test/Modules/merge-anon-in-template-3.cpp | 45 ++++++++++++++++++
 2 files changed, 92 insertions(+)
 create mode 100644 clang/test/Modules/merge-anon-in-template-2.cpp
 create mode 100644 clang/test/Modules/merge-anon-in-template-3.cpp

diff --git a/clang/test/Modules/merge-anon-in-template-2.cpp 
b/clang/test/Modules/merge-anon-in-template-2.cpp
new file mode 100644
index 0000000000000..15852f0120798
--- /dev/null
+++ b/clang/test/Modules/merge-anon-in-template-2.cpp
@@ -0,0 +1,47 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -fmodule-name=hu-01 -emit-header-unit 
-xc++-user-header %t/hu-01.h \
+// RUN:  -o %t/hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -fmodule-name=hu-02 -emit-header-unit 
-xc++-user-header %t/hu-02.h \
+// RUN:  -Wno-experimental-header-units \
+// RUN:  -fmodule-map-file=%t/hu-01.map -fmodule-file=hu-01=%t/hu-01.pcm \
+// RUN:  -o %t/hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj %t/main.cpp \
+// RUN:  -Wno-experimental-header-units \
+// RUN:  -fmodule-map-file=%t/hu-01.map -fmodule-file=hu-01=%t/hu-01.pcm \
+// RUN:  -fmodule-map-file=%t/hu-02.map -fmodule-file=hu-02=%t/hu-02.pcm
+
+//--- hu-01.map
+module "hu-01" {
+  header "hu-01.h"
+  export *
+}
+
+//--- hu-02.map
+module "hu-02" {
+  header "hu-02.h"
+  export *
+}
+
+//--- hu-01.h
+template <typename T>
+struct S { union { T x; }; };
+
+using SI = S<int>;
+
+//--- hu-02.h
+template <typename T>
+struct S { union { T x; }; };
+
+inline void f(S<int> s = {}) { s.x; }
+
+//--- main.cpp
+import "hu-01.h";
+void g(S<int>) {}
+
+import "hu-02.h";
+void h() { f(); }
diff --git a/clang/test/Modules/merge-anon-in-template-3.cpp 
b/clang/test/Modules/merge-anon-in-template-3.cpp
new file mode 100644
index 0000000000000..1ee447e3e524d
--- /dev/null
+++ b/clang/test/Modules/merge-anon-in-template-3.cpp
@@ -0,0 +1,45 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -fmodule-name=hu-01 -emit-header-unit 
-xc++-user-header %t/hu-01.h \
+// RUN:  -o %t/hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -fmodule-name=hu-02 -emit-header-unit 
-xc++-user-header %t/hu-02.h \
+// RUN:  -Wno-experimental-header-units \
+// RUN:  -fmodule-map-file=%t/hu-01.map -fmodule-file=hu-01=%t/hu-01.pcm \
+// RUN:  -o %t/hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj %t/main.cpp \
+// RUN:  -Wno-experimental-header-units \
+// RUN:  -fmodule-map-file=%t/hu-01.map -fmodule-file=hu-01=%t/hu-01.pcm \
+// RUN:  -fmodule-map-file=%t/hu-02.map -fmodule-file=hu-02=%t/hu-02.pcm
+
+//--- hu-01.map
+module "hu-01" {
+  header "hu-01.h"
+  export *
+}
+
+//--- hu-02.map
+module "hu-02" {
+  header "hu-02.h"
+  export *
+}
+
+//--- hu-01.h
+template <typename T>
+struct S { union { T x; }; };
+
+using SI = S<int>;
+
+//--- hu-02.h
+import "hu-01.h";
+inline void f(S<int> s = {}) { s.x; }
+
+//--- main.cpp
+import "hu-01.h";
+void g(S<int>) {}
+
+import "hu-02.h";
+void h() { f(); }

>From 7d782ec10fc6aae93bca79fa4f6e2ce718eccf0b Mon Sep 17 00:00:00 2001
From: Michael Park <mcyp...@gmail.com>
Date: Thu, 4 Sep 2025 23:14:03 -0700
Subject: [PATCH 2/3] [C++20][Modules] Maintain the first point of
 instantiation on UpdateDecl.

---
 clang/lib/Serialization/ASTReaderDecl.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 6b35b205079e5..ce203333d009f 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4796,7 +4796,8 @@ void ASTDeclReader::UpdateDecl(Decl *D) {
       } else {
         auto *Spec = cast<ClassTemplateSpecializationDecl>(RD);
         Spec->setTemplateSpecializationKind(TSK);
-        Spec->setPointOfInstantiation(POI);
+        if (Spec->getPointOfInstantiation().isInvalid())
+          Spec->setPointOfInstantiation(POI);
 
         if (Record.readInt()) {
           auto *PartialSpec =

>From c69375f2b69d28bf6244bda1961250bc2ea9fb80 Mon Sep 17 00:00:00 2001
From: Michael Park <mcyp...@gmail.com>
Date: Thu, 4 Sep 2025 23:15:04 -0700
Subject: [PATCH 3/3] [C++20][Modules] Number the anonymous members if the decl
 was instantiated locally.

---
 clang/lib/Serialization/ASTReaderDecl.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index ce203333d009f..31a1b3eaa8f55 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3425,7 +3425,13 @@ NamedDecl 
*ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader,
   // If this is the first time, but we have parsed a declaration of the 
context,
   // build the anonymous declaration list from the parsed declaration.
   auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC);
-  if (PrimaryDC && !cast<Decl>(PrimaryDC)->isFromASTFile()) {
+  auto InstantiatedLocally = [](Decl *D, SourceManager &SourceMgr) -> bool {
+    auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D);
+    return CTSD && CTSD->getPointOfInstantiation().isValid() &&
+           SourceMgr.isLocalSourceLocation(CTSD->getPointOfInstantiation());
+  };
+  if (PrimaryDC && (!cast<Decl>(PrimaryDC)->isFromASTFile() ||
+                    InstantiatedLocally(CanonDC, Reader.getSourceManager()))) {
     numberAnonymousDeclsWithin(PrimaryDC, [&](NamedDecl *ND, unsigned Number) {
       if (Previous.size() == Number)
         Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl()));

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to