208 lines · cpp
1// Requires a specific target as the "module file has a different size than expected" is not reliable on all architectures.2// REQUIRES: x86-registered-target3 4// RUN: rm -rf %t5 6// -------------------------------7// Build chained modules A, B, and C8// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \9// RUN: -fmodule-name=a -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/a.pcm \10// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty11//12// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \13// RUN: -fmodule-file=%t/a.pcm \14// RUN: -fmodule-name=b -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/b.pcm \15// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty16//17// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \18// RUN: -fmodule-file=%t/b.pcm \19// RUN: -fmodule-name=c -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/c.pcm \20// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty21//22// CHECK-NO-IMPLICIT-BUILD-NOT: building module23 24// -------------------------------25// Build B with an implicit build of A26// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \27// RUN: -fmodule-name=b -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/b-not-a.pcm \28// RUN: 2>&1 | FileCheck --check-prefix=CHECK-B-NO-A %s29//30// CHECK-B-NO-A: While building module 'b':31// CHECK-B-NO-A: building module 'a' as32 33// -------------------------------34// Check that we can use the explicitly-built A, B, and C modules.35// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \36// RUN: -I%S/Inputs/explicit-build \37// RUN: -fmodule-file=%t/a.pcm \38// RUN: -verify %s -DHAVE_A39//40// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \41// RUN: -I%S/Inputs/explicit-build \42// RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \43// RUN: -fmodule-file=%t/a.pcm \44// RUN: -verify %s -DHAVE_A45//46// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \47// RUN: -I%S/Inputs/explicit-build \48// RUN: -fmodule-file=%t/b.pcm \49// RUN: -verify %s -DHAVE_A -DHAVE_B50//51// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \52// RUN: -I%S/Inputs/explicit-build \53// RUN: -fmodule-file=%t/a.pcm \54// RUN: -fmodule-file=%t/b.pcm \55// RUN: -verify %s -DHAVE_A -DHAVE_B56//57// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \58// RUN: -I%S/Inputs/explicit-build \59// RUN: -fmodule-file=%t/a.pcm \60// RUN: -fmodule-file=%t/b.pcm \61// RUN: -fmodule-file=%t/c.pcm \62// RUN: -verify %s -DHAVE_A -DHAVE_B -DHAVE_C63//64// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \65// RUN: -I%S/Inputs/explicit-build \66// RUN: -fmodule-file=%t/a.pcm \67// RUN: -fmodule-file=%t/c.pcm \68// RUN: -verify %s -DHAVE_A -DHAVE_B -DHAVE_C69 70// -------------------------------71// Check that -fmodule-file= in a module build makes the file transitively72// available even if it's not used.73// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fno-implicit-modules -Rmodule-build -fno-modules-error-recovery \74// RUN: -fmodule-file=%t/b.pcm \75// RUN: -fmodule-name=d -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/d.pcm \76// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty77//78// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fno-implicit-modules -Rmodule-build -fno-modules-error-recovery \79// RUN: -I%S/Inputs/explicit-build \80// RUN: -fmodule-file=%t/d.pcm \81// RUN: -verify %s -DHAVE_A -DHAVE_B82 83#if HAVE_A84 #include "a.h"85 static_assert(a == 1, "");86#else87 const int use_a = a; // expected-error {{undeclared identifier}}88#endif89 90#if HAVE_B91 #include "b.h"92 static_assert(b == 2, "");93#else94 const int use_b = b; // expected-error {{undeclared identifier}}95#endif96 97#if HAVE_C98 #include "c.h"99 static_assert(c == 3, "");100#else101 const int use_c = c; // expected-error {{undeclared identifier}}102#endif103 104#if HAVE_A && HAVE_B && HAVE_C105// expected-no-diagnostics106#endif107 108// -------------------------------109// Check that we can use a mixture of implicit and explicit modules.110// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \111// RUN: -I%S/Inputs/explicit-build \112// RUN: -fmodule-file=%t/b-not-a.pcm \113// RUN: -verify %s -DHAVE_A -DHAVE_B114 115// -------------------------------116// Try to use two different flavors of the 'a' module.117// RUN: not %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \118// RUN: -fmodule-file=%t/a.pcm \119// RUN: -fmodule-file=%t/b-not-a.pcm \120// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-MULTIPLE-AS %s121//122// RUN: not %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \123// RUN: -fmodule-file=%t/a.pcm \124// RUN: -fmodule-file=%t/b-not-a.pcm \125// RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \126// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-MULTIPLE-AS %s127//128// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \129// RUN: -fmodule-name=a -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/a-alt.pcm \130// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty131//132// RUN: not %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \133// RUN: -fmodule-file=%t/a.pcm \134// RUN: -fmodule-file=%t/a-alt.pcm \135// RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \136// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-MULTIPLE-AS %s137//138// RUN: not %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \139// RUN: -fmodule-file=%t/a-alt.pcm \140// RUN: -fmodule-file=%t/a.pcm \141// RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \142// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-MULTIPLE-AS %s143//144// CHECK-MULTIPLE-AS: error: module 'a' is defined in both '{{.*[/\\]}}a{{.*}}.pcm' and '{{.*[/\\]}}a{{.*}}.pcm'145 146// -------------------------------147// Try to import a PCH with -fmodule-file=148// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \149// RUN: -fmodule-name=a -emit-pch %S/Inputs/explicit-build/a.h -o %t/a.pch -DBUILDING_A_PCH \150// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty151//152// RUN: not %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \153// RUN: -fmodule-file=%t/a.pch \154// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-A-AS-PCH %s155//156// CHECK-A-AS-PCH: fatal error: precompiled file '{{.*}}a.pch' was not built as a module157 158// -------------------------------159// Try to import a non-AST file with -fmodule-file=160//161// RUN: touch %t/not.pcm162//163// RUN: not %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \164// RUN: -fmodule-file=%t/not.pcm \165// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-BAD-FILE %s166//167// CHECK-BAD-FILE: fatal error: file '{{.*}}not.pcm' is not a valid module file: file too small to contain precompiled file magic168 169// RUN: not %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \170// RUN: -fmodule-file=%t/nonexistent.pcm \171// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-NO-FILE %s172//173// CHECK-NO-FILE: fatal error: module file '{{.*}}nonexistent.pcm' not found: module file not found174 175// RUN: mv %t/a.pcm %t/a-tmp.pcm176// RUN: not %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \177// RUN: -I%S/Inputs/explicit-build \178// RUN: -fmodule-file=%t/c.pcm \179// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-NO-FILE-INDIRECT %s180// RUN: mv %t/a-tmp.pcm %t/a.pcm181//182// CHECK-NO-FILE-INDIRECT: error: module file '{{.*}}a.pcm' not found183// CHECK-NO-FILE-INDIRECT-NEXT: note: imported by module 'b' in '{{.*}}b.pcm'184// CHECK-NO-FILE-INDIRECT-NEXT: note: imported by module 'c' in '{{.*}}c.pcm'185// CHECK-NO-FILE-INDIRECT-NOT: note:186 187// -------------------------------188// Check that we don't get upset if B's timestamp is newer than C's.189// RUN: touch %t/b.pcm190//191// RUN: %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \192// RUN: -I%S/Inputs/explicit-build \193// RUN: -fmodule-file=%t/c.pcm \194// RUN: -verify %s -DHAVE_A -DHAVE_B -DHAVE_C195//196// ... but that we do get upset if our B is different from the B that C expects.197//198// RUN: cp %t/b-not-a.pcm %t/b.pcm199//200// RUN: not %clang_cc1 -triple=x86_64-linux-gnu -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \201// RUN: -I%S/Inputs/explicit-build \202// RUN: -fmodule-file=%t/c.pcm \203// RUN: %s -DHAVE_A -DHAVE_B -DHAVE_C 2>&1 | FileCheck --check-prefix=CHECK-MISMATCHED-B %s204//205// CHECK-MISMATCHED-B: fatal error: module file '{{.*}}b.pcm' is out of date and needs to be rebuilt: module file has a different size than expected206// CHECK-MISMATCHED-B-NEXT: note: imported by module 'c'207// CHECK-MISMATCHED-B-NOT: note:208