Commit Graph

467 Commits

Author SHA1 Message Date
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
rillig
fb2d84bf80 lint: add more rationale for removing effect-less code 2021-01-04 23:17:03 +00:00
rillig
8f3340157a lint: finish the comments in check_precedence_confusion 2021-01-04 22:41:56 +00:00
rillig
796f8d840b lint: replace LERROR with lint_assert in check_expr_misc
This reduces the visual clutter.  There is no reason for anyone to
modify the code around the CALL operator, therefore the assertion is not
expected to fail anytime soon.
2021-01-04 22:33:47 +00:00
rillig
4c2e526843 lint: reduce comment for xgetblk to the actually interesting part 2021-01-04 22:29:00 +00:00
rillig
0935430d9a lint: fix typos and other minor stylistic issues 2021-01-04 22:26:50 +00:00
rillig
c48d8a0ff1 lint: fix bugs in dprint_node in debug mode (since today)
The node was dereferenced before the null check.  GCC 5.5 didn't warn
about this obvious bug, not even with -Wall -Wextra -O2.  Such a case
didn't occur though in the few tests that this function was used in.

The indentation for the nested nodes only needs to be set for a few
lines of code, make this region as small as possible.

There are nodes that use both tn_left and tn_right, even though they are
not defined as binary operators.  An example is CALL, for which tn_left
is the address of the function name and tn_right, which are the
arguments, linked via PUSH nodes.  CALL is not a binary operator since
it doesn't do any calculations with its arguments.
2021-01-04 21:30:06 +00:00
rillig
4f7d5d5f25 lint: move dprint_node to the top of the file
It now resides right below dumpnode, which implements the same idea but
uses a fixed-size output buffer and prints everything in a single line,
which quickly gets hard to read.  Maybe that's the reason why it had
been commented out since it got added in 2014.
2021-01-04 21:17:31 +00:00
rillig
8c672c9179 lint: in debug mode, print node tree for precedence
From the code alone, it is too difficult to see how the various internal
operators are combined and what properties they have.  A simple tree
visualization helps to see all the details.

This is used to track down the typo in check_precedence_confusion, to
see whether it could have possibly had any influence at all.
2021-01-04 17:06:20 +00:00
rillig
d2a5bcaf42 lint: add test for "precedence confusion possible [169]" 2021-01-04 15:52:51 +00:00
rillig
1044039bbe lint: use consistent indentation for C grammar 2021-01-03 21:33:50 +00:00
rillig
7e95331a3d lint: fix code generation from err.c
That file does not need to be in the current directory.
2021-01-03 20:44:54 +00:00
rillig
eebb776c7b lint: rename funcarg and funccall to longer names
From the previous short names, it was no obvious that these functions
create a new tree node.

The function named funccall in lint2 has been left as-is, since it has a
completely different prototype.
2021-01-03 20:38:26 +00:00
rillig
78ea2303a8 lint: rename functions that create nodes 2021-01-03 20:31:08 +00:00
rillig
ef3ab72165 lint: rename prflstrg to printflike_argnum, likewise for scflstrg 2021-01-03 20:14:38 +00:00
rillig
225eb1e1c3 lint: rename cstk to cstmt
Most of the code that deals with control statements is only interested
in the innermost control statement, and not if that is a stack or not.
Therefore, emphasize that part in the variable name.

The member c_next was confusing since the "direction" of this "next
element" was ambiguous.  In a sequence of if statements, the "next"
element could have equally been the following one, not the surrounding
one.
2021-01-03 20:04:08 +00:00
rillig
9fdfd4f3b3 lint: rename t_ispacked to t_packed and d_ispacked to d_packed
It's shorter, and the other flags of the type or declaration also don't
have "is" in their names.  Except for t_isenum, but that's because there
is a macro named t_enum that would interfere with that name.
2021-01-03 19:15:36 +00:00
rillig
6a419e12c6 lint: rename type.t_isfield to t_bitfield 2021-01-03 19:10:47 +00:00
rillig
2c6ed6826b lint: in DEBUG mode, verify printf parameters for messages
Since several years GCC validates printf-style strings, and there is no
reason not to let GCC do that work.  This prevents bugs like the
segmentation fault that was fixed in tree.c 1.109 from 2021-01-01.

By default, lint is compiled with DEBUG off, but it's easy enough to
compile it in debug mode once in a while.
2021-01-03 18:48:37 +00:00
rillig
df33f93fa1 lint: remove redundant include of externs1.h
It is already included by lint1.h.
2021-01-03 18:35:51 +00:00
rillig
90901a1bb9 lint: let gnuism and c99ism return void instead of int
The return value was only used in a single case.  Duplicating the
condition for printing a message is ok in that case, since it makes all
other places in the code simpler.

The occasional "(void)" or "msg = " before the function call had hidden
the calls from check-msgs.lua, which didn't check the message texts in
such cases.
2021-01-03 17:42:45 +00:00
rillig
6eb357b43e lint: separate error and warning for 27 and 58
Even though this results in more lines of code, the benefit is that the
message text in the comment is verified by check-msgs.lua.  The code is
also easier to read, the parentheses and asterisk were not needed.
2021-01-03 17:11:19 +00:00
rillig
bd792b2822 lint: fix spelling of message 308
All other messages are lowercase as well.
2021-01-03 16:59:59 +00:00
rillig
6add3c2232 lint: add type information to message 124 "illegal pointer combination" 2021-01-03 15:51:16 +00:00
rillig
297061dc12 lint: convert bitfieldtype_ok from int to bool
No functional change intended, except for the output in debug mode.
2021-01-02 18:44:58 +00:00
rillig
1046aa5d34 lint: fix lint warning 161 "constant in conditional context" 2021-01-02 18:26:44 +00:00
rillig
ad4fbc2570 lint: add a few more tests
No serious bugs found this time.
2021-01-02 18:06:01 +00:00
rillig
5827a84bf2 lint: fix message 308 "Invalid type for _Complex"
Previously, lint aborted since it didn't expect tspec_name to be called
with NOTSPEC, which at that point was the only possible value of
dcs->d_cmod.
2021-01-02 17:17:00 +00:00
rillig
a52e33d19b lint: allow _Bool for bit-fields 2021-01-02 16:33:39 +00:00
rillig
3ea7d2a77a lint: fix buffer truncation for type names
Previously, most type names had been cut off after 63 significant
characters.  In some cases, 127 characters survived, or 255.  And for
the debugging messages, sometimes even 1023.  This inconsistency was
useless.

It was wrong in the first place to make the caller of the function
tyname responsible for handling the buffer.  That's not something a
caller of such a simple function should do.  These callers have better
things to do.

The API of the new function type_name is as simple as possible.

In the implementation, the name of the type is generated anew each time.
I just didn't know whether the type details could change, once the type
is initialized, and I didn't want to find out.  To be on the safe side,
the resulting type name is cached, independently of the type it was
generated for.  Using a trivial, unbalanced binary tree should be good
enough for now.

All this work is necessary to support adding new debug logging, without
being distracted by irrelevant implementation details such as these
buffer sizes.  Adding new debug messages should be fun and easy; up to
now, it was overly bureaucratic.
2021-01-02 03:49:25 +00:00
rillig
cf4174e436 lint: fix typo in check-msgs tool 2021-01-02 01:12:38 +00:00
rillig
11abe8f648 lint: use bool instead of u_int:1 in structures
Better late than never.
2021-01-02 01:06:15 +00:00
rillig
d82779b6ab lint: add debug logging for initialization using named members 2021-01-01 20:02:56 +00:00
rillig
2cd5c1a7b9 lint: document that C99-style initialization is necessarily buggy 2021-01-01 19:28:51 +00:00
rillig
5796421e62 lint: un-export struct istk 2021-01-01 19:15:58 +00:00
rillig
c1c5b23632 lint: fix wrong warning about bitfield in C99 structure initialization
The variable namemem is supposed to be a circular list, which is
"documented" implicitly in push_member.

The implementation was buggy though.  In pop_member, the circular list
was destroyed though.  Given the list (capital, major, favorite_color,
green), removing capital made major point to itself in the forward
direction, even though it should not have been modified at all.

In the test, I had been too optimistic to quickly understand the code
around variable initialization.  I was wrong though, so I had to adjust
the comments there to reality.
2021-01-01 19:11:19 +00:00
rillig
59e2f0df9e lint: demonstrate bug in handling of nested C9X struct initializers 2021-01-01 16:50:47 +00:00
rillig
2839f6f6bd lint: remove custom LINTFLAGS
These flags are missing the options -g (GNUisms) and -S (C9X mode).
Without these flags, NetBSD's system headers cannot be compiled as they
make heavy use of __inline and __attribute__.
2021-01-01 14:51:44 +00:00
rillig
836dfa4dee lint: combine duplicate case branches in popdecl
This works around GCC 9, which didn't see that the following statement
cannot terminate normally, even though 0 is obviously a constant expression
and assert_failed is marked as __attribute__((__noreturn__)).

	do {
		if (!(0))
			assert_failed(...);
	} while (0)
2021-01-01 14:11:20 +00:00
kre
d3bf6df7dc Build breakage fix (hopefully) - brain dead gcc. NFCI. 2021-01-01 13:43:34 +00:00
rillig
c4649232b6 lint: rename styp and utyp 2021-01-01 11:58:03 +00:00
rillig
d7a1ba0dec lint: remove NTSPEC from enum tspec_t
The number of elements in an enumeration is not a valid enum constant of
that enumeration itself.
2021-01-01 11:51:15 +00:00