Fix undefined reference to internal for CTFE instance in struct .init#23188
Draft
CyberShadow wants to merge 1 commit into
Draft
Fix undefined reference to internal for CTFE instance in struct .init#23188CyberShadow wants to merge 1 commit into
internal for CTFE instance in struct .init#23188CyberShadow wants to merge 1 commit into
Conversation
Contributor
|
Thanks for your pull request, @CyberShadow! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
… in struct .init with -c
A CTFE-evaluated class or struct instance baked into a struct's `.init` needs a
local backing symbol (named "internal", STB_LOCAL) in every object module that
emits the init image. That symbol was cached on the shared AST node
(`cre.value.origin.sym` / `sle.sym`), so when several modules are compiled in one
invocation (`dmd -c a.d b.d`) the symbol created for the first object module leaked
into the later ones, which then emitted only an undefined reference to a local
symbol they never define:
dmd -c a.d b.d
dmd a.o b.o -of=app # undefined reference to `internal'
Track the literals that cache a backing symbol in the current object module and
clear those caches at each object-module boundary (resetCtfeSymbolCache, called
from obj_start, alongside the existing per-object resets), so every object module
re-creates and emits its own self-contained local copy. This matches the
array-literal path (DtBuilder.dtoff) and the separate-compilation behavior, and
keeps intra-module dedup intact. Also fixes the `-lib` variant (dlang#19439).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
a65ce99 to
a4a20da
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A CTFE-evaluated class or struct instance baked into a struct's
.initneeds a local backing symbol (named "internal", STB_LOCAL) in every object module that emits the init image. That symbol was cached on the shared AST node (cre.value.origin.sym/sle.sym), so when several modules are compiled in one invocation (dmd -c a.d b.d) the symbol created for the first object module leaked into the later ones, which then emitted only an undefined reference to a local symbol they never define:Fix this by tracking the literals that cache a backing symbol in the current object module and clear those caches at each object-module boundary (
resetCtfeSymbolCache, called fromobj_start, alongside the existing per-object resets), so every object module re-creates and emits its own self-contained local copy. This matches the array-literal path (DtBuilder.dtoff) and the separate-compilation behavior, and keeps intra-module dedup intact.Fixes issue #20439
Fixes issue #19439