Skip to content

transpile: Conservatively disallow mutable lvalues inside macros - #1989

Open
Rua wants to merge 4 commits into
immunant:masterfrom
Rua:addrof-complit-macro
Open

transpile: Conservatively disallow mutable lvalues inside macros#1989
Rua wants to merge 4 commits into
immunant:masterfrom
Rua:addrof-complit-macro

Conversation

@Rua

@Rua Rua commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Mutable lvalues are values that can either be assigned to, or have a mutable pointer created to them. If they are in a macro, that could pose problems. DeclRefs (including those to mutable variables) are already disallowed in macros, but another "out of nothing" source of mutable lvalues is compound literals. Currently, a macro containing a mutable compound literal is translated as-is, including something like this:

#define MUTATE_ME (&(int){ 42 })

int *p1 = MUTATE_ME;
int *p2 = MUTATE_ME;

Each mutable compound literal expression is supposed to create its own distinct memory location (immutable ones are allowed to be coalesced). So these pointers must be different, and their pointees must be able to be modified independently.

I've been very conservative here and disallowed all mutable lvalues in macros. There are certainly instances that could be re-allowed on a case-by-case basis. Certain instances of lvalues that undergo an LValueToRValue cast for example.

@Rua
Rua force-pushed the addrof-complit-macro branch 3 times, most recently from ec84503 to cba7496 Compare September 2, 2026 11:24
@Rua
Rua marked this pull request as draft September 2, 2026 16:47
@Rua
Rua force-pushed the addrof-complit-macro branch 3 times, most recently from 93cd11c to 7612f6c Compare September 3, 2026 16:47
@Rua Rua changed the title transpile: Abort macro conversion when taking address of compound literal transpile: Conservatively disallow mutable lvalues inside macros Sep 3, 2026
@Rua
Rua force-pushed the addrof-complit-macro branch from 7612f6c to 848ff3e Compare September 3, 2026 17:05
@Rua
Rua marked this pull request as ready for review September 3, 2026 18:21
@Rua
Rua force-pushed the addrof-complit-macro branch 2 times, most recently from 9c364c6 to 79b04c9 Compare September 7, 2026 16:53
@Rua
Rua force-pushed the addrof-complit-macro branch from 79b04c9 to c3bf0bb Compare September 7, 2026 16:55
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.

1 participant