Commit Graph

4505 Commits

Author SHA1 Message Date
rillig
b9684d0f53 lint: update message text for 259 in test
That's the one place that is not checked for matching the actual message
by my usual pre-commit checks.
2021-02-04 07:39:39 +00:00
rillig
deb631d74d lint: add back "due to prototype" to message 259
That message is only supposed to warn about compatibility to traditional
C, in case the function should ever be compiled without its prototype
being in effect.  All other type checks are supposed to be in another
function, as documented, but that type check misses to report a few
error-prone type combinations (long to char, long to int).

30 years after the introduction of prototypes with C90, almost all
existing code uses prototypes.  The warning has thus lost most of its
usefulness and can rather be confusing since a conversion from 'char' to
'long' is not problematic with prototypes in action, and the probability
of the code being backported to a pre-C90 compiler is diminishingly
small.

The words "due to prototype" now serve as a hint again.  The proper fix
could be to suppress this warning in C99 mode since that's far enough
from traditional C.
2021-02-04 06:54:59 +00:00
rillig
1c1bd1bbee lint: document that message 108 doesn't abort anymore 2021-01-31 16:00:05 +00:00
rillig
70a1a91e7b lint: format tests in a common style
The lint tests do not focus on the whitespace since that is the most
boring part of code style.  Therefore, format the tests to be readable
by following share/misc/style as close as possible.
2021-01-31 14:57:28 +00:00
rillig
aadcb6a6f1 lint: add common header for all tests
For those tests that didn't use GCC-style line markers such as "# 2",
the line numbers of the diagnostics stay the same.  This is purely
conincidental.  Before, the 3 lines came from lint's built-in
definitions (see 'builtins' in main1.c), and line number counting
continued as if nothing had happened, making the first line of the
actual file line 4.  These 3 built-in lines are now replaced with 3
lines of file header.
2021-01-31 14:39:31 +00:00
rillig
9e66939b96 lint: reword message 259 about function argument conversion
The words "due to prototype" are an anachronism from the 1990s.
Nowadays every function is defined using a prototype, which makes these
words redundant.
2021-01-31 14:05:00 +00:00
rillig
43f40912b1 lint: make warning about function argument conversion more detailed
For every conversion it is useful to know both the source and the target
type since these are not always obvious from the code.

The only surprise is the warning in d_gcc_extension.  The conversion
there is from 'double' to 'long double', which is a lossless conversion.
This may be a bug in lint.
2021-01-31 13:56:14 +00:00
rillig
0b12920818 lint: demonstrate wrong and misleading warnings about reachability 2021-01-31 13:33:10 +00:00
rillig
eaade8c9b9 lint: add test for lossy assignments to bit-fields (164, 166) 2021-01-31 13:11:08 +00:00
rillig
2c260a3f3b lint: don't warn about constant condition in 'do { } while (0)' 2021-01-31 12:44:34 +00:00
rillig
7986832010 lint: add expectations to test for message 161 2021-01-31 12:30:53 +00:00
rillig
bed82d19b3 lint: add tests for 'constant in conditional context'
One of these tests explains why 'do { } while (0)' is so usual that
there is no reason to warn about it.  That warning will not survive for
long.
2021-01-31 12:29:16 +00:00
rillig
c4973480d0 lint: fix strange message about nested '==' operators
If one of the nested subexpressions is parenthesized, the author
probably knew how these expressions are evaluated.  Therefore don't warn
in such a situation.

Maybe the original author once made a typo and tried to initialize
variables but instead compared them, like this:

	int a, b, c;

	a == b == c;

This would explain the text of the message, which still sounds strange.
At least it doesn't show up as often anymore.
2021-01-31 12:20:00 +00:00
rillig
9ff24546ee lint: add more test cases for strange '==' warning 160 2021-01-31 11:59:56 +00:00
rillig
73fb62d3c1 lint: mention the operator in messages about bit shifts 2021-01-31 11:44:48 +00:00
rillig
6712cb633d lint: add quotes to messages 1 and 19 2021-01-31 11:23:01 +00:00
rillig
e9aa93027d lint: add expections to tests
msg_098: fix suffix for floating point constant
msg_127: remove prototype
msg_146: fix return type
2021-01-31 11:12:07 +00:00
rillig
d61a087385 lint: test messages 019 and 021 2021-01-31 09:48:47 +00:00
rillig
cfd7827cf3 lint: be more precise in message 003 "tag in argument list" 2021-01-31 09:26:27 +00:00
rillig
3cef4b4f94 lint: add a few more tests 2021-01-31 09:21:24 +00:00
rillig
c96543cdff lint: fix wrong 'expression has null effect' 2021-01-30 23:05:08 +00:00
rillig
d1d4e41c20 lint: add test for 129, possibly demonstrating a bug in lint 2021-01-30 22:38:54 +00:00
rillig
0872823424 lint: add test for message 259 about implicit conversions 2021-01-30 22:07:31 +00:00
rillig
4916b997a5 lint: remove message 189, add tests for a few other messages
Message 189 would have applied to traditional C and was supposed to
detect assignments between struct and union types.  The corresponding
check had never been implemented though.

Traditional C has been superseded for 30 years now, therefore there is no
point in adding this check retroactively.
2021-01-30 17:56:29 +00:00
rillig
3029566535 lint: add tests that trigger a few more messages 2021-01-30 17:02:58 +00:00
rillig
37de14639f lint: add test for message 325, undefined static function 2021-01-24 17:55:41 +00:00
rillig
e8cbbabf42 lint: add test for message 329, union cast with incompatible type 2021-01-24 17:44:37 +00:00
rillig
fe3677c509 lint: add tests for a few messages 2021-01-24 16:12:45 +00:00
rillig
1f640a49f4 lint: fix wrong warning about null pointer comparison 2021-01-24 11:21:58 +00:00
rillig
7b8d5df0f6 lint: demonstrate wrong 124 for flipped == as well
Since the fix in the next commit changes two places in the code, there
must be two wrong error messages that disappear then.
2021-01-24 11:17:44 +00:00
rillig
fc1964e307 lint: demonstrate wrong 124 due to bug in is_typeok_eq 2021-01-24 11:13:22 +00:00
rillig
adda8a3bab lint: document bug in typeok_eq
Since rt is an alias for rn->tn_type->t_tspec, it cannot be PTR and VOID
at the same time.  This makes the condition unsatisfiable.  Removing
that part of the code didn't show any change in behavior, as expected.

It may even be that fixing this obvious bug doesn't show any change in
behavior since that function is only used in a single place and
check_pointer_comparison performs its own checks before issuing any
warning.

At least the test cases added to msg_124.c all run as expected.
2021-01-24 10:50:42 +00:00
rillig
f2a08f3e9b lint: improve introduction of test d_c99_bool_strict_syshdr 2021-01-24 09:18:42 +00:00
rillig
378eb7af09 lint: explain why !finite(x) is not allowed in strict bool mode 2021-01-24 07:58:48 +00:00
rillig
4e7742bb74 lint: apply strict bool mode to lex.c
There are 2 remaining expressions:

In line 244, !(kw->kw_deco & deco) is a bitwise and.  This is already
allowed for enums, it needs to be allowed for arbitrary integer
expressions as well.  This covers the many places where plain integers
are used for bit fields, together with #define.  This pattern is not as
typesafe as using enums, still it is common practice.

In line 769, the expression !finite(f) is a legitimate use of a function
that has return type int for traditional reasons.  It's the same as for
ferror.

There are several other functions like unlink, open or strcmp that have
return type int as well, but with a different meaning.  It is not yet
clear what the best way is to handle these different meanings.  Having
to write finite(f) == 0 in strict bool mode doesn't look idiomatic, on
the other hand, !strcmp(s1, s2) is exactly the pattern that strict bool
mode wants to avoid.
2021-01-23 23:11:40 +00:00
rillig
9cd64a121c lint: fix error message for relaxed bool operations in system headers
In strict mode, allowing 1 as bool constant expression is probably not
needed in practice since most comparisons are != 0 instead of == 0.

Furthermore, in the expression (flags & 0x0002) == true, comparing with
true is misleading since the '==' operator can never evaluate to true in
this case.
2021-01-23 22:34:01 +00:00
rillig
4e2fcabaa8 lint: fix two wrong error messages in strict bool mode
The strict bool mode gets complicated because for system headers the
rules need to be relaxed since they cannot be changed easily, often not at all.

Still, if lint validates a program in strict bool mode, that program
must run with equal behavior regarding boolean expressions even on a
pre-C99 platform.
2021-01-23 22:20:17 +00:00
rillig
afdff4f65d lint: extend test for strict bool mode and system headers 2021-01-23 19:03:55 +00:00
chs
6ab81237dc for the busypage test, replace atf_tc_expect_fail() with atf_tc_skip()
because atf apparently has no way to expect a test program to crash.
fixes PR 55945.
2021-01-22 22:03:01 +00:00
simonb
14893fad26 Use .set noreorder and use reg names.
atf- lib/libc/sys/t_mprotect mprotect_mremap_exec is a bit happier now.
2021-01-21 00:56:41 +00:00
rillig
f7ed7c6314 lint: clean up code (mostly comments) 2021-01-18 20:02:34 +00:00
rillig
17f1c77b1c lint: fix assertion failure for restrict and _Thread_local 2021-01-18 17:43:43 +00:00
rillig
8981d6d027 lint: add more test cases for duplicate type qualifiers 2021-01-18 17:41:04 +00:00
simonb
b64a04d2b4 Check for MAP_FAILED instead of NULL when looking for an error from mmap(2). 2021-01-18 05:44:20 +00:00
rillig
8274970958 lint: allow system headers to use int as bool, even in strict bool mode 2021-01-17 23:04:09 +00:00
rillig
fb08819de8 lint: add more tests for system headers in strict bool mode 2021-01-17 23:00:41 +00:00
rillig
d5ff218b54 lint: add test for macro from system header in strict bool mode
Seen in usr.bin/make/meta.c:1670: FD_ZERO(&readfds).  These macros
cannot be fixed since system headers must not include <stdbool.h>.
Therefore INT constants should be accepted as controlling expressions as
well.
2021-01-17 21:19:06 +00:00
rillig
bf9c8d819d lint: add type information to message 126 2021-01-17 17:14:34 +00:00
rillig
8e597c87a3 lint: add test for incrementing const variable 2021-01-17 16:19:54 +00:00
rillig
2ba3ae8c78 lint: add test for rvalue ++ after cast 2021-01-17 16:16:09 +00:00