fix: resolve segfault in typechecker_collect_decls when processing extern declarations (fixes #2)#34
Open
onurege3467 wants to merge 1 commit into
Conversation
…tern declarations (fixes Raulgooo#2) The typechecker_collect_decls function received a declarations list from its callers (program->as.program.declarations or block->as.block.statements) but incorrectly accessed node->as.program.declarations to get the first element. When extern declarations were present (including in src/std/prelude.runes), the misaligned pointer dereference caused a segfault (SIGSEGV). Fix: change all 3 occurrences of node->as.program.declarations to node (the parameter is already the declarations list). Adds regression test 99_extern_decl_regression.runes that exercises extern declaration typechecking.
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
Fixes the segfault (SIGSEGV) in
typechecker_collect_declsthat blocked all typechecker tests. The function received a declarations list from callers but incorrectly accessednode->as.program.declarations, causing a misaligned pointer dereference (address 0x1) whenexterndeclarations were present.Root Cause
typechecker_collect_declsis called from two sites:typechecker_check: passesprogram->as.program.declarations(declarations list)typechecker_check_nodeforAST_BLOCK: passesnode->as.block.statements(statements list)In both cases, the parameter
nodeis already the list head. But the function didnode->as.program.declarationsto initialize the loop variable, treating the list as aAST_PROGRAMnode. Whenexterndeclarations are present (e.g.,src/std/prelude.runes), this reads garbage memory and dereferences address 0x1.Fix
Changed all 3 occurrences of
node->as.program.declarationstonodeinsidetypechecker_collect_decls:AstNode *decl = nodedecl = nodedecl = nodeRegression Test
Added
src/tests/samples/99_extern_decl_regression.runesthat exercises extern declaration typechecking with both an extern function and extern variable.Verification
Before fix:
./runes src/std/prelude.runessegfaults (SIGSEGV, exit 139)After fix: compiles successfully, all test suite samples pass
Closes #2