[PATCH] D143128: [-Wunsafe-buffer-usage] Fix-Its transforming `&DRE[any]` to `&DRE.data()[any]`

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 3 12:27:50 PDT 2023


NoQ accepted this revision.
NoQ added a comment.

Looks great! LGTM except there's some dead code.



================
Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:570-573
+    if (const auto *ArraySubst =
+            dyn_cast<ArraySubscriptExpr>(Node->getSubExpr()))
+      if (const auto *DRE =
+              dyn_cast<DeclRefExpr>(ArraySubst->getBase()->IgnoreImpCasts())) {
----------------
These `dyn_cast`s are already checked by the matcher. They can be turned into `cast`s and this function can return `{DRE}` unconditionally.


================
Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1002
+
+  if (DREs.size() == 1)
+    if (const auto *VD = dyn_cast<VarDecl>(DREs.front()->getDecl())) {
----------------
Similarly, this check is redundant, it's already guaranteed by the matcher.


================
Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1077-1079
+  if (const auto *ArraySub = dyn_cast<ArraySubscriptExpr>(Node->getSubExpr()))
+    if (const auto *DRE =
+            dyn_cast<DeclRefExpr>(ArraySub->getBase()->IgnoreImpCasts())) {
----------------
Same here!


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

https://reviews.llvm.org/D143128



More information about the cfe-commits mailing list