[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-02-03 Thread Ilya Biryukov via cfe-commits
ilya-biryukov wrote: FYI: this PR was taking too long to pick changes after rebase, so the discussions continued in #125492. https://github.com/llvm/llvm-project/pull/124554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.or

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-02-03 Thread Ivana Ivanovska via cfe-commits
https://github.com/ivanaivanovska closed https://github.com/llvm/llvm-project/pull/124554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ilya Biryukov via cfe-commits
@@ -1986,112 +2362,117 @@ class DerefSimplePtrArithFixableGadget : public FixableGadget { } }; -/// Scan the function and return a list of gadgets found with provided kits. -static void findGadgets(const Stmt *S, ASTContext &Ctx, -const UnsafeBufferU

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov commented: This generally looks good, just one more minor comment from me. Could we put this out of the draft state and send to upstream owners of the check to start a discussion about landing it? https://github.com/llvm/llvm-project/pull/124554

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov edited https://github.com/llvm/llvm-project/pull/124554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ivana Ivanovska via cfe-commits
https://github.com/ivanaivanovska edited https://github.com/llvm/llvm-project/pull/124554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ivana Ivanovska via cfe-commits
@@ -68,32 +70,60 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, if (StParents.size() > 1) return "unavailable due to multiple parents"; -if (StParents.size() == 0) +if (StParents.empty()) break; St = StParents.begin()->get();

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ivana Ivanovska via cfe-commits
@@ -68,32 +70,60 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, if (StParents.size() > 1) return "unavailable due to multiple parents"; -if (StParents.size() == 0) +if (StParents.empty()) break; St = StParents.begin()->get();

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-30 Thread Ivana Ivanovska via cfe-commits
https://github.com/ivanaivanovska updated https://github.com/llvm/llvm-project/pull/124554 504 Gateway Time-out The server didn't respond in time. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-30 Thread Ilya Biryukov via cfe-commits
@@ -68,32 +70,60 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, if (StParents.size() > 1) return "unavailable due to multiple parents"; -if (StParents.size() == 0) +if (StParents.empty()) break; St = StParents.begin()->get();

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-30 Thread Ilya Biryukov via cfe-commits
@@ -68,32 +70,60 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, if (StParents.size() > 1) return "unavailable due to multiple parents"; -if (StParents.size() == 0) +if (StParents.empty()) break; St = StParents.begin()->get();

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-30 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov commented: I only have a few suggestions left, overall this LG. Could you also add a description for the PR that explains the motivation and approach taken for the rewrite? Benchmark numbers would also be needed there. Thanks! https://github.com/llvm/llvm-pro

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-30 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov edited https://github.com/llvm/llvm-project/pull/124554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
https://github.com/ivanaivanovska edited https://github.com/llvm/llvm-project/pull/124554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -186,106 +213,221 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void setASTContext(ASTContext &Context) { ActiveASTContext = &Context; } + + void setHandler(const UnsafeBufferUsageHa

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
https://github.com/ivanaivanovska updated https://github.com/llvm/llvm-project/pull/124554 >From 9890ff5dd8977a5d70538a2034517d19b8399536 Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Mon, 2 Dec 2024 14:17:06 + Subject: [PATCH] Optimize -Wunsafe-buffer-usage. --- clang/lib/Analysis

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread Ilya Biryukov via cfe-commits
@@ -186,106 +213,221 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void setASTContext(ASTContext &Context) { ActiveASTContext = &Context; } + + void setHandler(const UnsafeBufferUsageHa

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov edited https://github.com/llvm/llvm-project/pull/124554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov edited https://github.com/llvm/llvm-project/pull/124554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov edited https://github.com/llvm/llvm-project/pull/124554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -1986,112 +2327,142 @@ class DerefSimplePtrArithFixableGadget : public FixableGadget { } }; -/// Scan the function and return a list of gadgets found with provided kits. -static void findGadgets(const Stmt *S, ASTContext &Ctx, -const UnsafeBufferU

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -79,21 +81,39 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +class CustomMatcher { +public: + virtual bool matches(const DynTypedNode &DynNode, ASTContext &Ctx, +

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } ivanaivanovska wrote: Done

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -79,21 +81,39 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +class CustomMatcher { ivanaivanovska wrote: Done. https://github.com/llvm/llvm-project/pull/124554 _

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -79,21 +81,39 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +class CustomMatcher { +public: + virtual bool matches(const DynTypedNode &DynNode, ASTContext &Ctx, +

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -79,21 +81,39 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +class CustomMatcher { ivanaivanovska wrote: Done. https://github.com/llvm/llvm-project/pull/124554 _

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -79,21 +81,39 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +class CustomMatcher { +public: + virtual bool matches(const DynTypedNode &DynNode, ASTContext &Ctx, +

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
@@ -31,27 +35,34 @@ #define FIXABLE_GADGET(name) GADGET(name) #endif +/// A subset of the safe gadgets that may return multiple results. +#ifndef FIXABLE_GADGET_MULTY_RES +#define FIXABLE_GADGET_MULTY_RES(name) GADGET(name) +#endif + WARNING_GADGET(Increment) WARNING_GADGET(

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-29 Thread via cfe-commits
https://github.com/ivanaivanovska updated https://github.com/llvm/llvm-project/pull/124554 >From 3cda247a87fc4f084b33edb69e33f6d3797d0d92 Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Mon, 2 Dec 2024 14:17:06 + Subject: [PATCH] Optimize -Wunsafe-buffer-usage. --- clang/lib/Analysis

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -1986,112 +2327,142 @@ class DerefSimplePtrArithFixableGadget : public FixableGadget { } }; -/// Scan the function and return a list of gadgets found with provided kits. -static void findGadgets(const Stmt *S, ASTContext &Ctx, -const UnsafeBufferU

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -79,21 +81,39 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +class CustomMatcher { +public: + virtual bool matches(const DynTypedNode &DynNode, ASTContext &Ctx, +

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -79,21 +81,39 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +class CustomMatcher { ilya-biryukov wrote: NIT: maybe rename to `FastMatcher`? We should definitely add

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov edited https://github.com/llvm/llvm-project/pull/124554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -31,27 +35,34 @@ #define FIXABLE_GADGET(name) GADGET(name) #endif +/// A subset of the safe gadgets that may return multiple results. +#ifndef FIXABLE_GADGET_MULTY_RES +#define FIXABLE_GADGET_MULTY_RES(name) GADGET(name) +#endif + WARNING_GADGET(Increment) WARNING_GADGET(

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -79,21 +81,39 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +class CustomMatcher { +public: + virtual bool matches(const DynTypedNode &DynNode, ASTContext &Ctx, +

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -79,21 +81,39 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +class CustomMatcher { ilya-biryukov wrote: this class must go into an anonymous `namespace {}` to avoid O

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } + + void set_handler(const UnsafeBufferUsag

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; } ilya-biryukov wrote: NIT:

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
@@ -79,21 +81,39 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +class CustomMatcher { +public: + virtual bool matches(const DynTypedNode &DynNode, ASTContext &Ctx, +

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov commented: Thanks a lot for this! I have left quite a few comments, mostly NITs. A few things that really stood out and I think we should fix: - increasing the number of macros and signatures we use seems like a bad trade-off. It's much better to have more param

[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-27 Thread via cfe-commits
https://github.com/ivanaivanovska created https://github.com/llvm/llvm-project/pull/124554 Details of the optimization results will follow. >From 1bfe3f3fcf2385c67057a19baf9ddf3b14aeeb6d Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Mon, 2 Dec 2024 14:17:06 + Subject: [PATCH] Optimi