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:
parent
caae9e2693
commit
62ca6eacf1
|
@ -1264,6 +1264,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
struct Value *MacroResult;
|
struct Value *MacroResult;
|
||||||
|
|
||||||
ParserCopy(&MacroParser, &VariableValue->Val->MacroDef.Body);
|
ParserCopy(&MacroParser, &VariableValue->Val->MacroDef.Body);
|
||||||
|
MacroParser.Mode = Parser->Mode;
|
||||||
if (VariableValue->Val->MacroDef.NumParams != 0)
|
if (VariableValue->Val->MacroDef.NumParams != 0)
|
||||||
ProgramFail(&MacroParser, "macro arguments missing");
|
ProgramFail(&MacroParser, "macro arguments missing");
|
||||||
|
|
||||||
|
@ -1422,6 +1423,7 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack
|
||||||
ProgramFail(Parser, "'%s' is undefined", MacroName);
|
ProgramFail(Parser, "'%s' is undefined", MacroName);
|
||||||
|
|
||||||
ParserCopy(&MacroParser, &MDef->Body);
|
ParserCopy(&MacroParser, &MDef->Body);
|
||||||
|
MacroParser.Mode = Parser->Mode;
|
||||||
VariableStackFrameAdd(Parser, MacroName, 0);
|
VariableStackFrameAdd(Parser, MacroName, 0);
|
||||||
Parser->pc->TopStackFrame->NumParams = ArgCount;
|
Parser->pc->TopStackFrame->NumParams = ArgCount;
|
||||||
Parser->pc->TopStackFrame->ReturnValue = ReturnValue;
|
Parser->pc->TopStackFrame->ReturnValue = ReturnValue;
|
||||||
|
|
12
tests/67_macro_crash.c
Normal file
12
tests/67_macro_crash.c
Normal 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();
|
||||||
|
}
|
1
tests/67_macro_crash.expect
Normal file
1
tests/67_macro_crash.expect
Normal file
|
@ -0,0 +1 @@
|
||||||
|
4: 1
|
|
@ -60,6 +60,7 @@ TESTS= 00_assignment.test \
|
||||||
63_typedef.test \
|
63_typedef.test \
|
||||||
64_double_prefix_op.test \
|
64_double_prefix_op.test \
|
||||||
66_printf_undefined.test \
|
66_printf_undefined.test \
|
||||||
|
67_macro_crash.test \
|
||||||
|
|
||||||
|
|
||||||
include csmith/Makefile
|
include csmith/Makefile
|
||||||
|
|
Loading…
Reference in a new issue