llvm / llvm/llvm-project

[SSAF][PointerAnalysis] Extract from C++ binding declarations

Open
#200,711 9 comments 0 reactions 0 assignees View on GitHub
clang:ssaf
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following examples involving `BindingDecl`s cannot be handled by existing pointer analysis:

```c++
void f(int *p int *q) {
{
int *Arr[2] = {p, q};
auto [a, b] = Arr;
}

void g(int *p int *q) {
{
std::pair Pair = {p, q};
auto [a, b] = Pair;
}

void h(int *p int *q) {
{
struct {int *x; int *y;} S;
auto [a, b] = S;
}
```

The AST of the binding declaration is like:
```
-DeclStmt
| `-DecompositionDecl col:8 used 'int *[2]' cinit
| |-ArrayInitLoopExpr 'int *[2]'
| | |-...
| |-BindingDecl col:9 a 'int *'
| | `-ArraySubscriptExpr 'int *' lvalue
| | |-ImplicitCastExpr 'int **'
| | | `-DeclRefExpr 'int *[2]' lvalue Decomposition 0x48167c20 first_binding 'a' 'int *[2]'
| | `-IntegerLiteral 'int' 0
| | ....
```
A `DecompositionDecl`, which is a special kind of `VarDecl`, is introduced to hold the value of the initializer in the spelling.
For each binding `BindingDecl`, it is initialized then by an expression `E` (in this AST `E` is an array subscript) over the `DecompositionDecl` representing the corresponding sub-object.

The direct issue is that a `DecompositionDecl` is not an entity so that neither itself not `E` can be represented as EntityPointerLevels.

Contributor guide

Open the contributing guide

Research direction

Start with the three C++ examples and the shown AST, then trace the pointer-analysis handling of BindingDecl and DecompositionDecl. Determine how the binding initializer expressions and their decomposition sub-objects should be represented; done means the array, pair, and anonymous-struct decomposition cases can be extracted by pointer analysis.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.