[clang] 2ae1822 - [Diagnostics] Fixed -Wsizeof-array-div false positive when divisor is sizeof reference type (PR47495)
Dávid Bolvanský via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 20 08:43:20 PDT 2020
Author: Dávid Bolvanský
Date: 2020-09-20T17:43:06+02:00
New Revision: 2ae182258c49724e4daaae196de829ea65c116e8
URL: https://github.com/llvm/llvm-project/commit/2ae182258c49724e4daaae196de829ea65c116e8
DIFF: https://github.com/llvm/llvm-project/commit/2ae182258c49724e4daaae196de829ea65c116e8.diff
LOG: [Diagnostics] Fixed -Wsizeof-array-div false positive when divisor is sizeof reference type (PR47495)
Added:
Modified:
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/div-sizeof-array.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 501e1aed1509..736a6c166eb3 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10038,7 +10038,7 @@ static void DiagnoseDivisionSizeofPointerOrArray(Sema &S, Expr *LHS, Expr *RHS,
QualType ArrayElemTy = ArrayTy->getElementType();
if (ArrayElemTy != S.Context.getBaseElementType(ArrayTy) ||
ArrayElemTy->isDependentType() || RHSTy->isDependentType() ||
- ArrayElemTy->isCharType() ||
+ RHSTy->isReferenceType() || ArrayElemTy->isCharType() ||
S.Context.getTypeSize(ArrayElemTy) == S.Context.getTypeSize(RHSTy))
return;
S.Diag(Loc, diag::warn_division_sizeof_array)
diff --git a/clang/test/Sema/div-sizeof-array.cpp b/clang/test/Sema/div-sizeof-array.cpp
index e295a9dec6d8..898ff42a7bd4 100644
--- a/clang/test/Sema/div-sizeof-array.cpp
+++ b/clang/test/Sema/div-sizeof-array.cpp
@@ -42,4 +42,8 @@ void test(void) {
float m[4][4];
int d1 = sizeof(m) / sizeof(**m);
+
+ int array[10];
+ int narray = sizeof(array) / sizeof(int &);
+ int narray2 = sizeof(array) / sizeof(decltype(array[0]));
}
More information about the cfe-commits
mailing list