================
@@ -1490,6 +1490,52 @@ void
Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
<< FunctionName << DestinationStr << SourceStr);
}
+void Sema::checkFortifiedLibcArgument(FunctionDecl *FD, CallExpr *TheCall) {
+ if (TheCall->isValueDependent() || TheCall->isTypeDependent() ||
+ isConstantEvaluatedContext())
+ return;
+ if (!FD->isExternC())
+ return;
+ const IdentifierInfo *II = FD->getIdentifier();
+ if (!II)
+ return;
+
+ // umask(mode_t): warn when the constant-evaluated argument has bits set
+ // outside 0777 (those bits are silently discarded by the kernel).
+ // Require a matching system-header declaration to avoid warning on
+ // user-defined lookalikes. Do not match the `mode_t` typedef spelling:
+ // libc headers disagree on whether the prototype uses `mode_t` directly.
+ auto AnyDeclInSystemHeader = [&](const FunctionDecl *F) {
+ SourceManager &SM = getSourceManager();
+ for (const FunctionDecl *R : F->redecls())
+ if (SM.isInSystemHeader(R->getLocation()))
+ return true;
+ return false;
+ };
+ if (II->isStr("umask") && !FD->isVariadic() && TheCall->getNumArgs() == 1 &&
+ FD->getNumParams() == 1 &&
+ FD->getParamDecl(0)->getType()->isIntegerType() &&
+ FD->getReturnType()->isIntegerType() && AnyDeclInSystemHeader(FD)) {
----------------
nuclearcat wrote:
I wasn’t confident about the edge cases here, so I looked into it after your
comment.
You are right that extra checks are redundant. Thanks for pointing this out.
Fixing that.
https://github.com/llvm/llvm-project/pull/198130
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits