[clang] [analyzer][NFC] Document and centralize the CallEvent argument/parameter index mapping (PR #221252)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 8 09:52:06 PDT 2026


================
@@ -466,52 +471,77 @@ static SVal castArgToParamTypeIfNeeded(const CallEvent &Call, unsigned ArgIdx,
     return ArgVal;
 
   // Only do this cast if the number arguments at the callsite matches with
-  // the parameters at the runtime definition.
+  // the parameters at the runtime definition. Note that this point is only
+  // reached for C functions without a prototype, so the argument indices
+  // and the declared parameter indices coincide.
   if (Call.getNumArgs() != Definition->getNumParams())
     return UnknownVal();
 
-  const Expr *ArgExpr = Call.getArgExpr(ArgIdx);
-  const ParmVarDecl *Param = Definition->getParamDecl(ArgIdx);
+  const ParmVarDecl *Param = Definition->getParamDecl(DeclParamIdx);
   return SVB.evalCast(ArgVal, Param->getType(), ArgExpr->getType());
 }
 
+/// Binds the value of a single argument to the region of the parameter it
+/// initializes in the callee's stack frame.
+///
+/// \param ParamDecl the declared parameter initialized by this argument.
+/// \param DeclParamIdx index of \p ParamDecl among the callee's declared
+/// parameters. See CallEvent::getDeclaredParameterIndex().
+/// \param ASTArgIdx index of \p ArgExpr in the origin expression's argument
+/// list. See CallEvent::getASTArgumentIndex(). Note that this is not
+/// necessarily equal to \p DeclParamIdx.
+static void addParameterValueToBindings(const StackFrame *CalleeSF,
----------------
NagyDonat wrote:

This function is called only once, and its nine (!) parameters connect it very tightly to its call site. 
I think the code would remain much more readable if you didn't move this into a separate function, because the mapping between the arguments and the parameters is difficult to keep in mind and I'd need to back and forth between the implementation and the call site.

https://github.com/llvm/llvm-project/pull/221252


More information about the cfe-commits mailing list