[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

Domján Dániel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 9 01:25:10 PST 2022


isuckatcs added a comment.

Those `BindingDecl`s never appear in the CFG unless one of the is used.

Take a look at the other cases.

1.) Arrays

  void foo() {
      int arr[2];
  
      auto [i0, i1] = arr;
  }

  [B1]
     1: int arr[2];
     2: arr
     3: [B1.2] (ImplicitCastExpr, ArrayToPointerDecay, int *)
     4: *
     5: [B1.3][[B1.4]]
     6: [B1.5] (ImplicitCastExpr, LValueToRValue, int)
     7: {[B1.6]}
     8: auto = {arr[*]};
     Preds (1): B2
     Succs (1): B0

2.)  Structs

  struct S {
      int x;
      int y;
  };
  
  void foo() {
      S s;
  
      auto [i0, i1] = s;
  }

  [B1]
     1:  (CXXConstructExpr, [B1.2], S)
     2: S s;
     3: s
     4: [B1.3] (ImplicitCastExpr, NoOp, const struct S)
     5: [B1.4] (CXXConstructExpr, [B1.6], S)
     6: auto = s;
     Preds (1): B2
     Succs (1): B0

`i0` and `i1` are not in the CFG. They only get added, when one of them is actually used.

  int x = i0;

   9: i0
  10: [B1.9] (ImplicitCastExpr, LValueToRValue, int)
  11: int x = i0;

That means. when you see the `DeclRefExpr` you mentioned, the synthesized variable has already been created and the `BindingDecl` can see it.

  -DeclRefExpr <col:9> 'std::tuple_element<0, std::tuple<int, int>>::type':'int' lvalue Binding 0x559942acf350 'i0' 'std::tuple_element<0, std::tuple<int, int>>::type':'int'

By the time you see this node, the variable has already been created and you can access it using `BindingDecl::getHoldingVar()`. You want to analyze these 
`BindingDecl`s when they are used not when you encounter the `DecompositionDecl`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544



More information about the cfe-commits mailing list