<div dir="ltr"><div dir="ltr">On Sun, 20 Sep 2020 at 08:43, Dávid Bolvanský via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: Dávid Bolvanský<br>
Date: 2020-09-20T17:43:06+02:00<br>
New Revision: 2ae182258c49724e4daaae196de829ea65c116e8<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/2ae182258c49724e4daaae196de829ea65c116e8" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/2ae182258c49724e4daaae196de829ea65c116e8</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/2ae182258c49724e4daaae196de829ea65c116e8.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/2ae182258c49724e4daaae196de829ea65c116e8.diff</a><br>
<br>
LOG: [Diagnostics] Fixed -Wsizeof-array-div false positive when divisor is sizeof reference type (PR47495)<br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
clang/lib/Sema/SemaExpr.cpp<br>
clang/test/Sema/div-sizeof-array.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp<br>
index 501e1aed1509..736a6c166eb3 100644<br>
--- a/clang/lib/Sema/SemaExpr.cpp<br>
+++ b/clang/lib/Sema/SemaExpr.cpp<br>
@@ -10038,7 +10038,7 @@ static void DiagnoseDivisionSizeofPointerOrArray(Sema &S, Expr *LHS, Expr *RHS,<br>
QualType ArrayElemTy = ArrayTy->getElementType();<br>
if (ArrayElemTy != S.Context.getBaseElementType(ArrayTy) ||<br>
ArrayElemTy->isDependentType() || RHSTy->isDependentType() ||<br>
- ArrayElemTy->isCharType() ||<br>
+ RHSTy->isReferenceType() || ArrayElemTy->isCharType() ||<br></blockquote><div><br></div><div>Instead of skipping the check for a reference type, could we instead replace RHSTy with its referenced type for the purpose of the check when RHSTy is a reference type? I think we do want to diagnose (for example) sizeof(array) / sizeof(decltype(*array[0])) for an array of pointers.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
S.Context.getTypeSize(ArrayElemTy) == S.Context.getTypeSize(RHSTy))<br>
return;<br>
S.Diag(Loc, diag::warn_division_sizeof_array)<br>
<br>
diff --git a/clang/test/Sema/div-sizeof-array.cpp b/clang/test/Sema/div-sizeof-array.cpp<br>
index e295a9dec6d8..898ff42a7bd4 100644<br>
--- a/clang/test/Sema/div-sizeof-array.cpp<br>
+++ b/clang/test/Sema/div-sizeof-array.cpp<br>
@@ -42,4 +42,8 @@ void test(void) {<br>
<br>
float m[4][4];<br>
int d1 = sizeof(m) / sizeof(**m);<br>
+<br>
+ int array[10];<br>
+ int narray = sizeof(array) / sizeof(int &);<br>
+ int narray2 = sizeof(array) / sizeof(decltype(array[0]));<br>
}<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div>