From e1d7ba775c41d5701d6e754b9f8bddfff55d1139 Mon Sep 17 00:00:00 2001 From: roybaer Date: Sat, 1 Feb 2025 09:29:38 +0000 Subject: [PATCH] Fix bug #3822. git-svn-id: https://svn.code.sf.net/p/sdcc/code/trunk@15257 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- sdcc/ChangeLog | 6 ++++++ sdcc/src/SDCC.y | 14 ++++++++------ sdcc/support/regression/tests/bug-3822.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 sdcc/support/regression/tests/bug-3822.c diff --git a/sdcc/ChangeLog b/sdcc/ChangeLog index 7040e03dc..36f55936e 100644 --- a/sdcc/ChangeLog +++ b/sdcc/ChangeLog @@ -1,3 +1,9 @@ +2025-02-01 Benedikt Freisen + + * src/SDCC.y, + support/regression/tests/bug-3822.c: + Fix bug #3822. + 2025-01-31 Philipp Klaus Krause * doc/sdccman.lyx: diff --git a/sdcc/src/SDCC.y b/sdcc/src/SDCC.y index 403da68f0..a9e0d920a 100644 --- a/sdcc/src/SDCC.y +++ b/sdcc/src/SDCC.y @@ -1436,9 +1436,10 @@ function_declarator currBlockno = STACK_POP(blockNum); seqPointNo++; /* not a true sequence point, but helps resolve scope */ - // if this was a pointer (to a function) - if (!IS_FUNC($1->type)) - cleanUpLevel(SymbolTab, NestLevel + LEVEL_UNIT); + // NOTE: Removed to fix bug 3822. It is unclear whether this was leftover code or still served a purpose. + // // if this was a pointer (to a function) + // if (!IS_FUNC($1->type)) + // cleanUpLevel(SymbolTab, NestLevel + LEVEL_UNIT); $$ = $1; } @@ -1494,9 +1495,10 @@ function_declarator currBlockno = STACK_POP(blockNum); seqPointNo++; /* not a true sequence point, but helps resolve scope */ - // if this was a pointer (to a function) - if (!IS_FUNC($1->type)) - cleanUpLevel(SymbolTab, NestLevel + LEVEL_UNIT); + // NOTE: Removed to fix bug 3822. It is unclear whether this was leftover code or still served a purpose. + // // if this was a pointer (to a function) + // if (!IS_FUNC($1->type)) + // cleanUpLevel(SymbolTab, NestLevel + LEVEL_UNIT); $$ = $1; } diff --git a/sdcc/support/regression/tests/bug-3822.c b/sdcc/support/regression/tests/bug-3822.c new file mode 100644 index 000000000..505e216ed --- /dev/null +++ b/sdcc/support/regression/tests/bug-3822.c @@ -0,0 +1,32 @@ +/** bug-3822.c: Function pointer declaration following a block erased variable declaration within. + */ + +#include + +void f1(void) { + + for (;;) { + char c; // this declaration got erased + c; // this became an unknown identifier + } + + void (*fun)(int i); + fun; + + int i; // make sure that function parameters do not leak into this scope + i; +} + +void f2(void) { + + if (1) { // also affected "if" since the implementation of if-declarations + char c; // this declaration got erased + c; // this became an unknown identifier + } + + void (*fun)(int i); + fun; + + int i; // make sure that function parameters do not leak into this scope + i; +} -- 2.11.4.GIT