Commit Graph

19438 Commits

Author SHA1 Message Date
rillig 86c56211f3 lint: do not warn about converting (1234567L & 0xFF) to unsigned char
Due to the '& 0xFF', there is no possible loss of accuracy.
2022-04-19 20:08:52 +00:00
sjg d3c45bc7c4 Comment on interaction of posix.mk with[out] -r 2022-04-18 16:09:05 +00:00
sjg e5f8f85da5 Never 'rm -rf ${TMPDIR}' when you cannot be sure what it is
Use a safer variable for a subdir of ${TMPDIR} that we know
we can remove safely.
2022-04-18 15:59:39 +00:00
rillig ddac43c43f make: only switch to POSIX mode if '.POSIX:' is the first line
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
says that in order to make a makefile POSIX-conforming, its first
non-comment line must be the special dependency line '.POSIX:' without
any source dependencies.

Previously, make switched to POSIX mode even if such a line occurred
anywhere else, which was allowed by POSIX but was deep in the
"unspecified behavior" area.  For NetBSD make, there is no big
difference since it doesn't ship any <posix.mk> file, this change mainly
affects the bmake distribution.

Previously, makefiles that contain '.POSIX:' somewhere in the middle
could fail due to <posix.mk> resetting .SUFFIXES, among other things.

Suggested by Simon J. Gerraty, who also reviewed an earlier version of
this change.
2022-04-18 15:06:27 +00:00
rillig 3b7543fb74 tests/make: refine documentation of test for .USEBEFORE 2022-04-18 14:41:42 +00:00
rillig 2f92faa198 tests/make: extend tests for .USE and .USEBEFORE 2022-04-18 14:38:24 +00:00
rillig 78a8d15996 lint: merge mod_t.m_test_context into m_requires_bool
These two flags mean exactly the same.

No functional change.
2022-04-16 22:21:10 +00:00
rillig b1dadfd56b lint: clean up table with operator properties
Now that lint may use C99, make use of empty macro arguments.

No binary change.
2022-04-16 21:22:12 +00:00
rillig ba92662bc0 lint: rename members of tnode_t to more closely match reality
The flags do not describe the left operand of the node but both, as for
most operators, either none or both operands are in test context or in
value context.

The one exception is the operator '?' from the '?:' conditional, for
which the left operand is in test context and the right operand is in
value context.

No binary change.
2022-04-16 21:14:33 +00:00
rillig 4ffab22634 lint: investigate why lint only warns about some constant conditions
Noticed in lex.c, in the macro kwdef, where lint complains about the
condition containing '||' but not about the conditions containing only
'>' or '=='.
2022-04-16 20:57:10 +00:00
rillig 82c1f72934 lint: fix instructions for adding a new test 2022-04-16 20:18:51 +00:00
rillig 18adea31f2 lint: remove null marker from keyword table
No functional change.
2022-04-16 20:08:35 +00:00
rillig f8dac4099a lint: prepare keyword table for C11
The C11 keywords had been listed as being C99 keywords.  Instead of
initializing the individual fields separately, merge them by specifying
the year of the standard in which they appeared.

No binary change, except for line numbers in assertions.
2022-04-16 20:02:55 +00:00
rillig f285ea576b lint: migrate gflag to allow_gcc
No functional change.
2022-04-16 19:18:17 +00:00
rillig 5db2a0cfc6 lint: clean up keyword definitions for the lexer
There is only one specialized keyword that is also a GCC attribute, it's
"section".  All other keywords passed 0 in that macro argument.

No binary change.
2022-04-16 18:13:54 +00:00
rillig a14c0654d8 lint: for gnuism and c99ism, calculate severity
Calculating the severity as a simple sum removes the condition sequence
'a && !b, or else a || !b', which can quickly become a brain twister,
especially when negations are involved.

No functional change.
2022-04-16 15:55:10 +00:00
rillig bf8454bb40 lint: clean up conditions for migration check between trad and C90
No functional change, as each of the conditions was effectively '!tflag
&& !sflag && !Sflag' (even if distributed over several statements).
2022-04-16 14:06:10 +00:00
rillig 4f5bc0bb10 lint: model C language levels in a future-compatible way
The options -t, -s and -S are confusing because they are used
inconsistently.  The option -S enables C99 features, but when using it
instead of -s, it also doesn't enable all checks required by C90 and
later.  Prepare fixing of these inconsistencies by replacing the flag
variables with language levels that can be extended in a
straight-forward way as new C standards arrive.

| option | allow_trad | allow_c90 | allow_c99 | allow_c11 |
|--------|------------|-----------|-----------|-----------|
| -t     | x          | -         | -         | -         |
| (none) | x          | x         | -         | -         |
| -s     | -          | x         | -         | -         |
| -S     | -          | x         | x         | -         |
| -Ac11  | -          | x         | x         | x         |

Each usage of the old flag variables will be inspected and migrated
individually, to clean up the subtle variations in the conditions and to
provide a simpler model.

When lint was created in 1995, its focus was migrating traditional C
code to C90 code.  Lint does not help in migrating from C90 to C99 or
from C99 to C11 since there are only few silent changes, and simply
because nobody took the time to implement these migration aids.  If
necessary, such migration modes could be added separately.

There is a small functional change: when the option -s is combined with
either -S or -Ac11, lint now only keeps the last of these options.
Previously, these options could be combined, leading to a mixture of
language levels, halfway between C90, C99 and C11.  Especially combining
traditional C with C11 doesn't make sense, but xlint currently allows
it.

The 3 tests that accidentally specified multiple language levels have
been adjusted to a single language level.
2022-04-16 13:25:27 +00:00
nia c0d3889267 telnet.1: update state of the art on Single DES encryption 2022-04-16 09:53:13 +00:00
rillig f87e5fc974 lint: in C99 mode, allow trailing comma in enum declarations
Adjust the test to be run in C90 mode instead of traditional mode, since
traditional C didn't have enums.
2022-04-16 09:22:25 +00:00
rillig 4857d69a78 lint: extend README 2022-04-16 09:18:33 +00:00
rillig 72c7fc3f3c lint: skip duplicate -llib and -Llibdir options
This removes many of the currently 26.000 'multiply defined' lines from
a typical NetBSD build.  Duplicate libraries happen a lot due to
overlapping transitive dependencies.  An example is usr.bin/telnet,
which links to -lcrypto and several other libraries twice.
2022-04-16 00:15:47 +00:00
rillig 6e5c40b112 lint: fix typography in manual page 2022-04-15 23:25:04 +00:00
rillig 59915d96df lint: in C99 mode, do not warn about non-prototype conversions
Message 259 is "argument #%d is converted from '%s' to '%s' due to
prototype", and it is intended to warn about compatibility between
traditional C where functions had no prototypes and standard C where
functions have prototypes.

Running lint in C99 mode is further away from traditional C than running
lint in C90 mode, so that warning doesn't make sense for C99.  There are
still some inconsistencies in the 5 language version modes that lint
offers:

	-t		for traditional C
	(no option)	for migrating traditional C to C90
	-s		for C90 code
	-S		for C99 code
	-Ac11		for C11 code

By disabling warning 259 in C99 mode, a typical NetBSD build produces
14.500 fewer warnings than before, of about 100.000 total.

Message 259 overlaps with message 298 "conversion from '%s' to '%s' may
lose accuracy, arg #%d", and in some cases of potentially lossy
conversions, lint now produces none of these messages.  In some other
cases, these warnings were reported redundantly.  The cases where
message 298 makes sense will be added back later, as needed.
2022-04-15 21:50:07 +00:00
rillig dd5757eacf lint: merge conditions in check_integer_conversion
No functional change.
2022-04-15 17:08:21 +00:00
rillig edcbd2cff8 lint: reduce indentation in check_integer_conversion
No functional change.
2022-04-15 16:38:30 +00:00
rillig 78db74c828 lint: fix typography in manual page 2022-04-15 16:18:14 +00:00
rillig 546dc578fa lint: in verbose mode, quote shell commands in output 2022-04-15 16:08:39 +00:00
rillig 6769b29d1b make: document the available preprocessor definitions for Makefile.boot 2022-04-15 13:44:57 +00:00
rillig 588ed71a5f make: do not use __CONCAT and __STRING in meta_needed
Using __CONCAT for identifiers makes it impossible to find their usages
easily, as could be seen in targ.c 1.22 from 2001-07-03.  It also
requires that the parts of the identifier are not macros themselves.

No binary change.
2022-04-15 12:28:16 +00:00
rillig 97dcd22758 make: add .USEBEFORE to Targ_PrintType
When .USEBEFORE was added in targ.c 1.22 from 2001-07-03, it was not
added to Targ_PrintType, probably because the PRINTBIT macro hid the
identifier OP_USE and only used USE.
2022-04-15 12:19:28 +00:00
rillig 88095434a6 tests/make: adjust expectations to actual behavior
The bug in deptgt-silent-jobs.mk has been fixed, the debug logging for
comparing conditions and for deleting global variables has changed
intentionally.
2022-04-15 09:33:20 +00:00
rillig 7e73bfffc8 lint: remove trailing whitespace from README, add useful breakpoints 2022-04-13 22:58:18 +00:00
rillig 46ce0edfbe lint: fix lint warning on platforms where size_t == unsigned int
lex.c(1451): warning: argument #1 is converted from 'int' to
    'unsigned int' due to prototype [259]

A more thorough fix would be to change the type of block_level from int
to size_t, to match mem_block_level, but that change would generate
further signedness warnings because the type of sym_t.s_block_level
would have to be changed from int to size_t as well, but some symbols
have s_block_level == -1, so that's a larger and more error-prone
change.  Leave that for later.

Whether message 259 makes sense at all in C99 mode is an entirely
different question that needs to be answered separately.

No functional change.
2022-04-13 22:20:42 +00:00
andvar d1ee79bf8c s/simular/similar/ 2022-04-11 21:23:07 +00:00
martin a47cc448b4 PR 56789: avoid -ftrapv for alpha, it triggers a gcc error.
OK: rillig
2022-04-10 13:21:34 +00:00
rillig 508315abb6 lint: fix assertion failure on duplicate qualifiers from __typeof__ 2022-04-10 12:14:10 +00:00
andvar 75d2abaeb1 fix various typos in comments and output/log messages. 2022-04-10 09:50:44 +00:00
rillig 45b909fe36 lint: add quickstart documentation to the implementation of lint 2022-04-10 00:42:29 +00:00
rillig 5c62dde852 lint: distinguish between storage class and declaration kind
These types overlap but are not the same.

No functional change.
2022-04-09 23:41:22 +00:00
rillig 43b30eb233 lint: ensure that lint itself compiles without lint warnings
It would be a pity if lint didn't even survive its own style checks.
2022-04-09 22:26:49 +00:00
rillig f0299d8d6c lint: rename dinfo_t.d_offset to d_offset_in_bits
Most often, offsets are measured in bytes, so better embed the unit in
the variable name.

No functional change.
2022-04-09 21:19:52 +00:00
rillig d1f29dcf9a lint: extract is_member into separate function
No functional change.
2022-04-09 16:02:14 +00:00
rillig 4d8538d58c lint: disambiguate sym_t.s_value
Having a single variable for 4 different purposes with different types
makes the code unnecessarily hard to follow.

No functional change.
2022-04-09 15:43:41 +00:00
rillig c4f4d3155b lint: split CTCONST into BOOL_CONST and ENUM_CONST
Having a unified compile-time constant "storage class" made the code
more difficult to understand.

No functional change.
2022-04-09 14:50:18 +00:00
rillig d6f4c1eddf lint: inline member access macros for sym_t
Having the 'u.' explicitly in the code serves as a reminder that these
members are only defined under certain conditions.

No functional change.
2022-04-09 13:38:17 +00:00
rillig 730d4d511e lint: rename length to length_in_bits
No functional change.
2022-04-09 13:22:05 +00:00
rillig cbe246cc1b lint: fix undefined behavior on enum overflow (since 1995)
GCC had optimized the check away, due to the obvious integer overflow 'x
- 1 == INT_MAX'.  To prevent further bugs like this, compile with
-ftrapv.
2022-04-08 21:48:19 +00:00
rillig 321092b8ae lint: remove unused message 70, add some more tests 2022-04-08 21:29:29 +00:00
andvar 2fa7e14158 fix various typos, mainly in comments, but also log messages, docs, game text. 2022-04-08 10:17:52 +00:00