Fixed code that caused a seg-fault after parsing a (deferred) post-count argument followed by a (nested) function-call argument.

The old broken code defers the count until the end of the (parent function's) argument list.  But, a nested function call clears the pointer to the deferred type.  That leads to an access violation.
The new code defers only until the end of each argument.  Fixes #1320.
This commit is contained in:
Greg King
2020-11-20 17:29:26 -05:00
parent 79bdc2d51f
commit 8b42f570e9
3 changed files with 34 additions and 37 deletions

View File

@@ -100,12 +100,6 @@ $(WORKDIR)/bug1263.$1.$2.prg: bug1263.c | $(WORKDIR)
$(if $(QUIET),echo misc/bug1263.$1.$2.prg)
$(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR)
# should compile, but gives an error (segfault)
$(WORKDIR)/bug1320.$1.$2.prg: bug1320.c | $(WORKDIR)
@echo "FIXME: " $$@ "currently does not compile."
$(if $(QUIET),echo misc/bug1320.$1.$2.prg)
$(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR)
# this one requires --std=c89, it fails with --std=c99
# it fails currently at runtime
$(WORKDIR)/bug1265.$1.$2.prg: bug1265.c | $(WORKDIR)
@@ -114,7 +108,7 @@ $(WORKDIR)/bug1265.$1.$2.prg: bug1265.c | $(WORKDIR)
$(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR)
$(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR)
$(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR)
# should compile, but then hangs in an endless loop
$(WORKDIR)/endless.$1.$2.prg: endless.c | $(WORKDIR)
$(if $(QUIET),echo misc/endless.$1.$2.prg)
@@ -130,7 +124,7 @@ $(WORKDIR)/bug1348.$1.$2.prg: bug1348.c | $(WORKDIR)
$(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR)
$(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR)
$(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR)
# these need reference data that can't be generated by a host-compiled program,
# in a useful way
$(WORKDIR)/limits.$1.$2.prg: limits.c $(ISEQUAL) | $(WORKDIR)

View File

@@ -1,5 +1,5 @@
/*
Copyright 2020 The cc65 Authors
Copyright 2020, The cc65 Authors
This software is provided "as-is", without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -21,18 +21,23 @@
/*
Test of a post-counted pointer argument,
followed by a (nested) function-call argument.
Test that compiling it doesn't cause a seg-fault.
https://github.com/cc65/cc65/issues/1320
After the bug is fixed, this file should be moved to "test/val/".
*/
static char *var;
void foo (char *, char);
char bar (void);
static void foo (char *, char)
{
}
void main (void)
static char bar (void)
{
return 'b';
}
int main (void)
{
foo (var++, bar ());
return 0;