Commit Graph

447 Commits

Author SHA1 Message Date
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
rillig
f78ee5c0ea lint: add missing redundant messages in source code 2021-01-01 11:41:01 +00:00
rillig
cc7508a53e lint: complete message 203 for case labels 2021-01-01 11:14:06 +00:00
rillig
ffe80b8ff2 lint: rename tokens for left and right parentheses 2021-01-01 11:09:40 +00:00
rillig
124253e8af lint: extract main part of case_label into separate function 2021-01-01 11:01:03 +00:00
rillig
620f102450 lint: split label handling into separate functions
The only thing these cases have in common is the name "label" and the
"reached = 1" assignment.  That's not reason enough to combine
completely unrelated functions.
2021-01-01 10:55:27 +00:00
rillig
cca12cba58 lint: replace simple LERROR with lint_assert 2021-01-01 09:28:22 +00:00
rillig
194bb9b625 lint: replace some more LERROR with lint_assert 2021-01-01 09:11:40 +00:00
rillig
259b122f43 lint: rename basic_type_name to tspec_name
The term "basic type" is precisely defined in C99 6.2.5p14, and tspec_t
is close to that, but nowhere identical.
2021-01-01 01:42:55 +00:00
rillig
15ccb490cc lint: clean up warn_incompatible_types
Splitting the code arbitrarily in separate phases made the code harder
to understand, both for humans as well as automated tools.

One of these tools, check-msgs.lua, couldn't check whether the comments
match the actual messages, and of course, the comments were wrong.
There was no good reason to deviate from the pattern followed by all the
rest of the code.
2021-01-01 01:38:14 +00:00
rillig
5cf99a8e7a lint: remove redundant printf arguments 2021-01-01 01:29:30 +00:00
rillig
6451720632 lint: align comments with actual message, in the lexer and parser 2021-01-01 01:26:02 +00:00
rillig
e93292def1 lint: fix segmentation fault when checking returned enum types (211) 2021-01-01 01:07:07 +00:00
rillig
d4b0f2fea7 lint: align comments in code with actual messages
Redundancy is bad.  Especially in this case, separating the format
strings from the actual arguments prevents the compiler from
cross-checking them.
2021-01-01 00:00:24 +00:00
rillig
2e28c52323 lint: check messages and their IDs for consistency 2020-12-31 22:48:33 +00:00
rillig
ee607e0b85 lint: check that in "if (cond)", cond is scalar 2020-12-31 18:51:28 +00:00
rillig
fbeb97dcac lint: in mkops, replace printf with println
One less backslash per line of code.
2020-12-31 16:19:05 +00:00
rillig
0197fc8fc4 lint: split cluparg into separate functions
That function did more than its short name could express, and the things
it did were not related in any way.
2020-12-30 13:17:42 +00:00
rillig
47bf7e655e lint: replace LERROR with lint_assert
This removes the redundancy of mentioning the function name in the error
message.  This redundancy had been correct in all but 2 cases:
build_real_imag and tsize.
2020-12-30 12:22:51 +00:00
rillig
6bddcb2931 lint: spell check comments 2020-12-30 11:56:10 +00:00
rillig
ea78491f30 lint: inline STRUCT_ASSIGN
This had only been necessary for some pre-C90 compilers.
2020-12-30 11:39:55 +00:00