From 62ca6eacf1a93629ed54d9440338c0bcb9f05742 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Sat, 1 Mar 2014 02:54:09 +0000 Subject: [PATCH] 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 --- expression.c | 2 ++ tests/67_macro_crash.c | 12 ++++++++++++ tests/67_macro_crash.expect | 1 + tests/Makefile | 1 + 4 files changed, 16 insertions(+) create mode 100644 tests/67_macro_crash.c create mode 100644 tests/67_macro_crash.expect diff --git a/expression.c b/expression.c index 96105dc..60de722 100644 --- a/expression.c +++ b/expression.c @@ -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; diff --git a/tests/67_macro_crash.c b/tests/67_macro_crash.c new file mode 100644 index 0000000..0195f79 --- /dev/null +++ b/tests/67_macro_crash.c @@ -0,0 +1,12 @@ +#include + +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(); +} diff --git a/tests/67_macro_crash.expect b/tests/67_macro_crash.expect new file mode 100644 index 0000000..aec711b --- /dev/null +++ b/tests/67_macro_crash.expect @@ -0,0 +1 @@ +4: 1 diff --git a/tests/Makefile b/tests/Makefile index 4448bf9..f3a5894 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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