1*67e74705SXin Li // RUN: rm -rf %t 2*67e74705SXin Li 3*67e74705SXin Li // ------------------------------- 4*67e74705SXin Li // Build chained modules A, B, and C 5*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 6*67e74705SXin Li // RUN: -fmodule-name=a -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/a.pcm \ 7*67e74705SXin Li // RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty 8*67e74705SXin Li // 9*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 10*67e74705SXin Li // RUN: -fmodule-file=%t/a.pcm \ 11*67e74705SXin Li // RUN: -fmodule-name=b -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/b.pcm \ 12*67e74705SXin Li // RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty 13*67e74705SXin Li // 14*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 15*67e74705SXin Li // RUN: -fmodule-file=%t/b.pcm \ 16*67e74705SXin Li // RUN: -fmodule-name=c -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/c.pcm \ 17*67e74705SXin Li // RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty 18*67e74705SXin Li // 19*67e74705SXin Li // CHECK-NO-IMPLICIT-BUILD-NOT: building module 20*67e74705SXin Li 21*67e74705SXin Li // ------------------------------- 22*67e74705SXin Li // Build B with an implicit build of A 23*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 24*67e74705SXin Li // RUN: -fmodule-name=b -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/b-not-a.pcm \ 25*67e74705SXin Li // RUN: 2>&1 | FileCheck --check-prefix=CHECK-B-NO-A %s 26*67e74705SXin Li // 27*67e74705SXin Li // CHECK-B-NO-A: While building module 'b': 28*67e74705SXin Li // CHECK-B-NO-A: building module 'a' as 29*67e74705SXin Li 30*67e74705SXin Li // ------------------------------- 31*67e74705SXin Li // Check that we can use the explicitly-built A, B, and C modules. 32*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 33*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 34*67e74705SXin Li // RUN: -fmodule-file=%t/a.pcm \ 35*67e74705SXin Li // RUN: -verify %s -DHAVE_A 36*67e74705SXin Li // 37*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 38*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 39*67e74705SXin Li // RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \ 40*67e74705SXin Li // RUN: -fmodule-file=%t/a.pcm \ 41*67e74705SXin Li // RUN: -verify %s -DHAVE_A 42*67e74705SXin Li // 43*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 44*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 45*67e74705SXin Li // RUN: -fmodule-file=%t/b.pcm \ 46*67e74705SXin Li // RUN: -verify %s -DHAVE_A -DHAVE_B 47*67e74705SXin Li // 48*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 49*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 50*67e74705SXin Li // RUN: -fmodule-file=%t/a.pcm \ 51*67e74705SXin Li // RUN: -fmodule-file=%t/b.pcm \ 52*67e74705SXin Li // RUN: -verify %s -DHAVE_A -DHAVE_B 53*67e74705SXin Li // 54*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 55*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 56*67e74705SXin Li // RUN: -fmodule-file=%t/a.pcm \ 57*67e74705SXin Li // RUN: -fmodule-file=%t/b.pcm \ 58*67e74705SXin Li // RUN: -fmodule-file=%t/c.pcm \ 59*67e74705SXin Li // RUN: -verify %s -DHAVE_A -DHAVE_B -DHAVE_C 60*67e74705SXin Li // 61*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 62*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 63*67e74705SXin Li // RUN: -fmodule-file=%t/a.pcm \ 64*67e74705SXin Li // RUN: -fmodule-file=%t/c.pcm \ 65*67e74705SXin Li // RUN: -verify %s -DHAVE_A -DHAVE_B -DHAVE_C 66*67e74705SXin Li 67*67e74705SXin Li // ------------------------------- 68*67e74705SXin Li // Check that -fmodule-file= in a module build makes the file transitively 69*67e74705SXin Li // available even if it's not used. 70*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fno-implicit-modules -Rmodule-build -fno-modules-error-recovery \ 71*67e74705SXin Li // RUN: -fmodule-file=%t/b.pcm \ 72*67e74705SXin Li // RUN: -fmodule-name=d -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/d.pcm \ 73*67e74705SXin Li // RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty 74*67e74705SXin Li // 75*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fno-implicit-modules -Rmodule-build -fno-modules-error-recovery \ 76*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 77*67e74705SXin Li // RUN: -fmodule-file=%t/d.pcm \ 78*67e74705SXin Li // RUN: -verify %s -DHAVE_A -DHAVE_B 79*67e74705SXin Li 80*67e74705SXin Li #if HAVE_A 81*67e74705SXin Li #include "a.h" 82*67e74705SXin Li static_assert(a == 1, ""); 83*67e74705SXin Li #else 84*67e74705SXin Li const int use_a = a; // expected-error {{undeclared identifier}} 85*67e74705SXin Li #endif 86*67e74705SXin Li 87*67e74705SXin Li #if HAVE_B 88*67e74705SXin Li #include "b.h" 89*67e74705SXin Li static_assert(b == 2, ""); 90*67e74705SXin Li #else 91*67e74705SXin Li const int use_b = b; // expected-error {{undeclared identifier}} 92*67e74705SXin Li #endif 93*67e74705SXin Li 94*67e74705SXin Li #if HAVE_C 95*67e74705SXin Li #include "c.h" 96*67e74705SXin Li static_assert(c == 3, ""); 97*67e74705SXin Li #else 98*67e74705SXin Li const int use_c = c; // expected-error {{undeclared identifier}} 99*67e74705SXin Li #endif 100*67e74705SXin Li 101*67e74705SXin Li #if HAVE_A && HAVE_B && HAVE_C 102*67e74705SXin Li // expected-no-diagnostics 103*67e74705SXin Li #endif 104*67e74705SXin Li 105*67e74705SXin Li // ------------------------------- 106*67e74705SXin Li // Check that we can use a mixture of implicit and explicit modules. 107*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 108*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 109*67e74705SXin Li // RUN: -fmodule-file=%t/b-not-a.pcm \ 110*67e74705SXin Li // RUN: -verify %s -DHAVE_A -DHAVE_B 111*67e74705SXin Li 112*67e74705SXin Li // ------------------------------- 113*67e74705SXin Li // Try to use two different flavors of the 'a' module. 114*67e74705SXin Li // RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 115*67e74705SXin Li // RUN: -fmodule-file=%t/a.pcm \ 116*67e74705SXin Li // RUN: -fmodule-file=%t/b-not-a.pcm \ 117*67e74705SXin Li // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-MULTIPLE-AS %s 118*67e74705SXin Li // 119*67e74705SXin Li // RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 120*67e74705SXin Li // RUN: -fmodule-file=%t/a.pcm \ 121*67e74705SXin Li // RUN: -fmodule-file=%t/b-not-a.pcm \ 122*67e74705SXin Li // RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \ 123*67e74705SXin Li // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-MULTIPLE-AS %s 124*67e74705SXin Li // 125*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 126*67e74705SXin Li // RUN: -fmodule-name=a -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/a-alt.pcm \ 127*67e74705SXin Li // RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty 128*67e74705SXin Li // 129*67e74705SXin Li // RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 130*67e74705SXin Li // RUN: -fmodule-file=%t/a.pcm \ 131*67e74705SXin Li // RUN: -fmodule-file=%t/a-alt.pcm \ 132*67e74705SXin Li // RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \ 133*67e74705SXin Li // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-MULTIPLE-AS %s 134*67e74705SXin Li // 135*67e74705SXin Li // RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 136*67e74705SXin Li // RUN: -fmodule-file=%t/a-alt.pcm \ 137*67e74705SXin Li // RUN: -fmodule-file=%t/a.pcm \ 138*67e74705SXin Li // RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \ 139*67e74705SXin Li // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-MULTIPLE-AS %s 140*67e74705SXin Li // 141*67e74705SXin Li // CHECK-MULTIPLE-AS: error: module 'a' is defined in both '{{.*[/\\]}}a{{.*}}.pcm' and '{{.*[/\\]}}a{{.*}}.pcm' 142*67e74705SXin Li 143*67e74705SXin Li // ------------------------------- 144*67e74705SXin Li // Try to import a PCH with -fmodule-file= 145*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 146*67e74705SXin Li // RUN: -fmodule-name=a -emit-pch %S/Inputs/explicit-build/a.h -o %t/a.pch -DBUILDING_A_PCH \ 147*67e74705SXin Li // RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty 148*67e74705SXin Li // 149*67e74705SXin Li // RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 150*67e74705SXin Li // RUN: -fmodule-file=%t/a.pch \ 151*67e74705SXin Li // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-A-AS-PCH %s 152*67e74705SXin Li // 153*67e74705SXin Li // CHECK-A-AS-PCH: fatal error: AST file '{{.*}}a.pch' was not built as a module 154*67e74705SXin Li 155*67e74705SXin Li // ------------------------------- 156*67e74705SXin Li // Try to import a non-AST file with -fmodule-file= 157*67e74705SXin Li // 158*67e74705SXin Li // RUN: touch %t/not.pcm 159*67e74705SXin Li // 160*67e74705SXin Li // RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 161*67e74705SXin Li // RUN: -fmodule-file=%t/not.pcm \ 162*67e74705SXin Li // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-BAD-FILE %s 163*67e74705SXin Li // 164*67e74705SXin Li // CHECK-BAD-FILE: fatal error: file '{{.*}}not.pcm' is not a valid precompiled module file 165*67e74705SXin Li 166*67e74705SXin Li // RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 167*67e74705SXin Li // RUN: -fmodule-file=%t/nonexistent.pcm \ 168*67e74705SXin Li // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-NO-FILE %s 169*67e74705SXin Li // 170*67e74705SXin Li // CHECK-NO-FILE: fatal error: module file '{{.*}}nonexistent.pcm' not found 171*67e74705SXin Li 172*67e74705SXin Li // RUN: mv %t/a.pcm %t/a-tmp.pcm 173*67e74705SXin Li // RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 174*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 175*67e74705SXin Li // RUN: -fmodule-file=%t/c.pcm \ 176*67e74705SXin Li // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-NO-FILE-INDIRECT %s 177*67e74705SXin Li // RUN: mv %t/a-tmp.pcm %t/a.pcm 178*67e74705SXin Li // 179*67e74705SXin Li // CHECK-NO-FILE-INDIRECT: error: module file '{{.*}}a.pcm' not found 180*67e74705SXin Li // CHECK-NO-FILE-INDIRECT-NEXT: note: imported by module 'b' in '{{.*}}b.pcm' 181*67e74705SXin Li // CHECK-NO-FILE-INDIRECT-NEXT: note: imported by module 'c' in '{{.*}}c.pcm' 182*67e74705SXin Li // CHECK-NO-FILE-INDIRECT-NOT: note: 183*67e74705SXin Li 184*67e74705SXin Li // ------------------------------- 185*67e74705SXin Li // Check that we don't get upset if B's timestamp is newer than C's. 186*67e74705SXin Li // RUN: touch %t/b.pcm 187*67e74705SXin Li // 188*67e74705SXin Li // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 189*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 190*67e74705SXin Li // RUN: -fmodule-file=%t/c.pcm \ 191*67e74705SXin Li // RUN: -verify %s -DHAVE_A -DHAVE_B -DHAVE_C 192*67e74705SXin Li // 193*67e74705SXin Li // ... but that we do get upset if our B is different from the B that C expects. 194*67e74705SXin Li // 195*67e74705SXin Li // RUN: cp %t/b-not-a.pcm %t/b.pcm 196*67e74705SXin Li // 197*67e74705SXin Li // RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ 198*67e74705SXin Li // RUN: -I%S/Inputs/explicit-build \ 199*67e74705SXin Li // RUN: -fmodule-file=%t/c.pcm \ 200*67e74705SXin Li // RUN: %s -DHAVE_A -DHAVE_B -DHAVE_C 2>&1 | FileCheck --check-prefix=CHECK-MISMATCHED-B %s 201*67e74705SXin Li // 202*67e74705SXin Li // CHECK-MISMATCHED-B: fatal error: module file '{{.*}}b.pcm' is out of date and needs to be rebuilt 203*67e74705SXin Li // CHECK-MISMATCHED-B-NEXT: note: imported by module 'c' 204*67e74705SXin Li // CHECK-MISMATCHED-B-NOT: note: 205