Commit Graph

18186 Commits

Author SHA1 Message Date
rillig 0343dc604a lint: remove 8 of the grammar conflicts, 142 remaining
No functional change.
2021-07-10 04:57:41 +00:00
rillig 5a5d3bc5b2 lint: merge duplicate code in declmods and declmod
No functional change.
2021-07-10 04:47:25 +00:00
rillig 0f07dd8016 lint: remove duplicate code for parsing declarations
No functional change.
2021-07-10 04:25:47 +00:00
rillig 154b71395a lint: remove 6 conflicts from the grammar, in type_direct_decl
No functional change.
2021-07-09 20:51:27 +00:00
rillig a9a95a6338 lint: remove 6 of the remaining 162 conflicts from the grammar
No functional change.
2021-07-09 20:36:34 +00:00
rillig 6818082fe2 lint: indent grammar actions properly
No functional change.
2021-07-09 06:37:11 +00:00
rillig 4114c20a2b lint: fix assignment to midrule in grammar (since today)
When compiling the grammar with Bison, it complains:

	error: $$ for the midrule at $2 of 'struct' has no declared type

Yacc does not complain, instead it assumes that a midrule has the same
type as the rule itself.

The assignment '$$ = $1' in the midrule action does not influence the $$
of the whole rule, it only assigns to $2.  The assignment to $$ was done
via the default action, therefore everything worked as expected.  Any
missing assignment in this rule would have been caught quickly by the
strict assertion in mktag.

No functional change.
2021-07-08 19:08:03 +00:00
rillig edf4510155 lint: fix wrong check for enum constants in switch (since today) 2021-07-08 18:53:57 +00:00
rillig a94824d394 lint: demonstrate bug in handling enum declarations (since today)
Since cgram.y 1.270 from today (a "cleanup" commit), the enum constants
were only registered in the symbol table, but they were not added to the
enum type (en_first_enumerator).  That information is used for
validating switch statements on enum types.

The actual bug is an off-by-one error in the grammar, in the grammar
rule 'enum_declaration'.  Yacc does not notice this obvious error.
Bison does, but it is not involved in building lint.

In the grammar rule 'enum_declaration', the intended $3 contains the
first enumeration constant of the type, while $2, which yacc interprets
as a symbol, contains a null pointer, at least on x86_64.

The existing tests did not cover this scenario, so the bug went
unnoticed.
2021-07-08 18:50:57 +00:00
rillig 3a16f78e73 lint: add grammar rule type_attribute_list_opt
Since type attributes (and GCC attributes as well) often modify the
preceding identifier, without referring to $$, the easiest way to
integrate them into the grammar is to define a separate grammar rule
that can be placed wherever these attributes are allowed.  This avoids
duplicate actions like in direct_param_decl.

No functional change.
2021-07-08 04:09:10 +00:00
rillig 79667b1e11 lint: clean up grammar
enum_decl_lbrace was only used once and was small enough to be inlined.

Renamed expr_statement and added block_item_list_opt to match the
wording from C99.

Added references to C99.

No functional change.
2021-07-08 03:55:54 +00:00
rillig c42555c28a lint: clean up grammar for member declarations
No functional change.
2021-07-08 03:35:07 +00:00
rillig 7580978075 lint: move optional grammar rules above their corresponding rules
No functional change.
2021-07-08 03:22:47 +00:00
rillig 509717aced lint: move grammar rules for generic_selection around
They were misplaced between the statements, as they belong to the
expressions, as indicated by the C99 section number.

No functional change.
2021-07-08 03:19:17 +00:00
rillig 85a42ed97b lint: remove irrelevant type information from __attribute__ tokens
The grammar once declared that an __attribute__ contained type
information, but that was not used anyway.

No functional change.
2021-07-08 03:14:56 +00:00
rillig aa99fa9f49 lint: remove double negation in comment
No functional change.
2021-07-08 03:10:39 +00:00
rillig 7cd2fbf849 lint: constify keyword in lexer
No functional change.
2021-07-08 02:59:22 +00:00
martin 5c18a11ba1 Allow to set sanitizer flags for the rump build from the
build.sh command line, like: -V RUMP_SANITIZE=address
2021-07-07 11:51:45 +00:00
rillig 7949930972 lint: document further shift/reduce conflicts
These cannot be resolved as easily as those from the previous commit.
Anyway, the relevant code from the grammar is not yet covered by the
tests, this needs to be done first.
2021-07-06 21:41:36 +00:00
rillig 2c0bfe917a lint: document the cause for 24 of the 162 grammar conflicts 2021-07-06 20:56:38 +00:00
rillig 651d9e1434 lint: resolve conflict in grammar for __real__ and __imag__
There is no need for extra rules for '__real__(term)' since that is
already handled by the simpler '__real__ term', just a few lines further
up in the grammar.  Likewise for __imag__.

The GCC manual does not mention anything about parentheses either.
2021-07-06 20:29:08 +00:00
rillig 8636180887 lint: __real__ and __imag__ are GNU extensions
https://gcc.gnu.org/onlinedocs/gcc/Complex.html
2021-07-06 20:17:15 +00:00
rillig cbf601a4c6 lint: do not allow _Alignas (from C11) or __packed after a label 2021-07-06 19:08:28 +00:00
rillig be27375e82 lint: rename grammar rules for GCC __attribute__
No functional change.
2021-07-06 18:28:08 +00:00
rillig 50afc9c6cb lint: move grammar rules for GCC __attribute__ to the bottom
In GCC 2.95.3, attributes had already been available for functions,
variables and types.  At that time they were indeed related to
declarations, and that's where they ended up in lint's grammar.  Later,
attributes were extended to labels, enumerators and statements as well.

To keep the grammar for declarations short and comprehensible, move the
rather large part about __attribute__ at the bottom of the grammar,
creating a new section called "GCC extensions".

The grammar rules are not named accurately (and never were).  They are
called "type attributes" but apply not only to types.  These names will
be improved in a follow-up commit.

No functional change.
2021-07-06 18:22:40 +00:00
rillig 493e3a220b lint: align grammar rules for enum-specifier with C99
No functional change.
2021-07-06 17:52:04 +00:00
rillig 8a9e7adf93 lint: document grammar rule that deviates from C99 2021-07-06 16:02:44 +00:00
christos ee9a791b28 Use raw write(2) instead of fwrite(3) to avoid stream corruption because
of the progress bar interrupts. From RVP.
2021-07-06 09:26:47 +00:00
rillig 01fa1b0b28 lint: rearrange and rename grammar rules for parameter declarations
Place the notype/type variants close to each other to be able to compare
them visually.

No functional change.
2021-07-06 05:39:27 +00:00
rillig ce2ecf346d lint: move the grammar rule array_size out of the type/notype section
An array size is used in several grammar rules for different types of
declarations, therefore it doesn't make sense to place that rule
somewhere in the middle, where it disrupted the flow of notype/type
rules.  The whole point of having the notype/type rules grouped is to be
able to quickly compare them, since they are almost equal.

No functional change.
2021-07-06 05:22:34 +00:00
rillig 9c9cafe7a2 lint: reduce grammar conflicts for GCC attributes
In all but one case, the use of type_attribute_list introduced an
unnecessary ambiguity in the grammar.  It appeared in a place where it
could be repeated either by the type_attribute_list or by the enclosing
rule.  Both variants have the same effect.

No functional change.
2021-07-06 05:12:44 +00:00
rillig 12376b019b lint: clean up style in grammar
No functional change.
2021-07-06 04:48:17 +00:00
rillig a3946b7223 lint: rename type generic_association_types to generic_association
The word 'types' was misleading and unnecessary.

No functional change.
2021-07-06 04:44:20 +00:00
rillig adc54400fe lint: refer to documentation about the 'notype' rules in the grammar 2021-07-05 19:59:10 +00:00
rillig bb094b3a08 lint: reduce noise in storage_class_name
No functional change.
2021-07-05 19:55:51 +00:00
rillig 7b8a9549f6 lint: rename message 340 to talk about "GCC extension", not "GNU" 2021-07-05 19:53:43 +00:00
rillig a3df5655f7 lint: rename dinfo_t.d_stralign to d_sou_align_in_bits
When talking about alignment, offset and size of a type, the measurement
unit must be mentioned in the variable name, especially when it differs
from the standard unit of measurement, which is a byte, not a bit.

No functional change.
2021-07-05 19:48:32 +00:00
rillig 672b592172 lint: fix type warnings in emit1.c
The plain character strings in strg_t are saved as an array of unsigned
char.  When such a character is passed to ch_isdigit, it requires a
cast.  This is exactly the situation that ch_isdigit tried to avoid in
the first place.

No functional change.
2021-07-05 19:39:12 +00:00
hgutch fb0e1b46a6 GCC git commit 91f66e78cc141da77ff9e0e3c8519e1af3f26c07[1] introduced
a regression in sh.  In addition to the intended change (based on the
commit message), an apparently unintended change was made, inverting a
comparison.  This broke sh builds and our workaround (so far) was to
compile xlint/lint1 with -O0.

Revert the comparison to what it was before and remove the -O0 hack
from xlint/lint1.

[1] https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=91f66e78cc141da77ff9e0e3c8519e1af3f26c07
2021-07-05 10:34:25 +00:00
rillig 17d555dd84 lint: replace wrong assumption with citation from C99
No functional change.
2021-07-04 17:28:05 +00:00
rillig 469326d25e lint: document where to fix missing const in lvalue-to-rvalue
No functional change.
2021-07-04 17:16:09 +00:00
rillig 8b62008a54 lint: align messages for invalid left operand of '.' or '->' 2021-07-04 17:01:58 +00:00
rillig 090f19d307 lint: clean up new_tnode
No functional change.
2021-07-04 16:44:13 +00:00
rillig 12eb88ecaa lint: improve wording for incomplete struct or union 2021-07-04 13:31:10 +00:00
rillig 68c2fce363 lint: remove remaining support for lvalue casts
These had been GCC extensions until GCC 3.4, they were removed in GCC
4.0.
2021-07-04 13:14:53 +00:00
rillig eb81ba228f lint: remove support for obsolete GCC-style lvalue casts
Since GCC 4.0, a cast results in an rvalue.
2021-07-04 12:24:38 +00:00
rillig 79b730c71f lint: in strict bool mode, allow mixed types in generated C code
This allows flex lexers to be run through lint in strict bool mode.
2021-07-04 09:13:59 +00:00
rillig da15f8a834 lint: include scan.c in 'make lint'
This theoretically enables strict bool mode for the few remaining code
in scan.l.  Since scan.l is not yet detected as generated code, all
interesting errors have to be suppressed though.
2021-07-04 08:49:41 +00:00
rillig d5273b4cbf lint: remove outdated assertion
Since err.c 1.12 from 2000-07-06, lint allows to suppress individual
error messages.  Suppressed error messages do not increment nerr.
Keeping nerr at 0 had triggered the assertion.
2021-07-04 08:19:05 +00:00
rillig 8d5c9f256b lint: in strict bool mode, continue after error message
If a controlling expression is not of type bool but of any other scalar
type, keep the expression.  Its value is still useful for control flow
analysis.

This prevents an assertion failure when running lint on the generated
scan.c, which contains a "while (1)" that does not stem from a system
header.  If it did, lint would accept it, see tn_from_system_header. But
"scan.c" is not considered a system header.  Maybe lint's definition of
a system header needs to be revisited.

After fixing this, there is another assertion failure though, so scan.c
is not yet ready to be inspected by lint.
2021-07-04 07:09:39 +00:00
rillig f075e51d8d lint: sync stdout and stderr when compiled in debug mode
If lint is compiled with -DDEBUG, its debug output goes to stdout, no
matter whether the option -d is given or not.
2021-07-04 05:49:20 +00:00
sjg 9ec9d7e560 Do not assume /tmp is safe to use if TMPDIR is set 2021-07-04 01:28:54 +00:00
rillig 1c866cb93c tests/make: make test job-output-null more portable
Previously, the test dependend on implementation details of the system's
printf command.

Thank you sjg for the detailed analysis on macOS, FreeBSD and Linux.
2021-07-03 22:39:40 +00:00
rillig 8de06dd8b6 lint: do not define 'long double' GCC builtins for traditional C 2021-07-03 21:27:48 +00:00
rillig df08ae1a2e lint: guard against segmentation fault when parsing struct
Found by afl.  The code that triggers this case is:

	struct{const}
2021-07-03 21:18:40 +00:00
rillig 101dcba48f lint: fix segmentation fault on malformed preprocessor output
# 0 ""
# 0 ""2

Found using afl, does not happen in practice though since every C
preprocessor generates balanced 'enter' (1) and 'leave' (2) events.
2021-07-03 20:54:08 +00:00
rillig 78c5135ad4 lint: make stdout unbuffered in debug mode
Some debug log messages are on stdout, others on stderr.  Make sure that
they occur in the correct order, even when the output is redirected.
2021-07-03 20:43:35 +00:00
rillig 3bb26a8d1c lint: fix assertion failure in display_expression for bool constants 2021-07-03 20:40:17 +00:00
rillig 645b9bd4df lint: fix initialization of array of unknown size
The size of the resulting array was computed wrong.
2021-07-02 22:46:43 +00:00
rillig 70f3c407f9 lint: in strict bool mode, make (flag & FLAG) simpler
This is a tiny change in an edge case that does not occur in practice,
which is that the left-hand side of the '&' is explicitly cast to an
enum type.  The apparent "loss of information" from the deleted comment
has already been explained in the previous commit.
2021-07-02 21:22:26 +00:00
rillig 6a7428ed1f lint: no special check for unary operators in strict bool mode
All interesting constellations regarding unary operators are already
covered by the simple model from ops.def.

No functional change.
2021-07-02 18:52:20 +00:00
rillig 2910d22772 lint: document lint1_type.t_is_enum
Enum types are subject to implicit conversions, as opposed to struct,
union, pointer and function types.
2021-07-02 18:22:09 +00:00
rillig f63ca675b2 lint: do not warn about use of implicitly declared GCC builtins 2021-06-30 14:42:13 +00:00
rillig 0077b8828b lint: in C99 mode, only warn about implicit function declarations
Since tree.c 1.294 from 2021-06-28 (two days ago), lint errored out on
an implicit function declaration.  In principle it is correct to do so
since C99 requires it, but in practice there are a several functions
that are not declared in the translation unit itself since they are
provided by the compiler.  Typical examples for GCC and Clang are the
various functions named '__builtin_*' and '__atomic_*'.

For now, only warn about these but don't error out.
2021-06-30 14:32:41 +00:00
rillig 46698ec575 lint: mention the name of an implicitly declared function
In the regular NetBSD builds, this happened in swab.c:65.  That line
contains __predict_false, which may or may not be a macro.  In other
cases, there may be more than one function call in a single line.
2021-06-30 14:23:50 +00:00
rillig 19c3587496 lint: fix type name in message 101 for wrong member name 2021-06-30 14:11:08 +00:00
rillig 0af37f53e6 lint: improve comment about INT keeping t_is_enum 2021-06-30 12:28:03 +00:00
rillig 9c3944c3d9 lint: invert condition in control flow analysis of switch statements
The condition previously contained many negations, which was hard to
understand.

No functional change.
2021-06-30 11:29:29 +00:00
rillig a9ef3909b3 lint: fix bit-size of long double _Complex in portable mode
C99 6.2.5p13 says that LCOMPLEX has the same representation and
alignment requirements as an array type containing exactly two LDOUBLE.

When support for _Complex was added to lint in inittyp.c 1.10 from
2008-09-27, there was no explanation for making the bit-size of LCOMPLEX
different from what C99 says, so it was probably a mistake that went
unnoticed for more than 12 years.  It's an edge case anyway.
2021-06-30 10:56:24 +00:00
rillig 0547042064 lint: inline 'sign' into convert_integer
No functional change.
2021-06-30 10:25:02 +00:00
rillig 95d33e8c9b lint: fix wrong warning about out-of-range value '\xff' for char
This only affects platforms where char has the same representation as
unsigned char.
2021-06-29 21:33:08 +00:00
rillig f2ec522ec7 lint: rename xsign to convert_integer
The term sign-extend was too specific, the function actually does a
broader conversion.

No functional change.
2021-06-29 21:16:54 +00:00
rillig 1b367b1b6c lint: do not modify tnode_t->tn_type in check_init_expr
This is a very small step towards having all shared type_t objects only
referenced via const pointers.  Since the types may be shared, it is a
bad idea to try to modify them, so better let the compiler check this.
It's a long way to reach this goal, but this small step is already
possible.

No functional change.
2021-06-29 21:05:32 +00:00
rillig 465b0b6319 lint: do not sign-extend pointers
Sign extension only makes sense for integer types.

No idea why the code had tried to sign-extend pointers for the past 26
years.
2021-06-29 20:44:38 +00:00
rillig 1abf4d0075 lint: document where to fix the wrong warning for '\xff' 2021-06-29 14:19:51 +00:00
rillig 1ae8e740dd lint: clean up lex_character_constant
No functional change.
2021-06-29 13:48:24 +00:00
rillig 27cb0a7146 lint: fix typos in comment 2021-06-29 10:12:35 +00:00
rillig bd046308c8 tests/lint: do not modify t_integration on "make add-test"
The test names are no longer listed individually.
2021-06-29 07:37:34 +00:00
rillig 48c9c61aae lint: fix lexical analysis of character constants in traditional C
The code now follows the wording of the C Reference Manual from 1978.
2021-06-29 07:23:21 +00:00
rillig 8c50963b0a lint: remove comment from grammar rule type_direct_decl
The 'identifier' in type_direct_decl is necessary, as demonstrated in
the test d_typename_as_var.  Replacing T_NAME with 'identifier' in
notype_direct_decl would increase the shift/reduce conflicts by 6.  To
keep this number low, keep everything as-is.
2021-06-29 05:41:45 +00:00
sjg 837626497a Allow BROKEN_TESTS to cause TESTS to be skipped.
Some tests simply do not work in some environments.
Eg. shell-ksh on macos/arm64
Allow local site to set BROKEN_TESTS to skip those they know
will not work.

Reviewed by: rillig
2021-06-29 00:35:23 +00:00
rillig 61e921f9ea lint: in C99 mode, complain about implicitly declared functions
C99, foreword, p5, item 22 lists among the major changes from C90:
"remove implicit function declaration".
2021-06-28 11:27:00 +00:00
rillig d8a3f2eb44 lint: fix parse error for type 'void (*)[*]' 2021-06-28 11:09:35 +00:00
rillig 8b3bb5df80 lint: fix type name for prototype function without parameters 2021-06-28 10:29:05 +00:00
rillig 5953d76ca7 lint: add type information to message 155 (type mismatch) 2021-06-28 10:23:49 +00:00
rillig 3ce5ae23e6 lint: turn null pointer dereference into assertion failure
Originally I only needed a message that would output the type name from
an abstract-declarator (C99 6.7.6), to see whether lint interprets the
types correctly.

Message 155 looked like a good candidate, but it only revealed more
incomplete and untested code in lint.
2021-06-28 10:07:43 +00:00
rillig 72ed3a7a7b lint: rename grammar rules for abstract declarators
The previous name 'decl' was ambiguous, it could have meant declaration
as well as declarator.  The new names are aligned with C99.

No functional change.
2021-06-28 09:40:52 +00:00
rillig 15a96a9261 lint: align grammar with C99
C99 uses type-qualifier-list_opt in section 6.7.5.
2021-06-28 09:14:42 +00:00
mrg 45b6225a1a apply sh3 vs lex.c fix for GCC >= 9. use shorter idiom.
fixes build issue reported by jdbaker in private email.
2021-06-28 09:09:14 +00:00
rillig d90490f802 lint: refrain from renaming the grammar rule 'pointer'
That rule is called 'pointer' by C99 as well.

No functional change.
2021-06-28 09:01:48 +00:00
rillig 059f7d07e3 lint: rename pqinf_t to qual_ptr and clean up code
The 'inf' from the type name meant 'information' and was redundant. Each
object of that type represents a single pointer level, which made the
documentation about 'pointers' a bit confusing.

The members of struct qual_ptr are now in the canonical reading order,
which is 'const volatile pointer'.

No functional change.
2021-06-28 08:52:55 +00:00
rillig 4610aed791 lint: only accept assignment-expression in _Generic
That's what C11 says.
2021-06-28 07:55:05 +00:00
rillig 29345fcf90 lint: consistently use 'opt' as suffix
This corresponds to the usage in the C standards, where 'opt' is used as
a subscripted suffix.

No functional change.
2021-06-27 21:52:18 +00:00
rillig 7c596c19e8 lint: remove redundant '{ $$ = $1; }' from the grammar
In some cases the redundant code had been spelled out, in others it had
been left out.  Be consistent.
2021-06-27 21:46:17 +00:00
rillig 062a2d9cec lint: reorder grammar rules from big to small
No functional change.
2021-06-27 21:36:14 +00:00
rillig 25b67a1f3a lint: fix parsing of _Generic selection expressions
Previously, lint accepted comma-expressions where only
assignment-expressions are allowed.

This change does not make a difference in practice though since lint is
usually only run on source code that properly compiles.  Nevertheless,
rather be precise and accurate since the grammar might some day be
reused on less reliable input.
2021-06-27 21:30:46 +00:00
rillig d4e4f03cef lint: fix type comparison in _Generic selection expressions
In the newly added test comma_expression, there were two distinct type
objects for the tspec DOUBLE.
2021-06-27 21:16:40 +00:00
rillig bd01cfcf51 lint: fix result type of _Generic expressions 2021-06-27 20:47:13 +00:00
rillig cec0b2453a lint: require C11 for _Generic
This does not have any effect in practice since the option -g
(originally meant for GCC extensions to the C standards) implicitly
allows all features from C11, since err.c 1.111 from 2021-04-14.

Since the default lint flags for NetBSD builds include the option -g,
this allows all C11 features.

Currently it is not possible to say "allow GNU extensions but not C11".
2021-06-27 19:10:29 +00:00
rillig 7725923054 lint: sort and rename grammar rules for generic selection
No functional change.
2021-06-27 18:54:14 +00:00
rillig f1f9bbff8d lint: fix option -Ac11, add test for _Generic
Previously, selecting the option -Ac11 allowed features from C11 but at
the same time prohibited 'long long', which was added in C99.  This was
caused by the option -s, which is interpreted as "allow features from
C90, but no later".

The test for _Generic, which has been added in C11, demonstrates that
the current implementation is broken.  Lint currently thinks that the
return type of a _Generic selection is the type of the expression, but
it really is the type of the selected expression.  In the current tests,
this is always 'const char *', but C11 does not require that the types
of a generic selection are compatible.
2021-06-27 18:48:45 +00:00
rillig a15d37431c lint: fix uninitialized variable for declaration after statement 2021-06-27 18:19:13 +00:00
rillig 633216baff lint: proof-read the C grammar, remove unnecessary %type
After the fix from the previous commit (a missing assignment to $$ in an
error case), make sure that there are no other bugs of the same kind, by
manually checking that each rule with a %type assigns $$ in each and
every case.  There is one more instance in block_item_list, but that
does not lead to a crash since it affects only a boolean variable, not a
pointer.

It should not be necessary to check for this class of bugs manually, but
neither BSD yacc nor GNU Bison provide any warning option to help with
this scenario.  They should have remarked that the %type for
type_attribute is never used, since that is easy to detect.  They should
have also warned that the rule for block_item_list does not mention $$
at all.

Detecting the bug from the previous commit would probably be too much to
ask since it involves control flow analysis in the C code.  In this
particular case, it would have been necessary to visit each possible
branch from the 'if' statement and ensure that there is a $$ on the
left-hand side of an assignment.

While here, note down several small inconsistencies in the grammar that
should be fixed in follow-up commits.
2021-06-27 18:03:05 +00:00
rillig 42a93bede8 lint: fix undefined behavior after syntax error 'unnamed member'
There should really be a linter or other check that guards against
forgetting to assign a value to '$$'.
2021-06-27 13:59:29 +00:00
rillig c6b618e6da lint: fix typo in comment for target platform definitions 2021-06-27 08:43:46 +00:00
rillig 161c32bd45 lint: fix type of pqinf.p_pcnt
A counter that can either be 0 or 1 and is never incremented is not
really a counter, it's a flag.

No functional change.
2021-06-27 08:20:50 +00:00
tnn 8a7608a3b3 ensure defined(HAVE_GCC) before use of ${HAVE_GCC} 2021-06-25 20:17:56 +00:00
rillig 281951cf5a make: prevent newline injection in .for loops
When a value of a .for loop contained a literal newline, such as from
the expression ${.newline}, that newline was passed verbatim to the
"expanded current body" of the .for loop.  There it was interpreted as a
literal newline, which ended the current line and started a new one.
This resulted in several syntax errors.

In cases like these, print a more precise error message.
2021-06-25 16:10:07 +00:00
rillig aef5575359 tests/make: demonstrate newline injection in .for loop 2021-06-25 15:56:02 +00:00
rillig c27b1d1ec3 tests/make: test .for loop over a variable named '$'
It's an impractical edge case, nevertheless it's accepted by make.
2021-06-24 23:22:17 +00:00
rillig 96c8c9456a make: sprinkle const 2021-06-24 23:19:52 +00:00
simonb 6c26c0e372 Call check_siginfo() in compression loop to provide SIGINFO compression
progress.
Suggested by mrg@.
2021-06-24 07:16:49 +00:00
rillig c98dd4a405 lint1: add bug report for internal GCC compiler error 2021-06-23 07:11:41 +00:00
martin 157285c8e2 Hack to avoid gcc 9 internal compiler error for sh3. 2021-06-22 12:58:28 +00:00
rillig 2a36eea04d make: fix grammar in error message for malformed conditional 2021-06-21 21:10:01 +00:00
rillig a934c5f08c make: clean up comments in cond.c 2021-06-21 21:07:35 +00:00
rillig 009c8d860a make: use simpler upper bound for length in Buf_AddInt
No functional change.
2021-06-21 19:59:58 +00:00
rillig 4f1b4c49e1 make: replace macro is_shell_metachar with inline function
No functional change.
2021-06-21 18:54:41 +00:00
rillig 671a83268e make: use more practical data type in RegexReplace
While size_t is most appropriate for array indexes, make needs to be
compatible with C90, which does not support the %zu printf conversion.
To avoid type casts, use a simple unsigned int here, which is more than
enough for storing a single decimal digit.

No functional change.
2021-06-21 18:25:20 +00:00
rillig d90d0e20bd make: extract RegexReplace from ModifyWord_SubstRegex
No functional change.
2021-06-21 18:12:49 +00:00
rillig 8c39b4bff5 make: move all labels in ModifyWord_SubstRegex to the same level
No functional change.
2021-06-21 17:52:33 +00:00
rillig d1d9ce67a0 make: reduce indentation in ModifyWord_SubstRegex for ':C'
No functional change.
2021-06-21 17:21:37 +00:00
rillig 8e716a5983 make: eliminate local variable in Substring_Words
No functional change.
2021-06-21 16:59:18 +00:00
rillig 55e7ff5dbb make: document ParseDependencyOp 2021-06-21 10:42:06 +00:00
rillig 030187f9a8 make: document where to find tests for the dependency lines 2021-06-21 10:33:11 +00:00
rillig 6a3490c124 make: extract ParseDependencySources from ParseDependency
No functional change.
2021-06-21 10:29:08 +00:00
rillig 736d9284e1 make: fix documentation for ParseModifierPart 2021-06-21 08:40:44 +00:00
rillig fcb4d29810 tests/make: remove unnecessary -dL from moderrs.mk
It was only needed for the test for unmatched subexpressions in the
modifier ':C'.  That test has been moved to varmod-subst-regex.mk.
2021-06-21 08:28:37 +00:00
rillig 69b903452e tests/make: move and extend test for unmatched '\1' in ':C'
This test lived together with a few unrelated tests in moderrs.mk, it is
better placed in varmod-subst-regex.mk though.

While here, extend, document and explain the test since its purpose was
not obvious from reading the code alone.
2021-06-21 08:17:39 +00:00
sjg af2dd17048 Do not report unmatched regex subexpressions
It is not always an error for a subexpression to have not matched,
since the regex library can/does not convey how many matches are
expected, only report an error if opts.strict (-dL)

Reviewed by: christos
2021-06-21 04:24:17 +00:00
christos 3151045394 fix proplib deprecation 2021-06-21 03:04:27 +00:00
rillig df33d65f6d lint: remove unused print_tnode
The function display_expression serves the same purpose and prints more
details.
2021-06-20 20:59:08 +00:00
rillig cf5c3cc8d5 lint: remove unnecessary call to print_tnode
For the possible operators that occur in message 324, print_tnode is
equivalent to op_name, and the latter is simpler.

When the function print_node was added to the code base, it had another
use in init.c, for understanding how initialization works in lint.  That
code has since been rewritten completely, therefore print_tnode is no
longer needed.  For debugging, display_expression is the better choice
since it has multi-line output and does not suffer from a fixed-length
buffer.

No functional change.
2021-06-20 20:48:25 +00:00
rillig 5bf918ef4b lint: rename val_t.v_unsigned to avoid confusion
The name v_unsigned suggested that the value would be interpreted as
unsigned, which was wrong.  Whether a value is signed or unsigned is
decided by v_tspec instead.

Revert the previous commit for boolen constants since their value is
already interpreted as unsigned, and there is no need for any warning
about differences between traditional C and ANSI C since the _Bool type
has only been added ten years later in C99.

The code for printing a tree node was also confused by this struct
member, even with its old name v_ansiu.  That code will be fixed in a
follow-up commit.

No functional change.
2021-06-20 20:32:42 +00:00
rillig 1cd88fa065 lint: in strict bool mode, treat boolean constants as unsigned
In strict bool mode, bool is not an arithmetic type anyway, therefore it
doesn't matter whether the type is signed or unsigned.

C99 6.2.5p6 defines _Bool as one of the "standard unsigned integer
types", so making the constants unsigned is more accurate.

No functional change.
2021-06-20 19:15:58 +00:00
rillig b21f26247f lint: rename val_t.v_ansiu to v_unsigned
When lint was written in 1995, traditional C was still nearby since C90
had been around for only 5 years.  26 years later, almost all code
adheres to C90 or even C99 or C11, therefore "C90 or later" can safely
be assumed as the default.

No functional change.
2021-06-20 19:04:50 +00:00
rillig 3b0c4330c1 lint: sprinkle const in memory management
No functional change.
2021-06-20 18:51:50 +00:00
rillig 2bdf9055a3 lint: fix confusing variable name in lex_wide_character_constant
By convention, i is an index, not a count.

No functional change.
2021-06-20 18:44:48 +00:00
rillig feed52b6e1 lint: reduce indentation in lexer for character constants
No functional change.
2021-06-20 18:41:27 +00:00
rillig 38b6e324bc lint: fix check for empty wide character constant
This bug got almost 26 years old, it was already there at the initial
commit in 1995.
2021-06-20 18:38:12 +00:00
rillig abf598ed25 lint: use different tokens for operators '.' and '->'
Before C99, these tokens were only used in member access expressions.
C99 reused the operator '.' in initializations of structs and unions.
Let the grammar check for syntax errors instead of writing custom code.

No functional change.
2021-06-20 18:15:12 +00:00
rillig 2236887078 lint: fix crash on semantically wrong code in ({...})
Found by afl.
2021-06-20 11:42:25 +00:00
rillig c6433d2c1a lint: fix assertion failure on malformed struct declaration
Found using afl.
2021-06-20 11:24:32 +00:00
rillig 2337bc9cf6 lint: fix segmentation fault for malformed struct
Code to trigger this bug: struct{char a(_)0}

Found using afl.
2021-06-20 11:00:18 +00:00
chs 1b001e4c1d fix printf format string for xattr names (the length of the xattr name
needs to be a precision rather than a width).
2021-06-20 00:25:29 +00:00
rillig c8d33d92f3 lint: fix endless loop on unfinished comment at EOF
Found using afl.
2021-06-19 20:25:57 +00:00
rillig 921647eafa lint: fix assertion after malformed for loop
Found using afl.
2021-06-19 19:59:01 +00:00
rillig 8873496543 lint: fix assertion failure in struct with unnamed member
Found using afl.
2021-06-19 19:49:15 +00:00
rillig e4ad66c589 lint: fix assertion failure after malformed statement
Found using afl.
2021-06-19 16:05:07 +00:00
rillig 0c0b119a5d lint: fix crash in malformed initialization 2021-06-19 15:51:11 +00:00
rillig 1150940a6c lint: replace undefined behavior with assertion failure
Triggered by this malformed code:

	struct{int;
2021-06-19 15:23:57 +00:00
rillig 03b53d4d6d lint: fix assertion failure after syntax error in declaration
The code to trigger this case is:

	(s)(int(int););

This only happens with BSD yacc, but not with Bison since they differ in
error handling.
2021-06-19 14:28:04 +00:00
rillig ce2c9e15e8 lint: in debug mode, print name of the "storage class"
This helps in tracking down the internal errors related to declarations,
found by running afl.
2021-06-19 14:08:45 +00:00
rillig 8906844d84 lint: fix internal error for unfinished declaration
A translation unit that contains just 'void x' without the trailing
semicolon had crashed lint1 before:

assertion "dcs->d_ctx == AUTO" failed in declare at decl.c:2049

Found using afl.
2021-06-19 11:01:23 +00:00
rillig 148d425b99 lint: fix endless loop when scanning string or character literals
If the code contains an unfinished string or character literal at the
EOF, the lexer got into an endless loop.  Curiously, inpc() returned 0
in such a case instead of the common EOF.

Found by making lint1 with CC=afl-gcc and then running:

afl-fuzz \
    -m 200 \
    -i in_dir \
    -o lint1 \
    $src/usr.bin/xlint/lint1/lint1 @@ /dev/null
2021-06-19 08:57:24 +00:00
rillig 6054740bd7 lint: revert fix for endless loop in lexer for string literals
String literals may contain null bytes, and these must be passed further
on.

This reintroduces the endless loop in the lexer, but that must be fixed
in another way that doesn't destroy the error handling.
2021-06-19 08:37:18 +00:00
rillig 914e17dbfb lint: fix hang on unfinished string literal at end-of-file
The input file that triggered this bug was:

	a"b"c"d

Found using afl.
2021-06-18 20:29:00 +00:00
nia 21eaac5cba June 19 is Juneteenth in USA 2021-06-18 13:13:44 +00:00
rillig 33a45172e8 make: clean up access to character iterator
Having both p[0] and *p intermixed was inconsistent.

No functional change.
2021-06-18 12:54:17 +00:00
rillig c221219687 tests/make: add test for circular dependency in .ORDER 2021-06-17 15:25:33 +00:00
nia 8d791e8417 U.S.S.R no longer exists 2021-06-17 11:48:19 +00:00
nia b0051e6da9 November 20 is International Transgender Day of Remembrance
Officially recongized in Ontario, Canada. Originates from the murder
of Rita Hester in Allston, Massachusetts, on November 28, 1998.
2021-06-17 11:45:22 +00:00
nia 6dc2f20fe2 1985: first ARM silicon and first Amiga 2021-06-17 11:32:34 +00:00
snj d689945313 it's "its" 2021-06-16 19:31:03 +00:00
rillig 05a04127b6 make: fix error handling in jobs mode
By using the same error handling code as in the branch for non-empty
commands, the behavior is the same again as before 2021-01-29.
2021-06-16 09:47:51 +00:00
rillig e579b79c76 tests/make: demonstrate wrong error handling in jobs mode 2021-06-16 09:39:48 +00:00
rillig 1d687b5e81 make: extract commands-ok check from JobWriteShellCommands
This piece of code did not match the function name and thus could not
reasonably be expected in that function.

In job.c 1.399 from 2021-01-29 I missed exactly this little detail when
I added code to skip the apparently unnecessary creation of empty shell
files.  The code I added only handled the happy case, not the case where
the target could not be made.

That code path then differed, leading to a much more verbose error
message than before.

before:
don't know how to make ../missing/no-such.o. Stop

after:
don't know how to make ../missing/no-such.o. Stop
...
`../missing/no-such.o' was not built (made BEINGMADE, ...)!
`muck' was not built (made DEFERRED, type OP_DEPENDS|...)!
    `muck' has .ORDER dependency against build-all (made DEFERRED, ...)

Thanks to sjg for finding and reproducing this unintended change of
behavior.
2021-06-16 03:56:59 +00:00
rillig 8a8ee61edd make: clean up comment for JobStart
The parameter 'flags' was renamed in job.c 1.354 from 2020-12-10 without
adjusting the documentation.

The parameter 'previous' was removed in job.c 1.108 from 2006-03-12,
also without adjusting the documentation of JobStart.

No functional change.
2021-06-16 03:15:47 +00:00
rillig 8ae4c89806 lint: replace array access with function calls
First and foremost, the test d_c99_complex_split accessed the array
qlmasks out-of-bounds, with an index of 128 for the type 'double
_Complex'.  This invoked undefined behavior since the maximum allowed
index was 64.

Replacing the raw array accesses with function calls allows for bounds
checks to catch these errors early.

Determining the value bits for a 'double _Complex' does not make sense
at all since it is not an integer type.  This means that lint didn't
handle these types correctly for several years.  Support for int128_t
has been added in inittyp.c 1.12 from 2018-09-07, support for _Complex
has been added in inittyp.c 1.9 from 2008-04-26.

Determining the value bits for an int128_t would make sense, but the
unit tests don't contain examples for this type since at the moment all
unit tests must produce the same results on 32-bit and 64-bit platforms,
and the 32-bit platforms don't support int128_t.
2021-06-15 20:46:45 +00:00
rillig 88291d7b0e lint: extract convert_constant_to_floating 2021-06-15 18:23:39 +00:00
rillig 15bc77d3e3 lint: split convert_constant_check_range
No functional change.
2021-06-15 18:16:11 +00:00
rillig f815f0802b lint: merge duplicate code 2021-06-15 17:17:14 +00:00
rillig 43955ca5a1 lint: extract convert_constant_check_range
No functional change.
2021-06-15 17:13:08 +00:00
rillig 50a206e72b lint: extract convert_constant_floating
No functional change.
2021-06-15 16:56:00 +00:00
rillig 4d5c51ccb7 tests/lint1: make error handling in the lint1 linter simpler 2021-06-15 08:37:56 +00:00
christos e3db77d2d7 add alphabetic to lower for consistency (nabijaczleweli) 2021-06-14 17:22:22 +00:00
rillig bdb838755f make: inline strcmp when parsing conditions
GCC 10 does not do that even though it could easily.

No functional change.
2021-06-11 14:52:03 +00:00
rillig 22b50b031a make: clean up function names and documentation for conditions
No functional change.
2021-06-11 14:42:52 +00:00
rillig ac956ca694 make: rename If_Eval to EvalBare
No functional change.
2021-06-11 14:37:51 +00:00
rillig 89bfa91472 make: move parsing of function calls out of CondParser_LeafToken
The grammar above the parsing code says that a Leaf has nothing to do
with function calls, so don't mix these in the actual code.

No functional change.
2021-06-11 13:09:10 +00:00
rillig e837fedd83 tests/make: demonstrate handling of '+' and '*' in modifier ':?'
It doesn't make sense that these two characters are handled differently,
but that's what the current code has been doing for years.
2021-06-11 13:01:28 +00:00
rillig 60f06dae7d make: improve function names for parsing conditions
No functional change.
2021-06-11 12:23:00 +00:00
rillig daf1f5324f lint: fix function name in check for getopt
No functional change.
2021-06-04 21:12:10 +00:00
rillig 1cafaf0099 lint: fix typo in comment 2021-06-04 20:54:18 +00:00
lukem b6f942120f use fetch_*() for I/O with SMALLPROG / !WITH_SSL builds
Adapt the SMALLPROG / -UWITH_SSL build to also use the fetch_*()
methods from ssl.c, instead of using stdio, as stdio isn't robust
when using interruptable signals.

Disable ssl-specific support in the fetch_*() methods if WITH_SSL
isn't defined, so SMALLPROG still doesn't have ssl support (as expected).

The resulting SMALLPROG binary is slightly larger than before
(e.g., 157KiB vs 153KiB on amd64).

Set version to 20210603 for this fix and the SO_KEEPALIVE fix for PR 56129.

PR install/56219
2021-06-03 10:23:33 +00:00
lukem 689eea59e5 set SO_KEEPALIVE on control connection
Attempt to prevent timeouts of the control connection by setting SO_KEEPALIVE.
This matches the equivalent behaviour in ftpd.

Note: This is a much simpler change than adding a background polling event
to invoke "STAT" (or "NOOP") on the control connection during a transfer.
(It's unclear from RFC 959 whether "NOOP" is even permitted during a transfer).

PR bin/56129
2021-06-03 10:11:00 +00:00
riastradh 36d4e80c28 audiorecord(1): Handle read(2) return value gracefully. 2021-06-01 21:08:48 +00:00
rillig 0137ba05b0 make: inline str_concat4
This function is only ever used for forming strings of the form
"archive(member)".

No functional change.
2021-05-30 21:16:54 +00:00
rillig 91c42d4f3a make: fix reported code coverage for *.h
In 'make test-coverage', the number of uncovered lines for inline
functions in headers was reported too high.  The cause for this is that
gcov reports the coverage for these functions multiple times, once per
translation unit.  If some of the translation units don't use these
inline functions, summing the lines containing '#####' quickly leads to
numbers that are obviously too high.
2021-05-30 21:03:08 +00:00
rillig d327c9edd5 make: uncompress code in ApplyModifier_Unique
The algorithm is easier to understand when each line of code only
focuses on a single topic.

No change to the resulting binary, except for line numbers in assertion
messages.
2021-05-30 20:41:34 +00:00
rillig fd822471a0 make: inline VarUniq into ApplyModifier_Unique
No functional change.
2021-05-30 20:31:03 +00:00
rillig 176007d55e tests/make: test whitespace normalization for modifier ':u' 2021-05-30 20:26:41 +00:00
nia 1b67abe48a aiomixer: remove workaround for libcurses bug 2021-05-29 09:11:41 +00:00
cjep dca6da60c8 correct indentation. spotted by Roland. 2021-05-26 07:57:05 +00:00
cjep 9265e94bb9 As per OpenBSD, use malloc for the line buffer. Fixes the known issue
with long lines and makes our ATF test suite pass fully.
Closes PR bin/54620 from coypu who suggested the approach.
Reviewed by christos.
2021-05-25 11:25:59 +00:00
christos 1fd82bd9ab fix typo 2021-05-20 02:01:07 +00:00
kre 108061b040 Changes for POSIX conformance.
1.  exit(1) with an error message on stderr if an I/O error occurs.
1a. To work properly when built into /bin/sh sprinkle clearerr() at
    appropriate places.

2.  Verify that when a 'X data value is used with one of the numeric
    conversions, that nothing follows the 'X'.   It used to be unclear
    in the standard whether this was required or not, it is clear that
    with numeric conversions the entire data value must be used, or an
    error must result.   But with string conversions, that isn't the case
    and unused parts are simply ignored.   This one is a numeric conversion
    with a string value, so which applies?   The standard used to contain
    an example of '+3 being converted, producing the same as '+ ignoring
    the '3' with no mention of any error, so that's the approach we adopted,
    The forthcoming version now explicitly states that an error would also
    be generated from that case, as the '3' was not used by the numeric
    conversion.

2a. We support those conversions with floating as well as integer conversions,
    as the standard used to suggest that was required (but it makes no sense,
    the values are always integers, printing them in a floating format is
    dumb).  The standard has been revised to make it clear that only the
    integer numeric conversions %d %u %x (etc) are supposed to handle the 'X
    form of data value.   We still allow it with the floating formats as an
    extension, for backward compat, just in case someone (other than the ATF
    tests) is using it.   It might go away.

2b. These formats are sypposed to convert 'X where 'X' is a character
    (perhaps multibyte encoded) in the current LC_CTYPE locale category.
    We don't handle that, only 1 byte characters are handled currently.
    However the framework is now there to allow code to (one hopes, easily)
    be added to handle multi-byte locales.   (Note that for the purposes of
    #2 above, 'X' must be a single character, not a single byte.)
2021-05-19 22:41:19 +00:00
kre 6db93d573b Don't describe "%%: in the format as a format conversion, it isn't,
it is an escaped literal '%' character.   None of what applies to
format conversions applies to this.
2021-05-19 22:29:18 +00:00
sjg 13862ba5e3 Do not trust that /nonexistent does not exist
Use /nonexistent.${.MAKE.PID} to avoid failure when
/nonexistent actually exists.
2021-05-18 17:05:45 +00:00
martin 7639136097 Add NetBSD 9.1 and 9.2 release 2021-05-17 15:59:28 +00:00