LingDong- / wax

A tiny programming language that transpiles to C, C++, Java, TypeScript, Python, C#, Swift, Lua and WebAssembly 🚀
https://waxc.netlify.app/
MIT License
793 stars 45 forks source link

Segfault while multi transpilation #10

Open mingodad opened 3 years ago

mingodad commented 3 years ago

While trying to generate a multi transpilation we getting segfault see shell script bellow:

#!/bin/sh
#waxfn=examples/traceskeleton
waxfn=examples/vororelax
#valgrind 
./waxc \
    --c $waxfn.c \
    --cpp $waxfn.cpp \
    --cs $waxfn.cs \
    --java $waxfn.java \
    --json $waxfn.json \
    --lua $waxfn.lua \
    --py $waxfn.py \
    --swift $waxfn.swift \
    --ts $waxfn.ts \
    --wat $waxfn.wat \
    $waxfn.wax

Ouptut:

sh test-waxc.sh 
[info] transpiling 'examples/vororelax.wax' to C...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.c
[info] freeing 2332335 bytes (34695 objects).
[info] transpiling 'examples/vororelax.wax' to Java...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.java
[info] freeing 2333528 bytes (34637 objects).
[info] transpiling 'examples/vororelax.wax' to TypeScript...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.ts
[info] freeing 2358929 bytes (34719 objects).
[info] transpiling 'examples/vororelax.wax' to JSON...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.json
[info] freeing 2393164 bytes (36627 objects).
[info] transpiling 'examples/vororelax.wax' to Python...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.py
Segmentation fault (core dumped)

If executing under valgrind we get this output:

sh test-waxc.sh 
==28257== Memcheck, a memory error detector
==28257== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==28257== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==28257== Command: ./waxc --c examples/vororelax.c --cpp examples/vororelax.cpp --cs examples/vororelax.cs --java examples/vororelax.java --json examples/vororelax.json --lua examples/vororelax.lua --py examples/vororelax.py --swift examples/vororelax.swift --ts examples/vororelax.ts --wat examples/vororelax.wat examples/vororelax.wax
==28257== 
[info] transpiling 'examples/vororelax.wax' to C...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.c
[info] freeing 2332335 bytes (34695 objects).
[info] transpiling 'examples/vororelax.wax' to Java...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.java
[info] freeing 2333528 bytes (34637 objects).
[info] transpiling 'examples/vororelax.wax' to TypeScript...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.ts
[info] freeing 2358929 bytes (34719 objects).
[info] transpiling 'examples/vororelax.wax' to JSON...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.json
[info] freeing 2393164 bytes (36627 objects).
[info] transpiling 'examples/vororelax.wax' to Python...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.py
==28257== Conditional jump or move depends on uninitialised value(s)
==28257==    at 0x1174B5: lift_scope (parser.c:3351)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x12DCA2: tree_to_py (to_py.c:648)
==28257==    by 0x14930C: transpile (waxc.c:118)
==28257==    by 0x149B9A: main (waxc.c:234)
==28257== 
==28257== Invalid write of size 1
==28257==    at 0x12DB2D: expr_to_py (to_py.c:628)
==28257==    by 0x12DDCF: tree_to_py (to_py.c:673)
==28257==    by 0x14930C: transpile (waxc.c:118)
==28257==    by 0x149B9A: main (waxc.c:234)
==28257==  Address 0x7ed84ec is 4 bytes before a block of size 32 alloc'd
==28257==    at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28257==    by 0x109E8F: mallocx (common.c:79)
==28257==    by 0x10A029: str_new (common.c:129)
==28257==    by 0x129FD3: expr_to_py (to_py.c:69)
==28257==    by 0x12DDCF: tree_to_py (to_py.c:673)
==28257==    by 0x14930C: transpile (waxc.c:118)
==28257==    by 0x149B9A: main (waxc.c:234)
==28257== 
[info] freeing 2327161 bytes (34685 objects).
[info] transpiling 'examples/vororelax.wax' to C#...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.cs
[info] freeing 2357311 bytes (34733 objects).
[info] transpiling 'examples/vororelax.wax' to C++...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.cpp
[info] freeing 2329169 bytes (34596 objects).
[info] transpiling 'examples/vororelax.wax' to Swift...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.swift
[info] freeing 2358627 bytes (34797 objects).
[info] transpiling 'examples/vororelax.wax' to Lua...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.lua
==28257== Invalid write of size 1
==28257==    at 0x140122: expr_to_lua (to_lua.c:607)
==28257==    by 0x1403B8: tree_to_lua (to_lua.c:655)
==28257==    by 0x149464: transpile (waxc.c:126)
==28257==    by 0x149CB6: main (waxc.c:254)
==28257==  Address 0x75bddfe is 2 bytes before a block of size 32 alloc'd
==28257==    at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28257==    by 0x109E8F: mallocx (common.c:79)
==28257==    by 0x10A029: str_new (common.c:129)
==28257==    by 0x13C280: expr_to_lua (to_lua.c:31)
==28257==    by 0x1403B8: tree_to_lua (to_lua.c:655)
==28257==    by 0x149464: transpile (waxc.c:126)
==28257==    by 0x149CB6: main (waxc.c:254)
==28257== 
[info] freeing 2324454 bytes (34287 objects).
[info] transpiling 'examples/vororelax.wax' to WebAssembly Text...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.wat
==28257== Use of uninitialised value of size 8
==28257==    at 0x1174D5: lift_scope (parser.c:3355)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x1480EF: tree_to_wat (to_wat.c:1042)
==28257==    by 0x1494BB: transpile (waxc.c:128)
==28257==    by 0x149CFD: main (waxc.c:259)
==28257== 
==28257== Use of uninitialised value of size 8
==28257==    at 0x1174E2: lift_scope (parser.c:3355)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x1480EF: tree_to_wat (to_wat.c:1042)
==28257==    by 0x1494BB: transpile (waxc.c:128)
==28257==    by 0x149CFD: main (waxc.c:259)
==28257== 
==28257== Invalid read of size 2
==28257==    at 0x1174D5: lift_scope (parser.c:3355)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==  Address 0x20ba11 is not stack'd, malloc'd or (recently) free'd
==28257== 
==28257== 
==28257== Process terminating with default action of signal 11 (SIGSEGV)
==28257==  Access not within mapped region at address 0x20BA11
==28257==    at 0x1174D5: lift_scope (parser.c:3355)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==  If you believe this happened as a result of a stack
==28257==  overflow in your program's main thread (unlikely but
==28257==  possible), you can try to increase the size of the
==28257==  main thread stack using the --main-stacksize= flag.
==28257==  The main thread stack size used in this run was 8388608.
==28257== 
==28257== HEAP SUMMARY:
==28257==     in use at exit: 6,707,080 bytes in 103,968 blocks
==28257==   total heap usage: 753,269 allocs, 649,301 frees, 42,444,797 bytes allocated
==28257== 
==28257== LEAK SUMMARY:
==28257==    definitely lost: 0 bytes in 0 blocks
==28257==    indirectly lost: 0 bytes in 0 blocks
==28257==      possibly lost: 0 bytes in 0 blocks
==28257==    still reachable: 6,707,080 bytes in 103,968 blocks
==28257==         suppressed: 0 bytes in 0 blocks
==28257== Rerun with --leak-check=full to see details of leaked memory
==28257== 
==28257== For counts of detected and suppressed errors, rerun with: -v
==28257== Use --track-origins=yes to see where uninitialised values come from
==28257== ERROR SUMMARY: 100 errors from 6 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)