[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 3 07:06:04 PST 2025
================
@@ -68,32 +70,59 @@ 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<Stmt>();
if (St)
SS << " ==> ";
} while (St);
return SS.str();
}
+
} // namespace
#endif /* NDEBUG */
-namespace clang::ast_matchers {
+namespace {
+// Using a custom matcher instead of ASTMatchers to achieve better performance.
+class FastMatcher {
+public:
+ virtual bool matches(const DynTypedNode &DynNode, ASTContext &Ctx,
+ const UnsafeBufferUsageHandler &Handler) = 0;
+ virtual ~FastMatcher() = default;
+};
+
+class MatchResult {
+
+public:
+ template <typename T> const T *getNodeAs(StringRef ID) const {
+ auto It = Nodes.find(std::string(ID));
----------------
ilya-biryukov wrote:
NIT: we should be able to remove the std::string here, it should make the code more readable and save some memory allocations.
https://github.com/llvm/llvm-project/pull/125492
More information about the cfe-commits
mailing list