dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.13k stars 373 forks source link

ssa: support registers containing aggregates #619

Open dominikh opened 4 years ago

dominikh commented 4 years ago

Currently, our SSA implementation doesn't lift allocs into registers if they contain aggregate types (structs and arrays). The code states this is because there's currently no way for Const to represent their zero values. Even if it did, however, we'd need additional instructions for field access and modification.

We can look at Go's own SSA, which does support this. However, Go's SSA is not designed for writing bug finding tools. That is, being able to relate source code to instructions is not required. That is something we must keep in mind.

Lifting aggregates into registers by itself only has limited use, but it would help with #507. It may also lead to further improvements, such as implementing scalar replacement of aggregates.

dominikh commented 2 years ago

45e2119d24cb9e92b8fc4fd7b7236890c060f9ad introduces constants for aggregates. However, writing to fields still uses FieldAddr, so most structs still can't be lifted.