Repository navigation
Conversation
The root cause of #431 was a hardcoded struct size (24 bytes) that didn't account for C alignment padding. CVSplit has two ptr<i32> (8 bytes each) and two i32 (4 bytes each). Naive sum is 24, but the C compiler inserts 4 bytes of padding after n_train to align test_indices, and 4 bytes after n_test to align the next array element. The real sizeof is 32. The generated C code was always correct. The struct copy, pointer field access, and free all work when the allocation is sized properly. Under-allocation caused the heap-buffer-overflow. The test uses the correct size (32) and passes clean under AddressSanitizer. Documents the alignment pitfall in the test header so future users reach for sizeof<T>() or calloc instead of hardcoding. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
compiler/src/lexer.flow: fix TOK_DOTDOT off-by-one. The initial flowc_lexer_bump already consumed the first dot, so only one more bump is needed for the second dot. Two extra bumps skipped the first digit of the number after .. compiler/src/parser.flow: - Use check_kw/check instead of eat_kw/eat for the for-loop range separator. eat_kw sets err=1 on failure, which prevented the TOK_DOTDOT fallback from ever succeeding. - Allow newline-separated struct fields (no comma required). If the next token after a field type is an identifier or }, continue instead of erroring. compiler/src/cgen.flow: lower array<T> (ival == 0, no size) to T* in flowc_cgen_emit_type, matching the Python compiler's pointer lowering for unsized array parameters. compiler/bootstrap/flowc_stage_a.c: regenerated. lib/stdlib/array.flow, option.flow, result.flow now compile to valid C with zero errors. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
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.
Summary
compiler/src/lexer.flow: fixTOK_DOTDOToff-by-one. The initialflowc_lexer_bumpalready consumed the first dot, so only one more bump was needed. Two extra bumps skipped the first digit of the number after...compiler/src/parser.flow: usecheck_kw/checkinstead ofeat_kw/eatfor the for-loop range separator.eat_kwsetserr=1on failure, which prevented theTOK_DOTDOTfallback from ever succeeding. Also allow newline-separated struct fields (no comma required).compiler/src/cgen.flow: lowerarray<T>(no size,ival == 0) toT*inflowc_cgen_emit_type, matching the Python compiler's pointer lowering for unsized array parameters.compiler/bootstrap/flowc_stage_a.c: regenerated.Context
for i in 0..10 { }always failed because the..lexer skipped a character and the for-loop parser set an error flag on theKW_TOcheck before tryingTOK_DOTDOT. Struct fields without commas (common in the stdlib) also failed. Unsizedarray<T>parameters producedunknown type name 'array'in the C output.Test plan
./flow run compiler/src/main.flowpasses (flowc: PASS)lib/stdlib/array.flowcompiles to valid C with zero clang errorslib/stdlib/option.flowcompiles to valid C with zero clang errorslib/stdlib/result.flowcompiles to valid C with zero clang errorsfor i in 0..5 { println(i) }prints 0 1 2 3 4This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.
Generated with Devin