[clang] [Clang][Sema] Add fortify warnings for fread, fwrite, and fgets (PR #204337)
Radovan Božić via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 31 07:28:01 PDT 2026
================
@@ -1232,6 +1232,25 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
return std::nullopt;
};
+ auto ComputeExplicitObjectSizeArgumentProduct =
+ [&](unsigned LIndex, unsigned RIndex) -> std::optional<llvm::APSInt> {
+ auto L = ComputeExplicitObjectSizeArgument(LIndex);
+ auto R = ComputeExplicitObjectSizeArgument(RIndex);
+ if (!L || !R)
+ return std::nullopt;
+
+ unsigned W =
+ 2 * std::max({L->getBitWidth(), R->getBitWidth(), SizeTypeWidth});
+
+ llvm::APSInt LE = L->extOrTrunc(W);
+ llvm::APSInt RE = R->extOrTrunc(W);
+
+ LE.setIsUnsigned(true);
+ RE.setIsUnsigned(true);
----------------
bozicrHT wrote:
You're right! It preserves signedness
https://github.com/llvm/llvm-project/pull/204337
More information about the cfe-commits
mailing list