Skip to content

Take the comptime allocation before subtracting the memory base - #2526

Merged
bfiete merged 1 commit into
beefytech:masterfrom
jayrulez:fix/ce-alloc-address-evaluation-order
Sep 21, 2026
Merged

bfiete merged 1 commit into
beefytech:masterfrom
jayrulez:fix/ce-alloc-address-evaluation-order

Conversation

@jayrulez

Copy link
Copy Markdown
Contributor

CreateAttribute and the params span path computed a CE address as 'CeMalloc(...) - mMemory.mVals' in one expression. The allocation can grow mMemory, which moves mVals, and the operands of '-' are unsequenced: GCC and Clang evaluate the call first, MSVC reads the base first, so on Windows an attribute whose allocation was the one to grow the buffer got the new pointer minus the old base. Its constructor then failed the interpreter's bounds check as an access violation, and the type apply that followed wrote through the same address.

Only the allocation that crosses the buffer's capacity is affected. Two statements now, at both sites.

The test runs a comptime job large enough that the context's memory is not carried over, then constructs an attribute in the context that follows, whose allocation is then the one that grows the buffer.

CreateAttribute and the params span path computed a CE address as
'CeMalloc(...) - mMemory.mVals' in one expression. The allocation can
grow mMemory, which moves mVals, and the operands of '-' are
unsequenced: GCC and Clang evaluate the call first, MSVC reads the
base first, so on Windows an attribute whose allocation was the one to
grow the buffer got the new pointer minus the old base. Its constructor
then failed the interpreter's bounds check as an access violation, and
the type apply that followed wrote through the same address.

Only the allocation that crosses the buffer's capacity is affected,
which is why it surfaced on one type in one project and moved with any
change to allocation sizes. Two statements now, at both sites.

The test runs a comptime job large enough that the context's memory is
not carried over, then constructs an attribute in the context that
follows, whose allocation is then the one that grows the buffer.
@bfiete

bfiete commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Yah, I forget those C++ sequencing rules sometimes, or rather "lack of rules".

@bfiete
bfiete merged commit 683284b into beefytech:master Sep 21, 2026
6 checks passed
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.

2 participants