The NetBSD Project

CVS log for src/tests/usr.bin/xlint/lint1/d_c99_init.c

[BACK] Up to [cvs.NetBSD.org] / src / tests / usr.bin / xlint / lint1

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.47 / (download) - annotate - [select for diffs], Sun Jan 28 08:17:27 2024 UTC (5 weeks, 1 day ago) by rillig
Branch: MAIN
CVS Tags: HEAD
Changes since 1.46: +5 -5 lines
Diff to previous 1.46 (colored)

tests/lint: sort multiple diagnostics per line chronologically

For now, the chronologic order is not enforced but has to be established
manually, for example by removing all 'expect' comment lines and
regenerating them with 'accept.sh -u'.

While here, clean up a few instances that came up when regenerating the
'expect' comments, such as wrong indentation or needless deviation from
the 'expect+1' form.

Revision 1.46 / (download) - annotate - [select for diffs], Sun Jul 9 11:01:27 2023 UTC (7 months, 3 weeks ago) by rillig
Branch: MAIN
Changes since 1.45: +2 -2 lines
Diff to previous 1.45 (colored)

lint: clean up the wording of a few diagnostics

Revision 1.45 / (download) - annotate - [select for diffs], Tue Mar 28 14:44:34 2023 UTC (11 months, 1 week ago) by rillig
Branch: MAIN
Changes since 1.44: +3 -1 lines
Diff to previous 1.44 (colored)

lint: warn about extern declarations outside headers

https://mail-index.netbsd.org/tech-userlevel/2023/03/15/msg013727.html

Revision 1.44 / (download) - annotate - [select for diffs], Sun Feb 5 13:01:28 2023 UTC (12 months, 4 weeks ago) by rillig
Branch: MAIN
Changes since 1.43: +31 -1 lines
Diff to previous 1.43 (colored)

tests/lint: merge tests for initialization

Revision 1.43 / (download) - annotate - [select for diffs], Sun Feb 5 12:25:11 2023 UTC (12 months, 4 weeks ago) by rillig
Branch: MAIN
Changes since 1.42: +42 -1 lines
Diff to previous 1.42 (colored)

tests/lint: remove redundant tests

The names of the tests were misleading: 'recursive' should have been
'nested', and the interesting topic in the 'cast' tests was not the cast
but the pointer dereference.

Revision 1.42 / (download) - annotate - [select for diffs], Wed Jun 22 19:23:18 2022 UTC (20 months, 1 week ago) by rillig
Branch: MAIN
CVS Tags: netbsd-10-base, netbsd-10-0-RC5, netbsd-10-0-RC4, netbsd-10-0-RC3, netbsd-10-0-RC2, netbsd-10-0-RC1, netbsd-10
Changes since 1.41: +4 -4 lines
Diff to previous 1.41 (colored)

lint: add quotes around placeholders for the remaining messages

Reword some of the messages slightly, exchanging brevity for clarity.

Message 138 is kept as-is, as it is not yet covered by any tests.

Message 240 is kep as-is, as it is unreachable.

Revision 1.41 / (download) - annotate - [select for diffs], Fri Jun 17 18:54:53 2022 UTC (20 months, 2 weeks ago) by rillig
Branch: MAIN
Changes since 1.40: +6 -6 lines
Diff to previous 1.40 (colored)

tests/lint: make 'expect+-' comments stricter

Previously, the expectations from these comments were already satisfied
if the expectation occurred somewhere in the actual message from lint.
This meant that the prefix 'error:' or 'warning:' could be omitted from
the 'expect' comment.  These omissions were hard to see in a manual
review.  Now any omissions must be visually marked with '...'.

The test msg_342 now reports its messages properly as being in the file
msg_342.c, rather than msg_341.c.  This had been a copy-and-paste
mistake.

Revision 1.40 / (download) - annotate - [select for diffs], Sat Jan 15 14:22:03 2022 UTC (2 years, 1 month ago) by rillig
Branch: MAIN
Changes since 1.39: +29 -15 lines
Diff to previous 1.39 (colored)

tests/lint: expect complete messages in feature tests

Previously, the tests contained many comments like /* expect: 123 */,
which were useless to a casual reader since nobody is expected to learn
lint's message IDs by heart.  Replace these with the complete
diagnostics, to show what lint is complaining about.

The tests named msg_*.c have been left unmodified since they mention the
full message text in their header comment.

No functional change.

Revision 1.39 / (download) - annotate - [select for diffs], Tue Dec 28 22:54:08 2021 UTC (2 years, 2 months ago) by rillig
Branch: MAIN
Changes since 1.38: +7 -4 lines
Diff to previous 1.38 (colored)

tests/lint: extend documentation for omitted braces in initializer

Revision 1.38 / (download) - annotate - [select for diffs], Wed Dec 22 14:49:11 2021 UTC (2 years, 2 months ago) by rillig
Branch: MAIN
Changes since 1.37: +4 -4 lines
Diff to previous 1.37 (colored)

lint: remove spaces around bit-field colon

As seen in /usr/share/misc/style.

No binary change.

Revision 1.37 / (download) - annotate - [select for diffs], Wed Dec 22 14:32:31 2021 UTC (2 years, 2 months ago) by rillig
Branch: MAIN
Changes since 1.36: +5 -5 lines
Diff to previous 1.36 (colored)

tests/lint: improve test for initialization of array of unknown size

Previously, the test didn't show that the size of the resulting object
was updated too early.

Revision 1.36 / (download) - annotate - [select for diffs], Wed Dec 22 00:45:53 2021 UTC (2 years, 2 months ago) by rillig
Branch: MAIN
Changes since 1.35: +26 -11 lines
Diff to previous 1.35 (colored)

lint: fix handling of initializations

The implementation from March 2021 added proper support for designators
but didn't model the brace levels correctly.  In particular, it could
not handle additional braces or omitted braces.  In such a case, lint
skipped the remaining initializers from the initialization.  Due to
this, type errors in the remaining initializers went unnoticed.  Another
effect was that arrays of unknown size were wrongly reported as having
size 0.

Both GCC and Clang recommend placing braces around each sub-type that is
initialized, such as a struct, union or array.  Postfix does not follow
these recommendations, therefore lint had to be disabled in
external/ibm-public/postfix/Makefile.inc.  This commit fixes the bugs
mentioned there.

Revision 1.35 / (download) - annotate - [select for diffs], Tue Dec 21 16:50:11 2021 UTC (2 years, 2 months ago) by rillig
Branch: MAIN
Changes since 1.34: +2 -2 lines
Diff to previous 1.34 (colored)

lint: make function names a bit more concise

No binary change.

Revision 1.34 / (download) - annotate - [select for diffs], Fri Dec 17 15:52:30 2021 UTC (2 years, 2 months ago) by rillig
Branch: MAIN
Changes since 1.33: +74 -6 lines
Diff to previous 1.33 (colored)

tests/lint: add more examples for initialization, from C99

Revision 1.33 / (download) - annotate - [select for diffs], Fri Apr 9 23:03:26 2021 UTC (2 years, 10 months ago) by rillig
Branch: MAIN
CVS Tags: cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x
Changes since 1.32: +3 -4 lines
Diff to previous 1.32 (colored)

lint: fix initialization with brace-enclosed string literal

C99 allows this form in 6.7.8p14 and p15.

The previous lint tests did not cover the case of an array at the top
level of the object to be initialized, they only covered the error cases
(d_c99_init.c, variables 'prefixed_message' and 'message_with_suffix').

Lint is now more generous than strictly required by C99, but since GCC
and Clang already cover the case of 'message_with_suffix', this is ok.

The test d_init_array_using_string.c was wrong before in rejecting the
initializer for 'extra_braces'.  I had tested that Clang generated a
warning for this, but I had not inspected its warning carefully enough.
Clang had not warned about the extra braces but only about a type
mismatch since I tested on a platform where wchar_t was 16 bit.

Revision 1.32 / (download) - annotate - [select for diffs], Fri Apr 9 22:08:14 2021 UTC (2 years, 10 months ago) by rillig
Branch: MAIN
Changes since 1.31: +8 -1 lines
Diff to previous 1.31 (colored)

tests/lint: demonstrate wrong warning when initializing a string

Revision 1.31 / (download) - annotate - [select for diffs], Fri Apr 2 12:16:50 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.30: +2 -2 lines
Diff to previous 1.30 (colored)

lint: add parentheses after sizeof, as required by share/misc/style

No functional change.

Revision 1.30 / (download) - annotate - [select for diffs], Thu Apr 1 14:20:30 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.29: +3 -3 lines
Diff to previous 1.29 (colored)

lint: do not error out of a struct is initialized without braces

This allows to process lib/libc/gen/sysctl.c 1.38 from 2021-03-30, as
well as its precedessor 1.37, which had a workaround just for lint.

While unusual, C99 allows these.

Revision 1.29 / (download) - annotate - [select for diffs], Tue Mar 30 19:45:04 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.28: +10 -1 lines
Diff to previous 1.28 (colored)

tests/lint: test 'scalar type cannot use designator'

Revision 1.28 / (download) - annotate - [select for diffs], Tue Mar 30 16:09:30 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.27: +1 -3 lines
Diff to previous 1.27 (colored)

tests/lint: remove unnecessary empty lines from test

In a separate commit to not cause an unnecessarily large diff in the
previous commit.

Revision 1.27 / (download) - annotate - [select for diffs], Tue Mar 30 16:07:07 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.26: +6 -6 lines
Diff to previous 1.26 (colored)

lint: add error about out-of-bounds array subscripts

This check is not strictly necessary since any C99 compiler must
diagnose them as well, it is rather meant for demonstrating how to do
the check in lint, and for symmetry with the 'unknown member' error
message.  These provide insight into how the data structures in init.c
are meant to be accessed.

Revision 1.26 / (download) - annotate - [select for diffs], Tue Mar 30 15:18:19 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.25: +7 -7 lines
Diff to previous 1.25 (colored)

lint: add type information for message about unknown member name

Revision 1.25 / (download) - annotate - [select for diffs], Tue Mar 30 15:05:05 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.24: +3 -7 lines
Diff to previous 1.24 (colored)

tests/lint: remove outdated comments

Revision 1.24 / (download) - annotate - [select for diffs], Tue Mar 30 14:25:28 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.23: +36 -18 lines
Diff to previous 1.23 (colored)

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.

Revision 1.23 / (download) - annotate - [select for diffs], Mon Mar 29 22:42:10 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.22: +18 -1 lines
Diff to previous 1.22 (colored)

tests/lint: demonstrate assertion failures for union initialization

Revision 1.22 / (download) - annotate - [select for diffs], Mon Mar 29 22:36:31 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.21: +20 -1 lines
Diff to previous 1.21 (colored)

tests/lint: test unknown member name in struct

I had not expected to trigger another assertion, I just wanted to make
sure my latest ongoing refactoring will not break this case.  Apparently
there is no need to worry about that.

Revision 1.21 / (download) - annotate - [select for diffs], Mon Mar 29 22:07:00 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.20: +23 -1 lines
Diff to previous 1.20 (colored)

tests/lint: ensure initialization does not modify shared type

In my not yet published rewrite of lint's init.c, I forgot to copy the
array type. Guard against this bug, which would have been hard to find.

Given that in C, the declaration 'int a[], b[]' creates two different
type objects anyway, it's not easy to come up with a test case that
actually triggers this possible bug.  I'm not sure whether this test
indeed catches this bug.  If not, I'll add another test.

Revision 1.20 / (download) - annotate - [select for diffs], Mon Mar 29 17:13:07 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.19: +43 -1 lines
Diff to previous 1.19 (colored)

tests/lint: add examples for initialization from C99

These all pass lint without any warnings.  Both Clang and GCC warn about
these in -Wall mode, so they are unlikely to be seen in practice.

Revision 1.19 / (download) - annotate - [select for diffs], Sun Mar 28 19:53:58 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.18: +22 -1 lines
Diff to previous 1.18 (colored)

lint: add test for assertion failure in initialization

The 'cnt = level->bl_type->t_tspec == STRUCT ? 2 : 1;' in
initialization_push_struct_or_union is obviously wrong since not every
struct has exactly 1 remaining member after the first member that has an
initializer with designation.

This bug started its life in init.c 1.12 from 2002-10-21, a little over
18 years ago.

Revision 1.18 / (download) - annotate - [select for diffs], Sun Mar 28 18:48:32 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.17: +29 -4 lines
Diff to previous 1.17 (colored)

tests/lint: add tests for initialization

Revision 1.17 / (download) - annotate - [select for diffs], Sun Mar 28 14:01:50 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.16: +5 -5 lines
Diff to previous 1.16 (colored)

lint: remove wrong warning about wrong initializer type

The following code is valid:

	int valid = {{{ 3 }}};

C90 3.5.7 and C99 6.7.8 both say that the "initializer for a scalar
shall be a single expression, optionally enclosed in braces".  They
don't put any upper bound on the amount of braces, not even in the
"Translation limits" section.

Revision 1.16 / (download) - annotate - [select for diffs], Sat Mar 27 23:13:48 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.15: +10 -1 lines
Diff to previous 1.15 (colored)

tests/lint: test initializing a struct ending with unnamed bit-field

Revision 1.15 / (download) - annotate - [select for diffs], Sat Mar 27 16:13:41 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.14: +11 -8 lines
Diff to previous 1.14 (colored)

tests/lint: document expectations in test about array initialization

Revision 1.14 / (download) - annotate - [select for diffs], Sat Mar 27 15:49:33 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.13: +30 -1 lines
Diff to previous 1.13 (colored)

tests/lint: trigger assertion failure in array initialization

Revision 1.13 / (download) - annotate - [select for diffs], Tue Mar 23 23:12:21 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.12: +1 -2 lines
Diff to previous 1.12 (colored)

tests/lint: fix outdated comments

Revision 1.12 / (download) - annotate - [select for diffs], Sat Mar 20 08:59:46 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.11: +34 -1 lines
Diff to previous 1.11 (colored)

tests/lint: add more tests for initialization, based on C99 6.7.8

Revision 1.11 / (download) - annotate - [select for diffs], Sat Mar 20 08:54:27 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.10: +5 -3 lines
Diff to previous 1.10 (colored)

lint: fix assertion failure after error in designation

In d_c99_init.c, the initialization of array_with_designator failed.
The designator '.member' from that initialization was not cleaned up
before starting the next initialization.

Revision 1.10 / (download) - annotate - [select for diffs], Sat Mar 20 08:16:30 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.9: +11 -1 lines
Diff to previous 1.9 (colored)

lint: replace segmentation fault with assertion failure

Revision 1.9 / (download) - annotate - [select for diffs], Fri Mar 19 01:02:52 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.8: +2 -3 lines
Diff to previous 1.8 (colored)

lint: replace assertion in initialization with proper error message

Revision 1.8 / (download) - annotate - [select for diffs], Thu Mar 18 22:51:32 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.7: +8 -1 lines
Diff to previous 1.7 (colored)

lint: replace undefined behavior during initialization with assertion

This only affects code that is already rejected by the compiler.

Revision 1.7 / (download) - annotate - [select for diffs], Thu Mar 18 20:20:55 2021 UTC (2 years, 11 months ago) by rillig
Branch: MAIN
Changes since 1.6: +77 -3 lines
Diff to previous 1.6 (colored)

tests/lint: add more examples for initialization

Revision 1.6 / (download) - annotate - [select for diffs], Sun Feb 21 14:19:27 2021 UTC (3 years ago) by rillig
Branch: MAIN
Changes since 1.5: +4 -1 lines
Diff to previous 1.5 (colored)

lint: add debug logging for initializing an array of unknown size

It is possible that the type name 'array[unknown_size]' may spill into
the user-visible diagnostics.  The current test suite does not cover
such a case.  Anyway, saying 'array[unknown_size]' is still better than
saying 'array[0]', which would be misleading.

Revision 1.5 / (download) - annotate - [select for diffs], Sun Feb 21 13:10:57 2021 UTC (3 years ago) by rillig
Branch: MAIN
Changes since 1.4: +6 -2 lines
Diff to previous 1.4 (colored)

lint: add test for initializing a character array using a string

The previous attempt took another code path than expected.  The
initialization of static_duration actually calls initstack_string.

Revision 1.4 / (download) - annotate - [select for diffs], Sun Feb 21 12:49:05 2021 UTC (3 years ago) by rillig
Branch: MAIN
Changes since 1.3: +33 -2 lines
Diff to previous 1.3 (colored)

lint: add more tests for C99 initialization

Revision 1.3 / (download) - annotate - [select for diffs], Sun Feb 21 09:19:53 2021 UTC (3 years ago) by rillig
Branch: MAIN
Changes since 1.2: +3 -2 lines
Diff to previous 1.2 (colored)

lint: add another test case for initializing an object

Revision 1.2 / (download) - annotate - [select for diffs], Sun Feb 21 09:07:58 2021 UTC (3 years ago) by rillig
Branch: MAIN
Changes since 1.1: +2 -2 lines
Diff to previous 1.1 (colored)

lint: force each test to declare the expected diagnostics

By listing the expected diagnostics directly at the code that triggers
the diagnostics, it is easier to cross-check whether the diagnostics
make sense.

No functional change to lint itself.

Revision 1.1 / (download) - annotate - [select for diffs], Sun Feb 21 08:05:51 2021 UTC (3 years ago) by rillig
Branch: MAIN

lint: add another test for C99 initializers

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.




CVSweb <webmaster@jp.NetBSD.org>