llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: hanbeom (ParkHanbum) <details> <summary>Changes</summary> Previously, C++ overloads like strcmp(char*, char) caused assertions. Now validates argument types match standard signatures. Fixed: #<!-- -->180422 --- Full diff: https://github.com/llvm/llvm-project/pull/180544.diff 1 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (+16-1) ``````````diff diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp index 144411495f5a1..c3ca128ce5246 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -2801,8 +2801,23 @@ CStringChecker::FnCheck CStringChecker::identifyCall(const CallEvent &Call, } const FnCheck *Callback = Callbacks.lookup(Call); - if (Callback) + if (Callback) { + if (const IdentifierInfo *II = FD->getIdentifier()) { + StringRef Name = II->getName(); + // Logic to confirm if the function has the same type as the known + // standard function. String comparison functions (like strcmp) are + // expected to take pointers as arguments. + // Signature: int strcmp(const char *s1, const char *s2); + // Requirement: Exactly 2 arguments, both must be pointers. + if (Name == "strcmp" || Name == "strcasecmp" || Name == "strcoll") + if (FD->getNumParams() != 2 || + !FD->getParamDecl(0)->getType()->isPointerType() || + !FD->getParamDecl(1)->getType()->isPointerType()) + return nullptr; + } + return *Callback; + } return nullptr; } `````````` </details> https://github.com/llvm/llvm-project/pull/180544 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
