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

Yitzhak Mandelbaum via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 13 05:52:33 PST 2022


ymandel added a comment.

In D139737#3989927 <https://reviews.llvm.org/D139737#3989927>, @NoQ wrote:

> Ok so at the conference @ymandel suggested us to use libTooling's Transformers API to make our lives easier (https://clang.llvm.org/docs/ClangTransformerTutorial.html). I'm fairly certain we should at least consider using them, but I haven't looked into it deeply enough yet. "Changing the type of a variable" is a problem that ideally should be solved only once, because it's a problem that's easy to formulate but difficult to "get right". Transformers appear to be a collection of solutions to problems of this kind. We should see if they already provide an out-of-the-box solution, or if they have bits and pieces of machinery we can reuse in our solution.



1. Transformer is good when you are basing your changes around AST matchers.  It is a collection of combinators over the `MatchResult` type. From what I'm seeing here, though, you don't seem to be basing it on AST matchers, in which case the libraries are not as useful.
2. We (google) have a tool for changing the type of a variable which takes into account all cascading changes to other declarations that result from that type change. It is built on Transformer and another library that builds a graph of relationships in the AST, relevant to the type-rewriting problem.  Unfortunately, that's all internal -- not for IP reasons but simply because we never had reason to upstream it (nor an obvioius place to put it). So, I'd say that this advanced tooling is useful here if you want to _selectively_ change type T to type S, so you need tooling to tell you specifically which S's to update. If you're changing all T to S, then the problem is simpler.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139737



More information about the cfe-commits mailing list