[PATCH] D68526: [Diagnostics] Silence -Wsizeof-array-div for character buffers
James Clarke via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 16:28:21 PDT 2019
jrtc27 created this revision.
jrtc27 added reviewers: rsmith, xbolva00.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68526
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/div-sizeof-array.cpp
Index: clang/test/Sema/div-sizeof-array.cpp
===================================================================
--- clang/test/Sema/div-sizeof-array.cpp
+++ clang/test/Sema/div-sizeof-array.cpp
@@ -21,6 +21,8 @@
int a9 = sizeof(arr) / sizeof(unsigned int);
const char arr3[2] = "A";
int a10 = sizeof(arr3) / sizeof(char);
+ int a11 = sizeof(arr3) / sizeof(p);
+ int a12 = sizeof(arr3) / sizeof(int);
int arr4[10][12]; // expected-note 3 {{array 'arr4' declared here}}
int b1 = sizeof(arr4) / sizeof(arr2[12]); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'unsigned long long'}}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -9191,6 +9191,7 @@
} else if (const auto *ArrayTy = S.Context.getAsArrayType(LHSTy)) {
QualType ArrayElemTy = ArrayTy->getElementType();
if (ArrayElemTy->isDependentType() || RHSTy->isDependentType() ||
+ ArrayElemTy->isCharType() ||
S.Context.getTypeSize(ArrayElemTy) == S.Context.getTypeSize(RHSTy))
return;
S.Diag(Loc, diag::warn_division_sizeof_array)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68526.223337.patch
Type: text/x-patch
Size: 1263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191004/e528d534/attachment-0001.bin>
More information about the cfe-commits
mailing list