================ @@ -5918,6 +5918,181 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI)); } +// Diagnosing missing format attributes is implemented in two steps: +// 1. Detect missing format attributes while checking function calls. +// 2. Emit diagnostic in part that processes function body. +// For this purpose it is created vector that stores information about format +// attributes. There are no two format attributes with same arguments in a +// vector. Vector could contains attributes that only store information about +// format type (format string and first to check argument are set to -1). +namespace { +std::vector<FormatAttr *> MissingAttributes; +} // end anonymous namespace + +// This function is called only if function call is not inside template body. +// TODO: Add call for function calls inside template body. +// Detects and stores missing format attributes in a vector. +void Sema::DetectMissingFormatAttributes(const FunctionDecl *Callee, + ArrayRef<const Expr *> Args, + SourceLocation Loc) { + assert(Callee); + + // If there is no caller, exit. + const FunctionDecl *Caller = getCurFunctionDecl(); + if (!getCurFunctionDecl()) + return; + + // Check if callee function is a format function. + // If it is, check if caller function misses format attributes. + + if (!Callee->hasAttr<FormatAttr>()) + return; + + // va_list is not intended to be passed to variadic function. + if (Callee->isVariadic()) + return; + + // Check if va_list is passed to callee function. + // If va_list is not passed, return. + bool hasVaList = false; + for (const auto *Param : Callee->parameters()) { + if (Param->getOriginalType().getCanonicalType() == + getASTContext().getBuiltinVaListType().getCanonicalType()) { + hasVaList = true; + break; + } + } + if (!hasVaList) + return; ---------------- aaronpuchert wrote:
The attribute is also about checking the format string. So I don't think we should bail out here either. Just forwarding a parameter as format string should be enough to trigger the warning. Only for the fix-it we have to figure out what happens to the arguments. https://github.com/llvm/llvm-project/pull/105479 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits