xref: /aosp_15_r20/external/clang/test/Sema/warn-sizeof-array-decay.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li 
f(int x)3*67e74705SXin Li void f(int x) {
4*67e74705SXin Li   char foo[10];
5*67e74705SXin Li   int bar[20];
6*67e74705SXin Li   char qux[30];
7*67e74705SXin Li 
8*67e74705SXin Li   (void)sizeof(bar + 10); // expected-warning{{sizeof on pointer operation will return size of 'int *' instead of 'int [20]'}}
9*67e74705SXin Li   (void)sizeof(foo - 20); // expected-warning{{sizeof on pointer operation will return size of 'char *' instead of 'char [10]'}}
10*67e74705SXin Li   (void)sizeof(bar - x); // expected-warning{{sizeof on pointer operation will return size of 'int *' instead of 'int [20]'}}
11*67e74705SXin Li   (void)sizeof(foo + x); // expected-warning{{sizeof on pointer operation will return size of 'char *' instead of 'char [10]'}}
12*67e74705SXin Li 
13*67e74705SXin Li   // This is ptrdiff_t.
14*67e74705SXin Li   (void)sizeof(foo - qux); // no-warning
15*67e74705SXin Li 
16*67e74705SXin Li   (void)sizeof(foo, x); // no-warning
17*67e74705SXin Li   (void)sizeof(x, foo); // expected-warning{{sizeof on pointer operation will return size of 'char *' instead of 'char [10]'}}
18*67e74705SXin Li }
19