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

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 9 13:29:47 PDT 2022


xazax.hun 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)) {
----------------
samestep wrote:
> 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`?
Here is an example: https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaInit.cpp#L7086


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