git: 0171f9ccfed8 - stable/14 - unifdef: Handle redefined symbols correctly.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 07 Sep 2023 20:28:55 UTC
The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=0171f9ccfed8400a42a6cc44dc7bb0211a955603 commit 0171f9ccfed8400a42a6cc44dc7bb0211a955603 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2023-09-06 17:11:04 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2023-09-07 20:28:31 +0000 unifdef: Handle redefined symbols correctly. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D41758 (cherry picked from commit aacbe7384221d2eafa326864bbbe2f22a10063ce) Approved by: re (gjb) --- contrib/unifdef/unifdef.c | 6 +++++- usr.bin/unifdef/tests/unifdef_test.sh | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/contrib/unifdef/unifdef.c b/contrib/unifdef/unifdef.c index 82f6acd66038..3dd4ace7b81e 100644 --- a/contrib/unifdef/unifdef.c +++ b/contrib/unifdef/unifdef.c @@ -1550,8 +1550,12 @@ addsym2(bool ignorethis, const char *symname, const char *val) sym->value = val; r = RB_INSERT(MACROMAP, ¯o_tree, sym); assert(r == NULL); + debugsym("addsym", sym); + } else { + sym->ignore = ignorethis; + sym->value = val; + debugsym("updsym", sym); } - debugsym("addsym", sym); } static void diff --git a/usr.bin/unifdef/tests/unifdef_test.sh b/usr.bin/unifdef/tests/unifdef_test.sh index 98adef3adfdc..dfb08c187724 100644 --- a/usr.bin/unifdef/tests/unifdef_test.sh +++ b/usr.bin/unifdef/tests/unifdef_test.sh @@ -17,6 +17,27 @@ EOF atf_check -o file:f unifdef <f } +atf_test_case redefine +redefine_head() { + atf_set descr "redefine the same symbol" +} +redefine_body() { + cat >file <<EOF +#if FOO +a +#else +b +#endif +EOF + atf_check -s exit:1 -o inline:"a\n" unifdef -DFOO <file + atf_check -s exit:1 -o inline:"a\n" unifdef -UFOO -DFOO <file + atf_check -s exit:1 -o inline:"a\n" unifdef -DFOO=0 -DFOO <file + atf_check -s exit:1 -o inline:"b\n" unifdef -UFOO <file + atf_check -s exit:1 -o inline:"b\n" unifdef -DFOO -UFOO <file + atf_check -s exit:1 -o inline:"b\n" unifdef -DFOO -DFOO=0 <file +} + atf_init_test_cases() { atf_add_test_case hash_comment + atf_add_test_case redefine }