Home | History | Annotate | Download | only in lint1
History log of /src/usr.bin/xlint/lint1/decl.c
RevisionDateAuthorComments
 1.421  18-Sep-2025  rillig lint: in C23 mode, do not warn about an empty parameter list
 1.420  14-May-2025  rillig lint: extract type_attributes functions from grammar
 1.419  14-May-2025  rillig lint: accept '__attribute__((mode(TI)))' before 'unsigned'
 1.418  04-May-2025  rillig lint: in a parameter declaration using typedef, keep the qualifiers

While C23 6.7.7.4p6 doesn't explicitly mention this particular case of a
'const typedef', keeping the qualifiers fixes a warning in probably
legitimate code.

Seen in cvs, regex_internal.c, function 'bitset_contain'.
 1.417  12-Apr-2025  rillig lint: reword messages that apply to traditional C
 1.416  12-Apr-2025  rillig lint: s/illegal/invalid/g

Lint does not provide legal advice.
 1.415  10-Apr-2025  rillig lint: remove now-unnecessary CONSTCOND comments
 1.414  10-Mar-2025  rillig lint: in C99 mode and later, warn about non-prototype functions

Suggested by Christos Zoulas.
 1.413  27-Feb-2025  rillig lint: normalize whitespace
 1.412  03-Jan-2025  rillig lint: add detail to message about obsolete identifier list
 1.411  30-Nov-2024  rillig lint: add back optimization for non-query mode

The main point of the optimization is to skip the expensive calls to
type_name when preparing the message details. This was not spelled out
explicitly in the comment.

While here, fix the stray 'previous declaration' message that occurred
whenever a function was first declared as 'static' and later defined
without 'static', see query 16.
 1.410  29-Nov-2024  rillig lint: remove premature optimization for non-query scenarios
 1.409  28-Nov-2024  rillig lint: add queries for typedefs to struct/union and their pointers

As suggested in share/misc/style since 1.75 from August 2023.

These are queries instead of warnings as the number of false positives or
historical practice is too high; these queries are only intended for
detecting these typedefs on newly added types.
 1.408  13-Nov-2024  rillig lint: handle _Noreturn, [[noreturn]] and __attribute__((__noreturn__))
 1.407  29-Oct-2024  rillig lint: add details to message about too large integer constant
 1.406  14-Oct-2024  rillig lint: add more details to messages about hidden symbols
 1.405  28-Sep-2024  rillig lint: handle __attribute__((__unused__)) for functions and variables

Previously, lint ignored the '__unused' marker, requiring its own /*
ARGSUSED */ marker instead.

Previously, attributes were interpreted as soon as the closing
parenthesis was parsed. For a function definition such as '__unused
static void f(void) {}', this was too early, as the attribute was not
connected to the function, as the function was not parsed yet.

Now, the 'unused' attribute is passed around by the parser, until it is
merged into the declarator where it belongs. Due to an inaccuracy in
the grammar, the 'used' attribute has to be passed through a
parameter_list, even though a parameter list is not related to
attributes. Still, it's better than before.
 1.404  04-Sep-2024  rillig lint: clean up checks for declarations
 1.403  12-May-2024  rillig branches: 1.403.2;
lint: add wrapper for <ctype.h> functions, for strict bool mode

When using the Clang preprocessor (with MKLLVM=yes), the preprocessor
output does not indicate which tokens come from a system header and
which tokens come from the user code. Lint's strict bool mode relies on
this information to treat the character classification functions from
<ctype.h> as if their return type were bool instead of int.

These wrapper functions are only used when their argument is indeed a
'char', but not when the argument might be 'EOF or representable as an
unsigned char', such as when reading a byte from the input.
 1.402  04-May-2024  rillig lint: increase debug logging for declarations

All changes to the global variable 'dcs' are tracked now, to help
identify the cause of the failing tests in expr_sizeof and
gcc_attribute_aligned.

While here, test more invalid type combinations in typedefs.
 1.401  03-May-2024  rillig lint: measure the alignment in bytes, not bits

While measuring the alignment in bits makes sense when building a struct
type with bit-fields, in all other places it is more confusing than
helpful.

The only visible change is that in debug mode, the format of type sizes
and alignment changed. Since the size of all complete types is a
multiple of a byte (as defined in the C standard), sizes and alignments
are reported in bytes as well. Only while a struct is being built, the
type size may include an additional '+x' for the bits of a bit-field.
 1.400  01-May-2024  rillig lint: fix size of struct with large alignment

Lint now successfully passes all compile-time assertions in the amd64
kernel that deal with struct sizes.
 1.399  01-May-2024  rillig lint: support _Alignas and __attribute__((__aligned(4)))
 1.398  30-Mar-2024  rillig lint: document which fields are not reset when starting a new type

Setting all visible fields to their null value seemed as if the whole
object were reset.
 1.397  29-Mar-2024  rillig lint: clean up
 1.396  09-Mar-2024  rillig lint: inline accessor macros for type_t
 1.395  09-Mar-2024  rillig lint: use fewer struct keywords
 1.394  02-Mar-2024  rillig lint: remove custom wrappers around <ctype.h> functions
 1.393  08-Feb-2024  rillig lint: clean up variable names, parameter order, comments

No functional change.
 1.392  08-Feb-2024  rillig lint: clean up redundant braces

No functional change.
 1.391  03-Feb-2024  rillig lint: clean up comments, reduce scope of variables
 1.390  23-Jan-2024  rillig lint: unconst parameters

These were leftovers from earlier refactorings and are no longer needed.

No binary change.
 1.389  23-Jan-2024  rillig lint: rename symt_t to symbol_kind

It was confusing to have two kinds of "symbol type" (s_type and s_symt),
so rename all related identifiers to be more distinctive.

No functional change.
 1.388  21-Jan-2024  rillig lint: clean up redundant const from parameters and local variables

These were leftovers from splitting large functions into smaller
functions, to ensure that variables were not unintentionally reassigned.
Those refactorings are finished, and the extra help from the compiler is
no longer necessary.

No binary change.
 1.387  20-Jan-2024  rillig lint: add query for const automatic variables
 1.386  06-Jan-2024  rillig lint: remove redundant parentheses, braces and comments

Rename the functions for folding constant expressions, to make the
comments redundant.
 1.385  10-Dec-2023  rillig lint: allow querying for 'static' followed by non-'static' declaration
 1.384  10-Dec-2023  rillig lint: clean up comments

No functional change.
 1.383  03-Dec-2023  rillig lint: in declarations, replace tab with space

Previously, in some cases, the keywords 'const' or 'struct' were
followed by a tab, which doesn't make sense.

No functional change.
 1.382  03-Dec-2023  rillig lint: re-wrap comments

No functional change.
 1.381  03-Dec-2023  rillig lint: indent statement continuations consistently

No binary change.
 1.380  02-Dec-2023  rillig lint: rename NOSCL to NO_SCL

For symmetry with NO_TSPEC. No functional change.
 1.379  14-Sep-2023  rillig lint: fix wording of diagnostics about 'C99 extension'

The term 'extension' means an extension to a C standard. C99 by itself
is not an extension but a revision of the C standard.
 1.378  26-Aug-2023  rillig lint: make diagnostics about ANSI C more international
 1.377  02-Aug-2023  rillig lint: remove unused string literals
 1.376  02-Aug-2023  rillig lint: do not return bogus types for unnamed function parameters

Since decl.c 1.18 from 2000-07-05, lint has returned bogus type
information in cases where it couldn't interpret complicated
declarators.

In cases like these, rather fail than proceed with wrong data.
 1.375  02-Aug-2023  rillig lint: fix handling of unnamed function parameters
 1.374  02-Aug-2023  rillig lint: distinguish between arguments and parameters
 1.373  02-Aug-2023  rillig lint: simplify handling of old-style arguments
 1.372  01-Aug-2023  rillig lint: clear global variable 'dcs' after use

Having unnecessarily set members is confusing during debugging.
 1.371  01-Aug-2023  rillig lint: improve debug logging for declarators
 1.370  31-Jul-2023  rillig lint: fix assertion failure after unnamed bit-field member

Since 2023-07-15.
 1.369  30-Jul-2023  rillig lint: increase debug logging for declarations, constify

Lint doesn't parse declarators correctly, see msg_347.c, and fixing this
part is nontrivial.
 1.368  30-Jul-2023  rillig lint: remove outdated comment (since decl.c 1.6 from 1995-10-02)
 1.367  29-Jul-2023  rillig lint: eliminate redundant code

No functional change.
 1.366  29-Jul-2023  rillig lint: condense code for ending a function

No functional change.
 1.365  29-Jul-2023  rillig lint: constify
 1.364  29-Jul-2023  rillig lint: remove forward declarations for functions

No functional change.
 1.363  28-Jul-2023  rillig lint: extract 'vararg' and 'prototype' flags from global 'dcs'

These flags are only relevant for parameter lists, so add a separate
type for it.

No functional change.
 1.362  25-Jul-2023  rillig lint: allow 'thread_local' to be combined with 'static'
 1.361  18-Jul-2023  rin lint1:initdecl(): Remove hack for now-fixed PR port-sh3/56311
 1.360  15-Jul-2023  rillig lint: allow 'extern' and 'thread_local' to be combined
 1.359  15-Jul-2023  rillig lint: properly initialize unnamed struct/union members

Previously, their 'containing type' was not initialized. The code for
initializing them is adapted from declarator_name.
 1.358  15-Jul-2023  rillig lint: add detailed logging for finding memory allocation bugs
 1.357  15-Jul-2023  rillig lint: add debug logging for memory management and the symbol table
 1.356  14-Jul-2023  rillig lint: clean up redundant and verbose code
 1.355  13-Jul-2023  rillig lint: merge duplicate code for checking duplicate type qualifiers
 1.354  13-Jul-2023  rillig lint: use separate types for parsing pointer types and type qualifiers

The documentation of the previous 'qual_ptr_t' was misleading, as that
type was used for other type qualifier lists as well, even if these were
not related to pointer types.
 1.353  13-Jul-2023  rillig lint: in C23 mode, recognize the keyword 'thread_local'
 1.352  13-Jul-2023  rillig lint: _Thread_local is a storage class, not a type qualifier
 1.351  13-Jul-2023  rillig lint: indent copyright lines consistently
 1.350  13-Jul-2023  rillig lint: clean up code related to lint comments

Remove type information from variable names, as the word 'flag' did not
indicate that the variables were negated.

Remove contradicting comments. Suppressing a warning for 'this line',
'this and the following line' and 'this statement or declaration' cannot
all be accurate at the same time.
 1.349  12-Jul-2023  rillig lint: don't treat 'inline' as a storage class

The additional conflict in the grammar is in the same place as the other
conflicts, as T_SCLASS and T_FUNCTION_SPECIFIER are now separate tokens.

No functional change.
 1.348  09-Jul-2023  rillig lint: miscellaneous cleanup
 1.347  09-Jul-2023  rillig lint: clean up wording in diagnostics

Use the term 'parameter' as defined in C99 3.15.
 1.346  09-Jul-2023  rillig lint: clean up the wording of a few diagnostics
 1.345  08-Jul-2023  rillig lint: warn about pointer casts between different kinds of types

Pointer casts from an integer type to a floating-point type and vice
versa get a 'maybe troublesome' warning now. The previous assumption
that all types of the same bit-size are convertible may have been valid
from a technical point of view, but still such code should get more
attention.

The rules for struct and union types could be made more fine-grained
later, if the need arises. To suppress this warning, it's always
possible to cast to an intermediate 'void *'.
 1.344  08-Jul-2023  rillig lint: clarify the meaning of 'portable size in bits' of a type

No functional change.
 1.343  07-Jul-2023  rillig lint: warn about function definitions without header declaration

The existing warning was only issued for function declarations, not for
function definitions.

The interesting change in the tests is in msg_351.c. Many other tests
use non-static functions due to their syntactic brevity. In these
tests, the warning is disabled individually, to allow new functions to
be added without generating warning 351.
 1.342  07-Jul-2023  rillig lint: only skip 'unused' warnings after errors, not other warnings

Previously, in -w mode, any warning suppressed further 'unused'
warnings, even though there was no need to do that. This can be seen in
the test gcc_attribute_var.c, where only the last unused variable from a
function was marked as unused, the others slipped through.

Fixed by counting the errors and the warnings separately and only
combining them if actually desired.
 1.341  03-Jul-2023  rillig lint: invert the -u, -v and -z flags

Now they behave the same as in the manual page.

No functional change.
 1.340  03-Jul-2023  rillig lint: rename uppercase QUAD to LLONG

No binary change.
 1.339  02-Jul-2023  rillig lint: eliminate redundant conditions
 1.338  02-Jul-2023  rillig lint: clean up variable names relating to structure padding
 1.337  02-Jul-2023  rillig lint: rename 'quad' to 'signed int' or 'unsigned int'

No functional change.
 1.336  02-Jul-2023  rillig lint: use unsigned int for struct alignment

This gets rid of 'unsigned short', which saved a few bytes of memory but
was inconvenient to deal with.

No functional change.
 1.335  02-Jul-2023  rillig lint: extend debug logging for declaration levels

Indent the debug logging according to the declaration level.

Since there are a few cases where the enclosing declaration levels are
modified, log the whole declaration level stack whenever a level begins
or ends.
 1.334  02-Jul-2023  rillig lint: initialize unnamed member like an unnamed bit-field

See set_bit_field_width.
 1.333  02-Jul-2023  rillig lint: clean up variable names
 1.332  01-Jul-2023  rillig lint: constify, reduce indentation

No functional change.
 1.331  01-Jul-2023  rillig lint: clean up duplicate and dead code for integer constants

No functional change.
 1.330  30-Jun-2023  rillig lint: clean up names related to declaration levels

The previous prefix 'DK_' (declaration level kind) had a conflict with
the 'DK_' (designator kind) in init.c, so change the prefix to 'DLK_'.
The new name for dinfo_t is decl_level, which is more expressive.

No functional change.
 1.329  30-Jun-2023  rillig lint: fix handling of unnamed struct/union members

The support for unnamed struct/union members that was added in decl.c
1.60 from 2015-10-13 was simple but wrong. It didn't cover initializers
of these structures and computed wrong sizes for structures containing
anonymous unions. At that time, the handling of initializers was broken
as well, it was fixed 6 years later in init.c 1.229 from 2021-12-22.

Real-life examples for code that lint couldn't handle are:

* external/bsd/jemalloc/dist/src/jemalloc.c
* external/mit/xorg/lib/dri.old/Makefile
 1.328  30-Jun-2023  rillig lint: replace macro for unique identifiers with function

No functional change.
 1.327  30-Jun-2023  rillig lint: clean up handling of declarations

No functional change.
 1.326  30-Jun-2023  rillig lint: fix computation of bit-field width

When bit-fields in packed structs were added on 2009-10-02, lint assumed
that they would only use 'signed int' or 'unsigned int' as storage unit,
even though C99 also allows _Bool.

The cleanup commit for decl.c 1.225 from 2021-08-28 accidentally changed
the rounding mode for bit-field storage units from round-up to
round-down.
 1.325  30-Jun-2023  rillig lint: clean up packing of structs and unions

No functional change outside debug mode.
 1.324  30-Jun-2023  rillig tests/lint: demonstrate bugs in anonymous struct/union handling
 1.323  29-Jun-2023  rillig lint: clean up member names of declaration levels

No functional change outside debug mode.
 1.322  29-Jun-2023  rillig lint: use standard terminology for bit-field width

No functional change.
 1.321  29-Jun-2023  rillig lint: clean up initialization of type properties

No functional change.
 1.320  29-Jun-2023  rillig lint: clean up function names

No functional change.
 1.319  29-Jun-2023  rillig lint: clean up completion of struct, union and enum declarations

No functional change.
 1.318  24-Jun-2023  rillig lint: add query for redundant 'extern' in function declaration
 1.317  09-Jun-2023  rillig lint: miscellaneous clean-ups

No binary change, except for line numbers in assertions.
 1.316  09-Jun-2023  rillig lint: indent local variables consistently

No binary change.
 1.315  03-Jun-2023  rillig lint: add query for static variables in functions

This query allows finding hidden global variables, as an easier-to-read
alternative to 'objdump -t'.
 1.314  22-May-2023  rillig lint: use consistent variable name for redeclared symbol

No binary change.
 1.313  22-May-2023  rillig lint: fix emitted type for arrays of unknown size
 1.312  22-May-2023  rillig lint: clean up the name of a local variable

No binary change.
 1.311  22-May-2023  rillig lint: rename constant NOTSPEC to NO_TSPEC

It was too easy to misread the old name as NOT_SPEC instead of the
intended NO_TSPEC.
 1.310  25-Apr-2023  rillig lint: reword message for missing declaration in header

Suggested by Christos.
 1.309  22-Apr-2023  rillig lint: fix wrong warning about 'extern' temporary identifier
 1.308  22-Apr-2023  rillig lint: rename type_t.t_str to t_sou

The name 't_str' could have meant 'string' or 'struct'. Since both
struct and union types have members, rename it to 't_sou'.

No functional change.
 1.307  28-Mar-2023  rillig lint: warn about 'extern' declarations inside function bodies

https://mail-index.netbsd.org/tech-userlevel/2023/03/15/msg013727.html

The previous attempt (message 351 about 'extern' declarations outside
headers) did not cover the proposal from the tech-userlevel mailing list
but instead warns about a different usage pattern of the 'extern'
keyword.
 1.306  28-Mar-2023  rillig lint: warn about extern declarations outside headers

https://mail-index.netbsd.org/tech-userlevel/2023/03/15/msg013727.html
 1.305  29-Jan-2023  rillig lint: rename functions for function definition

No functional change.
 1.304  21-Jan-2023  rillig lint: add support for the C11 type qualifier '_Atomic'

That keyword can be used as a type specifier as well, support for that
will be added later.
 1.303  14-Jan-2023  rillig lint: use fewer abbreviations

No binary change except for line numbers in assertions in decl.c.
 1.302  01-Oct-2022  rillig branches: 1.302.2;
lint: miscellaneous cleanup

No functional change.
 1.301  01-Oct-2022  rillig lint: reduce pointer indirection for unnamed entities

No functional change.
 1.300  01-Oct-2022  rillig lint: add hyphen to adjective 'old-style'
 1.299  28-Aug-2022  rillig lint: inline previous_declaration for nonconstant message IDs

This adds back the compile-time printf validation in debug mode that was
missing before.
 1.298  28-Aug-2022  rillig lint: clean up visual clutter

No functional change.
 1.297  28-Aug-2022  rillig lint: rename functions to be clearer

No need anymore to keep external identifiers at the "6 significant
initial characters" mandated by C90.
 1.296  28-Aug-2022  rillig lint: rename dcs manipulation functions to be clearer

No functional change.
 1.295  26-Aug-2022  rillig lint: clean up to_int_constant

No functional change.
 1.294  03-Jul-2022  rillig lint: include the width of bit-fields in the type name
 1.293  22-Jun-2022  rillig lint: add quotes around placeholders for the remaining messages

Reword some of the messages slightly, exchanging brevity for clarity.

Message 138 is kept as-is, as it is not yet covered by any tests.

Message 240 is kep as-is, as it is unreachable.
 1.292  21-Jun-2022  rillig lint: use is_struct_or_union instead of comparing twice

No functional change.
 1.291  21-Jun-2022  rillig lint: add quotes and details to some more messages
 1.290  20-Jun-2022  rillig lint: add quotes around several placeholders in messages
 1.289  19-Jun-2022  rillig lint: add quotes around placeholders in 4 messages
 1.288  19-Jun-2022  rillig tests/lint: add quotes around placeholders in a few messages
 1.287  15-Jun-2022  rillig lint: unexport lint's messages

There was only a single place where a message was used directly, instead
of calling one of the several functions for this purpose.
 1.286  15-Jun-2022  rillig lint: remove unnecessary memory allocation

No functional change.
 1.285  11-Jun-2022  rillig lint: add quotes around placeholders for a few more messages
 1.284  11-Jun-2022  rillig lint: add quotes around a few more placeholders in messages
 1.283  31-May-2022  rillig lint: fix null pointer dereference after syntax error

Found by afl, starting with the malformed input '/**/f=({;/**/};}' that
no longer crashes. This input led to 'f=({L:;}', which is at least a
syntactically valid prefix of a translation unit, containing a GCC
statement expression with an unused label. The error message for this
unused label assumed that it would always be inside a function
definition.

While here, document incomplete recovery after syntax errors, in
msg_249.c.
 1.282  26-May-2022  rillig lint: rename olwarn and LWARN_BAD to be more expressive

No functional change.
 1.281  20-May-2022  rillig lint: use __RCSID in lint mode as well

Since 1995-10-02, lint supports __asm statements and __asm modifiers.

No binary change.
 1.280  30-Apr-2022  rillig lint: inline macro 'sflag'

Mark all places where lint's C90 mode is stricter than its C99 mode.

Most of the situations in which lint produces only warnings instead of
errors covered by the "Constraints" sections in the relevant standards.
This doesn't prevent a specific compiler from accepting it though.

No functional change.
 1.279  30-Apr-2022  rillig lint: inline macro 'tflag'

The definition of the macro tested both allow_trad and allow_c90, but
there is only a single mode in which allow_c90 is false, therefore it
suffices to test only that.

While double-checking each occurrence of tflag individually, I learned
why lint performs lookups of struct members only by name, independently
of the struct in which they are declared. See typeok_arrow for details.

No functional change.
 1.278  16-Apr-2022  rillig lint: migrate gflag to allow_gcc

No functional change.
 1.277  10-Apr-2022  rillig lint: fix assertion failure on duplicate qualifiers from __typeof__
 1.276  09-Apr-2022  rillig lint: distinguish between storage class and declaration kind

These types overlap but are not the same.

No functional change.
 1.275  09-Apr-2022  rillig lint: rename dinfo_t.d_offset to d_offset_in_bits

Most often, offsets are measured in bytes, so better embed the unit in
the variable name.

No functional change.
 1.274  09-Apr-2022  rillig lint: extract is_member into separate function

No functional change.
 1.273  09-Apr-2022  rillig lint: disambiguate sym_t.s_value

Having a single variable for 4 different purposes with different types
makes the code unnecessarily hard to follow.

No functional change.
 1.272  09-Apr-2022  rillig lint: split CTCONST into BOOL_CONST and ENUM_CONST

Having a unified compile-time constant "storage class" made the code
more difficult to understand.

No functional change.
 1.271  09-Apr-2022  rillig lint: inline member access macros for sym_t

Having the 'u.' explicitly in the code serves as a reminder that these
members are only defined under certain conditions.

No functional change.
 1.270  09-Apr-2022  rillig lint: rename length to length_in_bits

No functional change.
 1.269  08-Apr-2022  rillig lint: fix undefined behavior on enum overflow (since 1995)

GCC had optimized the check away, due to the obvious integer overflow 'x
- 1 == INT_MAX'. To prevent further bugs like this, compile with
-ftrapv.
 1.268  03-Apr-2022  rillig lint: fix crash after syntax error in array declaration
 1.267  02-Apr-2022  rillig lint: clean up style

Remove outdated ARGSUSED (the one in tree.c had been wrong since 1995),
remove unused argument.

No functional change.
 1.266  02-Apr-2022  rillig lint: use appropriate alignment on both the host and target platform
 1.265  02-Apr-2022  rillig lint: remove unreachable message 'compiler takes alignment of function'
 1.264  02-Apr-2022  rillig lint: try harder to recover after syntax errors

lint: assertion "false" failed in declarator_name at decl.c:1596
near msg_022.c:22
 1.263  02-Apr-2022  rillig lint: extract type creation into separate functions

No functional change.
 1.262  02-Apr-2022  rillig lint: inline setcomplete

No functional change.
 1.261  02-Apr-2022  rillig lint: untangle nested variable assignments

The code is buggy (see decl_direct_abstract.c), so at least make it
readable, making it hopefully easier to fix the bugs.

Before decl.c 1.18 from 2000-07-05, lint crashed when it parsed
'sizeof(int(double))', since that commit it has been hiding the bugs,
working with wrong type information instead.

Fix the logged type in add_function (had been wrong since today).
 1.260  02-Apr-2022  rillig lint: do not log dinfo_t pointers in debug mode

Before the addition of debug_dinfo from today, this had been the only
way to notice changes to the global 'dcs' variable. Since the content
of that variable is now logged, the pointer is not needed anymore.
 1.259  02-Apr-2022  rillig lint: rename dinfo_t.d_next to d_enclosing

The name d_next gave the wrong impression that the declaration infos
would be independent of each other, but they are nested.

No functional change.
 1.258  02-Apr-2022  rillig lint: add debug logging for the declaration stack

To track down the wrong edge cases in decl_direct_abstract.c.
 1.257  01-Apr-2022  rillig lint: improve determination of abstract typename

Still not perfect, but at least a step in the right direction. See
decl_direct_abstract.c for the missing edge cases.

See PR#22119.
 1.256  01-Apr-2022  rillig lint: add details to message about illegal return type
 1.255  01-Apr-2022  rillig lint: add debug logging for type declarators

This will help in fixing the wrong type in msg_347.c, as well as the
assertion failure for 'sizeof(int())'.
 1.254  01-Apr-2022  rillig lint: fix indentation and spacing, add a missing 'else' to 'else if'

No functional change.
 1.253  13-Mar-2022  rillig lint: rename function 'cleanup' to be more expressive

No functional change.
 1.252  01-Mar-2022  rillig lint: add debug logging for symbols and the symbol table

This logging is not active by default, the functions debug_sym and
debug_symtab can be called as needed during a debug session.
 1.251  27-Feb-2022  rillig tests/lint: add tests for messages about old-style functions
 1.250  27-Feb-2022  rillig lint: C99 has been released, so refer to it by its proper name
 1.249  27-Feb-2022  rillig lint: unabbreviate two more members of sym_t

No functional change.
 1.248  27-Feb-2022  rillig lint: unabbreviate some fields in sym_t

No functional change.
 1.247  27-Feb-2022  rillig lint: encode lifetime of allocated memory in function names

No functional change.
 1.246  27-Feb-2022  rillig lint: encode lifetime of allocated memory in the function names

No functional change.
 1.245  27-Feb-2022  rillig lint: rename ARG to OLD_STYLE_ARG

Pre-C90 argument declarations have been old for more than 30 years now,
so mention that fact in the constant name. This reduces potential
confusion with other occurrences of the words 'arg' or 'argument'.

No functional change.
 1.244  07-Feb-2022  rillig lint: reword message about bit-field in a union

There is nothing illegal about a bit-field in a union, it is allowed by
C90, C99 and C11.

Fixes PR toolchain/53219.
 1.243  22-Dec-2021  rillig lint: use C90 instead of C89 when referring to the C standard
 1.242  01-Nov-2021  rillig lint: move all declarations above statements

All code that is used by src/tools is supposed to be compatible with C90.

No functional change.
 1.241  17-Sep-2021  christos downgrade bitfield in union to a warnings (ldpd uses it).
 1.240  13-Sep-2021  rillig lint: continue analysis of wrong type in abstract declaration

No functional change.
 1.239  13-Sep-2021  rillig lint: replace comment in new_style_function with equivalent code

No functional change.
 1.238  13-Sep-2021  rillig lint: eliminate local variable in new_style_function

No functional change.
 1.237  12-Sep-2021  rillig lint: track down wrong function type in abstract type
 1.236  12-Sep-2021  rillig lint: add more details to error about redeclaration

Message 27 is triggered by several conditions. The one triggered by
register_vget in sbin/fsck_lfs/vnode.c needs more details than the
others.
 1.235  05-Sep-2021  rillig lint: fix some more lint warnings

The only remaining warnings are in scan.c, which is a generated Flex
scanner.

No functional change.
 1.234  05-Sep-2021  rillig lint: fix lint warnings
 1.233  04-Sep-2021  rillig lint: reduce indentation in tdeferr

No functional change.
 1.232  04-Sep-2021  rillig lint: use unsigned integers for size calculations

No change for type definitions that are smaller than 128 MB. For larger
types, integer overflow might occur, just like before.
 1.231  04-Sep-2021  rillig lint: remove redundant and duplicate code
 1.230  04-Sep-2021  rillig lint: spell out abbreviations in comments

No functional change.
 1.229  04-Sep-2021  rillig lint: split declare_local into smaller functions
 1.228  29-Aug-2021  rillig lint: add __sync_ and _mm_ as prefixes for builtin functions

These two additions cover all cases that occur in the current NetBSD
build on x86_64. This allows build_name to use the usual pattern 'if
Sflag then error else if sflag then warning'. That function currently
issues a warning in C99 as well, even though C99 prohibits implicit
function declarations.
 1.227  28-Aug-2021  rillig lint: do not emit GCC builtin functions

Lint1 no longer emits declarations of GCC builtin functions and calls to
them.

Previously, lint generated 3421 useless warnings in a default NetBSD
build, like this:

__atomic_load_n, arg 1 used inconsistently
acl.c(216)[pointer to unsigned int]
rbtdb.c(921)[pointer to unsigned short]

This was because lint just doesn't understand that these functions are
type-generic, which is indeed unusual in C.

These useless warnings made the lint output more frightening than it
should actually be. Together with the strange formatting of the
diagnostics (space-space-tab after the main message, two spaces and two
colons between the occurrences, symbols are listed in hashcode order),
this creates the impression that lint is not intended to be a
user-friendly tool.

For now, fix the excess warnings, leaving the other items for later.
 1.226  28-Aug-2021  rillig lint: use 'unsigned int' for bit-size of types

Lint does not need to support any types larger than 256 MB since they
don't occur in practice. Practically, such large types have never been
supported at all since the function type_size_in_bits used int for the
internal calculations, resulting in overflows.
 1.225  28-Aug-2021  rillig lint: fix a few lint warnings about type conversions

A simple 'unsigned int' is more than enough for representing the size of
a bit-field, as well as the maximum alignment of any type.

No functional change.
 1.224  28-Aug-2021  rillig lint: un-abbreviate unsigned integer types

No functional change.
 1.223  28-Aug-2021  rillig lint: clean up alignment_in_bits

The given type can never be NULL, and an array can never have NULL as
subtype.
 1.222  16-Aug-2021  rillig lint: add more details to message about redeclared tag
 1.221  10-Aug-2021  rillig lint: fix 3 of the 4 wrong messages about lvalue in initial assignment
 1.220  10-Aug-2021  rillig lint: remove redundant test for negative bit-field size

A bit-field can never have negative size. Its type is an unsigned
integer.

Strangely, GCC 10.3.0 only complains about this if the extra struct
level lint1_type.t_b is removed. Clang 12.0.1 does not complain at all.
 1.219  03-Aug-2021  rillig lint: in strict enum mode, error out on enum type mismatch in union cast
 1.218  03-Aug-2021  rillig lint: casting to a struct is not allowed in C99, only with GCC
 1.217  01-Aug-2021  rillig lint: remove option -d, clean up debug logging

The command line option -d was not used by /usr/bin/lint, and it only
triggered a handful of debug messages. Move this debug logging over to
the compile-time -DDEBUG setting.

Move display_expression further up to avoid the forward declaration.
 1.216  01-Aug-2021  rillig lint: add debug logging for symbol table, clean up debug logging

When I tried to fix msg_115, I quickly ran into a segmentation fault,
probably related to the symbol table. To better understand this part,
log insertions and deletions.

The other debug log messages do not need to mention the current file
position anymore, this is what lex_next_line takes care of since scan.l
1.113 from 2021-01-05.
 1.215  31-Jul-2021  rillig lint: improve support for __int128_t and __uint128_t

For the .ln files, I chose the letter 'J' to represent the 128-bit
integer types since it is close to 'I' for int. The naming of 'L' for
'long' is obvious, but 'Q' for 64-bit integers is a quad-16-bit word,
which is an unusual measurement unit nowadays. One benefit of choosing
'J' is that the next letter, 'K' can then be used for 256-bit integer
types.

Support for 128-bit integer types is still very basic. Plus, it is only
supported on LP64 platforms, which means that lint cannot be
cross-compiled to check for an LP64 platform while running on an ILP32
platform.
 1.214  31-Jul-2021  rillig lint: initialize shared types in the same order as in tspec_t

This makes it easier to see whether there are any types missing, such as
__uint128_t.

No functional change.
 1.213  31-Jul-2021  rillig lint: clean up debug logging

The calls to debug_step, unlike printf, don't need a trailing newline.

Remove the debug_step0 macro and its relatives since lint already uses
enough other features from C99 that it essentially requires this
standard, which supports varargs macro arguments. Among these features
are __func__ and printf("%zu").

In non-debug mode, do not evaluate the arguments of debug_step.
Evaluating the arguments had caused an internal error when running the
test op_shl_lp64. This is indeed a bug since initdecl should have
initialized the type table for __uint128_t. This had been forgotten
when support for __uint128_t was added in decl.c 1.69 from 2018-09-07.

No functional change.
 1.212  31-Jul-2021  rillig lint: add debugging output for the grammar tokens

No functional change outside debug mode.
 1.211  31-Jul-2021  rillig lint: merge duplicate code for generating unqualified type

This is a preparation for fixing the wrong warnings in msg_115.c.

No functional change.
 1.210  25-Jul-2021  rillig lint: move scl_name from print.c to decl.c

It is only needed there.
 1.209  23-Jul-2021  rillig lint: remove a few unnecessary abbreviations

No functional change.
 1.208  23-Jul-2021  rillig lint: make offset and alignment positive numbers

There's no use case for negative alignment or offsets in structures.

No functional change.
 1.207  15-Jul-2021  rillig lint: reduce verboseness of merge_signedness

No functional change.
 1.206  15-Jul-2021  rillig lint: rename merge_type_specifiers to merge_signedness

No functional change.
 1.205  15-Jul-2021  rillig lint: replace switch statement in dcs_merge_declaration_specifiers

Grouping the rules by their abstract type took a lot of visual space.
Instead, move each of the rules from C11 6.7.2 into its own if
statement, so that the rules almost read like in the standard.

No functional change.
 1.204  15-Jul-2021  rillig lint: extract dcs_merge_declaration_specifiers from end_type

No functional change.
 1.203  15-Jul-2021  rillig lint: clean up mix of 'case' and 'if'

No functional change.
 1.202  15-Jul-2021  rillig lint: remove warning about _Complex long double in traditional C

Complex types have been introduced in C99, so there is no danger of
anyone trying to use them in traditional C.
 1.201  15-Jul-2021  rillig lint: fix internal error for sizeof(typeof)
 1.200  15-Jul-2021  rin PR port-sh3/56311

As a workaround for GCC bug, compile initdecl() with -O0 for sh3.
 1.199  13-Jul-2021  rillig lint: fix wording of message for incomplete struct (2021-07-04)

A struct member is not an argument. In err.c 1.124 from 2021-07-04, the
wording had been changed, without noticing that the message was used
twice: once for an argument, once for a struct member.
 1.198  11-Jul-2021  rillig lint: add quotes around placeholders in message 23 and 232
 1.197  10-Jul-2021  rillig lint: rename clrtyp/deftyp to begin_type/end_type

The abbreviations clr/def did not make it obvious that these two
functions or grammar rules form pairs.

No functional change.
 1.196  10-Jul-2021  rillig lint: fix assertion failure in declare_argument
 1.195  05-Jul-2021  rillig lint: reduce noise in storage_class_name

No functional change.
 1.194  05-Jul-2021  rillig 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.
 1.193  04-Jul-2021  rillig lint: improve wording for incomplete struct or union
 1.192  28-Jun-2021  rillig 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.
 1.191  28-Jun-2021  rillig lint: align grammar with C99

C99 uses type-qualifier-list_opt in section 6.7.5.
 1.190  28-Jun-2021  rillig 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.
 1.189  27-Jun-2021  rillig 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.
 1.188  20-Jun-2021  rillig lint: fix assertion failure on malformed struct declaration

Found using afl.
 1.187  20-Jun-2021  rillig lint: fix segmentation fault for malformed struct

Code to trigger this bug: struct{char a(_)0}

Found using afl.
 1.186  19-Jun-2021  rillig lint: fix crash in malformed initialization
 1.185  19-Jun-2021  rillig 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.
 1.184  19-Jun-2021  rillig 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.
 1.183  19-Jun-2021  rillig 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.
 1.182  16-May-2021  rillig lint: add more specific warning for bit-field of type plain 'int'

Previously, declaring a bit-field of type plain 'int' resulted in this
warning:

warning: nonportable bit-field type 'int' [34]

This warning was too unspecific to be actionable, and until yesterday it
didn't even include the type. In order to allow this warning to be
understood and properly fixed, describe the actual nonportability more
precisely:

warning: bit-field of type plain 'int' has
implementation-defined signedness [344]
 1.181  16-May-2021  rillig lint: add type information to unportable bit-field type

Seeing the message "unportable bit-field type 'int'" may sound strange
at first, but that's a strict interpretation of the wording in C99
6.7.2.1p4, which requires that the bit-field type is "'_Bool', 'unsigned
int' or 'signed int', or some other implementation-defined type".

The rationale for C99 6.7.2.1 explicitly lists plain 'int' among the
allowed types for bit-fields, regardless of any additional
implementation-defined types. This means that lint had interpreted this
paragraph wrong, and it should be fixed to allow plain int as well.
 1.180  02-May-2021  rillig branches: 1.180.2;
lint: allow large integer types for bit-fields in GCC mode

These types are explicitly allowed by GCC.

I'm not sure which of the flags -g and -p should be stronger. That is,
if both -g and -p are given, should 'unsigned char' be allowed as a
bit-field type since -g would allow it, or should it be warned about
since -p warns about it? For now, continue to warn about these.
 1.179  02-May-2021  rillig lint: extract check_bit_field_type from declare_bit_field

No functional change.
 1.178  18-Apr-2021  rillig lint: pass pos_t via const pointer

Thanks for the suggestion, christos@.
 1.177  18-Apr-2021  rillig 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.
 1.176  18-Apr-2021  rillig lint: do not modify curr_pos in check_global_symbols

No functional change.
 1.175  18-Apr-2021  rillig lint: in check_global_variable_size, restore curr_pos

This affects only calls to lint_assert, all other code stays
functionally the same.
 1.174  18-Apr-2021  rillig 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.
 1.173  18-Apr-2021  rillig lint: migrate print_previous_declaration to message_at
 1.172  10-Apr-2021  rillig 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.
 1.171  09-Apr-2021  rillig lint: quote placeholders in messages for unused variables
 1.170  02-Apr-2021  rillig lint: add parentheses after sizeof, as required by share/misc/style

No functional change.
 1.169  02-Apr-2021  rillig lint: rename functions for duplicating types

No functional change.
 1.168  02-Apr-2021  rillig lint: name memory allocation functions consistently

No functional change.
 1.167  30-Mar-2021  rillig lint: rewrite handling of initializations, fixing several bugs

The previous implementation had a wrong model of how initialization
happens in C99, its assertions failed in all kind of edge cases and it
was not possible to fix the remaining bugs one at a time without running
into even more obscure assertion failures.

The debug logging was detailed but did not help to clarify the
situation. After about 20 failed attempts at fixing the small details I
decided to start all over and rewrite the initialization code from
scratch. I left the low-level parts of handling designators, the code
that is independent of brace_level and the high-level parts of how the
parser calls into this module. Everything else is completely new.

The concept of a brace level stays since that is how C99 describes
initialization. The previous code could not handle multi-level
designations (see d_init_pop_member.c). There are no more assertion
failures in the initialization code.

Some TODO comments have been left in the tests to keep the line numbers
the same in this commit. These will be cleaned up in a follow-up
commit.

The new implementation does not handle initialization with "missing"
braces. This is an edge case that both GCC and Clang warn about, so it
is not widely used. If necessary, it may be added later.

The new implementation does not use any global variables in the vast
majority of the functions, to make all dependencies and possible
modifications obvious.
 1.166  27-Mar-2021  rillig lint: move handling of function renaming over to declare_extern

No functional change.
 1.165  27-Mar-2021  rillig lint: rename decl1ext, reduce visibility

No functional change.
 1.164  27-Mar-2021  rillig lint: rename LERROR to INTERNAL_ERROR

The '#ifndef' in tyname.c is meant to distinguish between lint1 and
lint2, it is not meant to be defined from anywhere outside the lint code
itself.

No functional change.
 1.163  27-Mar-2021  rillig lint: remove space between 'sizeof ('

No functional change.
 1.162  26-Mar-2021  christos use __func__
 1.161  26-Mar-2021  rillig lint: in malloc calls, use 'sizeof *ptr' instead of 'sizeof(type)'

No functional change.
 1.160  26-Mar-2021  rillig lint: rename pushdecl and popdecl to be more expressive

The previous names were highly ambiguous. The 'decl' could have meant
'declaration', which would be the usual abbreviation. It could also be
split into 'dec' and 'l', meaning 'declaration level', which would make
more sense in this particular context.

To avoid having to guess anything about these names, rename the
functions. Instead of 'push' and 'pop', I renamed them to 'begin' and
'end' since these are the high-level operation that are of interest.
That the hierarchy of declaration levels is implemented as a stack is
nice to know but not as important to understand the whole situation.

No functional change.
 1.159  23-Mar-2021  rillig lint: fix wrong error message about type mismatch in compound literal

Now that the code contains explicit markers for starting and ending an
initialization, and having the guarantee that an assertion fails
whenever some code accesses the state of the "current initialization"
even though there is no ongoing initialization gives me much more
confidence in the correctness of the code. The calls to
begin_initialization and end_initialization always appear in pairs,
enclosing the minimal amount of code necessary for initialization.

In a nutshell, global modifiable state is error-prone and hard to
understand.

A nice side effect is that the grammar no longer needs a special rule
for the outermost initializer since the functions for the debug logging
are now called explicitly.

The code that misuses the initialization state just because it needs to
temporarily store a sym_t somewhere is now clearly marked as such. A
GCC statement expression can appear anywhere and is therefore
independent of the initialization. Most probably the code can simply
refer to the local variable in the grammar rule itself, or this variable
needs to be encoded in the grammar %union. For sure there is a better
way to handle this.

There is no longer a need that the function 'declare' initializes the
initialization state, it was just the wrong place to do this.
 1.158  23-Mar-2021  rillig lint: add indirection for accessing the current initialization

This indirection will be needed to handle nested initializations, which
are a new feature of C99. These are currently not handled correctly,
see msg_171.c.

No functional change.
 1.157  21-Mar-2021  rillig lint: adjust type in documentation of add_array

No functional change.
 1.156  21-Mar-2021  rillig lint: rename d_fargs, d_fdpos and d_fpsyms to be less abbreviated

No functional change.
 1.155  21-Mar-2021  rillig lint: rename d_nedecl to d_nonempty_decl

No functional change.
 1.154  21-Mar-2021  rillig lint: rename d_rdcsym to d_redeclared_symbol

No functional change.
 1.153  21-Mar-2021  rillig lint: inline local variable in declarator_1_struct_union

No functional change.
 1.152  20-Mar-2021  rillig lint: update comment on setasm for C99

No functional change.
 1.151  20-Mar-2021  rillig lint: reduce indentation and braces in merge_type_specifiers

No functional change.
 1.150  20-Mar-2021  rillig lint: extract adjusting of the storage class into separate function

No functional change.
 1.149  19-Mar-2021  rillig lint: rename in_bit to in_bits

No functional change.
 1.148  19-Mar-2021  rillig lint: rename tsize to type_size_in_bits

The shorter name size_in_bits was already taken by the function-like
macro with argument type tspec_t.

No functional change.
 1.147  17-Mar-2021  rillig lint: rename dinfo_t members to be more expressive

While here, sync redundant but diverging comments, split
multi-assignments and initialize the members in declaration order.

No functional change.
 1.146  17-Mar-2021  rillig lint: move to_int_constant from the grammar to decl.c

This way, the code is covered by running 'make lint'. The code from the
grammar is not covered, therefore it still uses int instead of bool in a
few places.

Inline the comparison functions for uint64_t. These functions didn't
add any clarity to the code.

No functional change.
 1.145  17-Mar-2021  rillig lint: move main part of idecl over to decl.c and rename it

No functional change.
 1.144  17-Mar-2021  rillig lint: rename 'blklev' to 'block_level'

No functional change.
 1.143  28-Feb-2021  rillig lint: rename members and access macros of the basic types

Having the measurement unit in the variable name prevents accidental
confusion between bits and bytes, especially since usually the word
'size' means the size in bytes, while 'width' means the size in bits, at
least for integer types.

No functional change.
 1.142  28-Feb-2021  rillig lint: document allowed types for bit-fields

No functional change.
 1.141  28-Feb-2021  rillig lint: extract declare_bit_field from declarator_1_struct_union

No functional change.
 1.140  28-Feb-2021  rillig lint: add type information to 'illegal bit-field type'
 1.139  28-Feb-2021  rillig lint: rename getbound to alignment_in_bits

No functional change.
 1.138  22-Feb-2021  rillig lint: change spelling of initialisation to initialization

That's the wording from the ISO C99 standard.
 1.137  19-Feb-2021  rillig lint: rename storage class constants to be more expressive

No functional change.
 1.136  19-Feb-2021  rillig lint: rename t_isenum and t_aincompl to be more expressive

No functional change.
 1.135  19-Feb-2021  rillig lint: rename tenum_t and its members to be more expressive
 1.134  19-Feb-2021  rillig lint: rename str_t and its members to be more expressive

No functional change.
 1.133  31-Jan-2021  rillig lint: add quotes to messages 1 and 19
 1.132  30-Jan-2021  rillig lint: rename incompl to is_incomplete

No functional change.
 1.131  24-Jan-2021  rillig lint: update data types in comments from int to bool
 1.130  18-Jan-2021  rillig lint: clean up member names of control_structure and comments
 1.129  18-Jan-2021  rillig lint: flatten check_global_variable_size
 1.128  18-Jan-2021  rillig lint: fix assertion failure for restrict and _Thread_local
 1.127  17-Jan-2021  rillig lint: extend a few message comments
 1.126  17-Jan-2021  rillig lint: replace integer constants with bool constants
 1.125  17-Jan-2021  rillig lint: fix type mismatch for strict bool mode

No functional change.
 1.124  16-Jan-2021  rillig lint: replace integer constant expressions with true and false

LINTFLAGS=-gST make lint, with manual review.

The error messages from lint are all correct, they are not complete
though. The return value of a function returning bool may still be
compared to the integer 0.
 1.123  16-Jan-2021  rillig lint: in strict bool mode, integer constants do not have type bool

Previously, lint1 allowed integer constants such as 0 and 1 to be used
as bool constants. This was only half-baked since after fixing all
error messages from that strict mode, there may still be integer
literals in the code that should be replaced with true or false. This
would stop a migration from int to bool in the middle, leaving
inconsistent code around.

To find the remaining type inconsistencies, treat integers and bool as
completely incompatible, even for compile time constants.
 1.122  16-Jan-2021  rillig lint: replace 0 and 1 with false and true, where appropriate

Change in behavior: Passing the option -h exactly 4294967296 times or
any multiple thereof is no longer equivalent to passing it never at all,
it is now equivalent to passing it once. See main2.c, hflag++ for the
actual change.

Other than that, no functional change intended.

A very large portion of the code already conformed to the requirements
of the strict bool mode. The only missing thing was using the constant
literals false and true instead of 0 and 1. For sure there are some
integer literals left that can be converted. For now, all literals that
appeared in the form " = 0" or " = 1" have been replaced.
 1.121  11-Jan-2021  rillig lint: sprinkle a few const modifiers throughout the code
 1.120  10-Jan-2021  rillig lint: split check_global_variable into several functions

This reduces the indentation and allows the messages in the comments to
contain the complete text instead of only an abbreviated prefix.

No functional change.
 1.119  10-Jan-2021  rillig lint: fix assertion failure for syntax error in enum declaration
 1.118  10-Jan-2021  rillig lint: remove redundant parentheses around return value
 1.117  10-Jan-2021  rillig lint: change return type of eqptrtype to bool
 1.116  10-Jan-2021  rillig lint: rename functions with short names
 1.115  10-Jan-2021  rillig lint: use message 232 for unused label in function

This message had been defined but not used before.
 1.114  10-Jan-2021  rillig 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.
 1.113  09-Jan-2021  rillig 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.
 1.112  09-Jan-2021  rillig lint: rename ename to enumeration_constant
 1.111  04-Jan-2021  rillig lint: fix typos and other minor stylistic issues
 1.110  03-Jan-2021  rillig lint: rename prflstrg to printflike_argnum, likewise for scflstrg
 1.109  03-Jan-2021  rillig 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.
 1.108  03-Jan-2021  rillig lint: rename type.t_isfield to t_bitfield
 1.107  03-Jan-2021  rillig 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.
 1.106  03-Jan-2021  rillig 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.
 1.105  03-Jan-2021  rillig 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.
 1.104  03-Jan-2021  rillig lint: fix spelling of message 308

All other messages are lowercase as well.
 1.103  02-Jan-2021  rillig lint: convert bitfieldtype_ok from int to bool

No functional change intended, except for the output in debug mode.
 1.102  02-Jan-2021  rillig lint: fix lint warning 161 "constant in conditional context"
 1.101  02-Jan-2021  rillig lint: add a few more tests

No serious bugs found this time.
 1.100  02-Jan-2021  rillig 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.
 1.99  02-Jan-2021  rillig lint: allow _Bool for bit-fields
 1.98  02-Jan-2021  rillig 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.
 1.97  01-Jan-2021  rillig 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)
 1.96  01-Jan-2021  kre Build breakage fix (hopefully) - brain dead gcc. NFCI.
 1.95  01-Jan-2021  rillig lint: remove NTSPEC from enum tspec_t

The number of elements in an enumeration is not a valid enum constant of
that enumeration itself.
 1.94  01-Jan-2021  rillig lint: add missing redundant messages in source code
 1.93  01-Jan-2021  rillig lint: replace simple LERROR with lint_assert
 1.92  01-Jan-2021  rillig lint: replace some more LERROR with lint_assert
 1.91  01-Jan-2021  rillig 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.
 1.90  01-Jan-2021  rillig lint: remove redundant printf arguments
 1.89  01-Jan-2021  rillig lint: align comments with actual message, in the lexer and parser
 1.88  01-Jan-2021  rillig 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.
 1.87  30-Dec-2020  rillig 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.
 1.86  30-Dec-2020  rillig lint: spell check comments
 1.85  30-Dec-2020  rillig lint: inline STRUCT_ASSIGN

This had only been necessary for some pre-C90 compilers.
 1.84  30-Dec-2020  rillig lint: un-abbreviate s_dpos, s_spos and s_upos
 1.83  30-Dec-2020  rillig lint: un-abbreviate s_field, s_keyw and s_xsym
 1.82  30-Dec-2020  rillig lint: rename remaining _nxt members to _next
 1.81  30-Dec-2020  rillig lint: rename symt_t constants

There's no need to abbreviate them, furthermore FMOS was imprecise.
 1.80  30-Dec-2020  rillig lint: rename s_nxt to s_next
 1.79  29-Dec-2020  rillig lint: fix typo in comments
 1.78  29-Dec-2020  rillig lint: split complete_tag into separate functions
 1.77  29-Dec-2020  rillig lint: rename functions with very short names
 1.76  29-Dec-2020  rillig lint: remove redundant parentheses around return value
 1.75  29-Dec-2020  rillig lint: rename functions that had very short names

C99 guarantees that the first 31 characters of an identifier with
external linkage are significant. This removes the need to use
abbreviations for common words.
 1.74  28-Dec-2020  rillig lint: rename confusing function setcompl

The previous function name suggested that it would set the complete flag
of the type, but it was the exact opposite. To reduce confusion, negate
the meaning of the parameter.
 1.73  28-Dec-2020  rillig lint: spell check
 1.72  28-Dec-2020  rillig lint: rename tspec macros
 1.71  02-Jun-2020  christos Fix return of alignof()
 1.70  04-Mar-2019  christos Add __thread/tls_model attribute
 1.69  07-Sep-2018  christos recognize int128
 1.68  06-Mar-2017  christos branches: 1.68.10; 1.68.12;
Accept PTR for addtype
 1.67  27-Dec-2016  christos branches: 1.67.2;
teach lint __attribute__((__unused__))
 1.66  03-Nov-2016  kamil Prefer modern simple past tense and past participle of catch

The "catched" form is obsolete and nonstandard, prefer "caught".
 1.65  23-Aug-2016  christos compute anonymous bitfield sizes properly.
 1.64  19-Aug-2016  christos Don't warn about empty structs twice.
 1.63  18-Aug-2016  christos - handle sizes of structs/unions with anon members
- handle structs/unions with only anon members
 1.62  31-Jul-2016  dholland typo in comment
 1.61  02-Jan-2016  christos branches: 1.61.2;
print the length on error.
 1.60  13-Oct-2015  christos handle anonymous struct/union members.
 1.59  18-Apr-2014  christos handle LDOUBLE
 1.58  15-Dec-2013  christos branches: 1.58.2;
downgrade illegal bitfield from error to warning so we can ignore it.
 1.57  19-Apr-2013  christos make NOSTRICT behave the same a LINTED; use the new format.
 1.56  19-Apr-2013  christos Allow linted comments to take an argument that defines which error to suppress.
 1.55  17-Feb-2013  christos rename enum_t to avoid rpc/types.h lossage.
 1.54  27-Mar-2012  christos branches: 1.54.2;
more cross lint friendlyness
XXX: needs more constants converted double/float
 1.53  24-Jun-2011  christos branches: 1.53.2;
Always use our own align macro and explain a bit more why this is bogus.
 1.52  24-May-2011  joerg Fix format string usage
 1.51  02-Oct-2009  christos handle bit fields in packed structures.
 1.50  02-Oct-2009  christos compute sizes by the new tsize() function.
 1.49  02-Oct-2009  christos fix typedef struct __packed
 1.48  02-Oct-2009  christos recognize struct __packed x { }; in addition to struct x { } __packed;
 1.47  02-Oct-2009  christos understand __attribute__((__packed__)) and __packed.
 1.46  15-Apr-2009  christos Lukemify (WARNS=4)
 1.45  02-Mar-2009  christos Don't produce type mismatch warnings if one side of ?: is "[qual] void *"
and the other side is "[qual] pointer".
 1.44  16-Nov-2008  dholland branches: 1.44.2;
WARNS=4
 1.43  27-Sep-2008  dholland Don't accidentally treat "long double" as "long". PR bin/39639.
 1.42  26-Sep-2008  matt Teach lint about long double _Complex (C99)
 1.41  27-Apr-2008  christos reorder a couple of error messages.
 1.40  26-Apr-2008  christos fix "long double" type recognition which broke with the complex changes.
 1.39  25-Apr-2008  christos preliminary _Complex support.
NB: Does not really understand type conversions between complex and doubles.
 1.38  08-Nov-2006  christos branches: 1.38.16;
- add debugging to track nowarns
- make /*LINTED*/ take effect on unused functions
 1.37  23-Oct-2006  christos allow 0 sized structs in c9x
 1.36  23-Oct-2006  christos add zero sized array handling. It is a little too chatty now.
 1.35  13-Jul-2006  christos flex arrays are a c9x feature.
 1.34  12-Sep-2004  yamt recognize _Bool.
 1.33  20-Jun-2004  jmc Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944
 1.32  02-Nov-2002  perry branches: 1.32.2;
Make long long a c99ism, not a gnuism.
 1.31  13-Sep-2002  christos Minimize diffs with my C99 capable version [this commit does not include
C99 support.

- turn lerror() into a macro so that the filename and the line number of the
error are printed before we abort.
- recurse in type printing to provide the proper type name.
 1.30  31-Jan-2002  tv Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.29  18-Jan-2002  thorpej Centralize the initialization/declaration of the ttab.
 1.28  03-Jan-2002  thorpej Make sure the tspec_t enum starts at 0, and declare NTSPEC in
the enum proper.
 1.27  03-Jan-2002  thorpej Simplify test for integer types in the BITFIELDTYPE handling path.
 1.26  03-Jan-2002  thorpej * Add header files (ilp32.h and lp64.h) that describe the two
models of type sizes that we currently support, and include
the appropriate one in each arch's targparam.h.
* Use the type size constants provided by targparam.h in the
type table, rather than using "sizeof(type) * CHAR_BIT" (which
would get the host's type size, not the target's). XXX Not
yet done for floating point types.
* Add a new BITFIELDTYPE lint comment that suppresses illegal
bitfield type errors if the type is an integer type (e.g.
long, long long), and also suppresses non-portable bitfield
type warnings.
 1.25  21-Nov-2001  wiz "than" instead of "then".
 1.24  16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.23  26-Jul-2001  wiz Various typos in comments (neccessary, sceme, choise, ...).
 1.22  28-May-2001  lukem cleanup (prior to more adding more features):
- convert to ANSI KNF
- remove trailing whitespace
- translate some comments from german into english

code compiles and runs clean, and tested by running "make lint" against
xlint source using previous and this lint produces same results.
 1.21  24-May-2001  lukem minor whitespace/knf
 1.20  19-May-2001  sommerfeld Change type of anonymous bitfield pads so that lint -p no longer generates a
portability warning.
 1.19  24-Feb-2001  cgd fix broken NetBSD RCS id tags
 1.18  05-Jul-2000  christos Prevent lint1 from coredumping on invalid c code such as:

foo((sockaddr *(void *))0);

This fix is imperfect, because right now we just check the subtype
chains for NULL and we return to the caller when the loop ends, leaving
the upper layers to cope with the syntax error. Ideally we should:

a.) return an error to the upper layer, or
b.) not call the type analysis routines in the presence of a syntax
error.

That would require a significant re-write which would take much more time
than I have...
 1.17  14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.16  13-Mar-2000  soren branches: 1.16.2;
Fix doubled 'the's.
 1.15  27-Jul-1998  mycroft Fix a recurring typo: comparision -> comparison.
 1.14  27-Jul-1998  mycroft Fix uses of uninitialized memory, and incorrect types for initializers.
From ITOH Yasufumi, PR 5861.
 1.13  22-Feb-1998  christos WARNSify
 1.12  22-Dec-1996  cgd * recognize that pointers to identical unnamed and untyped structs,
unions, and enums are, in fact, identical. This is done by tagging
each of unnamed and untyped structure, union and enum with a unique
position of creation, which is used as a unique identifier that
when determine whether or not a pair of structures, unions, or enums
are identical.
 1.11  02-Oct-1995  jpo no need to print a warning about inline keywords
"inline" is a valid keyword only with -g, and "__inline" is always
a valid keyword
 1.10  02-Oct-1995  jpo don't print warnings about unused variables or arguments in compound
statements which contain asm statements.
 1.9  02-Oct-1995  jpo LINTED and CONSTCOND are now valid up to the next end of a
global or local declaration/definition/statement. Originally they were
valid on the current and next line, which made it hard to suppress
warnings in constructs with more then one line.

LONGLONG can now be used to suppress errors or warnings in the next
declaration, definition or statement.
 1.8  02-Oct-1995  jpo support asm statements and asm modifiers in declarations

asm statements consist of an asm keyword, an optional qualifier, a
left paren, a list of tokens up to and including the matching right
paren, and a semicolon.

asm modifiers consist of an asm keyword, an left paren, a string and a
right paren.

asm statements and modifiers have no semantic for lint(1), they exist only
to avoid complaints about them.
 1.7  02-Oct-1995  jpo some minor bug fixes
 1.6  02-Oct-1995  jpo prototypes override old style function definitions
this is a gnu extension to ansi c
 1.5  02-Oct-1995  jpo __{const,signed,volatile}{__,} added
const, signed and volatile are disabled with -t
 1.4  02-Oct-1995  jpo added inline keywords
"inline" is enabled by -g, "__inline" and "__inline__" are always available
 1.3  02-Oct-1995  jpo prefixed members of dinfo_t with 'd_'
 1.2  03-Jul-1995  cgd RCS id cleanup
 1.1  03-Jul-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.1  03-Jul-1995  cgd lint(1) implementation, by Jochen Pohl. named 'xlint' for a similar
reason to why 'install' is named 'xinstall'.
 1.16.2.1  23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.32.2.1  22-Jun-2004  tron Pull up revision 1.33 (requested by jmc in ticket #527):
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')
Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).
Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.
Fixes PR's: PR#17762 PR#25944
 1.38.16.1  18-May-2008  yamt sync with head.
 1.44.2.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.53.2.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.53.2.1  17-Apr-2012  yamt sync with head
 1.54.2.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.54.2.2  23-Jun-2013  tls resync from head
 1.54.2.1  25-Feb-2013  tls resync with head
 1.58.2.1  10-Aug-2014  tls Rebase.
 1.61.2.4  20-Mar-2017  pgoyette Sync with HEAD
 1.61.2.3  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.61.2.2  04-Nov-2016  pgoyette Sync with HEAD
 1.61.2.1  06-Aug-2016  pgoyette Sync with HEAD
 1.67.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.68.12.1  10-Jun-2019  christos Sync with HEAD
 1.68.10.1  30-Sep-2018  pgoyette Ssync with HEAD
 1.180.2.1  31-May-2021  cjep sync with head
 1.302.2.1  19-Jul-2023  martin Pull up following revision(s) (requested by rin in ticket #237):

usr.bin/xlint/lint1/decl.c: revision 1.361
doc/HACKS: revision 1.239

lint1:initdecl(): Remove hack for now-fixed PR port-sh3/56311
doc/HACKS: PR port-sh3/56311 has been fixed.
 1.403.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed