diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-03-01 00:08:04 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-03-01 00:08:04 +0000 |
commit | 49f906a36fdad83a9935d6f1815d620a7d0bf57a (patch) | |
tree | 8cd2c4e93b4c73e04c2af692c044eadb55c809ca /clang/test/Modules/macros2.c | |
parent | 49133948a96617a67631c59d3158a8aa3463136c (diff) | |
download | bcm5719-llvm-49f906a36fdad83a9935d6f1815d620a7d0bf57a.tar.gz bcm5719-llvm-49f906a36fdad83a9935d6f1815d620a7d0bf57a.zip |
If a module A exports a macro M, and a module B imports that macro and #undef's
it, importers of B should not see the macro. This is complicated by the fact
that A's macro could also be visible through a different path. The rules (as
hashed out on cfe-commits) are included as a documentation update in this
change.
With this, the number of regressions in libc++'s testsuite when modules are
enabled drops from 47 to 7. Those remaining 7 are also macro-related, and are
due to remaining bugs in this change (in particular, the handling of submodules
is imperfect).
llvm-svn: 202560
Diffstat (limited to 'clang/test/Modules/macros2.c')
-rw-r--r-- | clang/test/Modules/macros2.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/clang/test/Modules/macros2.c b/clang/test/Modules/macros2.c new file mode 100644 index 00000000000..87b4c97d96d --- /dev/null +++ b/clang/test/Modules/macros2.c @@ -0,0 +1,77 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_top %S/Inputs/module.map +// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_left %S/Inputs/module.map +// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_right %S/Inputs/module.map +// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros %S/Inputs/module.map +// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s + +// This test checks some of the same things as macros.c, but imports modules in +// a different order. + +@import macros_other; + +int n0 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok + +@import macros_top; + +TOP_OTHER_DEF_RIGHT_UNDEF *n0b; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_DEF_RIGHT_UNDEF'}} +// expected-note@macros_top.h:22 {{expanding this definition of 'TOP_OTHER_DEF_RIGHT_UNDEF'}} +// expected-note@macros_other.h:6 {{other definition of 'TOP_OTHER_DEF_RIGHT_UNDEF'}} + +@import macros_right; +@import macros_left; + +#ifdef TOP_LEFT_UNDEF +# error TOP_LEFT_UNDEF should not be defined +#endif + +#ifndef TOP_RIGHT_UNDEF +# error TOP_RIGHT_UNDEF should still be defined +#endif + +void test() { + float f; + TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition + + // Note, left's definition wins here, whereas right's definition wins in + // macros.c. + int i; + LEFT_RIGHT_IDENTICAL *ip = &i; + LEFT_RIGHT_DIFFERENT *ip2 = &f; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}} + // expected-note@macros_left.h:14 {{expanding this}} + // expected-note@macros_right.h:12 {{other}} + LEFT_RIGHT_DIFFERENT2 *ip3 = &f; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT2}} + // expected-note@macros_left.h:11 {{expanding this}} + // expected-note@macros_right.h:13 {{other}} +#undef LEFT_RIGHT_DIFFERENT3 + int LEFT_RIGHT_DIFFERENT3; +} + +@import macros_right.undef; + +// FIXME: See macros.c. +#ifdef TOP_RIGHT_UNDEF +# error TOP_RIGHT_UNDEF should not be defined +#endif + +#ifndef TOP_OTHER_UNDEF1 +# error TOP_OTHER_UNDEF1 should still be defined +#endif + +#ifndef TOP_OTHER_UNDEF2 +# error TOP_OTHER_UNDEF2 should still be defined +#endif + +#ifndef TOP_OTHER_REDEF1 +# error TOP_OTHER_REDEF1 should still be defined +#endif +int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}} +// expected-note@macros_top.h:19 {{expanding this definition}} +// expected-note@macros_other.h:4 {{other definition}} + +#ifndef TOP_OTHER_REDEF2 +# error TOP_OTHER_REDEF2 should still be defined +#endif +int n2 = TOP_OTHER_REDEF2; // ok + +int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok |