brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · adb2a8f Raw
77 lines · plain
1// This test verifies that config macro warnings are emitted when it looks like2// the user expected a `#define` to impact the import of a module.3 4// RUN: rm -rf %t5// RUN: split-file %s %t6 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.modulemap9 10// Verify that each time the `config` module is imported the current macro state11// is checked.12// RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %t -DWANT_FOO=1 %t/config.m -verify13 14// Verify that warnings are emitted before building a module in case the command15// 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 -verify17 18//--- module.modulemap19 20module config {21  header "config.h"22  config_macros [exhaustive] WANT_FOO, WANT_BAR23}24 25module config_error {26  header "config_error.h"27  config_macros SOME_VALUE28}29 30//--- config.h31 32#ifdef WANT_FOO33int* foo(void);34#endif35 36#ifdef WANT_BAR37char *bar(void);38#endif39 40//--- config_error.h41 42struct my_thing {43  char buf[SOME_VALUE];44};45 46//--- config.m47 48@import config;49 50int *test_foo(void) {51  return foo();52}53 54char *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}}57}58 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}}61 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}}64 65#undef WANT_FOO66#define WANT_FOO 167@import config; // okay68 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}}71 72//--- config_error.m73 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';}}77