diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:11:37 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:11:37 +0000 |
commit | 461a67fa15370a9ec88f8f8a240bf7c123bb2029 (patch) | |
tree | 6942083d7d56bba40ec790a453ca58ad3baf6832 /test/CXX/modules-ts/basic | |
parent | 75c3240472ba6ac2669ee72ca67eb72d4e2851fc (diff) |
Notes
Diffstat (limited to 'test/CXX/modules-ts/basic')
9 files changed, 213 insertions, 40 deletions
diff --git a/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp b/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp index dc6a3635a8ee..79e68655b45b 100644 --- a/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp +++ b/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp @@ -2,17 +2,14 @@ // RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s --implicit-check-not=unused --implicit-check-not=global_module // CHECK-DAG: @extern_var_exported = external global -// FIXME: Should this be 'external global'? // CHECK-DAG: @inline_var_exported = linkonce_odr global -// CHECK-DAG: @_ZL19static_var_exported = external global -// CHECK-DAG: @const_var_exported = external constant +// CHECK-DAG: @_ZW6ModuleE19static_var_exported = available_externally global i32 0, +// CHECK-DAG: @const_var_exported = available_externally constant i32 3, // -// FIXME: The module name should be mangled into all of these. -// CHECK-DAG: @extern_var_module_linkage = external global -// FIXME: Should this be 'external global'? -// CHECK-DAG: @inline_var_module_linkage = linkonce_odr global -// CHECK-DAG: @_ZL25static_var_module_linkage = external global -// CHECK-DAG: @_ZL24const_var_module_linkage = external constant +// CHECK-DAG: @_ZW6ModuleE25extern_var_module_linkage = external global +// CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = linkonce_odr global +// CHECK-DAG: @_ZW6ModuleE25static_var_module_linkage = available_externally global i32 0, +// CHECK-DAG: @_ZW6ModuleE24const_var_module_linkage = available_externally constant i32 3, module Module; @@ -28,15 +25,13 @@ void use() { (void)&const_var_exported; // FIXME: This symbol should not be visible here. - // CHECK: declare {{.*}}@_ZL26used_static_module_linkagev + // CHECK: declare {{.*}}@_ZW6ModuleE26used_static_module_linkagev used_static_module_linkage(); - // FIXME: The module name should be mangled into the name of this function. - // CHECK: define linkonce_odr {{.*}}@_Z26used_inline_module_linkagev + // CHECK: define linkonce_odr {{.*}}@_ZW6ModuleE26used_inline_module_linkagev used_inline_module_linkage(); - // FIXME: The module name should be mangled into the name of this function. - // CHECK: declare {{.*}}@_Z24noninline_module_linkagev + // CHECK: declare {{.*}}@_ZW6ModuleE24noninline_module_linkagev noninline_module_linkage(); (void)&extern_var_module_linkage; diff --git a/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm b/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm index d452f741a0fb..15d1114fb03f 100644 --- a/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm +++ b/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm @@ -11,17 +11,20 @@ // can discard this global and its initializer (if any), and other TUs are not // permitted to run the initializer for this variable. // CHECK-DAG: @inline_var_exported = linkonce_odr global -// CHECK-DAG: @_ZL19static_var_exported = global +// CHECK-DAG: @_ZW6ModuleE19static_var_exported = global // CHECK-DAG: @const_var_exported = constant // -// FIXME: The module name should be mangled into all of these. -// CHECK-DAG: @extern_var_module_linkage = external global +// CHECK-DAG: @_ZW6ModuleE25extern_var_module_linkage = external global // FIXME: Should this be 'weak_odr global'? Presumably it must be, since we // can discard this global and its initializer (if any), and other TUs are not // permitted to run the initializer for this variable. -// CHECK-DAG: @inline_var_module_linkage = linkonce_odr global -// CHECK-DAG: @_ZL25static_var_module_linkage = global -// CHECK-DAG: @_ZL24const_var_module_linkage = constant +// CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = linkonce_odr global +// CHECK-DAG: @_ZW6ModuleE25static_var_module_linkage = global +// CHECK-DAG: @_ZW6ModuleE24const_var_module_linkage = constant +// +// CHECK-DAG: @_ZW6ModuleE25unused_var_module_linkage = global i32 4 +// CHECK-DAG: @_ZW6ModuleE32unused_static_var_module_linkage = global i32 5 +// CHECK-DAG: @_ZW6ModuleE31unused_const_var_module_linkage = constant i32 7 static void unused_static_global_module() {} static void used_static_global_module() {} @@ -57,9 +60,9 @@ export module Module; export { // FIXME: These should be ill-formed: you can't export an internal linkage // symbol, per [dcl.module.interface]p2. - // CHECK: define void {{.*}}@_ZL22unused_static_exportedv + // CHECK: define void {{.*}}@_ZW6ModuleE22unused_static_exportedv static void unused_static_exported() {} - // CHECK: define void {{.*}}@_ZL20used_static_exportedv + // CHECK: define void {{.*}}@_ZW6ModuleE20used_static_exportedv static void used_static_exported() {} inline void unused_inline_exported() {} @@ -88,11 +91,9 @@ export { // FIXME: Ideally we wouldn't emit this as its name is not visible outside this // TU, but this module interface might contain a template that can use this // function so we conservatively emit it for now. -// FIXME: The module name should be mangled into the name of this function. -// CHECK: define void {{.*}}@_ZL28unused_static_module_linkagev +// CHECK: define void {{.*}}@_ZW6ModuleE28unused_static_module_linkagev static void unused_static_module_linkage() {} -// FIXME: The module name should be mangled into the name of this function. -// CHECK: define void {{.*}}@_ZL26used_static_module_linkagev +// CHECK: define void {{.*}}@_ZW6ModuleE26used_static_module_linkagev static void used_static_module_linkage() {} inline void unused_inline_module_linkage() {} @@ -103,12 +104,10 @@ inline int inline_var_module_linkage; static int static_var_module_linkage; const int const_var_module_linkage = 3; -// FIXME: The module name should be mangled into the name of this function. -// CHECK: define void {{.*}}@_Z24noninline_module_linkagev +// CHECK: define void {{.*}}@_ZW6ModuleE24noninline_module_linkagev void noninline_module_linkage() { used_static_module_linkage(); - // FIXME: The module name should be mangled into the name of this function. - // CHECK: define linkonce_odr {{.*}}@_Z26used_inline_module_linkagev + // CHECK: define linkonce_odr {{.*}}@_ZW6ModuleE26used_inline_module_linkagev used_inline_module_linkage(); (void)&extern_var_module_linkage; @@ -116,3 +115,15 @@ void noninline_module_linkage() { (void)&static_var_module_linkage; (void)&const_var_module_linkage; } + +int unused_var_module_linkage = 4; +static int unused_static_var_module_linkage = 5; +inline int unused_inline_var_module_linkage = 6; +const int unused_const_var_module_linkage = 7; + +struct a { + struct b {}; + struct c {}; +}; +// CHECK: define void @_ZW6ModuleE1fW_0EN1a1bEW_0ENS_1cE( +void f(a::b, a::c) {} diff --git a/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp b/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp index f6e0238c6b4b..5e9f7ecf5bab 100644 --- a/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp +++ b/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp @@ -2,11 +2,9 @@ // RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s --implicit-check-not=unused --implicit-check-not=global_module // CHECK-DAG: @extern_var_exported = external global -// FIXME: Should this be 'external global'? // CHECK-DAG: @inline_var_exported = linkonce_odr global -// FIXME: These should be 'extern global' and 'extern constant'. -// CHECK-DAG: @_ZL19static_var_exported = global -// CHECK-DAG: @const_var_exported = constant +// CHECK-DAG: @_ZW6ModuleE19static_var_exported = available_externally global i32 0 +// CHECK-DAG: @const_var_exported = available_externally constant i32 3 import Module; diff --git a/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp b/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp new file mode 100644 index 000000000000..cceca5106cae --- /dev/null +++ b/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -fmodules-ts -verify -std=c++17 %s +// RUN: %clang_cc1 -fmodules-ts -verify -std=c++17 %s -DEXPORT +// RUN: %clang_cc1 -fmodules-ts -verify -std=c++17 %s -DUSING + +#ifndef NO_GLOBAL +extern int var; // expected-note {{previous declaration is here}} +int func(); // expected-note {{previous declaration is here}} +struct str; // expected-note {{previous declaration is here}} +using type = int; + +template<typename> extern int var_tpl; // expected-note {{previous declaration is here}} +template<typename> int func_tpl(); // expected-note-re {{{{previous declaration is here|target of using declaration}}}} +template<typename> struct str_tpl; // expected-note {{previous declaration is here}} +template<typename> using type_tpl = int; // expected-note {{previous declaration is here}} + +typedef int type; +namespace ns { using ::func; } +namespace ns_alias = ns; +#endif + +export module M; + +#ifdef USING +using ::var; +using ::func; +using ::str; +using ::type; +using ::var_tpl; +using ::func_tpl; // expected-note {{using declaration}} +using ::str_tpl; +using ::type_tpl; +#endif + +#ifdef EXPORT +export { +#endif + +extern int var; // expected-error {{declaration of 'var' in module M follows declaration in the global module}} +int func(); // expected-error {{declaration of 'func' in module M follows declaration in the global module}} +struct str; // expected-error {{declaration of 'str' in module M follows declaration in the global module}} +using type = int; + +template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module M follows declaration in the global module}} +// FIXME: Is this the right diagnostic in the -DUSING case? +template<typename> int func_tpl(); // expected-error-re {{{{declaration of 'func_tpl' in module M follows declaration in the global module|conflicts with target of using declaration}}}} +template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module M follows declaration in the global module}} +template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module M follows declaration in the global module}} + +typedef int type; +namespace ns { using ::func; } +namespace ns_alias = ns; + +#ifdef EXPORT +} +#endif diff --git a/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp b/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp new file mode 100644 index 000000000000..f58506dd9c46 --- /dev/null +++ b/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp @@ -0,0 +1,19 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules-ts -emit-module-interface -std=c++17 %S/global-vs-module.cpp -o %t -DNO_GLOBAL -DEXPORT +// RUN: %clang_cc1 -fmodules-ts -verify -std=c++17 %s -fmodule-file=%t + +import M; + +extern int var; // expected-error {{declaration of 'var' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:38 {{previous}} +int func(); // expected-error {{declaration of 'func' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:39 {{previous}} +struct str; // expected-error {{declaration of 'str' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:40 {{previous}} +using type = int; + +template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:43 {{previous}} +template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:45 {{previous}} +template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:46 {{previous}} +template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:47 {{previous}} + +typedef int type; +namespace ns { using ::func; } +namespace ns_alias = ns; diff --git a/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp b/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp new file mode 100644 index 000000000000..39e210c4ad80 --- /dev/null +++ b/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp @@ -0,0 +1,44 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// +// Some of the following tests intentionally have no -verify in their RUN +// lines; we are testing that those cases do not produce errors. +// +// RUN: %clang_cc1 -fmodules-ts -std=c++17 %S/global-vs-module.cpp -emit-module-interface -o %t/M.pcm -DNO_GLOBAL -DEXPORT +// RUN: %clang_cc1 -fmodules-ts -std=c++17 %s -fmodule-file=%t/M.pcm -DMODULE_INTERFACE -verify +// RUN: %clang_cc1 -fmodules-ts -std=c++17 %s -fmodule-file=%t/M.pcm -DMODULE_INTERFACE -DNO_IMPORT +// +// RUN: %clang_cc1 -fmodules-ts -std=c++17 %s -fmodule-file=%t/M.pcm -emit-module-interface -o %t/N.pcm -DMODULE_INTERFACE -DNO_ERRORS +// RUN: %clang_cc1 -fmodules-ts -std=c++17 %s -fmodule-file=%t/N.pcm -verify +// FIXME: Once we start importing "import" declarations properly, this should +// be rejected (-verify should be added to the following line). +// RUN: %clang_cc1 -fmodules-ts -std=c++17 %s -fmodule-file=%t/N.pcm -DNO_IMPORT +// +// RUN: %clang_cc1 -fmodules-ts -std=c++17 %s -fmodule-file=%t/M.pcm -emit-module-interface -o %t/N-no-M.pcm -DMODULE_INTERFACE -DNO_ERRORS -DNO_IMPORT +// RUN: %clang_cc1 -fmodules-ts -std=c++17 %s -fmodule-file=%t/N-no-M.pcm -verify +// RUN: %clang_cc1 -fmodules-ts -std=c++17 %s -fmodule-file=%t/N-no-M.pcm -DNO_IMPORT + +#ifdef MODULE_INTERFACE +export +#endif +module N; + +#ifndef NO_IMPORT +import M; +#endif + +#ifndef NO_ERRORS +extern int var; // expected-error {{declaration of 'var' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:38 {{previous}} +int func(); // expected-error {{declaration of 'func' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:39 {{previous}} +struct str; // expected-error {{declaration of 'str' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:40 {{previous}} +using type = int; + +template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:43 {{previous}} +template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:45 {{previous}} +template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:46 {{previous}} +template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:47 {{previous}} + +typedef int type; +namespace ns { using ::func; } +namespace ns_alias = ns; +#endif diff --git a/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp b/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp index ee696d14585c..feb0afdda07b 100644 --- a/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp +++ b/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp @@ -9,7 +9,6 @@ // RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface -fmodule-file=%t/x.pcm %t/x.y.cppm -o %t/x.y.pcm // // Module implementation for unknown and known module. (The former is ill-formed.) -// FIXME: TEST=1 should fail because we don't have an interface for module z. // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ // RUN: -DTEST=1 -DEXPORT= -DPARTITION= -DMODULE_NAME=z // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ @@ -32,24 +31,26 @@ // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ // RUN: -DTEST=7 -DEXPORT= -DPARTITION=elderberry -DMODULE_NAME=z // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=8 -DEXPORT= -DPARTITION= -DMODULE_NAME='z [[]]' +// RUN: -DTEST=8 -DEXPORT=export -DPARTITION= -DMODULE_NAME='z [[]]' // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=9 -DEXPORT= -DPARTITION= -DMODULE_NAME='z [[fancy]]' +// RUN: -DTEST=9 -DEXPORT=export -DPARTITION= -DMODULE_NAME='z [[fancy]]' // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=10 -DEXPORT= -DPARTITION= -DMODULE_NAME='z [[maybe_unused]]' +// RUN: -DTEST=10 -DEXPORT=export -DPARTITION= -DMODULE_NAME='z [[maybe_unused]]' EXPORT module PARTITION MODULE_NAME; #if TEST == 4 // expected-error@-2 {{redefinition of module 'x'}} -// expected-note-re@module-declaration.cpp:* {{loaded from '{{.*}}/x.pcm'}} +// expected-note-re@module-declaration.cpp:* {{loaded from '{{.*[/\\]}}x.pcm'}} #elif TEST == 6 // expected-error@-5 {{module partition must be declared 'export'}} #elif TEST == 7 -// expected-error@-7 {{expected ';'}} expected-error@-7 {{requires a type specifier}} +// expected-error@-7 {{expected ';'}} expected-error@-7 {{requires a type specifier}} expected-error@-7 {{definition of module 'elderberry' is not available}} #elif TEST == 9 // expected-warning@-9 {{unknown attribute 'fancy' ignored}} #elif TEST == 10 // expected-error-re@-11 {{'maybe_unused' attribute cannot be applied to a module{{$}}}} +#elif TEST == 1 +// expected-error@-13 {{definition of module 'z' is not available}} #else // expected-no-diagnostics #endif diff --git a/test/CXX/modules-ts/basic/basic.link/p3.cppm b/test/CXX/modules-ts/basic/basic.link/p3.cppm new file mode 100644 index 000000000000..8ff141c5ff6b --- /dev/null +++ b/test/CXX/modules-ts/basic/basic.link/p3.cppm @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fmodules-ts -triple x86_64-linux %s -emit-module-interface -o %t +// RUN: %clang_cc1 -fmodules-ts -triple x86_64-linux -x pcm %t -emit-llvm -o - | FileCheck %s + +export module M; + +// CHECK-DAG: @_ZW1ME1a = constant i32 1 +const int a = 1; +// CHECK-DAG: @b = constant i32 2 +export const int b = 2; + +export int f() { return a + b; } diff --git a/test/CXX/modules-ts/basic/basic.search/module-import.cpp b/test/CXX/modules-ts/basic/basic.search/module-import.cpp new file mode 100644 index 000000000000..0b5f39d072a3 --- /dev/null +++ b/test/CXX/modules-ts/basic/basic.search/module-import.cpp @@ -0,0 +1,39 @@ +// Tests for imported module search. +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: echo 'export module x; int a, b;' > %t/x.cppm +// RUN: echo 'export module y; import x; int c;' > %t/y.cppm +// RUN: echo 'export module z; import y; int d;' > %t/z.cppm +// +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %t/x.cppm -o %t/x.pcm +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface -fmodule-file=%t/x.pcm %t/y.cppm -o %t/y.pcm +// +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.pcm -verify %s \ +// RUN: -DMODULE_NAME=x +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/y.pcm -verify %s \ +// RUN: -DMODULE_NAME=y +// +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=x=%t/x.pcm -verify %s \ +// RUN: -DMODULE_NAME=x +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=y=%t/y.pcm -verify %s \ +// RUN: -DMODULE_NAME=y +// +// RUN: mv %t/x.pcm %t/a.pcm +// +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=x=%t/a.pcm -verify %s \ +// RUN: -DMODULE_NAME=x +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/y.pcm -fmodule-file=x=%t/a.pcm -verify %s \ +// RUN: -DMODULE_NAME=y +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=y=%t/y.pcm -fmodule-file=x=%t/a.pcm -verify %s \ +// RUN: -DMODULE_NAME=y +// +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface -fmodule-file=y=%t/y.pcm -fmodule-file=x=%t/a.pcm %t/z.cppm -o %t/z.pcm +// +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=z=%t/z.pcm -fmodule-file=y=%t/y.pcm -fmodule-file=x=%t/a.pcm -verify %s \ +// RUN: -DMODULE_NAME=z +// + +import MODULE_NAME; + +// expected-no-diagnostics |