Fixed issue #192 - "Define macro inside a function block will crash picoc".

Macros inside functions now work correctly.


git-svn-id: http://picoc.googlecode.com/svn/trunk@605 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2014-03-01 02:54:09 +00:00
parent caae9e2693
commit 62ca6eacf1
4 changed files with 16 additions and 0 deletions

View file

@ -1264,6 +1264,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
struct Value *MacroResult;
ParserCopy(&MacroParser, &VariableValue->Val->MacroDef.Body);
MacroParser.Mode = Parser->Mode;
if (VariableValue->Val->MacroDef.NumParams != 0)
ProgramFail(&MacroParser, "macro arguments missing");
@ -1422,6 +1423,7 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack
ProgramFail(Parser, "'%s' is undefined", MacroName);
ParserCopy(&MacroParser, &MDef->Body);
MacroParser.Mode = Parser->Mode;
VariableStackFrameAdd(Parser, MacroName, 0);
Parser->pc->TopStackFrame->NumParams = ArgCount;
Parser->pc->TopStackFrame->ReturnValue = ReturnValue;

12
tests/67_macro_crash.c Normal file
View file

@ -0,0 +1,12 @@
#include <stdio.h>
void printArray(void) {
#define SIZE 10
int array[SIZE] = {5, 4, 3, 9, 1, 8, 6, 7, 5, 2};
printf("4: %d\n", array[4]);
}
void main()
{
printArray();
}

View file

@ -0,0 +1 @@
4: 1

View file

@ -60,6 +60,7 @@ TESTS= 00_assignment.test \
63_typedef.test \
64_double_prefix_op.test \
66_printf_undefined.test \
67_macro_crash.test \
include csmith/Makefile