Skip to content

transpile: Properly handle address-of static compound literals#1644

Open
Rua wants to merge 5 commits intoimmunant:masterfrom
Rua:static-compound-literal
Open

transpile: Properly handle address-of static compound literals#1644
Rua wants to merge 5 commits intoimmunant:masterfrom
Rua:static-compound-literal

Conversation

@Rua
Copy link
Contributor

@Rua Rua commented Mar 6, 2026

This allows limited use of statements in translations of statics, only if the statements are Stmt::Item. This is then used to solve the original bug, by declaring a fresh static variable to take the address of.

This code doesn't currently account for situations in which the compound literal expression needs to be sectioned off for late initialisation, as that would have complicated the code a fair bit further.

@Rua Rua force-pushed the static-compound-literal branch from dcbe0fa to 8a200eb Compare March 6, 2026 17:49
@Rua Rua marked this pull request as ready for review March 6, 2026 17:51
@Rua Rua force-pushed the static-compound-literal branch 4 times, most recently from 4a06d79 to b768426 Compare March 6, 2026 18:51
@Rua Rua force-pushed the static-compound-literal branch 4 times, most recently from 3e04701 to e485aae Compare March 17, 2026 10:58
@Rua Rua force-pushed the static-compound-literal branch from e485aae to 2be8ad5 Compare March 23, 2026 18:09
@Rua
Copy link
Contributor Author

Rua commented Mar 23, 2026

I realised that in the current nightly, taking the raw address of a static is unsafe, but it's not unsafe in the final stabilised version of the raw_ref_op feature. So I gated that to only apply to the 2021 edition. I also did the same for DeclRefs of variables, where it seemed to have been missing all this time.

@Rua Rua force-pushed the static-compound-literal branch from 2be8ad5 to 3d6951c Compare March 23, 2026 18:21
@Rua Rua force-pushed the static-compound-literal branch from 3d6951c to dccadf5 Compare March 23, 2026 18:30
@Rua Rua requested a review from kkysen March 23, 2026 19:05
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.

Allow WithStmts in static initialisers to contain statements File-scope compound literal translated incorrectly, causing segfault on write

2 participants