r371223 - [NFC] Added new tests for r371222

David Bolvansky via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 6 09:18:18 PDT 2019


Author: xbolva00
Date: Fri Sep  6 09:18:18 2019
New Revision: 371223

URL: http://llvm.org/viewvc/llvm-project?rev=371223&view=rev
Log:
[NFC] Added new tests for r371222

Added:
    cfe/trunk/test/Sema/div-sizeof-array.cpp

Added: cfe/trunk/test/Sema/div-sizeof-array.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=371223&view=auto
==============================================================================
--- cfe/trunk/test/Sema/div-sizeof-array.cpp (added)
+++ cfe/trunk/test/Sema/div-sizeof-array.cpp Fri Sep  6 09:18:18 2019
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -Wsizeof-array-div -fsyntax-only
+
+template <typename Ty, int N>
+int f(Ty (&Array)[N]) {
+  return sizeof(Array) / sizeof(Ty); // Should not warn
+}
+
+typedef int int32;
+
+void test(void) {
+  int arr[12]; // expected-note 2 {{array 'arr' declared here}}
+  unsigned long long arr2[4]; // expected-note {{array 'arr2' declared here}}
+  int *p = &arr[0];
+  int a1 = sizeof(arr) / sizeof(*arr);
+  int a2 = sizeof arr / sizeof p;       // expected-warning {{expresion will return the incorrect number of elements in the array; the array element type is 'int', not 'int *'}}
+  int a4 = sizeof arr2 / sizeof p;      // expected-warning {{expresion will return the incorrect number of elements in the array; the array element type is 'unsigned long long', not 'int *'}}
+  int a5 = sizeof(arr) / sizeof(short); // expected-warning {{expresion will return the incorrect number of elements in the array; the array element type is 'int', not 'short'}}
+  int a6 = sizeof(arr) / sizeof(int32);
+  const char arr3[2] = "A";
+  int a7 = sizeof(arr3) / sizeof(char);
+
+  int arr4[10][12];
+  int b1 = sizeof(arr4) / sizeof(arr2[12]);
+  int b2 = sizeof(arr4) / sizeof(int *);
+  int b3 = sizeof(arr4) / sizeof(short *);
+}




More information about the cfe-commits mailing list