[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / macros2.c
blob82a749bf0881ac7456e530dcd37fd2d2f282742f
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
5 // This test checks some of the same things as macros.c, but imports modules in
6 // a different order.
8 @import macros_other;
10 int n0 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok
12 @import macros_top;
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'}}
18 @import macros_right;
19 @import macros_left;
21 #ifdef TOP_LEFT_UNDEF
22 # error TOP_LEFT_UNDEF should not be defined
23 #endif
25 #ifndef TOP_RIGHT_UNDEF
26 # error TOP_RIGHT_UNDEF should still be defined
27 #endif
29 void test(void) {
30 float f;
31 TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition
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;
47 @import macros_right.undef;
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
60 #ifndef TOP_OTHER_UNDEF1
61 # error TOP_OTHER_UNDEF1 should still be defined
62 #endif
64 #ifndef TOP_OTHER_UNDEF2
65 # error TOP_OTHER_UNDEF2 should still be defined
66 #endif
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}}
75 #ifndef TOP_OTHER_REDEF2
76 # error TOP_OTHER_REDEF2 should still be defined
77 #endif
78 int n2 = TOP_OTHER_REDEF2; // ok
80 int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok
82 int top_redef_in_submodules = TOP_REDEF_IN_SUBMODULES;
83 @import macros_top.c;
84 void test2(void) {
85 int TOP_REDEF_IN_SUBMODULES = top_redef_in_submodules;