[clang] e74a4fe - [NFC] [C++20] [Modules] Add a test

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 23:40:36 PDT 2023


Author: Chuanqi Xu
Date: 2023-05-23T14:40:17+08:00
New Revision: e74a4fe317385ce2ca4045d3a0fac00e64ca3ee4

URL: https://github.com/llvm/llvm-project/commit/e74a4fe317385ce2ca4045d3a0fac00e64ca3ee4
DIFF: https://github.com/llvm/llvm-project/commit/e74a4fe317385ce2ca4045d3a0fac00e64ca3ee4.diff

LOG: [NFC] [C++20] [Modules] Add a test

Add a test from https://github.com/llvm/llvm-project/issues/59999. It is
always good to have more tests.

Added: 
    clang/test/Modules/pr59999.cppm

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/clang/test/Modules/pr59999.cppm b/clang/test/Modules/pr59999.cppm
new file mode 100644
index 000000000000..23710de9fe1c
--- /dev/null
+++ b/clang/test/Modules/pr59999.cppm
@@ -0,0 +1,44 @@
+// Test case from https://github.com/llvm/llvm-project/issues/59999
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Module.cppm \
+// RUN:     -emit-module-interface -o %t/Module.pcm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Object.cppm \
+// RUN:     -fmodule-file=Module=%t/Module.pcm -emit-module-interface -o %t/Object.pcm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Object.pcm \
+// RUN:     -fmodule-file=Module=%t/Module.pcm -S -emit-llvm -o - | FileCheck %t/Object.cppm
+
+//--- Module.cppm
+export module Module;
+
+export template <class ObjectType> bool ModuleRegister() { return true; };
+
+export struct ModuleEntry {
+  static const bool bRegistered;
+};
+
+const bool ModuleEntry::bRegistered = ModuleRegister<ModuleEntry>();
+
+//--- Object.cppm
+export module Object;
+
+import Module;
+
+export template <class ObjectType> bool ObjectRegister() { return true; }
+export struct NObject {
+  static const bool bRegistered;
+};
+export struct ObjectModuleEntry {
+  static const bool bRegistered;
+};
+
+// This function is also required for crash
+const bool NObject::bRegistered = ObjectRegister<NObject>();
+// One another function, that helps clang crash
+const bool ObjectModuleEntry::bRegistered = ModuleRegister<ObjectModuleEntry>();
+
+// Check that the LLVM IR is generated correctly instead of crashing.
+// CHECK: define{{.*}}@_ZGIW6Object


        


More information about the cfe-commits mailing list