diff options
author | David Bolvansky <david.bolvansky@gmail.com> | 2019-08-18 10:10:09 +0000 |
---|---|---|
committer | David Bolvansky <david.bolvansky@gmail.com> | 2019-08-18 10:10:09 +0000 |
commit | b4806822d2d52e0e7a29ba1c15a435e2e97a82e7 (patch) | |
tree | eeb720b2837d122950294f43b5361b8e49fdd308 /clang/lib/Sema/SemaExpr.cpp | |
parent | 74168ded0399a30fe9cf4d73a28a6045cc685088 (diff) | |
download | bcm5719-llvm-b4806822d2d52e0e7a29ba1c15a435e2e97a82e7.tar.gz bcm5719-llvm-b4806822d2d52e0e7a29ba1c15a435e2e97a82e7.zip |
[Diagnostics] Improve -Wsizeof-pointer-div
Emit diag note with a location of pointer declaration.
Revisited/added tests.
llvm-svn: 369206
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index de06cc8363f..b218ad1f66c 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9075,7 +9075,8 @@ static void DiagnoseDivisionSizeofPointer(Sema &S, Expr *LHS, Expr *RHS, RUE->getKind() != UETT_SizeOf) return; - QualType LHSTy = LUE->getArgumentExpr()->IgnoreParens()->getType(); + const Expr *LHSArg = LUE->getArgumentExpr()->IgnoreParens(); + QualType LHSTy = LHSArg->getType(); QualType RHSTy; if (RUE->isArgumentType()) @@ -9085,10 +9086,15 @@ static void DiagnoseDivisionSizeofPointer(Sema &S, Expr *LHS, Expr *RHS, if (!LHSTy->isPointerType() || RHSTy->isPointerType()) return; - if (LHSTy->getPointeeType() != RHSTy) + if (LHSTy->getPointeeType().getCanonicalType() != RHSTy.getCanonicalType()) return; S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << LHS->getSourceRange(); + if (const auto *DRE = dyn_cast<DeclRefExpr>(LHSArg)) { + if (const ValueDecl *LHSArgDecl = DRE->getDecl()) + S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here) + << LHSArgDecl; + } } static void DiagnoseBadDivideOrRemainderValues(Sema& S, ExprResult &LHS, |