Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access violation in cc65 #1320

Closed
mzattera opened this issue Oct 31, 2020 · 9 comments
Closed

Access violation in cc65 #1320

mzattera opened this issue Oct 31, 2020 · 9 comments
Labels

Comments

@mzattera
Copy link

mzattera commented Oct 31, 2020

cl65: Cannot execute 'D:\cc6529\bin\cc65': No error

This error appeared in Windows snapshot I downloaded on Oct. 29th and later, but NOT in the snapshot I downloaded on Oct 19th.

It happens compiling javavm\interpreter.c in the attached sources. It sucessfully compiles other files.

Verions from Oct. 19th compiles the whole solution without issues.

src.zip

@mzattera
Copy link
Author

Line that causes the error:

D:\cc6529\bin\cl65 -c --cpu 6502 -Oi -t none -I .\javavm -I .\platform\c64 -I .\util javavm\interpreter.c

@oliverschmidt oliverschmidt changed the title cl65: Cannot execute 'D:\cc6529\bin\cc65': No error Access violation in cc65 Nov 13, 2020
@oliverschmidt
Copy link
Contributor

oliverschmidt commented Nov 13, 2020

The issue at hand is caused by an access violation in cc65. It can be reproduced by compiling

char *var;

void foo(char, char);
char bar(void);

void main(void)
{
  foo(*var++, bar());
}

without any options.

The access violation happens in https://github.com/cc65/cc65/blob/master/src/cc65/datatype.c#L706 because GetUnderlyingTypeCode() is called with a NULL pointer.

In the VC++ debug build, the callstack looks like this:

cc65.exe!GetUnderlyingTypeCode(const Type * Type) Line 706	C
cc65.exe!SizeOf(const Type * T) Line 747	C
cc65.exe!CheckedSizeOf(const Type * T) Line 834	C
cc65.exe!DoDeferred(unsigned int Flags, ExprDesc * Expr) Line 545	C
cc65.exe!FunctionParamList(FuncDesc * Func, int IsFastcall, ExprDesc * ED) Line 784	C
cc65.exe!FunctionCall(ExprDesc * Expr) Line 882	C
cc65.exe!hie11(ExprDesc * Expr) Line 1762	C
cc65.exe!hie10(ExprDesc * Expr) Line 2329	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_internal(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext, int * UsedGen) Line 2360	C
cc65.exe!hie9(ExprDesc * Expr) Line 2973	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie8(ExprDesc * Expr) Line 3403	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!ShiftExpr(ExprDesc * Expr) Line 76	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_compare(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext) Line 2583	C
cc65.exe!hie6(ExprDesc * Expr) Line 3425	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_compare(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext) Line 2583	C
cc65.exe!hie5(ExprDesc * Expr) Line 3438	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_internal(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext, int * UsedGen) Line 2360	C
cc65.exe!hie4(ExprDesc * Expr) Line 3452	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_internal(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext, int * UsedGen) Line 2360	C
cc65.exe!hie3(ExprDesc * Expr) Line 3466	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_internal(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext, int * UsedGen) Line 2360	C
cc65.exe!hie2(ExprDesc * Expr) Line 3480	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hieAnd(ExprDesc * Expr, unsigned int * TrueLab, int * TrueLabAllocated) Line 3541	C
cc65.exe!hieOr(ExprDesc * Expr) Line 3705	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hieQuest(ExprDesc * Expr) Line 3865	C
cc65.exe!hie1(ExprDesc * Expr) Line 4319	C
cc65.exe!FunctionParamList(FuncDesc * Func, int IsFastcall, ExprDesc * ED) Line 697	C
cc65.exe!FunctionCall(ExprDesc * Expr) Line 882	C
cc65.exe!hie11(ExprDesc * Expr) Line 1762	C
cc65.exe!hie10(ExprDesc * Expr) Line 2329	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_internal(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext, int * UsedGen) Line 2360	C
cc65.exe!hie9(ExprDesc * Expr) Line 2973	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie8(ExprDesc * Expr) Line 3403	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!ShiftExpr(ExprDesc * Expr) Line 76	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_compare(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext) Line 2583	C
cc65.exe!hie6(ExprDesc * Expr) Line 3425	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_compare(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext) Line 2583	C
cc65.exe!hie5(ExprDesc * Expr) Line 3438	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_internal(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext, int * UsedGen) Line 2360	C
cc65.exe!hie4(ExprDesc * Expr) Line 3452	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_internal(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext, int * UsedGen) Line 2360	C
cc65.exe!hie3(ExprDesc * Expr) Line 3466	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hie_internal(const GenDesc * Ops, ExprDesc * Expr, void(*)(ExprDesc *) hienext, int * UsedGen) Line 2360	C
cc65.exe!hie2(ExprDesc * Expr) Line 3480	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hieAnd(ExprDesc * Expr, unsigned int * TrueLab, int * TrueLabAllocated) Line 3541	C
cc65.exe!hieOr(ExprDesc * Expr) Line 3705	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!hieQuest(ExprDesc * Expr) Line 3865	C
cc65.exe!hie1(ExprDesc * Expr) Line 4319	C
cc65.exe!hie0(ExprDesc * Expr) Line 4383	C
cc65.exe!ExprWithCheck(void(*)(ExprDesc *) Func, ExprDesc * Expr) Line 112	C
cc65.exe!Expression0(ExprDesc * Expr) Line 4421	C
cc65.exe!Statement(int * PendingToken) Line 697	C
cc65.exe!NewFunc(SymEntry * Func, FuncDesc * D) Line 650	C
cc65.exe!Parse() Line 322	C
cc65.exe!Compile(const char * FileName) Line 450	C
cc65.exe!main(int argc, char * * argv) Line 1070	C

@jmr
Copy link
Contributor

jmr commented Nov 16, 2020

@acqn Possibly related to your enum or prototype changes?

@oliverschmidt
Copy link
Contributor

oliverschmidt commented Nov 16, 2020

I already stretched my time budget to analyze the issue so far and come up with a minimal reproduction scenario. Therefore I explicitly asks others to pick up from where I left off!

@acqn, @jmr: It's almost certain that one of your recent changes caused this regression - which unfortunately wasn't detected by our exsisting tests. I'd appreciate if you would analyze the issue further based on the info provided above.

@mrdudz: You seem to both have experience and time budget for git-bisect. I'd appreciate if you could help to isolate the actual git change causing the regression. And it would of course be great to have an automated regression test for the issue.

Thanks in advance, Oliver

@jmr
Copy link
Contributor

jmr commented Nov 16, 2020

I will add a test case and bisect it.

jmr added a commit to jmr/cc65 that referenced this issue Nov 16, 2020
@jmr
Copy link
Contributor

jmr commented Nov 16, 2020

@acqn

5c43d1e is the first bad commit

commit 5c43d1e04f48c51c743fb3fa66cb00b58ccc0f33
Author: acqn <acqn163@outlook.com>
Date:   Thu Apr 16 17:19:16 2020 +0800

    Changed codegen for postfix inc/dec operations by deferring them till sequence points.
    This usually allows faster & smaller code.
    Note that deferred operations must still be called at sequence points even if the whole expressions containing them had constant values.

@oliverschmidt
Copy link
Contributor

@jmr: Thanks!

@acqn: Given that I can't see activity on #1322 for two weeks I'm wondering if you're currently actively working on cc65 topics. Please provide feedback if you are able to have a look at the regression at hand.

oliverschmidt pushed a commit that referenced this issue Nov 17, 2020
@mrdudz
Copy link
Contributor

mrdudz commented Nov 19, 2020

shouldnt this testcase go to test/todo ? or at least test/misc ? test/err is for tests that are supposed to not compile...

@oliverschmidt
Copy link
Contributor

You're right. I'd be happy if you would adjust it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants