diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-03-20 00:22:05 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-03-20 00:22:05 +0000 |
commit | 63a726870b486e0470c3a4b11cf62bab8be00b73 (patch) | |
tree | 59a81fd634baac897c49f1dbf639ad69ec7af55d /test/Modules | |
parent | 8a40cc6f9cba0aaa1aac477e2b4c4605629dc587 (diff) |
<rdar://problem/10796651> Introduce configuration macros into module maps.
Configuration macros are macros that are intended to alter how a
module works, such that we need to build different module variants
for different values of these macros. A module can declare its
configuration macros, in which case we will complain if the definition
of a configation macro on the command line (or lack thereof) differs
from the current preprocessor state at the point where the module is
imported. This should eliminate some surprises when enabling modules,
because "#define CONFIG_MACRO ..." followed by "#include
<module/header.h>" would silently ignore the CONFIG_MACRO setting. At
least it will no longer be silent about it.
Configuration macros are eventually intended to help reduce the number
of module variants that need to be built. When the list of
configuration macros for a module is exhaustive, we only need to
consider the settings for those macros when building/finding the
module, which can help isolate modules for various project-specific -D
flags that should never affect how modules are build (but currently do).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177466 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Modules')
-rw-r--r-- | test/Modules/Inputs/config.h | 7 | ||||
-rw-r--r-- | test/Modules/Inputs/module.map | 5 | ||||
-rw-r--r-- | test/Modules/config_macros.m | 28 |
3 files changed, 40 insertions, 0 deletions
diff --git a/test/Modules/Inputs/config.h b/test/Modules/Inputs/config.h new file mode 100644 index 0000000000..f2dfda64c3 --- /dev/null +++ b/test/Modules/Inputs/config.h @@ -0,0 +1,7 @@ +#ifdef WANT_FOO +int* foo(); +#endif + +#ifdef WANT_BAR +char *bar(); +#endif diff --git a/test/Modules/Inputs/module.map b/test/Modules/Inputs/module.map index 53f2fd65d3..479bfcfa7f 100644 --- a/test/Modules/Inputs/module.map +++ b/test/Modules/Inputs/module.map @@ -183,3 +183,8 @@ module cxx_inline_namespace { module cxx_linkage_cache { header "cxx-linkage-cache.h" } + +module config { + header "config.h" + config_macros [exhaustive] WANT_FOO, WANT_BAR +} diff --git a/test/Modules/config_macros.m b/test/Modules/config_macros.m new file mode 100644 index 0000000000..200744d614 --- /dev/null +++ b/test/Modules/config_macros.m @@ -0,0 +1,28 @@ +@import config; + +int *test_foo() { + return foo(); +} + +char *test_bar() { + return bar(); // expected-warning{{implicit declaration of function 'bar' is invalid in C99}} \ + // expected-warning{{incompatible integer to pointer conversion}} +} + +#undef WANT_FOO // expected-note{{macro was #undef'd here}} +@import config; // expected-warning{{#undef of configuration macro 'WANT_FOO' has no effect on the import of 'config'; pass '-UWANT_FOO' on the command line to configure the module}} + +#define WANT_FOO 2 // expected-note{{macro was defined here}} +@import config; // expected-warning{{definition of configuration macro 'WANT_FOO' has no effect on the import of 'config'; pass '-DWANT_FOO=...' on the command line to configure the module}} + +#undef WANT_FOO +#define WANT_FOO 1 +@import config; // okay + +#define WANT_BAR 1 // expected-note{{macro was defined here}} +@import config; // expected-warning{{definition of configuration macro 'WANT_BAR' has no effect on the import of 'config'; pass '-DWANT_BAR=...' on the command line to configure the module}} + +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -DWANT_FOO=1 -emit-module -fmodule-name=config %S/Inputs/module.map +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -DWANT_FOO=1 %s -verify + |