Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
The check to(varDecl()) is repeated in every gadget as well as here, now they go even further out of sync. It probably makes sense to make a reusable matcher toSupportedVariable() that covers all cases we want to cover(?)
Aha great! Code reuse!!
I'm further trying to sort out this issue once and for all, because we keep running into it, so I have, uhh, further suggestions.
clang/lib/Analysis/UnsafeBufferUsage.cpp | ||
---|---|---|
384 | Now, I don't think we actually support BindingDecl yet. We don't really know how to emit a fixit for it, and this is very likely to be as hard as struct member fixits, given that it's about decomposing structs into individual members. Maybe we'll have explicit support for std::pair and std::tuple in the future, but we're not there yet. So we should probably leave it as to(varDecl()) for now. It's still great that we reused it though! Another thing we can put there, is the check that the variable is *local*. Then we can remove a lot of manual imperative checks for that in all the getFixits() methods. | |
699–700 | I found one more place where these checks are missing. |
clang/lib/Analysis/UnsafeBufferUsage.cpp | ||
---|---|---|
384 |
As is tradition, I appear to be making it up as there aren't any duplicated checks for local variables in getFixits() methods. They're already deduplicated to like 2 places. It's definitely a good question who's really responsible to performing these checks; it depends on whether we see it as a strategy thing ("fix this variable with span, but as if it's a global variable, so slap an attribute on it and introduce safe accessors - that's a different strategy from changing the type of a local variable to span, and we can technically choose the local strategy for a static global, or a global-like strategy for a local variable, kinda why not"), or as a fixable thing ("I'm a fixable who knows how to fix a use of a local variable with span, there's supposed to be another fixable who knows how to fix a similar use of a global variable with span, and we never talk to each other"). But as Rashmi correctly pointed out offline, it's not really valuable to resolve this question right away, and trying to make fixables responsible for this check will only get in the way of gathering statistics and improving parts that actually matter. It's really valuable to have every part of the machine agree what a supported variable is, but not every aspect needs to be actually checked by each gadget. |
Now, I don't think we actually support BindingDecl yet. We don't really know how to emit a fixit for it, and this is very likely to be as hard as struct member fixits, given that it's about decomposing structs into individual members. Maybe we'll have explicit support for std::pair and std::tuple in the future, but we're not there yet.
So we should probably leave it as to(varDecl()) for now. It's still great that we reused it though!
Another thing we can put there, is the check that the variable is *local*. Then we can remove a lot of manual imperative checks for that in all the getFixits() methods.