1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-11 04:29:53 +00:00

Fixed problem with illegal call giving exception. Closes #689

This commit is contained in:
jespergravgaard 2021-08-02 08:00:08 +02:00
parent dbd8a3cbac
commit 66cfcc4824
3 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.Comment;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.ControlFlowBlock;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.statements.*;
@ -44,7 +45,11 @@ public class Pass1CallStackVarConvert extends Pass2SsaOptimization {
StatementCallPointer call = (StatementCallPointer) statement;
boolean hasParamOrReturn = call.getNumParameters() > 0 || call.getlValue() != null;
//if(hasParamOrReturn) {
SymbolTypeProcedure procedureType = (SymbolTypeProcedure) SymbolTypeInference.inferType(getScope(), call.getProcedure());
final SymbolType procType = SymbolTypeInference.inferType(getScope(), call.getProcedure());
if(!(procType instanceof SymbolTypeProcedure)) {
throw new CompileError("Called object is not a function or function pointer "+call.getProcedure().toString(), call);
}
SymbolTypeProcedure procedureType = (SymbolTypeProcedure) procType;
// Perform stack call
stmtIt.remove();
stmtIt.add(new StatementCallPrepare(procedureType, null, call.getParameters(), Procedure.CallingConvention.STACK_CALL, call.getSource(), hasParamOrReturn?call.getComments():Comment.NO_COMMENTS));

View File

@ -1706,6 +1706,11 @@ public class TestProgramsFast extends TestPrograms {
compileAndCompare("euclid-problem.c");
}
@Test
public void testProblemCallIllegal() throws IOException {
assertError("problem-call-illegal.c", "Called object is not a function or function pointer");
}
@Test
public void testProblemNegativeWordConst() throws IOException {
compileAndCompare("problem-negative-word-const.c");

View File

@ -0,0 +1,5 @@
// An illegal call on an integer results in an exception
void main() {
char a=0();
}