Commit Graph

17831 Commits

Author SHA1 Message Date
rillig
063d68d52b lint: reduce duplicate code for parsing .ln files 2021-04-18 21:12:50 +00:00
rillig
8edef9ff6a lint: fix error message in lint2 for missing record type in .ln file 2021-04-18 20:40:51 +00:00
rillig
fd674c8ffb lint: clean up option parsing 2021-04-18 20:15:17 +00:00
rillig
3f5e7494f3 lint: test emitting of symbol information in the .ln files
Even though the new test is quite large, it didn't find any bugs in the
code.  The only thing I'm unsure about is why static functions are
exported as well, since they are supposed to be local to the translation
unit.
2021-04-18 20:02:56 +00:00
rillig
9941f15572 lint: rename parameter to expr
That parameter used to be used for a single purpose, later it got used
for checking the reachability as well, which made the name misleading.
2021-04-18 17:54:33 +00:00
rillig
dd5ca14fc1 lint: remove redundant CONSTCOND
In do-while-0 loops, these are no longer needed since tree.c 1.202 from
2021-01-31.
2021-04-18 17:47:32 +00:00
rillig
6de49ab08a lint: pass pos_t via const pointer
Thanks for the suggestion, christos@.
2021-04-18 17:36:18 +00:00
rillig
e87d5ae6f7 lint: rename parameter to diagnostic functions and macros
The first parameter is not just an arbitrary number, it's a message ID.
2021-04-18 10:09:49 +00:00
rillig
bc66c81fb4 lint: align the member access macros for tnode_t 2021-04-18 10:04:23 +00:00
rillig
2e8075d978 lint: flip parameters in verror_at, vwarning_at, vmessage_at
The parameters are in the same order now as in the corresponding macros.
2021-04-18 10:02:16 +00:00
rillig
06b9102e6b lint: extend documentation about handling initializations 2021-04-18 09:53:03 +00:00
rillig
0fa816d74c lint: remove redundant test for tflag in initialization handling 2021-04-18 09:50:00 +00:00
rillig
1afc787893 lint: migrate global_clean_up_decl to warning_at 2021-04-18 09:39:53 +00:00
rillig
381fecf673 lint: preserve curr_pos when checking whether a symbol is used
At the end of a function definition (funcend), curr_pos was not
restored, probably because the very next action is to read the next
token, which will then set curr_pos.

Again, this may affect the location reported in assertion failures,
everything else is unchanged.
2021-04-18 09:37:18 +00:00
rillig
7dcdec7722 lint: do not modify curr_pos in check_global_symbols
No functional change.
2021-04-18 09:20:43 +00:00
rillig
4dc66409e9 lint: in check_global_variable_size, restore curr_pos
This affects only calls to lint_assert, all other code stays
functionally the same.
2021-04-18 09:15:16 +00:00
rillig
b9784b3ffa lint: migrate check_tag_usage to warning_at
This one is already a little trickier since it does not restore the
original curr_pos.  This function is only called in a few places, and
these either restore curr_pos themselves or only call functions
afterwards that immediately overwrite curr_pos.

Except for lint_assert, which may now report a different location.

The call to check_global_variable that is related to check_tag_usage was
the function that started this whole refactoring since its lint_assert
reported a completely wrong location when using a compound literal in an
initializer expression at block level 0.
2021-04-18 09:07:36 +00:00
rillig
ef084fd475 lint: migrate print_previous_declaration to message_at 2021-04-18 08:57:57 +00:00
rillig
152aae6b2f lint: migrate the getopt check to warning_at 2021-04-18 08:53:35 +00:00
rillig
1052a4a017 lint: add error_at, warning_at, message_at
Right now there are several places in the code that use the global
variable curr_pos for passing a parameter to the diagnostic functions.
That's not what global variables are for.

Make it easy for the code to migrate to the parameter-passing style.

No functional change.
2021-04-18 08:52:04 +00:00
rillig
48ee035ba0 lint: do not allow the diagnostics to be modified 2021-04-18 08:07:04 +00:00
rillig
1cf5b1560c lint: fix storage class of compound literal in initializer
A compound literal that occurs at block_level 0 does not have storage
class AUTO.  Instead, its storage class is either EXTERN or STATIC.

While removing the temporary objects from the symbol table had prevented
the assertion, it did not properly fix the underlying problem, which was
that since C99 the initializers can contain references to unnamed
objects that are created on-the-fly.  For C90 it was correct to always
use AUTO as the storage class of a temporary symbol.
2021-04-18 08:00:13 +00:00
rillig
73b70e7b0b lint: document wrong location information in diagnostics 2021-04-18 07:31:47 +00:00
rillig
0580bd7587 lint: fix assertion failure for temporary objects in initialization 2021-04-17 21:20:08 +00:00
rillig
c322b8c5b5 lint: do not warn about alignment when casting from incomplete struct
This removes a bunch of technically correct but practically useless
warnings from the regular NetBSD build.
2021-04-17 16:58:04 +00:00
rillig
3c425c406d lint1: remove redundant dependency
This is already handled by "make depend".
2021-04-17 11:01:34 +00:00
maya
5858bd6b8c Remove SCCS workarounds. No binary change. 2021-04-17 08:34:27 +00:00
maya
d8cc1107df Remove SCCS workarounds. No binary change. 2021-04-17 06:14:15 +00:00
christos
5f835dcadf appease gcc-9 2021-04-17 00:02:19 +00:00
christos
e598b150b9 PR/56112: Justin Parrott: Don't unlink a lock file without locking it, because
you can have races when multiple processes try to unlink it. Check the link
count to see if we have won the race.

While here:
- use snprintf
- use warn
- use size_t/ssize_t
- use loops instead of goto
- KNF
2021-04-16 22:41:12 +00:00
christos
4a8f7c3df0 make value an int to avoid all the casts and conversion warnings. 2021-04-16 18:31:28 +00:00
rillig
9e5a82eed4 make: use distinct wording for writing to the shell commands file
The word 'write' now means to write to the file that holds the shell
commands to be run later.

The word 'print' is now used exclusively for handling the output of the
child commands and printing them to make's stdout.

No functional change.
2021-04-16 16:49:27 +00:00
rillig
32bd955566 make: align name of jobs_table_dump to the other functions 2021-04-16 16:10:01 +00:00
christos
f1d025f4e1 Change octal and hex parsing to not use strtoul so that they don't handle
'-'. From Martijn van Duren.
Also add a warning if the conversion fails (like the gnu printf does)
2021-04-16 15:10:18 +00:00
rillig
87e1399e00 make: remove type name for the abort status in job handling 2021-04-15 19:06:42 +00:00
rillig
b089333f2a tests/make: demonstrate handling of null bytes 2021-04-15 19:02:29 +00:00
rillig
b1928e38b6 make: rename PrintOutput to PrintFilteredOutput to avoid confusion
In the default configuration, the function PrintOutput did nothing.
Only if the shell has defined an output filter, something happens at
all.
2021-04-15 18:36:17 +00:00
rillig
d11aa0ae3d make: document two previously unknown bugs in job mode 2021-04-15 18:21:27 +00:00
rillig
507ed84ad7 lint: remove stray semicolon from grammar, make empty rule visible
No functional change.
2021-04-14 22:08:28 +00:00
christos
4d60a3d6f9 there is also an optional type qualifier list in the array size 2021-04-14 21:20:21 +00:00
christos
268a84db7b gnu enables c11 extensions 2021-04-14 21:20:02 +00:00
rillig
9103e93ec9 lint: un-abbreviate code for passing options to cpp, lint1 and lint2
No functional change.
2021-04-14 20:35:31 +00:00
rillig
3874a90eb6 lint: add option to accept C11 features
The list of available letters for the command line options gets shorter
and shorter.  Most of the interesting letters are already used for some
warning categories.  Curiously, -A, -W and -E were all still available.

The option -A nicely matches the intention of the option, which is to
allow a certain set of language features.  To keep the option available
for further extensions, define -Ac11 as the currently only valid option
of that kind.  This allows straight-forward extension for C17 and future
language standards, as well as independent feature-sets.  The options -W
and -E may someday complement the -A option, using the allow/warn/error
categories.
2021-04-14 20:06:40 +00:00
rillig
c58b6a91cc lint: arrange options in the usage messages
* lowercase the word 'usage'
* group the preprocessor flags on a line of their own
* add missing closing ']' for '-X'
* properly indent the lines
2021-04-14 19:25:48 +00:00
rillig
08565001cc lint: remove redundant condition in update_location 2021-04-14 18:38:06 +00:00
rillig
67509c5839 lint: add support for C11-isms such as int[static 3] 2021-04-14 18:35:40 +00:00
rillig
6aa88d9625 lint: add test for newly added message about static array size 2021-04-14 18:27:11 +00:00
rillig
b40d5c12d2 make: let the compiler decide whether to inline string functions
On x86_64, this reduces the binary size by 2 kB.
2021-04-14 17:39:11 +00:00
rillig
56af7cb8e9 make: turn run-time string concatenation into compile-time
No functional change.
2021-04-14 17:24:48 +00:00
rillig
d6aef06ed9 make: remove unnecessary modifier ':U' for certain fixed expressions
No functional change, since the expression is evaluated using
VARE_WANTRES, not using VARE_UNDEFERR.
2021-04-14 17:20:48 +00:00
rillig
278b3755f7 make: reduce memory allocations in the modifiers ':D' and ':U' 2021-04-14 16:59:34 +00:00
rillig
e7ab8fe199 make: rename members of ModifyWord_LoopArgs
No functional change.
2021-04-14 16:12:26 +00:00
rillig
be9afdd585 make: clean up pattern flags for the modifiers ':S' and ':C'
No special handling is necessary for C90 since none of the struct
members is a const_member.

The prefix 'Var' is not necessary since this type does not apply to a
variable but only to a modifier.

No functional change.
2021-04-14 15:41:08 +00:00
christos
c5e4c84a3f support parsing c99's static class for array size expressions. 2021-04-14 13:34:08 +00:00
christos
72044c4d9b Allow type attributes after function pointer parameters 2021-04-13 22:22:02 +00:00
mrg
97b36aa771 more GCC 10 fixes.
mDNSResponder: another wrong return local address

dhcp: ignore a seemingly impossible stringop overflow

hpacel: avoid maybe uninitialised error that is wrong.

rsh: avoid impossible malloc(0)

udf: cast pointers through (uintptr_t) to fool invalid boundary checks
2021-04-13 06:25:48 +00:00
mrg
28fe3b2bee ensure that pointer is filled in when used upon return. 2021-04-13 03:09:42 +00:00
mrg
a96299c3e9 increase the size of a buffer by 1 byte.
i think GCC 10 is right here.
2021-04-13 02:07:35 +00:00
mrg
af153cbd78 properly terminate a string after strncpy(). 2021-04-13 01:38:04 +00:00
rillig
1bda87efba make: spell SysV in mixed case
No functional change.
2021-04-12 18:53:51 +00:00
rillig
36d6de73c9 make: reduce memory allocation and strlen calls in modifier ':from=to'
Previously, SysVMatch was quite verbose and felt like hand-optimized
assembler code, which made it difficult to discover the underlying idea
of the code.

All this code was replaced with two simple calls to Substring_HasPrefix
and Substring_HasSuffix.  Now that the operands of that modifier are no
longer passed as C strings, there is no need to collect all information
in a single scan through the word and the pattern.

It was not necessary to call Var_Subst unconditionally.  Calling it only
when the string contains a '$' saves another memory allocation and two
string copies (because of the Buf_DoneDataCompact).

No functional change.
2021-04-12 18:48:00 +00:00
rillig
8c934898f4 tests/make: fix test for modifier ':from=to'
I had forgotten to remove the single quotes, to produce a really empty
word.  Plus I had forgotten the modifier ':Q' for the result, which
meant that the single quotes did not show up in the output.
2021-04-12 16:09:57 +00:00
rillig
c0e41e6979 tests/make: add table test for the modifier ':from=to'
Just to prevent any accidental change in the upcoming refactoring to
reduce memory allocation in ApplyModifier_SysV.
2021-04-12 16:04:30 +00:00
christos
72ade848da Add attribute fallthrough 2021-04-12 15:55:26 +00:00
rillig
3a16441db8 make: in the ':Q' modifier, only allocate memory if necessary 2021-04-12 13:28:35 +00:00
rillig
a63a77a103 make: improve performance for LazyBuf
The previous O(n^2) time complexity for parsing a long string with many
variable expressions was not meant to last for long.  I had hoped to fix
it within a few minutes, but that will take more time.

For now, make LazyBuf simpler by using a traditional C string for the
expected part instead of a Substring.  This avoids a strlen call per
Var_Parse.

No functional change, only performance.
2021-04-11 22:53:45 +00:00
rillig
c8f17e3691 make: remove redundant parameter from ParseVarnameLong
No functional change.
2021-04-11 21:29:57 +00:00
rillig
5a149d2862 make: migrate ParseModifierPart to use Substring
This will reduce memory allocation for modifier parts without the escape
characters '$' or '\'.

No functional change.
2021-04-11 20:38:43 +00:00
rillig
b740ab5e2d make: avoid unnecessary calls to strlen when evaluating modifiers
No functional change.
2021-04-11 19:05:06 +00:00
rillig
3e3ada833b make: migrate ModifyWord functions to use Substring
This benefits the modifiers ':T' and ':H' since these scan the word from
the end.  The SysV modifier '.c=.o' does not benefit yet, this will be
done in a follow-up commit.

Currently ModifyWords calls strlen for each single word, which degrades
performance.  This will be cleaned up in a follow-up commit as well.

No functional change.
2021-04-11 18:44:57 +00:00
rillig
ecded382bc make: migrate handling of the modifier ':S,from,to,' to Substring
Right now this does not gain any performance, it only makes the code in
ModifyWord_Subst a little simpler since it only uses
Buf_AddBytesBetween, not a mixture with Buf_AddBytes.

When the word passed to the ModifyWord functions is converted to
Substring as well, the call to strlen will become redundant.

No functional change.
2021-04-11 17:48:01 +00:00
rillig
3e21e61f57 make: clean up remaining references to VarEvalFlags
VarEvalFlags has been replaced with VarEvalMode.  There were some
comments and tests that still referred to the old names.

No functional change.
2021-04-11 13:35:56 +00:00
rillig
04a60cfd07 make: avoid allocating memory for simple variable names
The main change is in ParseVarname, where a Buffer is replaced with the
newly introduced LazyBuf.  LazyBuf is inspired by
https://golang.org/src/path/path.go.

In CanonicalVarname, the pre-comparison of the first letter of the
variable name is no longer necessary.  GCC 9 optimizes a fixed-length
memcmp so well that the code can finally be written to target human
readers, leaving the optimization to the compiler.
2021-04-11 12:46:54 +00:00
rillig
b306e574c3 make: add types Substring and LazyBuf
These will be used for making the string handling more efficient,
avoiding allocations, especially when evaluating variable expressions.

Since the string handling has grown quite a bit in the last months,
extract it into its own header file.

No functional change.
2021-04-11 12:06:53 +00:00
rillig
48cf19f100 make: clean up Makefile
The dependencies on the header files are handled by 'make depend'.  They
do not need to be spelled out.
2021-04-11 11:41:27 +00:00
rillig
029cbc1c59 lint: fix build (missing include directory) 2021-04-10 23:51:37 +00:00
rillig
38ecb15534 make: fix out-of-bounds read in Var_Parse_FastLane (since 30 minutes)
This bug made the test varmod-edge.mk fail sometimes with varying error
messages, as can be expected for an out-of-bounds read.
2021-04-10 22:40:34 +00:00
rillig
ce0d1d2b03 make: reword debug log message for empty variable name
The function names did not match anymore, after one of the many
refactorings in the last few months.
2021-04-10 22:35:02 +00:00
rillig
9a44fe3a42 make: reduce debug logging and memory allocation for ${:U...}
Expressions of the form ${:U...} are often generated by .for loops.
Since these expressions are not generated knowingly by the make user, do
not fill the debug log with them since that would interrupt the normal
reading flow of the -dv log for nested expressions.
2021-04-10 22:09:54 +00:00
rillig
3bb1cbc2ae make: reduce debug logging and memory allocation for ${:U...}
Expressions of the form ${:U...} are often generated by .for loops.
Since these expressions are not generated knowingly by the make user, do
not fill the debug log with them since that would interrupt the normal
reading flow of the -dv log for nested expressions.
2021-04-10 22:09:53 +00:00
rillig
07861fad6f lint: use distinct struct tags for type_t in lint1 and lint2
Having two similar but still different definitions of 'struct type' is
unnecessarily confusing.  Exchange this confusion for 8 lines of
straight-forward preprocessing code.
2021-04-10 18:36:27 +00:00
rillig
15ece57a54 lint: prepare renaming of 'struct type'
It's confusing to have the same struct tag in both lint1 and lint2, with
mostly the same members, but also some differences.  Before actually
changing this, I reviewed all occurrences of the word 'type' in the
code.

No functional change.
2021-04-10 18:06:53 +00:00
rillig
8ffcb97a78 lint: fix initialization with brace-enclosed string literal
C99 allows this form in 6.7.8p14 and p15.

The previous lint tests did not cover the case of an array at the top
level of the object to be initialized, they only covered the error cases
(d_c99_init.c, variables 'prefixed_message' and 'message_with_suffix').

Lint is now more generous than strictly required by C99, but since GCC
and Clang already cover the case of 'message_with_suffix', this is ok.

The test d_init_array_using_string.c was wrong before in rejecting the
initializer for 'extra_braces'.  I had tested that Clang generated a
warning for this, but I had not inspected its warning carefully enough.
Clang had not warned about the extra braces but only about a type
mismatch since I tested on a platform where wchar_t was 16 bit.
2021-04-09 23:03:26 +00:00
rillig
c1c59b2873 lint: fix wrong warning about uninitialized _Complex variable
Seen in divxc3.c.
2021-04-09 21:42:12 +00:00
rillig
18955dccde lint: quote placeholders in messages for unused variables 2021-04-09 20:12:00 +00:00
rillig
f9065e3b5b lint: do not warn about pointer conversion to or from incomplete type
This cuts down the warnings in a NetBSD release build by about 38,000.
2021-04-09 20:00:06 +00:00
rillig
0d9b51c034 lint: clean up the check for pointer conversions
No functional change.
2021-04-09 19:52:59 +00:00
rillig
9c458e1376 lint: for structs and unions, include incompleteness in the type name
This mainly helps to assess the situation where lint warns that a
pointer cast "may be troublesome", see msg_247.exp.
2021-04-09 19:37:39 +00:00
rillig
eec39f7564 lint: clean up handling of preprocessing output lines
No functional change.
2021-04-09 15:58:43 +00:00
christos
a31556df76 Don't use a shell pattern to copy files, copy them explicitly. When running
as non-root, [at]*.mk matches archive.mk which we already copied. This was
copied as 444 and trying to overwrite it gives EACCES.
2021-04-09 14:42:00 +00:00
rillig
ee726345e6 lint: in code from included files, print stack trace
Previously, the standard NetBSD build generated several lint warnings in
lhash.h from OpenSSL, without providing any hint as to which file
actually included that header.  In cases like these, lint now interprets
the line number information in the preprocessor output from GCC to
reconstruct the exact include path to the file in question.

The program check-expect.lua had to be rewritten almost completely since
it assumed that all diagnostics would come from the main file.  In all
existing tests, this was true, but these tests did not cover all cases
that occurred in practice.  Now it records the complete location of the
diagnostic instead of just the line number.
2021-04-08 22:18:26 +00:00
rillig
50e0ad27e4 lint: don't warn about cast between pointers to compatible structs 2021-04-08 19:20:54 +00:00
nia
35fbfbb85b audiocfg(1): add examples 2021-04-07 09:58:58 +00:00
rillig
b5412104dc lint: sync comment with reality after renaming several functions
No functional change.
2021-04-06 22:21:53 +00:00
rillig
b4b7f28d0e lint: for shift in C99 mode, do not warn about difference to pre-C90
C99 is too far away from traditional C to make this warning useful.
There are 3 different situations in which this warning is generated:

For '1 << (unsigned char)1', the result type is 'unsigned int' in
traditional C.  The result type is unsigned because at least 1 of the
operators is unsigned, and it is 'unsigned int' because the usual
arithmetic promotions are applied.

For '1 >> (long)1', as well as for '1 << (long)1', the result type is
'long' in traditional C since the usual arithmetic promotions are
applied.

Omitting this warning in C99 mode reduces the amount of lint warnings in
a typical NetBSD release build by approximately 6800 of 107000 total.
2021-04-06 21:59:58 +00:00
rillig
a32b9aafdf lint: reduce indentation of typeok_shift
No functional change.
2021-04-06 21:35:25 +00:00
rillig
4148550ebb lint: add details to warning about too large shift amount
The previous message 'shift greater than size of object' was too short
to give reasonable hints, especially when the expressions involve
typedefs or macros.
2021-04-06 21:32:57 +00:00
rillig
4329029317 lint: fix wrong warning about losing accuracy when converting to _Bool 2021-04-06 21:17:27 +00:00
rillig
279f657cbd lint: move check for strict bool mode into separate file
No functional change.
2021-04-06 13:17:04 +00:00
rillig
194772e0d9 make: reduce verbosity of the -dv debug logging for standard cases
The verbosity was already removed from LogBeforeApply, now it is
consistent between LogBeforeApply and LogAfterApply.
2021-04-06 01:38:39 +00:00