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