1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc // rdar: // 8125274 4*f4a2713aSLionel Sambuc static int a16[]; // expected-warning {{tentative array definition assumed to have one element}} 5*f4a2713aSLionel Sambuc f16(void)6*f4a2713aSLionel Sambucvoid f16(void) { 7*f4a2713aSLionel Sambuc extern int a16[]; 8*f4a2713aSLionel Sambuc } 9*f4a2713aSLionel Sambuc 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc // PR10013: Scope of extern declarations extend past enclosing block 12*f4a2713aSLionel Sambuc extern int PR10013_x; PR10013(void)13*f4a2713aSLionel Sambucint PR10013(void) { 14*f4a2713aSLionel Sambuc int *PR10013_x = 0; 15*f4a2713aSLionel Sambuc { 16*f4a2713aSLionel Sambuc extern int PR10013_x; 17*f4a2713aSLionel Sambuc extern int PR10013_x; 18*f4a2713aSLionel Sambuc } 19*f4a2713aSLionel Sambuc 20*f4a2713aSLionel Sambuc return PR10013_x; // expected-warning{{incompatible pointer to integer conversion}} 21*f4a2713aSLionel Sambuc } 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc static int test1_a[]; // expected-warning {{tentative array definition assumed to have one element}} 24*f4a2713aSLionel Sambuc extern int test1_a[]; 25*f4a2713aSLionel Sambuc 26*f4a2713aSLionel Sambuc // rdar://13535367 test2declarer()27*f4a2713aSLionel Sambucvoid test2declarer() { extern int test2_array[100]; } 28*f4a2713aSLionel Sambuc extern int test2_array[]; 29*f4a2713aSLionel Sambuc int test2v = sizeof(test2_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}} 30*f4a2713aSLionel Sambuc test3declarer()31*f4a2713aSLionel Sambucvoid test3declarer() { 32*f4a2713aSLionel Sambuc { extern int test3_array[100]; } 33*f4a2713aSLionel Sambuc extern int test3_array[]; 34*f4a2713aSLionel Sambuc int x = sizeof(test3_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}} 35*f4a2713aSLionel Sambuc } 36*f4a2713aSLionel Sambuc test4()37*f4a2713aSLionel Sambucvoid test4() { 38*f4a2713aSLionel Sambuc extern int test4_array[]; 39*f4a2713aSLionel Sambuc { 40*f4a2713aSLionel Sambuc extern int test4_array[100]; 41*f4a2713aSLionel Sambuc int x = sizeof(test4_array); // fine 42*f4a2713aSLionel Sambuc } 43*f4a2713aSLionel Sambuc int x = sizeof(test4_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}} 44*f4a2713aSLionel Sambuc } 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambuc // Test that invalid local extern declarations of library 47*f4a2713aSLionel Sambuc // builtins behave reasonably. 48*f4a2713aSLionel Sambuc extern void abort(void); // expected-note 2 {{previous declaration is here}} 49*f4a2713aSLionel Sambuc extern float *calloc(); // expected-warning {{incompatible redeclaration of library function}} expected-note {{is a builtin}} expected-note 2 {{previous declaration is here}} test5a()50*f4a2713aSLionel Sambucvoid test5a() { 51*f4a2713aSLionel Sambuc int abort(); // expected-error {{conflicting types}} 52*f4a2713aSLionel Sambuc float *malloc(); // expected-warning {{incompatible redeclaration of library function}} expected-note 2 {{is a builtin}} 53*f4a2713aSLionel Sambuc int *calloc(); // expected-error {{conflicting types}} 54*f4a2713aSLionel Sambuc } test5b()55*f4a2713aSLionel Sambucvoid test5b() { 56*f4a2713aSLionel Sambuc int abort(); // expected-error {{conflicting types}} 57*f4a2713aSLionel Sambuc float *malloc(); // expected-warning {{incompatible redeclaration of library function}} 58*f4a2713aSLionel Sambuc int *calloc(); // expected-error {{conflicting types}} 59*f4a2713aSLionel Sambuc } test5c()60*f4a2713aSLionel Sambucvoid test5c() { 61*f4a2713aSLionel Sambuc void (*_abort)(void) = &abort; 62*f4a2713aSLionel Sambuc void *(*_malloc)() = &malloc; 63*f4a2713aSLionel Sambuc float *(*_calloc)() = &calloc; 64*f4a2713aSLionel Sambuc } 65*f4a2713aSLionel Sambuc test6()66*f4a2713aSLionel Sambucvoid test6() { 67*f4a2713aSLionel Sambuc extern int test6_array1[100]; 68*f4a2713aSLionel Sambuc extern int test6_array2[100]; 69*f4a2713aSLionel Sambuc void test6_fn1(int*); 70*f4a2713aSLionel Sambuc void test6_fn2(int*); 71*f4a2713aSLionel Sambuc { 72*f4a2713aSLionel Sambuc // Types are only merged from visible declarations. 73*f4a2713aSLionel Sambuc char test6_array2; 74*f4a2713aSLionel Sambuc char test6_fn2; 75*f4a2713aSLionel Sambuc { 76*f4a2713aSLionel Sambuc extern int test6_array1[]; 77*f4a2713aSLionel Sambuc extern int test6_array2[]; 78*f4a2713aSLionel Sambuc (void)sizeof(test6_array1); // ok 79*f4a2713aSLionel Sambuc (void)sizeof(test6_array2); // expected-error {{incomplete type}} 80*f4a2713aSLionel Sambuc 81*f4a2713aSLionel Sambuc void test6_fn1(); 82*f4a2713aSLionel Sambuc void test6_fn2(); 83*f4a2713aSLionel Sambuc test6_fn1(1.2); // expected-error {{passing 'double' to parameter of incompatible type 'int *'}} 84*f4a2713aSLionel Sambuc // FIXME: This is valid, but we should warn on it. 85*f4a2713aSLionel Sambuc test6_fn2(1.2); 86*f4a2713aSLionel Sambuc } 87*f4a2713aSLionel Sambuc } 88*f4a2713aSLionel Sambuc } 89