1 // This test verifies that config macro warnings are emitted when it looks like
2 // the user expected a `#define` to impact the import of a module.
5 // RUN: split-file %s %t
7 // Prebuild the `config` module so it's in the module cache.
8 // RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -x objective-c -fmodules-cache-path=%t -DWANT_FOO=1 -emit-module -fmodule-name=config %t/module.modulemap
10 // Verify that each time the `config` module is imported the current macro state
12 // RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %t -DWANT_FOO=1 %t/config.m -verify
14 // Verify that warnings are emitted before building a module in case the command
15 // line macro state causes the module to fail to build.
16 // RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %t %t/config_error.m -verify
18 //--- module.modulemap
22 config_macros [exhaustive] WANT_FOO, WANT_BAR
26 header "config_error.h"
27 config_macros SOME_VALUE
54 char *test_bar(void) {
55 return bar(); // expected-error{{call to undeclared function 'bar'; ISO C99 and later do not support implicit function declarations}} \
56 // expected-error{{incompatible integer to pointer conversion}}
59 #undef WANT_FOO // expected-note{{macro was #undef'd here}}
60 @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}}
62 #define WANT_FOO 2 // expected-note{{macro was defined here}}
63 @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}}
67 @import config; // okay
69 #define WANT_BAR 1 // expected-note{{macro was defined here}}
70 @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}}
74 #define SOME_VALUE 5 // expected-note{{macro was defined here}}
75 @import config_error; // expected-error{{could not build module}} \
76 // expected-warning{{definition of configuration macro 'SOME_VALUE' has no effect on the import of 'config_error';}}