131 lines · cpp
1// RUN: rm -rf %t2// RUN: split-file %s %t3// RUN: cd %t4 5// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 O.cpp \6// RUN: -emit-module-interface -o O.pcm7// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 O.pcm -emit-llvm \8// RUN: -o - | FileCheck %s --check-prefix=CHECK-O9 10// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 P.cpp \11// RUN: -emit-module-interface -fprebuilt-module-path=%t -o P.pcm12// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 P.pcm -emit-llvm \13// RUN: -fprebuilt-module-path=%t -o - | FileCheck %s --check-prefix=CHECK-P14 15// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 Q.cpp \16// RUN: -emit-module-interface -o Q.pcm17// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 Q.pcm -emit-llvm \18// RUN: -o - | FileCheck %s --check-prefix=CHECK-Q19 20// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 R.cpp \21// RUN: -emit-module-interface -fprebuilt-module-path=%t -o R.pcm22// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 R.pcm -emit-llvm \23// RUN: -fprebuilt-module-path=%t -o - | FileCheck %s --check-prefix=CHECK-R24 25// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 S.cpp \26// RUN: -emit-module-interface -fprebuilt-module-path=%t -o S.pcm27// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 S.pcm -emit-llvm \28// RUN: -fprebuilt-module-path=%t -o - | FileCheck %s --check-prefix=CHECK-S29 30// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 T.cpp \31// RUN: -emit-module-interface -fprebuilt-module-path=%t -o T.pcm32// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 T.pcm -emit-llvm \33// RUN: -fprebuilt-module-path=%t -o - | FileCheck %s --check-prefix=CHECK-T34 35// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 U.cpp \36// RUN: -emit-module-interface -fprebuilt-module-path=%t -o U.pcm37// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 U.pcm -emit-llvm \38// RUN: -fprebuilt-module-path=%t -o - | FileCheck %s --check-prefix=CHECK-U39 40// Testing cases where we can elide the module initializer guard variable.41 42// This module has no global inits and does not import any other module43//--- O.cpp44 45export module O;46 47export int foo ();48 49// CHECK-O: define void @_ZGIW1O50// CHECK-O-LABEL: entry51// CHECK-O-NEXT: ret void52// CHECK-O-NOT: @_ZGIW1O__in_chrg53 54// This has no global inits and all the imported modules don't need inits. So55// guard variable is not needed.56//--- P.cpp57 58export module P;59 60export import O;61export int bar ();62 63// CHECK-P: define void @_ZGIW1P64// CHECK-P-LABEL: entry65// CHECK-P-NEXT: ret void66// CHECK-P-NOT: @_ZGIW1P__in_chrg67 68// This has global inits, so needs a guard.69//--- Q.cpp70 71export module Q;72 73export struct Quack {74 Quack(){};75};76 77export Quack Duck;78 79export int baz ();80 81// CHECK-Q: define internal void @__cxx_global_var_init82// CHECK-Q: call {{.*}} @_ZNW1Q5QuackC1Ev83// CHECK-Q: define void @_ZGIW1Q84// CHECK-Q: store i8 1, ptr @_ZGIW1Q__in_chrg85// CHECK-Q: call void @__cxx_global_var_init86 87// This doesn't have a global init, but it imports a module which needs global88// init, so needs a guard89//--- R.cpp90 91export module R;92export import Q;93 94// CHECK-R: define void @_ZGIW1R95// CHECK-R: store i8 1, ptr @_ZGIW1R__in_chrg96// CHECK-R: call{{.*}}@_ZGIW1Q97 98// This doesn't have a global init and the imported module doesn't have variables needs99// dynamic initialization.100// But the imported module contains modules initialization. So needs a guard.101//--- S.cpp102 103export module S;104export import R;105 106// CHECK-S: define void @_ZGIW1S107// CHECK-S: store i8 1, ptr @_ZGIW1S__in_chrg108// CHECK-S: call{{.*}}@_ZGIW1R109 110// The module itself doesn't have a global init and it doesn't import any module.111// But the global module fragment imports a module that needs an init. So needs a guard.112//--- T.cpp113module;114import S;115export module T;116 117// CHECK-T: define void @_ZGIW1T118// CHECK-T: store i8 1, ptr @_ZGIW1T__in_chrg119// CHECK-T: call{{.*}}@_ZGIW1S120 121// The module itself doesn't have a global init and it doesn't import any module.122// But the private module fragment imports a module that needs an init. So needs a guard.123//--- U.cpp124export module U;125module :private;126import T;127 128// CHECK-U: define void @_ZGIW1U129// CHECK-U: store i8 1, ptr @_ZGIW1U__in_chrg130// CHECK-U: call{{.*}}@_ZGIW1T131