Before this patch the array being decomposed was not present in the CFG, which lead to liveness issues.
Consider this snippet:
int uninit[2]; int init[2] = {0}; uninit[0] = init[0]; <-- init is marked as a dead symbol and gets removed auto [i, j] = init; <-- init is not referenced in the CFG
This patch makes sure, that the required array is referenced in the CFG, so the liveness of the variable is handled properly.
The AST of auto [i, j] = init; and the solution looks like the following:
`-DecompositionDecl |-ArrayInitLoopExpr | |-OpaqueValueExpr <-- ignore this OpaqueValueExpr | | `-DeclRefExpr 'int[2]' <-- put this DeclRefExpr to the CFG | `-ImplicitCastExpr | `-ArraySubscriptExpr | |-ImplicitCastExpr | | `-OpaqueValueExpr | | `-DeclRefExpr | `-ArrayInitIndexExpr ` ...
Comparing the old and the new CFG of DecompositionDecl:
Old CFG | New CFG | 15: init (ImplicitCastExpr, ArrayToPointerDecay, int *) | 15: init 16: * | 16: [B1.15] (ImplicitCastExpr, ArrayToPointerDecay, int *) 17: [B1.15][[B1.16]] | 17: * 18: [B1.17] (ImplicitCastExpr, LValueToRValue, int) | 18: [B1.16][[B1.17]] 19: {[B1.18]} | 19: [B1.18] (ImplicitCastExpr, LValueToRValue, int) 20: auto = {init[*]}; | 20: {[B1.19]} | 21: auto = {init[*]};
I think visiting the children we want explicitly would be cleaner. I.e., instead of using a loop, querying each child using getters like getCommonExpr.