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