Commit Graph

4886 Commits

Author SHA1 Message Date
rillig 3f8fd7950d tests/lint: add test for struct pointer cast 2021-04-08 19:08:17 +00:00
rillig b4b7f28d0e lint: for shift in C99 mode, do not warn about difference to pre-C90
C99 is too far away from traditional C to make this warning useful.
There are 3 different situations in which this warning is generated:

For '1 << (unsigned char)1', the result type is 'unsigned int' in
traditional C.  The result type is unsigned because at least 1 of the
operators is unsigned, and it is 'unsigned int' because the usual
arithmetic promotions are applied.

For '1 >> (long)1', as well as for '1 << (long)1', the result type is
'long' in traditional C since the usual arithmetic promotions are
applied.

Omitting this warning in C99 mode reduces the amount of lint warnings in
a typical NetBSD release build by approximately 6800 of 107000 total.
2021-04-06 21:59:58 +00:00
rillig 6e93208e35 lint: test what happens for 'int << double'
I just wanted to see whether typeok_shift would be reached in this case,
to ensure that is_uinteger applies as expected.  It does.
2021-04-06 21:44:12 +00:00
rillig 4148550ebb lint: add details to warning about too large shift amount
The previous message 'shift greater than size of object' was too short
to give reasonable hints, especially when the expressions involve
typedefs or macros.
2021-04-06 21:32:57 +00:00
rillig 4329029317 lint: fix wrong warning about losing accuracy when converting to _Bool 2021-04-06 21:17:27 +00:00
rillig 483f849cbf tests/lint: demonstrate wrong warning about losing accuracy 2021-04-06 21:10:37 +00:00
rillig c477a4b077 tests/libcurses: fix names of over-the-wire data types
The test 'mvscanw' reported that it would send '%s' as 'numeric', which
was rather suspicious.
2021-04-06 01:29:37 +00:00
rillig 5355aae702 tests/libcurses: clean up table of input functions
The previous "table" was an insult to any reader.  It was unsorted,
listed the functions shuffled, and was not even formatted consistently.

No functional change.
2021-04-06 00:47:00 +00:00
rillig 2f4525e1a8 tests/libcurses: don't waste time calling strlen needlessly 2021-04-06 00:35:58 +00:00
rillig b5bd70af56 lint: warn about for wrong type cast in argument to ctype.h functions
The argument to most of the functions from <ctype.h> "shall either be
representable as an 'unsigned char' or shall equal the value of the
macro EOF".

When confronted with the infamous warning 'array subscript has type
char', there are enough programmers who don't know the background of
that warning and thus fix it in a wrong way.  Neither GCC nor Clang
explain its warning to target these programmers.

Both GCC and Clang warn about 'array subscript has type char', but they
ignore the other requirements of the <ctype.h> functions, even though
these are in the C standard library.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94182
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95177
https://stackoverflow.com/a/60696378
2021-04-05 02:05:47 +00:00
rillig 5bbf966f2d tests/lint: one comment per expected diagnostic
This makes it possible to check for diagnostics that contain commas.
2021-04-05 01:35:34 +00:00
rin ddde04b66b Reapply fix for big-endian environments, which was lost when GSoC results
were merged...

http://www.nerv.org/netbsd/?q=id:20200620T075016Z.3584036ccf31f69ee76ea4a02e9be30ff081df21

> Fix false positive for mvscanw tests on big endian machines.
>
> When conversion specifier is not a derivative form of "%s", retrieve
> input as 32bit integer, and then convert to string literal. Then we
> can avoid interpretation from ASCII code to integer, which is
> apparently byte-order depended.
2021-04-04 09:49:13 +00:00
rin 32895f515e When mvscanw(3) fails, string is not modified.
Let's ignore the 2nd result for this case.
2021-04-04 09:42:08 +00:00
rin 2bfbad099a s/&string/string/ for mvscanw(3); string is already pointer to buffer. 2021-04-04 09:34:24 +00:00
rillig a5de3b3d6e lint: reword message about constant argument to '!'
In the other messages, operators are typically written in their literal
form as well.  Using single quotes disambiguates them from normal
punctuation.
2021-04-02 22:41:53 +00:00
rillig c0d1467e66 tests/lint: add test for constant argument to '!' 2021-04-02 22:38:42 +00:00
rillig 1cb2fa84ac tests/lint: prevent typo from tree.c 1.264 from happening again 2021-04-02 17:25:04 +00:00
rillig 59dc6d2516 tests/lint: add test for enum type mismatch 2021-04-02 13:16:38 +00:00
rillig 4a7db9da8e lint: add parentheses after sizeof, as required by share/misc/style
No functional change.
2021-04-02 12:16:50 +00:00
rillig 24351504d4 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.
2021-04-01 14:20:30 +00:00
rillig 31cf9748bb tests/lint: test 'scalar type cannot use designator' 2021-03-30 19:45:04 +00:00
rillig bdfe161d90 tests/lint: remove unnecessary empty lines from test
In a separate commit to not cause an unnecessarily large diff in the
previous commit.
2021-03-30 16:09:30 +00:00
rillig ea90fdfcdd 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.
2021-03-30 16:07:07 +00:00
rillig 94c797a88b lint: add type information for message about unknown member name 2021-03-30 15:18:19 +00:00
rillig ee9d2e6631 lint: reword message for very unlikely .member in array initialization 2021-03-30 15:10:46 +00:00
rillig 47d84fb81e lint: add type information to message 175 2021-03-30 15:07:53 +00:00
rillig 72bdbc4596 tests/lint: remove outdated comments 2021-03-30 15:05:05 +00:00
rillig 65a86d028a 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.
2021-03-30 14:25:28 +00:00
rillig a14413219e tests/lint: test initialization without braces 2021-03-29 22:59:03 +00:00
rillig e94cc75f40 tests/lint: demonstrate assertion failures for union initialization 2021-03-29 22:42:10 +00:00
rillig 8473828968 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.
2021-03-29 22:36:31 +00:00
rillig 58b48e79c1 tests/lint: test initialization of union in traditional C 2021-03-29 22:24:34 +00:00
rillig 4bf66febf4 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.
2021-03-29 22:07:00 +00:00
rillig 49daf9079c 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.
2021-03-29 17:13:07 +00:00
rillig af1032a21b 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.
2021-03-28 19:53:58 +00:00
rillig 46e70dbb1a tests/lint: add tests for initialization 2021-03-28 18:48:32 +00:00
christos 0ca9a87c3a yield so we can lose packets 2021-03-28 17:30:01 +00:00
rillig 94f17677cf lint: only define GCC builtins if -g is given
This removes 7 wrong warnings when running lint in -t mode.

Surprisingly, this added a warning that had not been there before in
msg_189.c.  This is because check_variable_usage skips the checks when
an error occurred before.  All diagnostics that happened were warnings,
but the -w option treats them as errors, see vwarning.
2021-03-28 15:36:37 +00:00
rillig 7261c8f667 tests/lint: add test for struct initialization in traditional C 2021-03-28 15:12:20 +00:00
rillig 034864b5d3 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.
2021-03-28 14:01:49 +00:00
rillig 7524fdaade tests/lint: test initializing a struct ending with unnamed bit-field 2021-03-27 23:13:48 +00:00
rillig 16d4772b31 tests/lint: document expectations in test about array initialization 2021-03-27 16:13:41 +00:00
rillig 8f24804db0 tests/lint: trigger assertion failure in array initialization 2021-03-27 15:49:33 +00:00
rillig c581ec06d7 tests/lint: move description of tests into the tests themselves
In most cases the descriptions didn't add much to the test name anyway.
2021-03-27 13:59:18 +00:00
rillig 125c83e1c2 tests/lint: do not force tests to start with 'd_'
Using only parts of the test name files in t_integration.sh made it
unnecessarily difficult to find a test based on its filename.  The tests
for the individual messages already have a different prefix.

No functional change.
2021-03-27 13:28:03 +00:00
rillig 13262e443a lint: add quotes around placeholder in message about undefined variable
Before: error: expected undefined [99]
After:  error: 'expected' undefined [99]

Seen in external/mpl/bind, which for Clang defines in stdatomic.h:
> #define atomic_exchange_explicit(obj, desired, order) \
>     __c11_atomic_exchange_explicit(obj, expected, order)
Note the mismatch between 'desired' and 'expected'.
2021-03-26 23:17:33 +00:00
rillig aead5d0dd4 lint: allow pointer cast to 'char *' and 'unsigned char *'
This reduces the number of warnings in the regular NetBSD build by 5560.
2021-03-26 16:59:18 +00:00
rillig 21c63f2ee3 tests/lint: add tests for warning about cast to character types 2021-03-26 16:19:43 +00:00
rillig f829424df6 lint: fix initialization for arrays with designators
From the previous commit, there was an off-by-one error left, which was
due to the interaction between designation_add_subscript and
extend_if_array_of_unknown_size.

The other crucial point was to call initstack_pop_nobrace before
accessing the "current initialization stack element".  Without this
call, in msg_168.c the "current element" would point to the initializer
level for 'const char *' instead of the one for 'array of const char *'.

One more step towards supporting C99.
2021-03-25 22:53:05 +00:00
rillig 23e30dfb46 lint: improve initialization of arrays with designators
Initialization is still buggy but better than before.  The remaining bug
is that only the first designator determines the array size, and after
that, the array is no longer considered of unknown size.  This
contradicts C99.  More improvements to come.
2021-03-25 22:15:38 +00:00
rillig aadb627a71 lint: fix C99 initialization with expression of type 'struct'
This has been a long-standing limitation of lint.  Now it is almost
ready for C99, see the list of "major changes" in the foreword of C99.

One known remaining bug in the area of initialization is designators
with several levels, such as '.member[2].member.member'.  Oh, and
designators for arrays are only supported in the parser but not in the
type checker.  There's still some work to do.
2021-03-25 01:42:53 +00:00
rillig 09d00b786a tests/lint: fix outdated comments 2021-03-23 23:12:21 +00:00
rillig e92d4ad150 lint: fix wrong warning about initialization using string literal
Missing braces after 'if', since init.c 1.68 from 2021-02-20.

GCC 10 doesn't complain about this even with -Wmisleading-indentation
since at least one of the involved lines is a macro invocation (in this
case both lines).  GCC 11 will warn about this.

Clang warns about this, but the regular Clang build currently fails for
other reasons, so this problem didn't show up there either.
2021-03-23 22:58:08 +00:00
rillig a0407258e3 tests/lint: test initialization using string literals
The errors in line 74 and 75 of the test are wrong.  Everything is fine
there.  The bug lies in init_array_using_string, try to see if you can
spot it, neither GCC 9.3.0 nor Clang 8.0.1 could.
2021-03-23 21:19:08 +00:00
rillig 131c7001fe lint: fix wrong error message about type mismatch in compound literal
Now that the code contains explicit markers for starting and ending an
initialization, and having the guarantee that an assertion fails
whenever some code accesses the state of the "current initialization"
even though there is no ongoing initialization gives me much more
confidence in the correctness of the code.  The calls to
begin_initialization and end_initialization always appear in pairs,
enclosing the minimal amount of code necessary for initialization.

In a nutshell, global modifiable state is error-prone and hard to
understand.

A nice side effect is that the grammar no longer needs a special rule
for the outermost initializer since the functions for the debug logging
are now called explicitly.

The code that misuses the initialization state just because it needs to
temporarily store a sym_t somewhere is now clearly marked as such.  A
GCC statement expression can appear anywhere and is therefore
independent of the initialization.  Most probably the code can simply
refer to the local variable in the grammar rule itself, or this variable
needs to be encoded in the grammar %union.  For sure there is a better
way to handle this.

There is no longer a need that the function 'declare' initializes the
initialization state, it was just the wrong place to do this.
2021-03-23 18:40:50 +00:00
rillig 56f5eec48a tests/lint: explain wrong type mismatch in compound literal
When a pointer to a compound literal is used as an initializer, lint
reports a wrong type mismatch.  The details of what happens are now
documented, which allows this problem to be fixed properly.
2021-03-22 16:51:24 +00:00
rillig 771299944e lint: use precise type information in message about type mismatch
While here, reword the message, avoiding operators and parentheses.

Since 2021-01-02, providing the precise type name is as easy as the
broad type classification (just replace tspec_name with type_name), and
it's definitely more useful to the human readers.
2021-03-22 15:29:43 +00:00
rillig 9e1bfe0e24 lint: demonstrate bug in assignment of compound literal
Seen in external/mpl/bind/dist/lib/dns/rbtdb.c, update_rrsetstats.
2021-03-22 15:05:00 +00:00
rillig ab16413a62 lint: prefix error messages with 'error:'
This makes it easier to find these errors in the build logs.
2021-03-21 20:44:59 +00:00
rillig a23b8b6d6f tests/lint: test reachability of goto and named labels 2021-03-21 20:08:21 +00:00
rillig 0676c13cad tests/lint: add test for reachability of non-constant conditions 2021-03-21 19:39:01 +00:00
rillig cd0f66fe16 tests/lint: add test for reachability of nested 'if' statements 2021-03-21 19:18:37 +00:00
rillig ac846d67c2 lint: warn about unreachable statement after joining the 'if' branches 2021-03-21 19:14:40 +00:00
christos 7085ce980b use a pipe instead of sched_yield() 2021-03-21 16:58:07 +00:00
christos b43f86b836 PR/56066: Jessica Clarke: Add tests for calling {_,}longjmp with a zero value. 2021-03-21 16:36:32 +00:00
rillig 792d6541e8 lint: fix reachability for while (0) 2021-03-21 15:44:57 +00:00
rillig 62b887ae9d lint: fix reachability for constant controlling expression in for loop 2021-03-21 15:34:13 +00:00
rillig 352b5b3b4b lint: fix reachability for if-then-else statements 2021-03-21 15:24:55 +00:00
rillig 97e5c72af7 lint: fix reachability computation in if statements
Previously, only loop statements were considered for reachability.  This
ignored the possibility of an early return in an if statement, or
unreachable branches.
2021-03-21 14:36:59 +00:00
rillig 4d15bfda11 tests/lint: sync redundant documentation in test for strict bool mode 2021-03-21 14:12:46 +00:00
rillig b37b780b84 tests/lint: add tests for reachability of statements
Right now, reachability is only implemented for loops, but not for
selection statements.
2021-03-21 14:09:40 +00:00
rillig 295da53276 tests/lint: demonstrate bug in endless loop detection 2021-03-21 12:19:36 +00:00
rillig 8c4298c341 lint: fix wrong 'falls off bottom' after return in do-while 2021-03-21 11:55:59 +00:00
rillig 85a09d20fa lint: fix wrong 'statement not reached' in do-while loop 2021-03-21 11:48:04 +00:00
rillig aa32b69997 tests/lint: clarify that a brace-enclosed initializer needs an expr 2021-03-21 10:43:08 +00:00
rillig 10736dfe07 lint: in strict bool mode, check initialization as well
C99 6.7.8p11 says for initialization that "the same type constraints and
conversions as for simple assignments apply", so actually apply them.
(I had just forgotten this "operator" when I first implemented strict
bool mode.)
2021-03-20 17:18:50 +00:00
rillig f6312109e2 tests/lint: test initialization in strict bool mode
I somehow forgot to list INIT as one of the operators in
is_assignment_bool_or_other.
2021-03-20 17:08:08 +00:00
rillig fb9b10bc8d lint: fix check for declaration after statement in pre-C99 mode
The new code may not be the most beautiful, but it fixes all bugs that
occurred while testing message 327.  The grammar rules are taken from
C99 6.8.2, so it's no surprise they work well.
2021-03-20 15:28:07 +00:00
rillig daef7ea921 lint: properly name C99 in message about declaration after statement
Now that C99 has been released and published, there is no reason anymore
to refer to it as C9X.
2021-03-20 14:17:56 +00:00
rillig 363ba317d3 tests/lint: add test for declaration after statement 2021-03-20 14:13:51 +00:00
rillig 941875ba2d lint: join grammar rules for initialization
The '%prec T_COMMA' is necessary to avoid lots of parse errors in the
lint1 unit tests.  Curiously, further down in the grammar, for compound
literals, the '%prec T_COMMA' is not necessary, even though the context
looks very similar.

No functional change.
2021-03-20 11:24:49 +00:00
rillig a11859207b tests/lint: add more tests for initialization, based on C99 6.7.8 2021-03-20 08:59:46 +00:00
rillig 80b7b20b36 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.
2021-03-20 08:54:27 +00:00
rillig 88e315e145 lint: replace segmentation fault with assertion failure 2021-03-20 08:16:30 +00:00
rillig c6daba3cac tests/lint: add comma to struct initialization
This places the error marker one line up, where it is expected.
2021-03-19 17:40:37 +00:00
rillig 91bffee2de tests/lint: add test for incompatible pointer types in return 2021-03-19 08:01:58 +00:00
rillig 0b45cbea90 lint: replace assertion in initialization with proper error message 2021-03-19 01:02:52 +00:00
simonb 7f74343bad Sprinkle a few more \n's and the end of some debug printfs. 2021-03-19 00:44:09 +00:00
rillig d30c5846db lint: replace undefined behavior during initialization with assertion
This only affects code that is already rejected by the compiler.
2021-03-18 22:51:32 +00:00
rillig ebe3bde9bf lint: reword message about type mismatch in initialization
Using parentheses for quotes is unusual, furthermore the previous
message didn't follow proper grammar rules, sacrificing clarity for
brevity.
2021-03-18 21:26:56 +00:00
rillig 79d8eaa978 tests/lint: add test for type mismatch in initialization
Copied and adapted from d_c99_init.c.
2021-03-18 21:20:21 +00:00
rillig d254ff0ed7 tests/lint: warning 210 has type information by now 2021-03-18 20:58:02 +00:00
rillig 0dfa224bf0 tests/lint: add more examples for initialization 2021-03-18 20:20:55 +00:00
rillig e80f308ca7 tests/lint: add tests for a few more messages 2021-03-16 23:39:41 +00:00
rillig b803b07d9e tests/lint: add test for message 139 about division by zero 2021-03-16 23:18:49 +00:00
rillig df6d0bccc3 tests/lint: add test for message 128 about incompatible pointers 2021-03-16 23:12:30 +00:00
rillig 0c8fc40bd0 tests/lint: document how lint discards the typedef name in 247 2021-03-14 22:24:24 +00:00
rillig 6941825e93 tests/lint: add test for message 247 for pointer to unnamed struct 2021-03-14 21:44:35 +00:00
rillig 1e4c413bac indent: fix off-by-one error in comment wrapping
The manual page says that the default maximum length of a comment line
is 78.  The test 'comments.0' wrongly assumed that this 78 would refer
to the maximum _column_ allowed, which is off by one.

Fix the wording in the test 'comments.0' and remove the (now satisfied)
expectation comments in the test 'token-comment.0'.

Several other tests just happened to hit that limit, fix these as well.
2021-03-14 01:34:13 +00:00
rillig 80a063b8f7 tests/indent: demonstrate off-by-one error in comment processing 2021-03-14 00:50:39 +00:00
rillig 93e110b15f indent: fix handling of '/*' in string literal in preprocessing line
Previously, the '/*' in the string literal had been interpreted as the
beginning of a comment, which was wrong.  Because of that, the variable
declaration in the following line was still interpreted as part of the
comment.  The comment even continued until the end of the file.

Due to indent's forgiving nature, it neither complained nor even
mentioned that anything had gone wrong.  The decision of rather
producing wrong output than failing early is a dangerous one.

At least, there should have been an error message that at the end of the
file, the parser was still in a a comment, expecting the closing '*/'.
2021-03-13 13:14:14 +00:00
rillig 658877681d tests/indent: add another test case for preprocessing directives
In process_preprocessing, the variable 'quote' is not used, which makes
the code suspicious of not handling the combination of string literals
and comments properly.
2021-03-13 13:04:13 +00:00
rillig b69ea1ee50 tests/indent: add test for preprocessor lines 2021-03-12 22:53:18 +00:00
rillig 40f5d5969a tests/indent: demonstrate stray empty line at end-of-file 2021-03-12 18:28:07 +00:00
rillig 23562e890e tests/indent: test tokenization of punctuation, mainly operators 2021-03-12 17:41:10 +00:00
rillig 3530c7d28f tests/indent: add test templates for testing specific parser symbols
The basic idea of indent is to split the input into tokens and then
reassemble them, reformatting them on the way.  These tokens determine
how the output is formatted, therefore add tests for each of the
terminal tokens and nonterminal parser symbols, to cover more common
cases, and edge cases as well.
2021-03-12 00:13:06 +00:00
rillig 5edf0687f7 lint: disable check for enum type mismatch in switch statement
This check has been too quick and broke the lint build.  Among others,
lib/libpuffs has -w included in LINTFLAGS, which means that the build
can fail even for new warnings, not only for errors.

libpuffs compares a uint16_t with constants from an unnamed enum type.
Since the enum type is completely unnamed (neither a tag nor a typedef),
there is no way to define a struct member having this type. This was a
scenario that I just didn't consider when I added the check to lint.

For now, disable the new check completely.  The previously existing lint
checks stay enabled, including the one that warns about mismatched
anonymous enum types in the '==' operator, which is very similar to the
now disabled check.
2021-03-10 00:02:00 +00:00
rillig 4b24f8a1b1 tests/lint: add example for anonymous enum type in switch expression 2021-03-09 23:40:43 +00:00
rillig 4fa1602dd1 tests/lint: add tests for comparison between unnamed enums
Since unnamed enum types cannot be used in type casts, there is no
sensible way that this type mismatch could be resolved, without changing
the definition of the enum type itself, but that may be in a
non-modifiable header.

Therefore, comparisons with enum constants of unnamed types cannot be
sensibly warned about.
2021-03-09 23:09:48 +00:00
rillig c280f5e623 tests/indent: demonstrate strange alignment for global variables 2021-03-09 20:43:19 +00:00
rillig 6abe7eedca tests/indent: demonstrate wrong removed empty line before '//' 2021-03-08 22:13:05 +00:00
rillig 09aa491484 tests/indent: demonstrate another bug in nested blocks 2021-03-08 20:55:34 +00:00
rillig 548d705b04 tests/indent: add test for output line counting 2021-03-08 20:12:04 +00:00
rillig 6383459232 tests/indent: allow golden stderr file, improve filenames, clean up code
When indent runs in filter mode, it may output messages to stderr.
Allow tests with non-empty expected stderr.

In the ATF output, the filename 'output_file.parsed' was not helpful for
casual readers of diff output since they expect the filenames to be
meaningful.  Embed the name of the test case in that filename.

Fix quoting of the shell variables.

Remove the repetition of the regular expression to clean up the test
files.
2021-03-08 20:01:16 +00:00
rillig 73071b8322 indent: fix handling of '//' end-of-line comments 2021-03-07 22:11:01 +00:00
rillig 7bd1775519 lint: in strict C mode, warn about initialization with '[a ... b]'
https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html
2021-03-07 19:42:54 +00:00
rillig f4d1bba78c lint: in the name of an array type, list the dimension first
before: array of unsigned int[4]
now:    array[4] of unsigned int

Listing the array dimension first keeps it in contact with the keyword
'array'.  This reduces confusion, especially for nested arrays.
2021-03-07 17:12:41 +00:00
rillig 05f8f43dfd tests/lint: demonstrate wrong warning for array subscript
Seen in usr.bin/indent/lexi.c.
2021-03-07 16:40:20 +00:00
christos d54a6e0c5d Add blocklist support to libwrap which enables all programs using libwrap
to block access from hosts we deny. (libwrap support from Greg A. Woods)
2021-03-07 15:09:12 +00:00
rillig 66c859742f tests/indent: add tests for the remaining command line options 2021-03-07 10:12:18 +00:00
rillig 39a9a45a21 tests/indent: allow for comments in either the input or output files 2021-03-07 08:57:38 +00:00
rillig eb45e52c0e tests/indent: add tests for negative options
Since most of these options are of the form "don't do anything", the
input and output of these tests is very similar.
2021-03-06 23:09:17 +00:00
rillig 634ae6266a tests/indent: add more tests, discover more bugs 2021-03-06 22:10:40 +00:00
rillig c9cd1c3aa6 tests/indent: add 17 more tests, found only a single new bug
Discovering one bug in 17 command line options is acceptable.  This
compensates the bad first impression I got in the previous batch of
tests, which consisted of 11 tests and found 8 bugs.
2021-03-06 21:27:39 +00:00
rillig 0bf3fecc64 tests/indent: fix unintended trailing whitespace and space-tab 2021-03-06 19:51:24 +00:00
rillig f4551e581c tests/indent: add 11 test cases, demonstrate 8 bugs 2021-03-06 19:30:44 +00:00
rillig 1a656e3597 tests/indent: add templates for options tests
Given that indent "has even more switches than ls(1)", there are far too
few tests.  To make it easier to add meaningful tests for each of the
options, add the templates for the tests right now, ready to be filled
in.
2021-03-06 17:56:33 +00:00
rillig 51d591549d tests/indent: extend test for '//' comments with more examples 2021-03-06 15:02:38 +00:00
rillig b5348831df lint: warn about enum/enum or enum/int type mismatch in switch
This is something that neither GCC 10 nor Clang 8 do, even though it
seems useful.  Lint didn't do it up to now, but that was probably an
oversight since it is easy to miss the implicit '==' operator in the
switch statement.
2021-03-05 17:10:05 +00:00
rillig 4e936ad287 tests/lint: mark tests for messages 130 and 241 as related 2021-03-05 16:35:52 +00:00
rillig 4c8d48e6d4 tests/lint: add test for incompatible enums in switch
Neither lint nor GCC 10 nor Clang 8 have a warning for an enum type
mismatch in a switch statement.

GCC 10 issues a warning but completely misses the point of the
mismatched enum types.  It only warns because in this test, EVENING has
the numeric value 3, which is out of bounds for enum color, where the
valid range is from 0 to 2.  It says:

> msg_130.c:45:2: warning:
>     case value ‘3’ not in enumerated type ‘enum color’ [-Wswitch]

Clang 8 behaves almost the same, it just doesn't mention the value of
the constant, saying merely 'case value not in enumerated type'.
2021-03-05 16:31:49 +00:00
simonb 60f64147e4 Revert previous, 11th time failed after commit. Problem must be elsewhere. 2021-03-02 07:16:24 +00:00
simonb d71e98b9d4 Bump tentative flag timeout (-w) from 10 to 20 seconds. Changes this
test from failing roughly half the time to working 100% over 10 tests on
evbmips er4.
2021-03-02 07:02:14 +00:00
rillig 523633c84d lint: fix null pointer dereference on parse error
Fixes PR bin/22119.
2021-02-28 22:12:16 +00:00
rillig 84a7228e25 tests/lint: add test for narrowing conversions
Lint can warn about narrowing conversions, it just doesn't do so by
default.

The option -a (which is included in the default LINTFLAGS in sys.mk)
only reports narrowing conversions from 'long' or larger.  To get
warnings about all possible narrowing conversions, the option -a has to
be given more than once.

PR bin/14531
2021-02-28 21:39:17 +00:00
rillig 3594934372 lint: add test to demonstrate that PR bin/20264 has been fixed 2021-02-28 20:17:13 +00:00
rillig f963c8e49b tests/lint: keep messages in test files in sync with actual messages
Each of the tests named msg_*.c repeats the template of the message, to
make the test somewhat self-contained when viewed in isolation.

This creates a redundancy, and keeping track of this manually is next to
impossible.  I tried it and failed in 9 cases, even though it has just
been 2 months since I myself created the initial files and I knew all
the time that this redundancy exists.

Be fool-proof for the future by checking this automatically.
2021-02-28 12:40:00 +00:00
rillig 0d0d46fd3a lint: do not warn about constant expressions involving sizeof
These expressions are indeed constant for a specific platform, but on
another platform their value may change.  This makes them unsuspicious
and legitimate for portable code.

Seen in rump_syscalls.c, as 'sizeof(int) > sizeof(register_t)'.
2021-02-28 03:59:28 +00:00
rillig 966d6a6413 tests/lint: add test for constant expression involving sizeof 2021-02-28 03:29:12 +00:00
rillig 089670865b lint: add type information to 'illegal bit-field type' 2021-02-28 02:45:37 +00:00
rillig ca54ab8987 lint: output precise type information for struct/union/enum
Previously, 'typedef enum { E } name' was output as 'name', which
omitted the information that this was an enum type.  Now it is output as
'enum typedef name'.

Previously, 'typedef struct { int member; } name' was output as 'struct
<unnamed>', which omitted the typedef name.  Now it is output as 'struct
typedef name'.
2021-02-28 02:29:28 +00:00
rillig 2317ba2476 lint: add type information for 'incompatible struct pointers' 2021-02-28 02:00:05 +00:00
rillig 3c4f693c91 tests/lint: add test for 'illegal structure pointer combination' 2021-02-28 01:53:49 +00:00
rillig e14e7c3dab tests/lint: add test for unconst pointer cast 2021-02-28 01:36:46 +00:00
rillig fb1e12220d lint: add type information to enum type mismatch 2021-02-28 01:30:22 +00:00
rillig 4a3dd2aa12 tests/lint: add test for '<<' in traditional C 2021-02-28 01:22:02 +00:00
rillig c331beff19 tests/lint: force 'expect' annotations 2021-02-28 01:20:54 +00:00
rillig 4b52b11627 lint: make messages for incompatible pointers more specific
Message 153 didn't state obviously which of the pointer types was the
one before conversion (or cast) and which was the resulting type.

Message 229 didn't have any type information at all.
2021-02-28 01:06:57 +00:00
rillig 033a381e0d tests/lint: add tests for function pointers 2021-02-28 00:52:16 +00:00
rillig b19a5288ba lint: add type information to 'possible pointer alignment problem [135]'
This warning occurs more than 7400 times in a regular NetBSD build, and
without giving any type information, leaves the reader clueless about
what the underlying issue might be.  Add type information since that is
a no-brainer to implement.
2021-02-28 00:40:22 +00:00