diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-10-22 02:05:46 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-10-22 02:05:46 +0000 |
commit | e842a47452223f9f3b683e0f7f9cccb48192cbb6 (patch) | |
tree | d86e1e37d64cc2aa392947392af816d5b79583ad /clang/test/Modules | |
parent | a672ecefef25bcc8cf0d7ac8d54c5139f6386df4 (diff) | |
download | bcm5719-llvm-e842a47452223f9f3b683e0f7f9cccb48192cbb6.tar.gz bcm5719-llvm-e842a47452223f9f3b683e0f7f9cccb48192cbb6.zip |
[modules] Initial support for explicitly loading .pcm files.
Implicit module builds are not well-suited to a lot of build systems. In
particular, they fare badly in distributed build systems, and they lead to
build artifacts that are not tracked as part of the usual dependency management
process. This change allows explicitly-built module files (which are already
supported through the -emit-module flag) to be explicitly loaded into a build,
allowing build systems to opt to manage module builds and dependencies
themselves.
This is only the first step in supporting such configurations, and it should
be considered experimental and subject to change or removal for now.
llvm-svn: 220359
Diffstat (limited to 'clang/test/Modules')
-rw-r--r-- | clang/test/Modules/Inputs/explicit-build/a.h | 5 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/explicit-build/b.h | 7 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/explicit-build/c.h | 7 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/explicit-build/module.modulemap | 3 | ||||
-rw-r--r-- | clang/test/Modules/explicit-build.cpp | 151 | ||||
-rw-r--r-- | clang/test/Modules/resolution-change.m | 4 |
6 files changed, 175 insertions, 2 deletions
diff --git a/clang/test/Modules/Inputs/explicit-build/a.h b/clang/test/Modules/Inputs/explicit-build/a.h new file mode 100644 index 00000000000..5e3602f58ff --- /dev/null +++ b/clang/test/Modules/Inputs/explicit-build/a.h @@ -0,0 +1,5 @@ +#if !__building_module(a) +#error "should only get here when building module a" +#endif + +const int a = 1; diff --git a/clang/test/Modules/Inputs/explicit-build/b.h b/clang/test/Modules/Inputs/explicit-build/b.h new file mode 100644 index 00000000000..449b3859ab4 --- /dev/null +++ b/clang/test/Modules/Inputs/explicit-build/b.h @@ -0,0 +1,7 @@ +#include "a.h" + +#if !__building_module(b) +#error "should only get here when building module b" +#endif + +const int b = 2; diff --git a/clang/test/Modules/Inputs/explicit-build/c.h b/clang/test/Modules/Inputs/explicit-build/c.h new file mode 100644 index 00000000000..2c66a23e892 --- /dev/null +++ b/clang/test/Modules/Inputs/explicit-build/c.h @@ -0,0 +1,7 @@ +#include "b.h" + +#if !__building_module(c) +#error "should only get here when building module c" +#endif + +const int c = 3; diff --git a/clang/test/Modules/Inputs/explicit-build/module.modulemap b/clang/test/Modules/Inputs/explicit-build/module.modulemap new file mode 100644 index 00000000000..bd6ea830c2d --- /dev/null +++ b/clang/test/Modules/Inputs/explicit-build/module.modulemap @@ -0,0 +1,3 @@ +module a { header "a.h" } +module b { header "b.h" export * } +module c { header "c.h" export * } diff --git a/clang/test/Modules/explicit-build.cpp b/clang/test/Modules/explicit-build.cpp new file mode 100644 index 00000000000..0911837ed8f --- /dev/null +++ b/clang/test/Modules/explicit-build.cpp @@ -0,0 +1,151 @@ +// RUN: rm -rf %t + +// ------------------------------- +// Build chained modules A, B, and C +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-name=a -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/a.pcm \ +// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty +// +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -fmodule-name=b -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/b.pcm \ +// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty +// +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/b.pcm \ +// RUN: -fmodule-name=c -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/c.pcm \ +// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty +// +// CHECK-NO-IMPLICIT-BUILD-NOT: building module + +// ------------------------------- +// Build B with an implicit build of A +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-name=b -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/b-not-a.pcm \ +// RUN: 2>&1 | FileCheck --check-prefix=CHECK-B-NO-A %s +// +// CHECK-B-NO-A: While building module 'b': +// CHECK-B-NO-A: building module 'a' as + +// ------------------------------- +// Check that we can use the explicitly-built A, B, and C modules. +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -verify %s -DHAVE_A +// +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \ +// RUN: -verify %s -DHAVE_A +// +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/b.pcm \ +// RUN: -verify %s -DHAVE_A -DHAVE_B +// +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -fmodule-file=%t/b.pcm \ +// RUN: -verify %s -DHAVE_A -DHAVE_B +// +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -fmodule-file=%t/b.pcm \ +// RUN: -fmodule-file=%t/c.pcm \ +// RUN: -verify %s -DHAVE_A -DHAVE_B -DHAVE_C +// +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -I%S/Inputs/explicit-build \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -fmodule-file=%t/b.pcm \ +// RUN: -fmodule-file=%t/c.pcm \ +// RUN: -verify %s -INCLUDE_ALL -DHAVE_A -DHAVE_B -DHAVE_C + +#ifdef INCLUDE_ALL + #include "a.h" + #include "b.h" + #include "c.h" + static_assert(a == 1, ""); + static_assert(b == 2, ""); + static_assert(c == 3, ""); +#else + const int use_a = a; + #ifndef HAVE_A + // expected-error@-2 {{undeclared identifier}} + #else + // expected-error@-4 {{must be imported from module 'a'}} + // expected-note@Inputs/explicit-build/a.h:* {{here}} + #endif + + const int use_b = b; + #ifndef HAVE_B + // expected-error@-2 {{undeclared identifier}} + #else + // expected-error@-4 {{must be imported from module 'b'}} + // expected-note@Inputs/explicit-build/b.h:* {{here}} + #endif + + const int use_c = c; + #ifndef HAVE_C + // expected-error@-2 {{undeclared identifier}} + #else + // expected-error@-4 {{must be imported from module 'c'}} + // expected-note@Inputs/explicit-build/c.h:* {{here}} + #endif +#endif + +// ------------------------------- +// Check that we can use a mixture of implicit and explicit modules. +// RUN: not %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/b-not-a.pcm \ +// RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-A-AND-B-NO-A %s + +// ------------------------------- +// Check that mixing an implicit and explicit form of the 'a' module is rejected. +// RUN: not %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -fmodule-file=%t/b-not-a.pcm \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-A-AND-B-NO-A %s +// +// RUN: not %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -fmodule-file=%t/b-not-a.pcm \ +// RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-A-AND-B-NO-A %s +// +// FIXME: We should load module map files specified on the command line and +// module map files in include paths on demand to allow this, and possibly +// also the previous case. +// CHECK-A-AND-B-NO-A: fatal error: module 'a' {{.*}} is not defined in any loaded module map + +// ------------------------------- +// Try to use two different flavors of the 'a' module. +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-name=a -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/a-alt.pcm \ +// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty +// +// RUN: not %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -fmodule-file=%t/a-alt.pcm \ +// RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-MULTIPLE-AS %s +// +// RUN: not %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/a-alt.pcm \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -fmodule-map-file=%S/Inputs/explicit-build/module.modulemap \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-MULTIPLE-AS %s +// +// CHECK-MULTIPLE-AS: error: module 'a' has already been loaded; cannot load module file '{{.*a(-alt)?}}.pcm' + +// ------------------------------- +// Try to import a PCH with -fmodule-file= +// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-name=a -emit-pch %S/Inputs/explicit-build/a.h -o %t/a.pch \ +// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty +// +// RUN: not %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \ +// RUN: -fmodule-file=%t/a.pch \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-A-AS-PCH %s +// +// CHECK-A-AS-PCH: fatal error: AST file '{{.*}}a.pch' was not built as a module diff --git a/clang/test/Modules/resolution-change.m b/clang/test/Modules/resolution-change.m index 011782eec2b..b725a64acb4 100644 --- a/clang/test/Modules/resolution-change.m +++ b/clang/test/Modules/resolution-change.m @@ -11,11 +11,11 @@ // Use the PCH with no way to resolve DependsOnA // RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -include-pch %t-A.pch %s -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-NODOA %s -// CHECK-NODOA: module 'DependsOnA' imported by AST file '{{.*A.pch}}' not found +// CHECK-NODOA: module 'DependsOnA' in AST file '{{.*DependsOnA.*pcm}}' (imported by AST file '{{.*A.pch}}') is not defined in any loaded module map // Use the PCH with no way to resolve A // RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -include-pch %t-A.pch %s -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-NOA %s -// CHECK-NOA: module 'A' imported by AST file '{{.*DependsOnA.*pcm}}' not found +// CHECK-NOA: module 'A' in AST file '{{.*A.*pcm}}' (imported by AST file '{{.*DependsOnA.*pcm}}') is not defined in any loaded module map // Use the PCH and have it resolve the the other A // RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I %S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-WRONGA %s |