[llvm-branch-commits] [clang] [analyzer][NFC] Index parameter lookups by argument position (PR #221977)
Benedek Kaibas via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Sep 11 06:59:23 PDT 2026
================
@@ -577,14 +577,13 @@ ProgramStateRef CallAndMessageChecker::checkArgInitializedness(
const BugType &BT = isa<ObjCMethodCall>(Call) ? MsgArgBug : CallArgBug;
- const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
+ ArrayRef<ParmVarDecl *> Params = Call.parameters();
for (unsigned i = 0, e = Call.getNumArgs(); i != e; ++i) {
- const ParmVarDecl *ParamDecl = nullptr;
- if (FD && i < FD->getNumParams())
- ParamDecl = FD->getParamDecl(i);
+ // For variadic functions a corresponding parameter decl might not exist.
+ const ParmVarDecl *PVD = i < Params.size() ? Params[i] : nullptr;
----------------
benedekaibas wrote:
There is no mismatch since by mapping the arguments and the parameters I make sure I index the right arguments based on the parameters. This avoids conflict when a function has both an explicit object parameter and ordinary parameters. If I would only stick to the parameters or arguments and index like that, the indexing could be wrong: if an explicit object parameter is present, it would not be counted, and then the following ordinary parameter would be at the wrong index. This is not a problem yet since explicit object parameters are not modeled, but once they are, the matching in this code is needed.
I agree that the naming and the documentation should be added/expanded.
https://github.com/llvm/llvm-project/pull/221977
More information about the llvm-branch-commits
mailing list