https://github.com/berkaysahiin created https://github.com/llvm/llvm-project/pull/221720
Importing TUs and module implementation units failed with "declaration of kind: Import". Initializers run through the imported module, as in classic CodeGen, so handle it as a no-op. >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] [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() _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
