[clang] [analyzer][NFC] Compute callee properties once per CallDescriptionMap lookup (PR #245630)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 03:53:20 PST 2026
================
@@ -48,57 +48,75 @@ StringRef CheckerContext::getDeclDescription(const Decl *D) {
bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD,
StringRef Name) {
- unsigned BId = FD->getBuiltinID();
- return isCLibraryFunction(FD, Name, getBuiltinName(FD, BId),
- isPredefinedLibFunction(FD, BId),
- isCLibraryDecl(FD));
+ CLibraryCallee C(FD);
+ return isCLibraryFunction(C, Name);
}
-std::string CheckerContext::getBuiltinName(const FunctionDecl *FD,
- unsigned BId) {
- if (BId == 0)
- return std::string();
- return FD->getASTContext().BuiltinInfo.getName(BId);
+StringRef CheckerContext::CLibraryCallee::getBuiltinName() {
+ if (!BuiltinName)
+ BuiltinName = FD->getASTContext().BuiltinInfo.getName(BId);
+ return *BuiltinName;
}
-bool CheckerContext::isPredefinedLibFunction(const FunctionDecl *FD,
- unsigned BId) {
- return BId != 0 &&
- FD->getASTContext().BuiltinInfo.isPredefinedLibFunction(BId);
+bool CheckerContext::CLibraryCallee::isPredefinedLibFunction() {
+ if (!IsPredefinedLibFunction)
+ IsPredefinedLibFunction =
+ FD->getASTContext().BuiltinInfo.isPredefinedLibFunction(BId);
+ return *IsPredefinedLibFunction;
}
-bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD, StringRef Name,
- StringRef BuiltinName,
- bool IsPredefinedLibFunction,
- bool IsCLibraryDecl) {
+bool CheckerContext::CLibraryCallee::isCLibraryDecl() {
+ if (IsCLibraryDecl)
+ return *IsCLibraryDecl;
+
+ IsCLibraryDecl = false;
+ // If this is a special C++ name without IdentifierInfo, it can't be a
+ // C library function.
+ if (!FD->getIdentifier())
+ return false;
+
+ // C library functions are either declared directly within a TU (the common
+ // case) or they are accessed through the namespace `std` (when they are used
+ // in C++ via headers like <cstdlib>).
+ const DeclContext *DC = FD->getDeclContext()->getRedeclContext();
+ if (!(DC->isTranslationUnit() || DC->isStdNamespace()))
+ return false;
----------------
steakhal wrote:
I know you just moved the code but as I was reading this I was wondering what it does for inline namespaces within `std`.
https://github.com/llvm/llvm-project/pull/245630
More information about the cfe-commits
mailing list