Repository navigation
bugc: make a bytes literal local hold the literal's bytes - #345
Merged
Merged
Conversation
Contributor
|
gnidan
force-pushed
the
bugc-bytes-literal
branch
from
October 6, 2026 14:31
bee9579 to
76b6551
Compare
A `bytes` literal compiles to a constant that already lays the literal out in memory (its length word, then its data) and gives its address. A declaration initialized with one allocated a second copy anyway, wrote the length there, and then wrote the first copy's address as the data. So the local's data read as zeros followed by that address, both in the program (as in `data[0:32]`) and through its debug pointer. Let the local refer to the constant, as a string literal local does.
gnidan
force-pushed
the
bugc-bytes-literal
branch
from
October 6, 2026 14:59
76b6551 to
8b5f1e8
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 local initialized with a
bytesliteral, such asdatainexamples/intermediate/memory-slices.bug, never held the literal's bytes. At every optimization level, its data read as zeros followed by a word such as0x154, both in the program (data[0:32]) and through its debug pointer from #328.The pointer was right; the code was wrong. A
bytesliteral compiles to aconstof typeref<memory>, and code generation for it already writes the literal to memory as bugc lays outbytes(a length word, then the data) and gives its address. The declaration treated that address as the data: it allocated a second copy, wrote the length there, then stored the first copy's address after it, and the local referred to the second copy. Now the local refers to the constant's memory, as a string literal local does, and the hex-specific allocation is gone.bytes-literal.test.tschecks a 40-byte literal's length and contents (through slices cast tobytes32) at levels 0 to 3, and the local-variable soundness tests gain abytesliteral whose pointer must read the literal's bytes.