[clang] [compiler-rt] [Clang][Sema] Add -Wstringop-overread warning for source buffer overreads (PR #183004)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 31 08:34:51 PDT 2026


================
@@ -1236,12 +1222,98 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
     const Expr *ObjArg = TheCall->getArg(NewIndex);
 
     if (std::optional<uint64_t> Result =
-            ObjArg->tryEvaluateStrLen(getASTContext())) {
+            ObjArg->tryEvaluateStrLen(S.getASTContext())) {
       // Add 1 for null byte.
       return llvm::APSInt::getUnsigned(*Result + 1).extOrTrunc(SizeTypeWidth);
     }
     return std::nullopt;
-  };
+  }
+
+  const DiagnoseAsBuiltinAttr *getDABAttr() const { return DABAttr; }
+  unsigned getSizeTypeWidth() const { return SizeTypeWidth; }
+
+  /// Return function name after stripping __builtin_ and _chk affixes.
+  std::string GetFunctionName(unsigned BuiltinID, bool IsChkVariant) const {
----------------
erichkeane wrote:

```suggestion
  std::string getFunctionName(unsigned BuiltinID, bool IsChkVariant) const {
```

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


More information about the cfe-commits mailing list