isuckatcs added a comment.

> If CFG can be updated so that the
> synthesized variables occur in the block *before* the DeclStmt containing the
> DecompositionDecl, then we can drop the workaround that is included in this
> patch.

I'm not sure that this is possible.

If you look at the AST of the following example

  std::pair<int, int> p{1, 2};
  
  auto [a, b] = p;

you get

  `-DecompositionDecl 0x55b0ac862428 'std::pair<int, int>':'std::pair<int, 
int>' cinit
    |-CXXConstructExpr 
    | `-ImplicitCastExpr
    |   `-DeclRefExpr  'p' 
    |-BindingDecl a
    | |-VarDecl a
    | | `-CallExpr 
    | |   |-ImplicitCastExpr 
    | |   | `-DeclRefExpr  'get' 
    | |   `-ImplicitCastExpr 
    | |     `-DeclRefExpr Decomposition 0x55b0ac862428 '' 
    | `-DeclRefExpr 'a' 
    ` ...

Basically `get<>()` is getting the element from the copy of the struct, that's 
being created when the `DecompositionDecl` happens.
The CFG reflects this accordingly.

   7: p
   8: [B1.7] (ImplicitCastExpr, NoOp, const pair<int, int>)
   9: [B1.8] (CXXConstructExpr, [B1.10], std::pair<int, int>)
  10: auto = p;
  11: get<0UL>
  12: [B1.11] (ImplicitCastExpr, FunctionToPointerDecay, typename 
tuple_element<0UL, pair<int, int> >::type &&(*)(pair<int, int> &&) noexcept)
  13:
  14: [B1.13] (ImplicitCastExpr, NoOp, std::pair<int, int>)
  15: [B1.12]([B1.14])
  16: std::tuple_element<0, std::pair<int, int>>::type a = get<0UL>();

Here `13` would be the `DecompositionDecl`. The variable declarations must 
appear after the `DecompositionDecl`, 
otherwhise the tuple, from which the variables are initialized cannot be 
accessed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to