Closed svhawkins closed 3 weeks ago
04.28.2024::13:50: Why the segfaults are occuring is definitely stack related.
Going through GDB at decl_resolve
in test function test_decl_codegen_array_matrix()
it fails to find strdup file, when it's defintiely there since all of the previous tests pass. Then it just jumps to expr_destroy()
:
decl_resolve (st=0x55555557da70, d=0x55555557db80) at src/decl.c:235
235 is_const_expr = ((d->value && kind == SYMBOL_GLOBAL) || d->type->size);
(gdb) p kind
$7 = SYMBOL_GLOBAL
(gdb) x d->value
0x55555557e560: 0x00000017
(gdb) p d->value
$8 = (struct expr *) 0x55555557e560
(gdb) s
237 d->symbol = symbol_create(kind, type_copy(d->type), strdup(d->name));
(gdb) p is_const_expr
$9 = true
(gdb) s
__GI___strdup (s=0x5555555819d0 "foo") at strdup.c:40
40 strdup.c: No such file or directory.
(gdb) s
41 in strdup.c
(gdb) s
42 in strdup.c
(gdb) s
Program received signal SIGSEGV, Segmentation fault.
expr_destroy (e=0x59) at src/expr.c:351
351 if (!(*e)) { return; }
(gdb)
FOR NOW, limit the coode generation to single dimensional arrays. This to be a later issue with later refactoring to fix basically everything after abstract syntax tree generation:
strdup
.2024.06.16:19:09: Memory errors due to buggy <struct>_copy()
functions and uninitialized values with printf
s here and there. Unrelated segfaults in expr_codegen
(logic errors) were also fixed. decl_array_codegen
, and decl_codegen
are able to run without issues from valgrind.
Fixed memory leak in grammar.bison
. There is still a leak, but the cause is from the generated scanner, not from me.
All but one of the text executables (test_expr_codegen
) are able to run without any error. Some tests still fail, but that's better than having memory issues.
Expressions, declarations, and whatnot are segfaulting with the involvement of arrays. #16 described a few instances, but there are now others:
test_expr_codegen_subscript_global()
and local counterpart (commented out/uncalled)symbol_copy()
when it has successfully been used beforeexpr_codegen
for local arrays when testing the subscript expressionHave fun with valgrind and gdb.