[PATCH] D139737: [-Wunsafe-buffer-usage] Initiate Fix-it generation for local variable declarations

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 3 13:43:53 PST 2023


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

As far as I'm concerned, I think this is great for the initial implementation! Let's commit as soon as Jan confirms that his problem is addressed.



================
Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:894
+    if (VD->getType()->isPointerType())
+      return fixVariableWithSpan(VD, Tracker, Ctx, Handler);
+    return {};
----------------
jkorous wrote:
> I believe we should add another condition here: `VD->isLocalVarDecl()` as we don't support globals (yet?).
> We run the matcher with `any_ds` tag only on function bodies so we won't discover globals anyway and the `assert(It != Defs.end() && "Definition never discovered!");` would fail.
I think this check should happen much earlier. Like, we shouldn't define a strategy for globals, and we shouldn't build fixables out of them. And then `assert()` here, just to double-check.


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

https://reviews.llvm.org/D139737



More information about the cfe-commits mailing list