[PATCH] D52949: [Diagnostics] Implement -Wsizeof-pointer-div

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 1 07:44:19 PDT 2018


aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM with a minor formatting nit.



================
Comment at: lib/Sema/SemaExpr.cpp:8729
 
+static void DiagnoseDivisionSizeofPointer(Sema &S, Expr *LHS, Expr *RHS,
+                                          SourceLocation Loc) {
----------------
xbolva00 wrote:
> aaron.ballman wrote:
> > `const Expr *`
> if const, i have build issues with "<< LHS"
That sounds like a bug with the diagnostic builder, but it can be addressed separately.


================
Comment at: test/Sema/div-sizeof-ptr.cpp:1
+// RUN: %clang_cc1 %s -verify -Wsizeof-pointer-div -fsyntax-only
+
----------------
Please run this file through clang-format as the formatting appears to be off.


================
Comment at: test/Sema/div-sizeof-ptr.cpp:27
+    int arr2[10][12];
+    int b8 = sizeof(arr2) / sizeof(*arr2); 
+}
----------------
GCC does not warn here, but I question whether we should. This evaluates to `10`, but is that what the user expects it to evaluate to, as opposed to `120`?

Regardless, I think it's reasonable to not warn on this right now (it would need different diagnostic text).


https://reviews.llvm.org/D52949





More information about the cfe-commits mailing list