blob: ff98f92b1f5556e7dbfd0270923ffa94c82571c3 [file] [log] [blame]
Richard Smithe842a472014-10-22 02:05:46 +00001// RUN: rm -rf %t
2
3// -------------------------------
4// Build chained modules A, B, and C
Richard Smithd4b230b2014-10-27 23:01:16 +00005// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
Richard Smithe842a472014-10-22 02:05:46 +00006// 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//
Richard Smithd4b230b2014-10-27 23:01:16 +00009// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
Richard Smithe842a472014-10-22 02:05:46 +000010// 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//
Richard Smithd4b230b2014-10-27 23:01:16 +000014// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
Richard Smithe842a472014-10-22 02:05:46 +000015// 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
Richard Smithd4b230b2014-10-27 23:01:16 +000023// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
Richard Smithe842a472014-10-22 02:05:46 +000024// 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.
Richard Smithd4b230b2014-10-27 23:01:16 +000032// 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 \
Richard Smithe842a472014-10-22 02:05:46 +000034// RUN: -fmodule-file=%t/a.pcm \
35// RUN: -verify %s -DHAVE_A
36//
Richard Smithd4b230b2014-10-27 23:01:16 +000037// 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 \
Richard Smithe842a472014-10-22 02:05:46 +000039// RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \
Richard Smithd4b230b2014-10-27 23:01:16 +000040// RUN: -fmodule-file=%t/a.pcm \
Richard Smithe842a472014-10-22 02:05:46 +000041// RUN: -verify %s -DHAVE_A
42//
Richard Smithd4b230b2014-10-27 23:01:16 +000043// 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 \
Richard Smithe842a472014-10-22 02:05:46 +000045// RUN: -fmodule-file=%t/b.pcm \
46// RUN: -verify %s -DHAVE_A -DHAVE_B
47//
Richard Smithd4b230b2014-10-27 23:01:16 +000048// 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 \
Richard Smithe842a472014-10-22 02:05:46 +000050// RUN: -fmodule-file=%t/a.pcm \
51// RUN: -fmodule-file=%t/b.pcm \
52// RUN: -verify %s -DHAVE_A -DHAVE_B
53//
Richard Smithd4b230b2014-10-27 23:01:16 +000054// 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 \
Richard Smithe842a472014-10-22 02:05:46 +000056// 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//
Richard Smithd4b230b2014-10-27 23:01:16 +000061// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
Richard Smithe842a472014-10-22 02:05:46 +000062// RUN: -I%S/Inputs/explicit-build \
63// RUN: -fmodule-file=%t/a.pcm \
Richard Smithe842a472014-10-22 02:05:46 +000064// RUN: -fmodule-file=%t/c.pcm \
Richard Smithd4b230b2014-10-27 23:01:16 +000065// RUN: -verify %s -DHAVE_A -DHAVE_B -DHAVE_C
Richard Smithe842a472014-10-22 02:05:46 +000066
Richard Smithd4b230b2014-10-27 23:01:16 +000067#if HAVE_A
Richard Smithe842a472014-10-22 02:05:46 +000068 #include "a.h"
Richard Smithe842a472014-10-22 02:05:46 +000069 static_assert(a == 1, "");
Richard Smithd4b230b2014-10-27 23:01:16 +000070#else
71 const int use_a = a; // expected-error {{undeclared identifier}}
72#endif
73
74#if HAVE_B
75 #include "b.h"
Richard Smithe842a472014-10-22 02:05:46 +000076 static_assert(b == 2, "");
Richard Smithd4b230b2014-10-27 23:01:16 +000077#else
78 const int use_b = b; // expected-error {{undeclared identifier}}
79#endif
80
81#if HAVE_C
82 #include "c.h"
Richard Smithe842a472014-10-22 02:05:46 +000083 static_assert(c == 3, "");
84#else
Richard Smithd4b230b2014-10-27 23:01:16 +000085 const int use_c = c; // expected-error {{undeclared identifier}}
86#endif
Richard Smithe842a472014-10-22 02:05:46 +000087
Richard Smithd4b230b2014-10-27 23:01:16 +000088#if HAVE_A && HAVE_B && HAVE_C
89// expected-no-diagnostics
Richard Smithe842a472014-10-22 02:05:46 +000090#endif
91
92// -------------------------------
93// Check that we can use a mixture of implicit and explicit modules.
Richard Smithd4b230b2014-10-27 23:01:16 +000094// 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 \
Richard Smithe842a472014-10-22 02:05:46 +000096// RUN: -fmodule-file=%t/b-not-a.pcm \
Richard Smithd4b230b2014-10-27 23:01:16 +000097// RUN: -verify %s -DHAVE_A -DHAVE_B
Richard Smithe842a472014-10-22 02:05:46 +000098
99// -------------------------------
100// Try to use two different flavors of the 'a' module.
Richard Smithd4b230b2014-10-27 23:01:16 +0000101// 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 \
Richard Smithe842a472014-10-22 02:05:46 +0000113// 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//
Richard Smithd4b230b2014-10-27 23:01:16 +0000116// RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
Richard Smithe842a472014-10-22 02:05:46 +0000117// 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//
Richard Smithd4b230b2014-10-27 23:01:16 +0000122// RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
Richard Smithe842a472014-10-22 02:05:46 +0000123// 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//
NAKAMURA Takumi314df7a2014-10-28 11:34:29 +0000128// CHECK-MULTIPLE-AS: error: module 'a' is defined in both '{{.*}}/a{{.*}}.pcm' and '{{.*[/\\]}}a{{.*}}.pcm'
Richard Smithe842a472014-10-22 02:05:46 +0000129
130// -------------------------------
131// Try to import a PCH with -fmodule-file=
Richard Smithd4b230b2014-10-27 23:01:16 +0000132// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
Richard Smithe842a472014-10-22 02:05:46 +0000133// 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//
Richard Smithd4b230b2014-10-27 23:01:16 +0000136// RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
Richard Smithe842a472014-10-22 02:05:46 +0000137// 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
Richard Smithd4b230b2014-10-27 23:01:16 +0000141
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//
Richard Smith37bd29a2015-02-28 03:09:52 +0000151// CHECK-BAD-FILE: fatal error: file '{{.*}}not.pcm' is not a valid precompiled module file
152
Richard Smithd4b230b2014-10-27 23:01:16 +0000153// RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
154// RUN: -fmodule-file=%t/nonexistent.pcm \
Richard Smith37bd29a2015-02-28 03:09:52 +0000155// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-NO-FILE %s
Richard Smithd4b230b2014-10-27 23:01:16 +0000156//
Richard Smith37bd29a2015-02-28 03:09:52 +0000157// CHECK-NO-FILE: fatal error: module file '{{.*}}nonexistent.pcm' not found
158
159// RUN: mv %t/a.pcm %t/a-tmp.pcm
160// RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
161// RUN: -I%S/Inputs/explicit-build \
162// RUN: -fmodule-file=%t/c.pcm \
163// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-NO-FILE-INDIRECT %s
164// RUN: mv %t/a-tmp.pcm %t/a.pcm
165//
166// CHECK-NO-FILE-INDIRECT: error: module file '{{.*}}a.pcm' not found
167// CHECK-NO-FILE-INDIRECT-NEXT: note: imported by module 'b' in '{{.*}}b.pcm'
168// CHECK-NO-FILE-INDIRECT-NEXT: note: imported by module 'c' in '{{.*}}c.pcm'
Richard Smith5b390752014-11-21 05:37:20 +0000169
170// -------------------------------
171// Check that we don't get upset if B's timestamp is newer than C's.
172// RUN: touch %t/b.pcm
173//
174// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
175// RUN: -I%S/Inputs/explicit-build \
176// RUN: -fmodule-file=%t/c.pcm \
177// RUN: -verify %s -DHAVE_A -DHAVE_B -DHAVE_C
178//
179// ... but that we do get upset if our B is different from the B that C expects.
180//
181// RUN: cp %t/b-not-a.pcm %t/b.pcm
182//
183// RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
184// RUN: -I%S/Inputs/explicit-build \
185// RUN: -fmodule-file=%t/c.pcm \
186// RUN: %s -DHAVE_A -DHAVE_B -DHAVE_C 2>&1 | FileCheck --check-prefix=CHECK-MISMATCHED-B %s
187//
188// CHECK-MISMATCHED-B: fatal error: malformed or corrupted AST file: {{.*}}b.pcm": module file out of date