Commit Graph

16884 Commits

Author SHA1 Message Date
rillig
a90a871c79 lint: fix conversion of non-constant scalar to _Bool 2021-01-10 12:46:38 +00:00
rillig
f8cc76a76d lint: fix conversion of constant expressions to _Bool 2021-01-10 12:34:56 +00:00
rillig
a0c63d1765 lint: automate adding a test for lint1 2021-01-10 12:05:07 +00:00
rillig
dadf0f419e lint: rename cvtcon to convert_constant
No functional change.
2021-01-10 11:17:53 +00:00
rillig
bfe7d5e162 lint: remove redundant braces in is_confusing_precedence
This nicely aligns the different branches, in which "l" and "r" are
swapped.

No functional change.
2021-01-10 00:12:50 +00:00
rillig
fe68124a52 lint: rename type classification macros
The previous names tspec_is_int and tspec_is_uint were confusing because
there are actually tspec_t constants called INT and UINT, these
classification macros return true for other integer types as well,
though.

While here, remove the prefix "tspec_" from these macros.  It wasn't as
helpful as intended, in many cases it was obviously redundant, when it
was called as tspec_is_integer(tn->tn_type->t_tspec).

No functional change.
2021-01-10 00:05:45 +00:00
rillig
13e81db968 lint: push down complexity from typeok to typeok_shr
Contrary to the comment in typeok, the types of the expressions before
promotions and conversions are not needed for SHL, SHLASS and SHRASS.
Move that code over to typeok_shr, the only place where it is actually
used.  This removes another 3 variables from typeok.
2021-01-09 23:18:19 +00:00
rillig
fe47a95707 lint: move pointer subtypes from typeok to the sub-functions
The code in typeok is already complicated enough.  Only few of the
checks actually examine the subtype of the pointer, the others don't
need to look at it.  Therefore don't initialize the variables lstp
(left-hand side subtype) and rstp unless they are actually needed.

This reduces the number of variables in typeok and the number of
parameters to the sub-functions.
2021-01-09 23:02:51 +00:00
rillig
6c55876374 lint: make the table containing the operator properties more readable
The C preprocessor does not require its arguments to be expressions, an
empty string is valid as well.  This allows to replace the 0 in the
operator properties table with a space, making the 1 stick out.

Since the table is quite long, divide it into sections and add section
headers.

No change in the generated code.
2021-01-09 22:19:11 +00:00
rillig
8668691139 lint: rename ops.c to oper.c
The file ops.c had previously been autogenerated.  This meant that in a
NetBSD build, it was generated in OBJDIR, and a build that had just
updated src/usr.bin would fail.  For a build that last ran on
2020-12-01, and again today, it looks like this:

	#      link  lint1/lint1
	cc ... -o lint1 cgram.lo ... ops.lo ... tyname.lo
	/usr/bin/ld: ops.lo: in function `initmtab':
	ops.c:(.text+0x63): undefined reference to `STRUCT_ASSIGN'

This is caused by ops.c existing in OBJDIR, so the new version in
NETBSDSRCDIR is not looked at.  To prevent this, use oper.c instead as
the filename, which has not been used before.

https://mail-index.netbsd.org/source-changes-d/2021/01/09/msg013096.html
2021-01-09 21:37:44 +00:00
rillig
c52bdc3223 lint: change return type of typeok to bool
No functional change.
2021-01-09 19:13:17 +00:00
rillig
1d7ebe5271 lint: split typeok into several smaller functions
This reduces the number of local variables from 16 to around 5, in most
of the smaller functions.

No functional change.
2021-01-09 19:07:07 +00:00
christos
ca969aae02 preserve errno because we are doing system calls between error printing
and error setting.
2021-01-09 18:26:03 +00:00
christos
d71ebb0175 restore perror -> warn (reported by Havard Eidnes) 2021-01-09 18:22:42 +00:00
rillig
956d051a07 lint: extract typeok_amper from typeok
No functional change.
2021-01-09 18:21:08 +00:00
rillig
7f72829d0c lint: extract typeok_incdec from typeok
No functional change.
2021-01-09 18:15:14 +00:00
rillig
1d90d5eca8 lint: reorder table of operator properties
The 4 "requires" properties are now listed together, in descending
strictness.
2021-01-09 17:36:10 +00:00
rillig
1043e742ed lint: fix crash for error 108 (invalid type of unary operator) 2021-01-09 17:21:33 +00:00
rillig
462cbdfa37 make(1): fix lint warnings 2021-01-09 16:06:09 +00:00
christos
63840c068e PR/55916: William Ahern: cmp -s + regular files + skipping is broken
Move test after length is adjusted
2021-01-09 15:16:28 +00:00
rillig
63bde02018 lint: make target platform independent of host platform
If lint is run on a platform that has CHAR_BIT == 10, this doesn't
magically make an ILP32 platform have 40 bits per uint32_t.

At the moment, all of the supported platforms are either ILP32 or
I32LP64 anyway, and all of them have CHAR_BIT == 8 == CHAR_SIZE,
so nothing changes practically.
2021-01-09 14:10:12 +00:00
rillig
6e4238f485 lint: remove trailing whitespace 2021-01-09 13:58:43 +00:00
rillig
4ba4b93100 lint: rename ename to enumeration_constant 2021-01-09 13:12:13 +00:00
rillig
16d75acecd lint: align grammar rules with C99 2021-01-09 03:28:47 +00:00
rillig
1119ffe1ba lint: expand abbreviations in grammar rules
stmnt -> statement
comp -> compound

The abbreviation "stmnt" was non-standard, and "comp" was ambiguous
since it is used for "comparison" as well.
2021-01-09 03:08:54 +00:00
rillig
e8115594bd lint: rename T_MULT to T_ASTERISK
In the early phase of lexical analysis, the '*' does not mean
multiplication, therefore its name should not suggest that.  It is only
an asterisk, and depending on the surrounding context, it will only
later turn into a pointer dereference or a multiplication.

The call operator(T_MULT, MULT) was misleading since the MULT was not
used at all.
2021-01-09 02:38:27 +00:00
sjg
336a7b2bd2 Ensure PrintOnError always reports 'stopped in' on first call.
We may still suppress the rest of the noise if shouldDieQuietly
says to, but the 'stopped in' output is too important to lose.
Avoid repeating it though in the same process.

For the case of aborting due to failure detected elsewhere,
exit 6 so we have a clue.

PR: 55578
Reviewed by:
2021-01-08 21:46:50 +00:00
sjg
7b0d20a9e4 Set wantToken when none available.
PR: 53285
Reviewed by: gson
2021-01-08 04:36:44 +00:00
rillig
dbe5d068b4 lint: fix function as controlling expression (since 2020-12-31)
It's perfectly valid to directly use a function name as the controlling
expression of an if statement.  That function name is converted
implicitly to a pointer to that function, and that is a scalar value
then.

Spotted by christos in lib/libpthread/pthread.c:634.
2021-01-08 02:11:45 +00:00
rillig
91017b3441 lint: demonstrate wrong message 204 (since 2020-12-31)
In func.c 1.39 from 2020-12-31 18:51:28, the check that controlling
expressions are indeed scalar was extended from while and for loops to
if statements as well.  It just seemed to have been an oversight.

This revealed a bug in lint, which didn't accept the following valid
code snippet from lib/libpthread/pthread.c:634:

	void _malloc_thread_cleanup(void) __weak;
	...
	if (_malloc_thread_cleanup)
		_malloc_thread_cleanup();

Testing a function (instead of a function pointer) for truthiness is
probably rare since most functions are defined unconditionally.  For
weak functions it comes in handy though.

Clang-Tidy suggests to prefix the function with '&' to silence its
warning.  Doing that revealed a non-obvious behavior in build_ampersand,
which does not add the AMPER node to the expression even though it is
clearly mentioned in the code.  That is left for further research.

Once the original bug is fixed, it probably doesn't matter whether the
AMPER is discarded or retained since check_controlling_expression would
add it back.  There's probably a reason though to sometimes discard the
AMPER and sometimes retain it.
2021-01-08 01:40:03 +00:00
sjg
3abd1687f2 Remove .MAKE from nested target which is not a sub-make
This does not fix the issue, just makes the unit-test more accurate.

PR: 55578
Reviewed by: rillig
2021-01-07 18:11:23 +00:00
joerg
7c219dd6db Optimize nbperf
- add fudge mode which gives a slightly slower hash function, but works
  almost always in the first iteration by avoiding degenerate edges
- avoid keeping incidence lists around reducing the memory foot print by
  30%
- split edge processing from hashing as in the non-fudge case it is a
  reasonable costly part that often gets thrown away
- merge graph2 and graph3 routines now that they are mostly the same
2021-01-07 16:03:08 +00:00
lukem
0de2ffcfac progress: handle EINTR in writes. PR/55914 2021-01-07 12:02:52 +00:00
lukem
5650392b38 ftp(1): fix description of "debug"
"debug" command and documentation got accidentally renamed
to "ftp_debug" 13 years ago, and was only partially fixed.
2021-01-06 09:15:59 +00:00
lukem
920389c199 ftp: don't use restartable signals
Refactor to not rely upon restartable signals (SA_RESTART),
possibly fixing intermittent failures with -q QUITTIME.

ftp transfers: handle EINTR/EAGAIN in copy_bytes(),
instead of relying upon restartable signals.

http/https transfers: Explicitly print an error similar to
progressmeter() when timing-out for -Q QUITTIME in fetch_wait(),
and set errno to ETIMEDOUT so that the warn() in fetch_url()
prints a more accurate error message.

PR/55857
2021-01-06 04:43:14 +00:00
rillig
bd9b719c88 lint: clean up generation of the operator tables
Instead of running a shell program that runs an AWK program that
generates the two files ops.c and ops.h, just define the operator tables
once in ops.def and use these definitions flexibly in ops.c and op.h.
2021-01-05 23:50:29 +00:00
rillig
15275571de lint: remove redundant symbolic operator names
These symbolic names for INCBEF, INCAFT, DECBEF and DECAFT were
non-standard and thus confusing.  All other operators were as expected.
Now that the operator names from ops.def are very similar, there is no
need to keep to almost identical lists around.

No change to the user-visible messages since the only place where these
operator names were used was in 324, and that message was restricted to
PLUS, MINUS, MULT and SHL.
2021-01-05 23:20:53 +00:00
rillig
b8104292aa lint: clean up symbolic operator names that are used in the messages
Including the "p" in the symbolic operator names was questionable, for
several reasons:

1.  The "p" could be taken to mean an actual variable name, which is
    confusing if the function doesn't have such a variable, or even more
    so if the line contains an unrelated variable called "p".

2.  For the binary operators, having the "p" mentioned on both sides of
    the operator (such as in "p + p") wrongly suggested that both
    operands of the expression were the same.

3.  The name "p" often stands for a pointer.  Most of the operators
    don't accept pointers, therefore the name was misleading.

For these reasons, the "p" was removed from the symbolic name of all
operators.  This makes several pairs of operators indistinguishable:

    INCBEF == INCAFT
    DECBEF == DECAFT
    UPLUS == PLUS
    UMINUS == MINUS
    STAR == MULT
    AMPER == AND

This is not expected to create any confusion since C programmers are
expected to know these double meanings.

The symbolic names for SHLASS and SHRASS were missing the '=' before.
This was added since omitting it was probably an oversight.
2021-01-05 23:07:49 +00:00
rillig
40291d99b5 lint: swap columns 1 and 2 in ops.def
List the ID of a record first, followed by the describing fields.
2021-01-05 21:40:42 +00:00
rillig
bb3299716f lint: make generating the operators table simpler
The generated files are exactly the same as before.
2021-01-05 21:32:47 +00:00
rillig
701a9913ea lint: make check_precedence_confusion simpler
In C, only binary operators have possibly confusing precedence.  All
binary operators have lower precedence than an explicit cast.  When an
expression is parsed, the parentheses are associated with the innermost
possible node.  This means that as soon as a cast operator is
parenthesized, its contained expression can no longer have confusing
precedence.

This allows the code to be written more succinct since the local
variables are no longer necessary.
2021-01-05 17:37:57 +00:00
rillig
09a0c30431 lint: in debug mode, log every newline
This helps to quickly see where in the source file the parser currently
is.  Previously, the parsing position was only printed after each
declaration, as part of "clear flags".
2021-01-05 17:13:44 +00:00
rillig
77051f68d6 lint: fix inconsistent whitespace in ops.def 2021-01-05 16:34:37 +00:00
rillig
be58920ae9 lint: add missing strings for operators
It's difficult to keep these lists in sync when they are spread over
several files.  The lists had been inconsistent since 2008-04-26.  The
inconsistency didn't lead to undefined behavior though since the
operator names are only used in 2 places:

1. check_integer_conversion in message 324 only calls that function with
a few selected operators, all of which are above the missing ones.

2. mkinit prints the node including its operator, but only in debug
mode.  Furthermore I'm not sure whether any of the broken operator names
could ever be accessed at this place since mkinit is only called for
expressions, and the node types are INIT, CASE, FARG, which are all
special.
2021-01-05 07:37:41 +00:00
rillig
3b9b565485 lint: clean up comments 2021-01-05 00:22:04 +00:00
rillig
870d1f87f1 lint: extract code for determining possible precedence confusion
The function check_precedence_confusion was pretty long, and right in
the middle of that function was the complicated part of determining
which of the operand combinations are confusing and which aren't.

Extract this part into a separate function to document on which
information this decision is based.  This makes it easier to understand
the code since there are fewer local variables around.

As a left-over from a previous commit, rop and rparn don't need to be
initialized twice, now that the assertion for a binary operator is in
place.

Remove the large and useless switch statement over all operator types.
This list was completely unsorted, for no apparent reason.  To see the
list of operators, better look them up in ops.def, there was no need to
have this list duplicated here.
2021-01-05 00:17:21 +00:00
rillig
6e4e9ad1dc lint: remove unused TBUILTIN_SIZEOF from the C grammar
This token is not generated by the lexer, and it was misspelled anyway.
All other token names start with "T_", this one was missing the
underscore.
2021-01-05 00:02:52 +00:00
rillig
8f289eec5d lint: precedence confusion is only possible with binary operators
No functional change.

The operator table in ops.def states that every operator that has
possibly confusing precedence is also a binary operator, so assert that
instead of having two different code paths.
2021-01-04 23:58:19 +00:00
rillig
9a3fecd259 lint: fix bug in "precedence confusion possible [169]" 2021-01-04 23:50:46 +00:00
rillig
6c2a2c1402 lint: document and demonstrate the bug in check_precedence_confusion
It took quite a while to get to the correct interpretation of this small
piece of code and to draw the right conclusions from it.  Now the bug is
finally ready to be fixed, as already announced in the test.
2021-01-04 23:47:26 +00:00