Repository navigation
Conversation
DMD 2.113 can retain stale register values after compound multiplication, causing valid contiguous slice accesses to fail bounds checks when inlined. Rewrite the stride multiplication for DMD 2.113 and later on x86/x64, retaining the original expression for other configurations. Reference the compiler issue and document when to bound the workaround. Add a guarded regression test preserving the scoped ownership and indexing sequence that triggers the failure. AI-Assisted-By: Codex (GPT-6 Astra Medium)
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.
Fixes #499.
Related compiler report: dlang/dmd#24145.
DMD 2.113.x can reuse stale register values after compound multiplication, causing valid contiguous slice accesses to fail bounds checks when inlined.
Rewrite the stride multiplication in contiguous
Slice.indexStridefor DMD 2.113 and later on x86/x64. Other compilers, architectures, and older DMD versions retain the original expression. The workaround preserves inlining, allocation behavior, function attributes, and the public API.The compiler guard has no upper bound yet. Its comment explains that one should be added when a fixed compiler version can be distinguished using
__VERSION__.Add a
mir_ndslice_testregression preserving the scoped ownership and indexing sequence that triggers the failure. The test remains enabled across compilers.Validation
The regression fails before the workaround and passes afterward. The final conditional change passes all 19 modules imported by the ndslice test runner with:
-inline.-O2 -enable-inlining.-inline.-O -inline -release -boundscheck=off.Compiler-guard checks confirm that the workaround is enabled for DMD 2.113.1 and disabled for DMD 2.112.1 and LDC. Both x86 and x64 DMD guard selections were checked; 32-bit runtime testing was not performed.
The original indexing reproducer passes on DMD 2.112.1 with the workaround disabled. Its broader ndslice run encounters a sorting assertion also reproduced on unchanged upstream source.
These are focused ndslice checks, not a full mir-algorithm test-suite run.
AI-Assisted-By: Codex (GPT-6 Astra Medium)