[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 29 13:04:14 PDT 2024


================
@@ -443,6 +443,426 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   return false;
 }
 
+AST_MATCHER_P(CallExpr, hasNumArgs, unsigned, Num) {
+  return Node.getNumArgs() == Num;
+}
+
+namespace libc_func_matchers {
+// Under `libc_func_matchers`, define a set of matchers that match unsafe
+// functions in libc and unsafe calls to them.
+
+//  A tiny parser to strip off common prefix and suffix of libc function names
+//  in real code.
+//
+//  Given a function name, `matchName` returns `CoreName` according to the
+//  following grammar:
+//
+//  LibcName     := CoreName | CoreName + "_s"
+//  MatchingName := "__builtin_" + LibcName              |
+//                  "__builtin___" + LibcName + "_chk"   |
+//                  "__asan_" + LibcName
+//
+struct LibcFunNamePrefixSuffixParser {
----------------
haoNoQ wrote:

This struct has no members. Should we turn it into a namespace?

https://github.com/llvm/llvm-project/pull/101583


More information about the cfe-commits mailing list