1 // RUN: rm -rf %t 2 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s 3 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-local-submodule-visibility -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s -DLOCAL_VISIBILITY 4 5 // This test checks some of the same things as macros.c, but imports modules in 6 // a different order. 7 8 @import macros_other; 9 10 int n0 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok 11 12 @import macros_top; 13 14 TOP_OTHER_DEF_RIGHT_UNDEF *n0b; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_DEF_RIGHT_UNDEF'}} 15 // expected-note@macros_top.h:22 {{expanding this definition of 'TOP_OTHER_DEF_RIGHT_UNDEF'}} 16 // expected-note@macros_other.h:6 {{other definition of 'TOP_OTHER_DEF_RIGHT_UNDEF'}} 17 18 @import macros_right; 19 @import macros_left; 20 21 #ifdef TOP_LEFT_UNDEF 22 # error TOP_LEFT_UNDEF should not be defined 23 #endif 24 25 #ifndef TOP_RIGHT_UNDEF 26 # error TOP_RIGHT_UNDEF should still be defined 27 #endif 28 test()29void test() { 30 float f; 31 TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition 32 33 // Note, left's definition wins here, whereas right's definition wins in 34 // macros.c. 35 int i; 36 LEFT_RIGHT_IDENTICAL *ip = &i; 37 LEFT_RIGHT_DIFFERENT *ip2 = &f; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}} 38 // expected-note@macros_left.h:14 {{expanding this}} 39 // expected-note@macros_right.h:12 {{other}} 40 LEFT_RIGHT_DIFFERENT2 *ip3 = &f; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT2}} 41 // expected-note@macros_left.h:11 {{expanding this}} 42 // expected-note@macros_right.h:13 {{other}} 43 #undef LEFT_RIGHT_DIFFERENT3 44 int LEFT_RIGHT_DIFFERENT3; 45 } 46 47 @import macros_right.undef; 48 49 // See macros.c. 50 #ifdef LOCAL_VISIBILITY 51 # ifndef TOP_RIGHT_UNDEF 52 # error TOP_RIGHT_UNDEF should still be defined 53 # endif 54 #else 55 # ifdef TOP_RIGHT_UNDEF 56 # error TOP_RIGHT_UNDEF should not be defined 57 # endif 58 #endif 59 60 #ifndef TOP_OTHER_UNDEF1 61 # error TOP_OTHER_UNDEF1 should still be defined 62 #endif 63 64 #ifndef TOP_OTHER_UNDEF2 65 # error TOP_OTHER_UNDEF2 should still be defined 66 #endif 67 68 #ifndef TOP_OTHER_REDEF1 69 # error TOP_OTHER_REDEF1 should still be defined 70 #endif 71 int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}} 72 // expected-note@macros_top.h:19 {{expanding this definition}} 73 // expected-note@macros_other.h:4 {{other definition}} 74 75 #ifndef TOP_OTHER_REDEF2 76 # error TOP_OTHER_REDEF2 should still be defined 77 #endif 78 int n2 = TOP_OTHER_REDEF2; // ok 79 80 int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok 81 82 int top_redef_in_submodules = TOP_REDEF_IN_SUBMODULES; 83 @import macros_top.c; test2()84void test2() { 85 int TOP_REDEF_IN_SUBMODULES = top_redef_in_submodules; 86 } 87