pawn-lang / compiler

Pawn compiler for SA-MP with bug fixes and new features - runs on Windows, Linux, macOS
Other
305 stars 72 forks source link

Assertion `glb_declared==0' failed #156

Closed C-far closed 5 years ago

C-far commented 7 years ago

Hello, with a friend we are working with a BitBucket repository, the machine pulls the last commit and compile, but we have a assertion when the compiler runs.

/home/travis/build/Zeex/pawn/source/compiler/sc4.c:76: writeleader: Assertion `glb_declared==0' failed.

So we went to see why the compiler told us that by looking at the last sources of the sc4.c file, but we did not understand why the variable glb_declared kept the value 0.

Here is the command line and the infos to compile :

'./pawncc -o"'+gmOutFile+'" -i"'+gmIncludesFile+'" "'+gmFile+'" -\(+ -\;+ -d2'

gmFile = "/home/test_server/gamemodes/roleplay.pwn" gmOutFile = "/home/test_server/gamemodes/roleplay.amx" gmIncludesFile = "/home/test_server/include"

Edit : I would point out that an almost virgin GM is perfectly compiled. We use the following includes (+ includes plugins) :

YashasSamaga commented 7 years ago

Can you show which line in your code caused the assertion?

C-far commented 7 years ago

@YashasSamaga The GM has +50 000 lines (it's horrible, but it was not I who made it), excluding includes. The assertion is caused by the variable glb_declared (see the file /compiler/sc4.c line 76).

YashasSamaga commented 7 years ago

The code in your GM which caused it is needed (not all your code). It is really difficult to find out what caused it without having something to start with.

C-far commented 7 years ago

@YashasSamaga Yes I know this a part of code which causes this assertion, but with so much lines, it is difficult for me to detect the line.

Do you have a technic to find easily ?

tmp64 commented 7 years ago

I think I've found a way to reprodeuce the bug or some other bug that causes the error.

#include <fixes>
main()
{
    print("\n----------------------------------");
    print("  Bare Script\n");
    print("----------------------------------\n");
    printf("Compiled on %s at %s\n", __date, __time);
}

The last printf() with the __date and __time constants causes the assertion error. But the error is reproduced only if you have the "fixes" include and only on Linux. The native Linux compiler exits with the error, the Windows version of the compiler under Wine prints out a lot of nonsense warnings, and the server just crashes. Windows compiler under Windows compiles the gamemode just fine.

Hope that helps.

P.S. Compiler cmd line:

LD_LIBRARY_PATH=../bin ../bin/pawncc filename.pwn -\; -\( -d1 -O1 -i=../pawno/include
wine ../pawno/pawncc.exe filename.pwn -\; -\( -d1 -O1
Y-Less commented 7 years ago

What are the nonsense warnings on wine?

tmp64 commented 7 years ago

The warnings are about unused symbols, but the symbols are actually in use.

filename.pwn(0) : warning 203: symbol is never used: "carid"
filename.pwn(0) : warning 203: symbol is never used: "cordx"
filename.pwn(0) : warning 203: symbol is never used: "cordy"
filename.pwn(0) : warning 203: symbol is never used: "cordz"
filename.pwn(28185 -- 0) : warning 203: symbol is never used: "string"
Daniel-Cortez commented 5 years ago

Found a way to trigger the same assertion failure without including fixes.inc:

#include <a_samp>

public OnGameModeInit()<automaton1:STATE1>{}

main()
{
    printf("File: %s", __file);
}

So what happens here is that string constants __file, __date and __time are predefined, so if they're used somewhere, then their data is being put into the assembler file before the automatons (and before everything else, including the halt 0 program exit point), thus causing an assertion failure.

The fix for this should be relatively simple.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity.

Daniel-Cortez commented 5 years ago

@pawn-lang You'll probably want to close this and #399 (fixed in #433).

Y-Less commented 5 years ago

Done. Thanks.