[PATCH] D131438: [clang][dataflow] Analyze constructor bodies

Sam Estep via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 9 13:26:28 PDT 2022


samestep added inline comments.


================
Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:248-258
+  for (unsigned ArgIndex = 0; ArgIndex < NumArgs; ++ParamIt, ++ArgIndex) {
     assert(ParamIt != FuncDecl->param_end());
 
-    const Expr *Arg = *ArgIt;
-    auto *ArgLoc = Env.getStorageLocation(*Arg, SkipPast::Reference);
+    const Expr *Arg;
+    if (const auto *ConstructExpr = dyn_cast<CXXConstructExpr>(Call)) {
+      Arg = ConstructExpr->getArg(ArgIndex);
+    } else if (const auto *NonConstructExpr = dyn_cast<CallExpr>(Call)) {
----------------
xazax.hun wrote:
> I think the more idiomatic solution in Clang is to create an ArrayRef for the arguments from the `ConstructExpr` and the `CallExpr`. The args should be stored in a continuous memory area in both cases so you should be able to create the ArrayRef in constant time and you would no longer need to have these pesky if statements in your loop. 
Ah OK, thanks! How should I do that? I was previously using iterators but it looked like the types were different between `CallExpr` and `CXXConstructExpr`, so I switched away from iterators in this patch; is there an easy way to make the `ArrayRef`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131438/new/

https://reviews.llvm.org/D131438



More information about the cfe-commits mailing list