[PATCH] D87990: [Diagnostics] Diagnose -Wsizeof-array-div for array of pointers
Dávid Bolvanský via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 9 03:56:33 PDT 2020
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcaf28b0a1288: [Diagnostics] Diagnose -Wsizeof-array-div for array of pointers (authored by xbolva00).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87990/new/
https://reviews.llvm.org/D87990
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/div-sizeof-array.cpp
clang/test/Sema/div-sizeof-ptr.cpp
Index: clang/test/Sema/div-sizeof-ptr.cpp
===================================================================
--- clang/test/Sema/div-sizeof-ptr.cpp
+++ clang/test/Sema/div-sizeof-ptr.cpp
@@ -7,7 +7,7 @@
typedef int int32;
-void test(int *p, int **q) { // expected-note 5 {{pointer 'p' declared here}}
+void test(int *p, int **q) { // expected-note 6 {{pointer 'p' declared here}}
const int *r; // expected-note {{pointer 'r' declared here}}
int a1 = sizeof(p) / sizeof(*p); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}}
int a2 = sizeof p / sizeof *p; // expected-warning {{'sizeof p' will return the size of the pointer, not the array itself}}
@@ -21,6 +21,7 @@
int a8 = sizeof(d) / sizeof(int); // expected-warning {{'sizeof (d)' will return the size of the pointer, not the array itself}}
int a9 = sizeof(*q) / sizeof(**q); // expected-warning {{'sizeof (*q)' will return the size of the pointer, not the array itself}}
+ int a10 = sizeof(p) / sizeof(decltype(*p)); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}}
// Should not warn
int b1 = sizeof(int *) / sizeof(int);
Index: clang/test/Sema/div-sizeof-array.cpp
===================================================================
--- clang/test/Sema/div-sizeof-array.cpp
+++ clang/test/Sema/div-sizeof-array.cpp
@@ -46,4 +46,8 @@
int array[10];
int narray = sizeof(array) / sizeof(int &);
int narray2 = sizeof(array) / sizeof(decltype(array[0]));
+
+ int *arrptrs[10]; // expected-note {{array 'arrptrs' declared here}}
+ 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'}}
+ // expected-note at -1 {{place parentheses around the 'sizeof(decltype(*arrptrs[0]))' expression to silence this warning}}
}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -10036,7 +10036,7 @@
QualType RHSTy;
if (RUE->isArgumentType())
- RHSTy = RUE->getArgumentType();
+ RHSTy = RUE->getArgumentType().getNonReferenceType();
else
RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87990.297181.patch
Type: text/x-patch
Size: 2428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201009/b48d6711/attachment.bin>
More information about the cfe-commits
mailing list