[clang] [compiler-rt] [Clang][Sema] Add -Wstringop-overread warning for source buffer overreads (PR #183004)
Erich Keane via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 31 08:34:51 PDT 2026
================
@@ -1141,36 +1141,23 @@ static bool ProcessFormatStringLiteral(const Expr *FormatExpr,
return false;
}
-void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
- CallExpr *TheCall) {
- if (TheCall->isValueDependent() || TheCall->isTypeDependent() ||
- isConstantEvaluatedContext())
- return;
-
- bool UseDABAttr = false;
- const FunctionDecl *UseDecl = FD;
-
- const auto *DABAttr = FD->getAttr<DiagnoseAsBuiltinAttr>();
- if (DABAttr) {
- UseDecl = DABAttr->getFunction();
- assert(UseDecl && "Missing FunctionDecl in DiagnoseAsBuiltin attribute!");
- UseDABAttr = true;
+namespace {
+/// Helper class for buffer overflow/overread checking in fortified functions.
+class FortifiedBufferChecker {
+public:
+ FortifiedBufferChecker(Sema &S, FunctionDecl *FD, CallExpr *TheCall)
+ : S(S), TheCall(TheCall), FD(FD),
+ DABAttr(FD ? FD->getAttr<DiagnoseAsBuiltinAttr>() : nullptr) {
+ const TargetInfo &TI = S.getASTContext().getTargetInfo();
+ SizeTypeWidth = TI.getTypeWidth(TI.getSizeType());
}
- unsigned BuiltinID = UseDecl->getBuiltinID(/*ConsiderWrappers=*/true);
-
- if (!BuiltinID)
- return;
-
- const TargetInfo &TI = getASTContext().getTargetInfo();
- unsigned SizeTypeWidth = TI.getTypeWidth(TI.getSizeType());
-
- auto TranslateIndex = [&](unsigned Index) -> std::optional<unsigned> {
+ std::optional<unsigned> TranslateIndex(unsigned Index) {
// If we refer to a diagnose_as_builtin attribute, we need to change the
// argument index to refer to the arguments of the called function. Unless
// the index is out of bounds, which presumably means it's a variadic
// function.
- if (!UseDABAttr)
+ if (DABAttr == nullptr) // Not using DABAttr.
----------------
erichkeane wrote:
This entire line of change should probably be reverted... it isn't adding anything (the change to ==nullptr, and the addition of the comment).
https://github.com/llvm/llvm-project/pull/183004
More information about the llvm-commits
mailing list