PlutoLang / Pluto

A superset of Lua 5.4 with a focus on general-purpose programming.
https://pluto-lang.org/docs/Introduction
MIT License
338 stars 20 forks source link

Assertion failure #805

Closed XmiliaH closed 2 months ago

XmiliaH commented 2 months ago

When commenting out the lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc)); check in lcode.cpp the following assertiong will trigger when running tests/_driver.pluto.

pluto: lauxlib.cpp:570: char* prepbuffsize(luaL_Buffer*, size_t, int): Assertion `((B)->b != (B)->init.b) ? lua_touserdata(B->L, boxidx) != __null : lua_touserdata(B->L, boxidx) == (void*)B' failed.

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt f
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
        set = {__val = {0, 140737352414928, 4222451712, 93824994225344, 93824994225445, 93824994225344, 93824994225344, 93824994225543, 93824994225644, 93824994225344, 
            93824994225644, 0, 0, 0, 0, 0}}
        pid = <optimized out>
        tid = <optimized out>
        ret = <optimized out>
#1  0x00007ffff7de3859 in __GI_abort () at abort.c:79
        save_stage = 1
        act = {__sigaction_handler = {sa_handler = 0x55555573acc0, sa_sigaction = 0x55555573acc0}, sa_mask = {__val = {199, 4, 4294939985, 0, 0, 140737353569304, 0, 21474836480, 
              140737488327776, 140737488346688, 140737353601040, 0, 536273584821441536, 140737353569304, 140737354117120, 140737353586056}}, sa_flags = 1432908299, 
          sa_restorer = 0x23a}
        sigs = {__val = {32, 0 <repeats 15 times>}}
#2  0x00007ffff7de3729 in __assert_fail_base (fmt=0x7ffff7f79588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=0x5555556936b8 "((B)->b != (B)->init.b) ? lua_touserdata(B->L, boxidx) != __null : lua_touserdata(B->L, boxidx) == (void*)B", file=0x55555568720b "lauxlib.cpp", 
    line=570, function=<optimized out>) at assert.c:92
        str = 0x55555573acc0 "\200\270rUUU"
        total = 4096
#3  0x00007ffff7df4fd6 in __GI___assert_fail (assertion=0x5555556936b8 "((B)->b != (B)->init.b) ? lua_touserdata(B->L, boxidx) != __null : lua_touserdata(B->L, boxidx) == (void*)B", 
    file=0x55555568720b "lauxlib.cpp", line=570, function=0x555555693688 "char* prepbuffsize(luaL_Buffer*, size_t, int)") at assert.c:101
No locals.
#4  0x00005555555ea337 in prepbuffsize (B=0x7fffffffb740, sz=191, boxidx=-1) at lauxlib.cpp:570
        __PRETTY_FUNCTION__ = <optimized out>
#5  0x00005555555ea4c7 in luaL_addlstring (B=0x7fffffffb740, 
    s=0x5555557561d0 "[string \"local a; local a\"]:1: warning: duplicate local declaration [var-shadow]\n    1 | local a; local a\n      | ", '^' <repeats 16 times>, " here: this shadows the initial declaration of 'a' on line 1.", l=191) at lauxlib.cpp:604
        b = 0xd8 <error: Cannot access memory at address 0xd8>
#6  0x00005555555ea536 in luaL_addstring (B=0x7fffffffb740, 
    s=0x5555557561d0 "[string \"local a; local a\"]:1: warning: duplicate local declaration [var-shadow]\n    1 | local a; local a\n      | ", '^' <repeats 16 times>, " here: this shadows the initial declaration of 'a' on line 1.") at lauxlib.cpp:612
No locals.
#7  0x00005555555ebfb2 in <lambda(void*, char const*, int)>::operator()(void *, const char *, int) const (__closure=0x0, ud=0x7fffffffb740, 
    message=0x5555557561d0 "[string \"local a; local a\"]:1: warning: duplicate local declaration [var-shadow]\n    1 | local a; local a\n      | ", '^' <repeats 16 times>, " here: this shadows the initial declaration of 'a' on line 1.", tocont=0) at lbaselib.cpp:80
        B = 0x7fffffffb740
#8  0x00005555555ec03f in <lambda(void*, char const*, int)>::_FUN(void *, const char *, int) () at lbaselib.cpp:84
No locals.
#9  0x00005555555c9674 in luaE_warning (L=0x5555557244b8, 
    msg=0x5555557561d0 "[string \"local a; local a\"]:1: warning: duplicate local declaration [var-shadow]\n    1 | local a; local a\n      | ", '^' <repeats 16 times>, " here: this shadows the initial declaration of 'a' on line 1.", tocont=0) at lstate.cpp:468
        wf = 0x5555555ec010 <<lambda(void*, char const*, int)>::_FUN(void *, const char *, int)>
#10 0x0000555555577a6d in lua_warning (L=0x5555557244b8, 
    msg=0x5555557561d0 "[string \"local a; local a\"]:1: warning: duplicate local declaration [var-shadow]\n    1 | local a; local a\n      | ", '^' <repeats 16 times>, " here: this shadows the initial declaration of 'a' on line 1.", tocont=0) at lapi.cpp:1455
No locals.
#11 0x00005555555980af in throw_warn (ls=0x7fffffffa2a0, err=0x55555568621e "duplicate local declaration", 
    here=0x555555759e48 "this shadows the initial declaration of 'a' on line 1.", line=1, warningType=WT_VAR_SHADOW) at lparser.cpp:145
        msg = 0x5555557b47c0
#12 0x000055555559a217 in checkforshadowing (ls=0x7fffffffa2a0, fs=0x7fffffffa0e0, name=0x555555730e40, line=1, check_globals=false, check_locals=true) at lparser.cpp:617
        desc = 0x55555572a9c0
        local = 0x55555575aeb0
        var = {k = VLOCAL, u = {ival = 93823560605184, nval = 4.6354998065525569e-310, strval = 0x555500005e00, info = 24064, {reg = 24064, pc = 21845}, ind = {idx = 24064, 
              t = 0 '\000'}, var = {ridx = 0 '\000', vidx = 0}}, t = -1, f = -1, code_primitive = -64}
        n = "a"
        current_fs = 0x7fffffffa0e0
#13 0x000055555559a4ca in new_localvar (ls=0x7fffffffa2a0, name=0x555555730e40, line=1, hint=..., check_globals=false) at lparser.cpp:657
        L = 0x5555557244b8
        fs = 0x7fffffffa0e0
        dyd = 0x7fffffffa6b0
        var = 0x77139fbedb51400
#14 0x00005555555ab2ce in localstat (ls=0x7fffffffa2a0) at lparser.cpp:4512
Sainan commented 2 months ago

Unable to reproduce with Pluto@main on Windows and Ubuntu.

XmiliaH commented 2 months ago

The following script already asserts for me wcall(||->warn("xx")).

I have the following changes to the Makefile (removed -O3 and added -g, -DLUAI_ASSERT, and -lpthread):

--- a/src/Makefile
+++ b/src/Makefile
@@ -6,10 +6,10 @@
 # Your platform. See PLATS for possible values.
 PLAT=

-CXX= g++ -std=c++17 -O3 -flto -fvisibility=hidden -fPIC
-CXXFLAGS= -Wno-multichar $(SYSCFLAGS) $(MYCFLAGS)
+CXX= g++ -std=c++17 -flto -fvisibility=hidden -fPIC -g
+CXXFLAGS= -Wno-multichar $(SYSCFLAGS) $(MYCFLAGS) -DLUAI_ASSERT
 LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
-LIBS= -lm $(SYSLIBS) $(MYLIBS)
+LIBS= -lm -lpthread $(SYSLIBS) $(MYLIBS)

 # Specifying DEBUG=0 (or any value) will remove any optimizations.
 ifdef DEBUG

and gcc version gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)

Sainan commented 2 months ago

I must've messed up my compiler flags at first, because I can indeed repro it on Ubuntu, still not on Windows, tho. What an odd one. I'll try to find out the cause.