[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)
Ziqing Luo via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 12 12:57:27 PDT 2025
================
@@ -1670,30 +1936,41 @@ class ULCArraySubscriptGadget : public FixableGadget {
};
// Fixable gadget to handle stand alone pointers of the form `UPC(DRE)` in the
-// unspecified pointer context (isInUnspecifiedPointerContext). The gadget emits
-// fixit of the form `UPC(DRE.data())`.
+// unspecified pointer context (findStmtsInUnspecifiedPointerContext). The
+// gadget emits fixit of the form `UPC(DRE.data())`.
class UPCStandalonePointerGadget : public FixableGadget {
private:
static constexpr const char *const DeclRefExprTag = "StandalonePointer";
const DeclRefExpr *Node;
public:
- UPCStandalonePointerGadget(const MatchFinder::MatchResult &Result)
+ UPCStandalonePointerGadget(const MatchResult &Result)
: FixableGadget(Kind::UPCStandalonePointer),
- Node(Result.Nodes.getNodeAs<DeclRefExpr>(DeclRefExprTag)) {
+ Node(Result.getNodeAs<DeclRefExpr>(DeclRefExprTag)) {
assert(Node != nullptr && "Expecting a non-null matching result");
}
static bool classof(const Gadget *G) {
return G->getKind() == Kind::UPCStandalonePointer;
}
- static Matcher matcher() {
- auto ArrayOrPtr = anyOf(hasPointerType(), hasArrayType());
- auto target = expr(ignoringParenImpCasts(
- declRefExpr(allOf(ArrayOrPtr, toSupportedVariable()))
- .bind(DeclRefExprTag)));
- return stmt(isInUnspecifiedPointerContext(target));
+ static bool matches(const Stmt *S,
+ llvm::SmallVectorImpl<MatchResult> &Results) {
+ bool Found = false;
+ findStmtsInUnspecifiedPointerContext(S, [&Found, &Results](const Stmt *S) {
----------------
ziqingluo-90 wrote:
nit: for these functions like `findStmtsInUnspecifiedPointerContext`, can we change the type of the second parameter to `llvm::function_ref<bool(const Stmt *)>`? I just feel like it would be a bit more intuitive than capturing `Found`.
https://github.com/llvm/llvm-project/pull/125492
More information about the cfe-commits
mailing list