Fix gawk miscompile

See testcase.  Function pointer use was hosed when the destination
function wasn't also called normally by the program.
This commit is contained in:
Michael Matz
2016-12-18 05:18:19 +01:00
parent cd9514abc4
commit 77d7ea04ac
5 changed files with 56 additions and 27 deletions

View File

@ -8,9 +8,13 @@ int fred(int p)
int (*f)(int) = &fred;
/* To test what this is supposed to test the destination function
(fprint here) must not be called directly anywhere in the test. */
int (*fprintfptr)(FILE *, const char *, ...) = &fprintf;
int main()
{
printf("%d\n", (*f)(24));
fprintfptr(stdout, "%d\n", (*f)(24));
return 0;
}

View File

@ -34,6 +34,10 @@ ARGS =
31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5
46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' $(SRC)/46_grep.c
# And some tests don't test the right thing with -run
NORUN =
42_function_pointer.test : NORUN = true
# Some tests might need different flags
76_dollars_in_identifiers.test : TCCFLAGS += -fdollars-in-identifiers
@ -49,7 +53,12 @@ all test: $(filter-out $(SKIP),$(TESTS))
%.test: %.c %.expect
@echo Test: $*...
# test -run
@$(TCC) -run $< $(ARGS) $(FILTER) >$*.output 2>&1 || true
@if test -z "$(NORUN)"; then \
$(TCC) -run $< $(ARGS) $(FILTER) >$*.output 2>&1 || true; \
else \
$(TCC) $< -o ./$*.exe $(FILTER) 2>&1 && \
./$*.exe $(ARGS) >$*.output 2>&1 || true; \
fi
@diff -Nbu $(SRC)/$*.expect $*.output && rm -f $*.output
# automatically generate .expect files with gcc: