https://github.com/berkaysahiin updated 
https://github.com/llvm/llvm-project/pull/221720

>From 278fe5492b8dd84039c0911ce115bd4abf824b10 Mon Sep 17 00:00:00 2001
From: Berkay Sahin <[email protected]>
Date: Mon, 7 Sep 2026 15:35:31 +0300
Subject: [PATCH 1/2] [CIR] Handle ImportDecl in emitTopLevelDecl

---
 clang/lib/CIR/CodeGen/CIRGenModule.cpp        |  5 ++++
 .../CodeGen/Inputs/modules-import-iface.cppm  |  2 ++
 .../test/CIR/CodeGen/modules-import-impl.cpp  | 24 +++++++++++++++++++
 clang/test/CIR/CodeGen/modules-import.cpp     | 24 +++++++++++++++++++
 4 files changed, 55 insertions(+)
 create mode 100644 clang/test/CIR/CodeGen/Inputs/modules-import-iface.cppm
 create mode 100644 clang/test/CIR/CodeGen/modules-import-impl.cpp
 create mode 100644 clang/test/CIR/CodeGen/modules-import.cpp

diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp 
b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index cb3f109da2bdf..d1fafe720ba61 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -2538,6 +2538,11 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
     emitDeclContext(cast<ExportDecl>(decl));
     break;
 
+  case Decl::Import:
+    // Nothing to emit for C++20 module imports. Initializers run through
+    // the imported module.
+    break;
+
   case Decl::Var:
   case Decl::Decomposition:
   case Decl::VarTemplateSpecialization: {
diff --git a/clang/test/CIR/CodeGen/Inputs/modules-import-iface.cppm 
b/clang/test/CIR/CodeGen/Inputs/modules-import-iface.cppm
new file mode 100644
index 0000000000000..7291c56519c08
--- /dev/null
+++ b/clang/test/CIR/CodeGen/Inputs/modules-import-iface.cppm
@@ -0,0 +1,2 @@
+export module m;
+export int f() { return 1; }
diff --git a/clang/test/CIR/CodeGen/modules-import-impl.cpp 
b/clang/test/CIR/CodeGen/modules-import-impl.cpp
new file mode 100644
index 0000000000000..97f70d4070257
--- /dev/null
+++ b/clang/test/CIR/CodeGen/modules-import-impl.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu \
+// RUN:   -emit-module-interface %S/Inputs/modules-import-iface.cppm -o %t.pcm
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu \
+// RUN:   -fclangir -emit-cir -fmodule-file=m=%t.pcm %s -o %t.cir
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu \
+// RUN:   -fclangir -emit-llvm -fmodule-file=m=%t.pcm %s -o %t.ll
+// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu \
+// RUN:   -emit-llvm -fmodule-file=m=%t.pcm %s -o %t.og.ll
+// RUN: FileCheck --check-prefix=OGCG --input-file=%t.og.ll %s
+
+module m;
+
+int g() { return f() + 1; }
+
+// CIR-LABEL: cir.func {{.*}} @_ZW1m1gv(
+// CIR:         {{%.+}} = cir.call @_ZW1m1fv() : () -> (!s32i {{.*}})
+
+// LLVM-LABEL: define {{.*}} i32 @_ZW1m1gv()
+// LLVM:         {{%.+}} = call {{.*}} i32 @_ZW1m1fv()
+
+// OGCG-LABEL: define {{.*}} i32 @_ZW1m1gv()
+// OGCG:         {{%.+}} = call {{.*}} i32 @_ZW1m1fv()
diff --git a/clang/test/CIR/CodeGen/modules-import.cpp 
b/clang/test/CIR/CodeGen/modules-import.cpp
new file mode 100644
index 0000000000000..11efc7e1f3d8e
--- /dev/null
+++ b/clang/test/CIR/CodeGen/modules-import.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu \
+// RUN:   -emit-module-interface %S/Inputs/modules-import-iface.cppm -o %t.pcm
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu \
+// RUN:   -fclangir -emit-cir -fmodule-file=m=%t.pcm %s -o %t.cir
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu \
+// RUN:   -fclangir -emit-llvm -fmodule-file=m=%t.pcm %s -o %t.ll
+// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu \
+// RUN:   -emit-llvm -fmodule-file=m=%t.pcm %s -o %t.og.ll
+// RUN: FileCheck --check-prefix=OGCG --input-file=%t.og.ll %s
+
+import m;
+
+int use_it() { return f(); }
+
+// CIR-LABEL: cir.func {{.*}} @_Z6use_itv(
+// CIR:         {{%.+}} = cir.call @_ZW1m1fv() : () -> (!s32i {{.*}})
+
+// LLVM-LABEL: define {{.*}} i32 @_Z6use_itv()
+// LLVM:         {{%.+}} = call {{.*}} i32 @_ZW1m1fv()
+
+// OGCG-LABEL: define {{.*}} i32 @_Z6use_itv()
+// OGCG:         {{%.+}} = call {{.*}} i32 @_ZW1m1fv()

>From b4518de0f7a93d52f4f7d01eaee996b0f96ffb74 Mon Sep 17 00:00:00 2001
From: Berkay Sahin <[email protected]>
Date: Wed, 9 Sep 2026 16:50:18 +0300
Subject: [PATCH 2/2] [CIR][NFC] Reuse LLVM prefix for classic CodeGen checks
 in modules-import tests

---
 clang/test/CIR/CodeGen/modules-import-impl.cpp | 5 +----
 clang/test/CIR/CodeGen/modules-import.cpp      | 5 +----
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/clang/test/CIR/CodeGen/modules-import-impl.cpp 
b/clang/test/CIR/CodeGen/modules-import-impl.cpp
index 97f70d4070257..859088e10b64e 100644
--- a/clang/test/CIR/CodeGen/modules-import-impl.cpp
+++ b/clang/test/CIR/CodeGen/modules-import-impl.cpp
@@ -8,7 +8,7 @@
 // RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu \
 // RUN:   -emit-llvm -fmodule-file=m=%t.pcm %s -o %t.og.ll
-// RUN: FileCheck --check-prefix=OGCG --input-file=%t.og.ll %s
+// RUN: FileCheck --check-prefix=LLVM --input-file=%t.og.ll %s
 
 module m;
 
@@ -19,6 +19,3 @@ int g() { return f() + 1; }
 
 // LLVM-LABEL: define {{.*}} i32 @_ZW1m1gv()
 // LLVM:         {{%.+}} = call {{.*}} i32 @_ZW1m1fv()
-
-// OGCG-LABEL: define {{.*}} i32 @_ZW1m1gv()
-// OGCG:         {{%.+}} = call {{.*}} i32 @_ZW1m1fv()
diff --git a/clang/test/CIR/CodeGen/modules-import.cpp 
b/clang/test/CIR/CodeGen/modules-import.cpp
index 11efc7e1f3d8e..b6f79d97c7a93 100644
--- a/clang/test/CIR/CodeGen/modules-import.cpp
+++ b/clang/test/CIR/CodeGen/modules-import.cpp
@@ -8,7 +8,7 @@
 // RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu \
 // RUN:   -emit-llvm -fmodule-file=m=%t.pcm %s -o %t.og.ll
-// RUN: FileCheck --check-prefix=OGCG --input-file=%t.og.ll %s
+// RUN: FileCheck --check-prefix=LLVM --input-file=%t.og.ll %s
 
 import m;
 
@@ -19,6 +19,3 @@ int use_it() { return f(); }
 
 // LLVM-LABEL: define {{.*}} i32 @_Z6use_itv()
 // LLVM:         {{%.+}} = call {{.*}} i32 @_ZW1m1fv()
-
-// OGCG-LABEL: define {{.*}} i32 @_Z6use_itv()
-// OGCG:         {{%.+}} = call {{.*}} i32 @_ZW1m1fv()

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

Reply via email to