llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Berkay Sahin (berkaysahiin) <details> <summary>Changes</summary> 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. --- Full diff: https://github.com/llvm/llvm-project/pull/221720.diff 4 Files Affected: - (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+5) - (added) clang/test/CIR/CodeGen/Inputs/modules-import-iface.cppm (+2) - (added) clang/test/CIR/CodeGen/modules-import-impl.cpp (+24) - (added) clang/test/CIR/CodeGen/modules-import.cpp (+24) ``````````diff 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() `````````` </details> https://github.com/llvm/llvm-project/pull/221720 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
