Skip to content

Dynamic local struct allocation#507

Open
s0mark wants to merge 1 commit into
ftsrg:masterfrom
s0mark:474-local-struct
Open

Dynamic local struct allocation#507
s0mark wants to merge 1 commit into
ftsrg:masterfrom
s0mark:474-local-struct

Conversation

@s0mark

@s0mark s0mark commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Makes local variable struct address allocation happen dynamically during verification, as opposed to statically in the frontend phase. Fixes #474.

The key challenge to overcome here is to figure out whether or not a local variable is a compound type when a procedure is called. From my understanding, this information is only tracked in the frontend and cannot be retrieved from a VarDecl or its .ref expression without some parseContext.

This solution adds optional initializers to all local variables of an XcfaProcedure, which can be called to generate an initializing expression. When a procedure call is encountered, the generated expression is assigned to the new instance of the local variable, at the same time when parameters are assigned. The initializers are added in the frontend phase and are only used for this purpose at this point.

Another approach I considered was to collect such local variables in a procedure pass and store them in a some heap class, along with their CComplexType (for the address type). Upon a procedure call, this collection could be queried to retrieve the initializing memory address for a local variable, if required. I decided on the former solution, as it seemed more cohesive.

If there's a preferred, perhaps less intrusive way of retrieving the necessary information, please let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recursion and structs cause unsound results

1 participant