In my project, I have a bunch of functions that take in a Type
tagged union. However, I am now getting a segmentation fault when reading this Type
parameter:
Segmentation fault at address 0x7547ece4700c
/home/sno2/projects/xlang/src/Smith.zig:154:13: 0x1021918 in genExpression__anon_2699 (smith)
switch (target_type) {
^
/home/sno2/projects/xlang/src/Smith.zig:132:36: 0x102185a in genExpression__anon_2699 (smith)
try smith.genExpression(target_type, writer);
^
/home/sno2/projects/xlang/src/Smith.zig:132:36: 0x102185a in genExpression__anon_2699 (smith)
try smith.genExpression(target_type, writer);
^
/home/sno2/projects/xlang/src/Smith.zig:240:36: 0x1021eea in genExpression__anon_2699 (smith)
try smith.genExpression(smith.type_extras.items[pair_i + 1], writer);
^
/home/sno2/projects/xlang/src/Smith.zig:238:36: 0x1021e6d in genExpression__anon_2699 (smith)
try smith.genExpression(smith.type_extras.items[pair_i], writer);
^
/home/sno2/projects/xlang/src/Smith.zig:265:32: 0x1023089 in main (smith)
try smith.genExpression(target_type, source.writer(smith.gpa));
^
/home/sno2/projects/zig/lib/std/start.zig:617:37: 0x10208b1 in posixCallMainAndExit (smith)
const result = root.main() catch |err| {
^
/home/sno2/projects/zig/lib/std/start.zig:248:5: 0x10204ed in _start (smith)
asm volatile (switch (native_arch) {
^
Now, the segfault stack traces that I get always include some instance of calling my functions with an index into smith.type_extras.items
. I believe that PRO is making my Type
parameter a reference, then I am modifying smith.type_extras
, and the PRO-optimized reference is now pointing to freed memory. Is there any way to work around this?