Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Sema / div-sizeof-array.cpp
blobf4d8c2d2a5fbaa1566e427dc7e6e464cadd2bb88
1 // RUN: %clang_cc1 %s -verify -Wsizeof-array-div -fsyntax-only -triple=x86_64-linux-gnu
2 // RUN: %clang_cc1 %s -verify -fsyntax-only -triple=x86_64-linux-gnu
4 template <typename Ty, int N>
5 int f(Ty (&Array)[N]) {
6 return sizeof(Array) / sizeof(Ty); // Should not warn
9 typedef int int32;
11 void test(void) {
12 int arr[12]; // expected-note 2 {{array 'arr' declared here}}
13 unsigned long long arr2[4];
14 int *p = &arr[0];
15 int a1 = sizeof(arr) / sizeof(*arr);
16 int a2 = sizeof arr / sizeof p; // expected-warning {{expression does not compute the number of elements in this array; element type is 'int', not 'int *'}}
17 // expected-note@-1 {{place parentheses around the 'sizeof p' expression to silence this warning}}
18 int a4 = sizeof arr2 / sizeof p;
19 int a5 = sizeof(arr) / sizeof(short); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int', not 'short'}}
20 // expected-note@-1 {{place parentheses around the 'sizeof(short)' expression to silence this warning}}
21 int a6 = sizeof(arr) / sizeof(int32);
22 int a7 = sizeof(arr) / sizeof(int);
23 int a9 = sizeof(arr) / sizeof(unsigned int);
24 const char arr3[2] = "A";
25 int a10 = sizeof(arr3) / sizeof(char);
26 int a11 = sizeof(arr2) / (sizeof(unsigned));
27 int a12 = sizeof(arr) / (sizeof(short));
28 int a13 = sizeof(arr3) / sizeof(p);
29 int a14 = sizeof(arr3) / sizeof(int);
31 int arr4[10][12];
32 int b1 = sizeof(arr4) / sizeof(arr2[12]);
33 int b2 = sizeof(arr4) / sizeof(int *);
34 int b3 = sizeof(arr4) / sizeof(short *);
35 int arr5[][5] = {
36 {1, 2, 3, 4, 5},
37 {6, 7, 8, 9, 0},
39 int c1 = sizeof(arr5) / sizeof(*arr5);
40 int c2 = sizeof(arr5) / sizeof(**arr5);
41 int c3 = sizeof(arr5) / sizeof(int);
43 float m[4][4];
44 int d1 = sizeof(m) / sizeof(**m);
46 int array[10];
47 int narray = sizeof(array) / sizeof(int &);
48 int narray2 = sizeof(array) / sizeof(decltype(array[0]));
50 int *arrptrs[10]; // expected-note {{array 'arrptrs' declared here}}
51 int len = sizeof(arrptrs) / sizeof(decltype(*arrptrs[0])); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int *', not 'int'}}
52 // expected-note@-1 {{place parentheses around the 'sizeof(decltype(*arrptrs[0]))' expression to silence this warning}}