Repository navigation
Boolean array literals read back their own elements - #537
Merged
Merged
Conversation
The constant data of an array literal was an LLVM vector. A vector of i1 is packed into bits, but elements are read one byte apart, so in `const FLAGS = [false, true, false, true]` `FLAGS[1]` was false, `if (FLAGS[i])` was never taken and a count of the true elements came out as 10. Elements narrower than a byte now get an array, a byte per element; wider ones keep the vector. Reported in docs/bugs/native-ts-graphics-findings.md (issue 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 11, 2026
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.
Problem
The elements of a boolean array literal read back wrong:
Reported in
docs/bugs/native-ts-graphics-findings.md, issue 2 (docs/bugs/ntg_boolean_array_elements.ts).Cause
getOrCreateGlobalArray(LLVMCodeHelper.h) emits the constant data of an integer or float array literal as an LLVM vector constant:<4 x i1> <i1 false, i1 true, ...>. A vector ofi1is packed into bits in memory, but the array that the data is copied into is read withgetelementptr i1/load i1, one byte per element. So element 1 read the second byte of a 1-byte bit field, which is whatever follows it.const c: boolean[] = [...]took another path and was fine.Fix
When the element type is narrower than a byte, the data is an LLVM array (
[4 x i1], one byte per element) built from a tensor-shapedDenseElementsAttr. Wider element types keep the vector, so their layout doesn't change.Testing
00bool_const_array.ts(compile + JIT, and inTSLANG_CORPUSso it runs under rc and none too): a global literal, locals, for-of, and 12 elements (more than one byte of bits). The current release fails withassertion failed: FLAGS[1].🤖 Generated with Claude Code