Module Name:    src
Committed By:   rillig
Date:           Tue Mar 30 14:25:28 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_bool.c d_c99_init.c d_c99_init.exp
            d_init_array_using_string.c d_init_array_using_string.exp
            d_init_pop_member.c d_init_pop_member.exp
        src/usr.bin/xlint/lint1: cgram.y decl.c externs1.h init.c

Log Message:
lint: rewrite handling of initializations, fixing several bugs

The previous implementation had a wrong model of how initialization
happens in C99, its assertions failed in all kind of edge cases and it
was not possible to fix the remaining bugs one at a time without running
into even more obscure assertion failures.

The debug logging was detailed but did not help to clarify the
situation.  After about 20 failed attempts at fixing the small details I
decided to start all over and rewrite the initialization code from
scratch.  I left the low-level parts of handling designators, the code
that is independent of brace_level and the high-level parts of how the
parser calls into this module.  Everything else is completely new.

The concept of a brace level stays since that is how C99 describes
initialization.  The previous code could not handle multi-level
designations (see d_init_pop_member.c).  There are no more assertion
failures in the initialization code.

Some TODO comments have been left in the tests to keep the line numbers
the same in this commit.  These will be cleaned up in a follow-up
commit.

The new implementation does not handle initialization with "missing"
braces.  This is an edge case that both GCC and Clang warn about, so it
is not widely used.  If necessary, it may be added later.

The new implementation does not use any global variables in the vast
majority of the functions, to make all dependencies and possible
modifications obvious.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/d_c99_bool.c \
    src/tests/usr.bin/xlint/lint1/d_init_pop_member.c
cvs rdiff -u -r1.23 -r1.24 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/d_c99_init.exp
cvs rdiff -u -r1.2 -r1.3 \
    src/tests/usr.bin/xlint/lint1/d_init_array_using_string.c \
    src/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_init_pop_member.exp
cvs rdiff -u -r1.206 -r1.207 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.166 -r1.167 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.178 -r1.179 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Reply via email to