[PATCH] D68526: [Diagnostics] Silence -Wsizeof-array-div for character buffers

James Clarke via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 8 04:33:39 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rG67f542aba72f: [Diagnostics] Silence -Wsizeof-array-div for character buffers (authored by jrtc27).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68526/new/

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
@@ -25,6 +25,8 @@
   int a10 = sizeof(arr3) / sizeof(char);
   int a11 = sizeof(arr2) / (sizeof(unsigned));
   int a12 = sizeof(arr) / (sizeof(short));
+  int a13 = sizeof(arr3) / sizeof(p);
+  int a14 = sizeof(arr3) / sizeof(int);
 
   int arr4[10][12];
   int b1 = sizeof(arr4) / sizeof(arr2[12]);
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -9197,6 +9197,7 @@
     QualType ArrayElemTy = ArrayTy->getElementType();
     if (ArrayElemTy != S.Context.getBaseElementType(ArrayTy) ||
         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.223826.patch
Type: text/x-patch
Size: 1055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191008/c45f2e1b/attachment.bin>


More information about the cfe-commits mailing list