Home | History | Annotate | Download | only in lint1
History log of /src/usr.bin/xlint/lint1/cgram.y
RevisionDateAuthorComments
 1.533  14-Sep-2025  rillig lint: add more type details to several messages

In most expressions, the integer promotions are performed on the
operands, making the actual type different from the "visible" type of an
operand. To properly explain the situation, mention the type before the
integer promotions in case it differs from the resulting type.
 1.532  16-May-2025  rillig lint: clean up
 1.531  16-May-2025  rillig lint: allow multiple attributes in member without type

It's a syntax error anyway and helps keep the grammar small.
 1.530  16-May-2025  rillig lint: merge values from multiple __attributes__

No change to the test suite as the grammar rules that contain multiple
attributes don't make use of the members from type_attributes.
 1.529  15-May-2025  rillig lint: fix build on 32-bit platforms
 1.528  15-May-2025  rillig lint: handle __attribute__ after a declarator
 1.527  15-May-2025  rillig lint: handle __attribute__ at the beginning of a declaration
 1.526  14-May-2025  rillig lint: extract type_attributes functions from grammar
 1.525  14-May-2025  rillig lint: accept '__attribute__((mode(TI)))' before 'unsigned'
 1.524  08-May-2025  rillig lint: fix merging type attributes
 1.523  12-Apr-2025  rillig lint: reword messages that apply to traditional C
 1.522  12-Apr-2025  rillig lint: s/illegal/invalid/g

Lint does not provide legal advice.
 1.521  05-Mar-2025  rillig lint: revert accidental commit
 1.520  05-Mar-2025  rillig tests/lint: demonstrate missing warning about non-prototype
 1.519  24-Feb-2025  rillig lint: add debug logging for function calls in the grammar
 1.518  20-Feb-2025  rillig lint: support __attribute__((__mode__(TI)))

This fixes the wrong lint warnings about the shift amount being greater
than the type size in compiler_rt/popcountti2.c.
 1.517  03-Jan-2025  rillig lint: add detail to message about obsolete identifier list
 1.516  01-Dec-2024  rillig lint: warn about function definitions that still use identifier lists
 1.515  13-Nov-2024  rillig lint: add more details to 'statement not reached' message

In lib/libcompat/regexp/regexp.c, the FAIL macro expands to a compound
statement containing a function call statement and a return statement,
and the macro invocation is followed by a semicolon, forming an extra
empty statement. Which of these statements is unreachable now becomes
clear from the diagnostic, without having to inspect the preprocessed
source code.
 1.514  13-Nov-2024  rillig lint: handle _Noreturn, [[noreturn]] and __attribute__((__noreturn__))
 1.513  29-Oct-2024  rillig lint: fix warning about null effect in GCC statement expressions
 1.512  04-Oct-2024  rillig lint: fix suppressed warnings after if-else-if statement

Seen in sbin/dump/main.c, the "cp = strchr" line.

The bug had been there since at least 2002.
 1.511  28-Sep-2024  rillig lint: treat __attribute__((__constructor__)) functions as used

Seen in jemalloc.c.
 1.510  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.509  28-Sep-2024  rillig lint: allow more than one __attribute__ on a parameter declaration
 1.508  28-Sep-2024  rillig lint: reduce shift/reduce conflicts in grammar

In an anonymous member declaration, the type attributes are already
parsed by the type specifier.
 1.507  29-Aug-2024  rillig lint: support GCC's __auto_type

Fixes PR toolchain/58654.
 1.506  17-Jun-2024  rillig branches: 1.506.2;
lint: don't warn about unused C23 [[maybe_unused]] parameters
 1.505  17-Jun-2024  rillig lint: accept C23 [[fallthrough]] statements

Needed by bind9/getaddresses.c:137.
 1.504  17-Jun-2024  rillig lint: accept C23 attributes at the beginning of a type declaration

The switch to GCC 12 brings support for C23, and localtime.c uses it to
mark [[maybe_unused]] parameters.

For now, accept C23 attributes independently from the language level. In
the end, the whole tree with the exception of the tools should be
switched to C23 mode instead of the current C99 mode.

For now, don't actually mark the argument as possibly unused, as lint
currently ignores __attribute__((__unused__)) as well.
 1.503  12-May-2024  rillig lint: don't call memcpy with null pointer

Even copying 0 bytes from a null pointer invokes undefined behavior.
 1.502  12-May-2024  rillig lint: move code for parsing balanced token sequences to lex.c

To access yytext from lex.c, the lexer needs to be in %pointer mode,
which was specified in IEEE Std 1003.1, 2004 Edition and thus should be
old enough to be available on platforms other than NetBSD, for use in
tools/lint1 where lint1 is built before yacc and lex.
 1.501  11-May-2024  rillig lint: clean up grammar rule name for 'type_specifier'
 1.500  11-May-2024  rillig lint: parse but otherwise ignore C23 attributes

The C23 attributes are only parsed before an expression in an expression
statement, as a proof of concept. Other places will follow later.
 1.499  09-May-2024  rillig lint: in C23 mode, allow storage classes in compound literals
 1.498  09-May-2024  rillig lint: sync grammar rule names with C11 and C23
 1.497  09-May-2024  rillig lint: sort grammar rules according to the order they appear in C23
 1.496  09-May-2024  rillig lint: in C23 mode, support the nullptr constant
 1.495  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.494  01-May-2024  rillig lint: support _Alignas and __attribute__((__aligned(4)))
 1.493  29-Mar-2024  rillig lint: clean up
 1.492  27-Mar-2024  rillig lint: add missing assignment to $$ in grammar

Byacc and Bison both provide this assignment for all actions, whether
default or not, but the wording in POSIX doesn't guarantee this.
 1.491  09-Mar-2024  rillig lint: inline accessor macros for tnode_t
 1.490  09-Mar-2024  rillig lint: use fewer struct keywords
 1.489  08-Feb-2024  rillig lint: clean up redundant braces

No functional change.
 1.488  08-Feb-2024  rillig lint: clean up comments, add debug output for Bison
 1.487  05-Feb-2024  rillig lint: make function call arguments directly accessible

Previously, the arguments of a function call expression were arranged in
a linear tree structure, from right to left. To allow easier access to
the arguments, store them in an array instead.
 1.486  02-Feb-2024  rillig lint: make newline in a string literal an error in C90 and later
 1.485  01-Feb-2024  rillig lint: use standard buffer for storing string values

No functional change.
 1.484  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.483  13-Jan-2024  rillig lint: clean up grammar for initializers
 1.482  13-Jan-2024  rillig lint: inline simple grammar rules
 1.481  12-Jan-2024  rillig lint: clean up grammar for array size
 1.480  11-Jan-2024  rillig lint: clean up enum constants for designators

In intializers and offsetof, both struct and union members are handled
in the same way, thus there is no need to distinguish them.
 1.479  11-Jan-2024  rillig lint: correctly set system-header flag on cast-expression

When a cast-expression comes partly from a system header, determine at
the ')' whether the whole cast-expression comes from the system header.
Previously, it was based on the operand, which contradicted the
documentation of tn_sys.

Mainly affects strict bool mode (where expressions from system headers
are handled more leniently), as well as query 9 for parenthesized return
expressions.

Discovered upon manual inspection, as calling expr_alloc_tnode should
never be necessary when creating an expression node with operands;
there's build_op for that purpose.
 1.478  09-Jan-2024  rillig lint: allow complex offsetof(type, member-designator)

Both GCC 11 and Clang 8 accept member-designators that are not
identifiers but designator sequences, such as in 'offsetof(struct stat,
st_atim.tv_sec)', so make lint accept them as well.
 1.477  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.476  17-Oct-2023  rillig lint: resolve shift/reduce conflict in labels with attributes
 1.475  17-Oct-2023  rillig lint: fix debug output of convert/cast operators

The default name of the 'CVT' operator is 'convert', therefore the
override is only needed for 'cast'.
 1.474  14-Sep-2023  rillig lint: remove pseudo operators INC and DEC

These operators were not used in expressions, they were only used as
additional token info. Use a plain bool instead.

No functional change.
 1.473  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.472  26-Aug-2023  rillig lint: make diagnostics about ANSI C more international
 1.471  12-Aug-2023  rillig lint: clean up
 1.470  03-Aug-2023  rillig lint: make '_Static_assert' only available in C11 or C23 mode
 1.469  02-Aug-2023  rillig lint: fix handling of unnamed function parameters
 1.468  02-Aug-2023  rillig lint: distinguish between arguments and parameters
 1.467  01-Aug-2023  rillig lint: improve debug logging for declarators
 1.466  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.465  15-Jul-2023  rillig lint: each member declarator may have attributes, not only the last one
 1.464  15-Jul-2023  rillig lint: fix use-after-free bug in GCC statement expressions
 1.463  15-Jul-2023  rillig lint: add detailed logging for finding memory allocation bugs
 1.462  15-Jul-2023  rillig lint: add debug logging for memory management and the symbol table
 1.461  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.460  13-Jul-2023  rillig lint: indent copyright lines consistently
 1.459  13-Jul-2023  rillig lint: reduce code size for handling lint comments
 1.458  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.457  12-Jul-2023  rillig lint: reject _Noreturn if it occurs in invalid places

C11 introduced _Noreturn as a function-specifier, not as a type
attribute. The latter may occur in more places.
 1.456  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.455  12-Jul-2023  rillig lint: indent grammar using tabs instead of spaces

Manually indenting the grammar rules using two spaces was too
cumbersome.
 1.454  11-Jul-2023  rillig lint: rename grammar rules to align with C23
 1.453  11-Jul-2023  rillig lint: update wording in diagnostic for C99
 1.452  10-Jul-2023  rillig lint: when debugging the parser, write messages on stderr

This way, all messages (regular debug, yacc debug, lint diagnostics)
occur in the correct order.
 1.451  10-Jul-2023  rillig lint: merge duplicate code for getting the name of an operator
 1.450  10-Jul-2023  rillig lint: update debug logging of the parser for Bison 3.8.2

Bison 3.8.2 no longer knows YYPRINT.
 1.449  10-Jul-2023  rillig lint: add debug logging for symbol kinds in the parser

An identifier can refer to a variable, type, member, tag or label.
Switching between these namespaces is tightly coupled with the
evaluation order of the grammar rules.
 1.448  10-Jul-2023  rillig lint: ensure that untyped grammar rules are listed

Untyped grammar rules are suspicious because they subtly affect the
order in which the grammar actions are performed. This leads to the
various bugs mentioned in msg_347.c.
 1.447  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.446  02-Jul-2023  rillig lint: add initial support for C23

Required by xsrc/external/mit/MesaLib.old, brw_eu_validate.c, which
initializes a struct using empty braces: 'return (struct string){};'.
 1.445  02-Jul-2023  rillig lint: allow empty statements in GCC statement expressions
 1.444  02-Jul-2023  rillig lint: clean up variable names relating to structure padding
 1.443  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.442  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.441  30-Jun-2023  rillig lint: clean up handling of declarations

No functional change.
 1.440  30-Jun-2023  rillig tests/lint: extend test for sizeof and offsetof
 1.439  29-Jun-2023  rillig lint: clean up member names of declaration levels

No functional change outside debug mode.
 1.438  29-Jun-2023  rillig lint: clean up function names

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

No functional change.
 1.436  22-May-2023  rillig lint: clean up the name of a local variable

No binary change.
 1.435  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.434  02-Apr-2023  rillig lint: clean up indentation and wrapping in C parser
 1.433  06-Feb-2023  rillig lint: eliminate unnecessary indirection

No functional change.
 1.432  29-Jan-2023  rillig lint: rename functions for function definition

No functional change.
 1.431  21-Jan-2023  rillig lint: add support for C11 '_Atomic' as atomic-type-specifier

Following the C11 grammar, the keyword '_Atomic' needs to be a separate
syntactic category, to avoid further conflicts in the grammar.

The two newly added conflicts in the grammar would come into play when
mixing traditional C with C11, in a type name without an implicit 'int'.
If the type '_Atomic(int)*' were parsed as '_Atomic int(int)*', the
trailing '*' would be a syntax error.
 1.430  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.429  21-Jan-2023  rillig lint: use type_qualifier rule instead of the token directly

No functional change.
 1.428  21-Jan-2023  rillig lint: clean up grammar for type-qualifier

A type-qualifier by itself does not carry pointer information, so add a
helper rule in the grammar for those cases where a type-qualifier is
actually used in a type like 'int *const'.

This allows general type qualifier checks to be performed during
parsing, for example to ensure that '_Atomic' is only used in C11 or
later.

No functional change.
 1.427  21-Jan-2023  rillig lint: fix null pointer dereference on invalid argument to __typeof__
 1.426  15-Jan-2023  rillig lint: make read_until_parent easier to understand

Previously, the '--level' in the loop condition looked as if it applied
more often than it really does.

No functional change.
 1.425  14-Jan-2023  rillig lint: use fewer abbreviations

No binary change except for line numbers in assertions in decl.c.
 1.424  01-Oct-2022  rillig lint: add hyphen to adjective 'old-style'
 1.423  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.422  28-Aug-2022  rillig lint: rename dcs manipulation functions to be clearer

No functional change.
 1.421  25-Aug-2022  rillig lint: remove explicit list of known GCC attributes

Most GCC attributes consist of a single identifier. Up to now, it was
necessary to list each of these identifiers in the grammar, even those
that only apply to a single target architecture.

Instead, parse the general form of attributes, matching the few
attributes that lint handles by name instead. While here, rename the
grammar rules to use the GCC terms.

To avoid conflicts between the global function 'printf' and the GCC
attribute of the same name, do not add GCC attributes to the symbol
table, and don't make these symbols 'extern' either.

ok christos@.
 1.420  20-Jun-2022  rillig lint: add quotes around several placeholders in messages
 1.419  26-May-2022  rillig lint: rename olwarn and LWARN_BAD to be more expressive

No functional change.
 1.418  26-May-2022  rillig lint: merge debug and non-debug code for saving and restoring warnings

No functional change.
 1.417  26-May-2022  rillig lint: remove assertion about saving and restoring warning flags

The assertion only triggers in debug mode, which is generally not used
as it adds lots of debug logging. In production mode, the assumption
didn't hold for many years now, so remove the assertion.
 1.416  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.415  12-May-2022  rillig lint: merge duplicate grammar rules for __alignof__ expr

This allows expressions like '__alignof__(ptr)->member', just as with
'sizeof'.

The upper rule in the grammar was preferred over the lower rule since it
shifted the T_LPAREN instead of reducing unary_expression. Its
implementation invoked undefined behavior if the expression was NULL
since it didn't assign anything to $$.
 1.414  12-May-2022  rillig lint: add message text to newly added call to gnuism

Required by check-msgs.lua.
 1.413  12-May-2022  martin We have 130 shift/reduce conflicts now
 1.412  12-May-2022  christos gcc allows __alignof__(unary-expression)
 1.411  12-May-2022  rillig lint: add support for __alignof__ expr, a GCC extension

Seen in lib/libc/gmon/gmon.c:153.
 1.410  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.409  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.408  30-Apr-2022  rillig lint: inline macro Sflag in cases of expected behavior

In the grammar rules 'enums_with_opt_comma' and 'block_item_list',
checking for allow_c99 was redundant since c99ism does not warn in C99
mode.

In the grammar rule 'designator', align the two actions structurally.

No functional change.
 1.407  29-Apr-2022  rillig lint: make grammar compatible with Bison

Bison and BSD Yacc differ in how they translate the grammar into C code.

Bison:
code above '%union' (YYDEBUG is either undefined or 1)
#include "cgram.h" (which defines YYDEBUG to 0 if undefined)
code from below '%union' until the first '%%'
actions
code below the second '%%'

BSD Yacc:
code above the first '%%' (YYDEBUG is either undefined or 1)
(no #include for "cgram.h")
define YYDEBUG to 0 if undefined
code below the second '%%' (YYDEBUG is either 0 or 1)
actions

The easiest way around these differences is to remove the 'defined(...)'
around the conditionals YYDEBUG, YYBISON and YYBYACC.
 1.406  29-Apr-2022  rillig lint: reorder grammar rule begin_type_typespec

This makes the rule structurally more similar to the other rules. The
goal is that all rules whose name starts with 'begin_type_' actually
start with the rule 'begin_type'. Currently, some rules parse their
type attributes before 'begin_type', which feels wrong, as type
attributes should be part of the type.

No functional change intended.
 1.405  29-Apr-2022  rillig lint: only allow GCC attribute in null statement

The only indented usage in that position is a fallthrough statement, as
a replacement for a /* FALLTHROUGH */ comment. There is no point in
using _Noreturn or _Alignas as a statement.

Ideally, instead of gcc_attribute, the grammar would allow
gcc_attribute_list here (as always with GCC attributes), but that would
have introduced a reduce/reduce conflict, due to the attributes in the
middle of labeled_statement.
 1.404  29-Apr-2022  rillig lint: do not allow type attributes after label

After a label, the type attributes _Alignas, __packed and _Noreturn do
not make sense, so don't allow them. The only kind of attributes that
makes sense there syntactically is GCC __attribute__. Allow multiple
such attributes, like everywhere in the GCC grammar.
 1.403  28-Apr-2022  rillig lint: revert resolving grammar conflicts for labeled statements

Restore the grammar rule for labeled_statement as it was before cgram.y
1.400 from 2022-04-24. This allows labels with attributes again. Fix
the wrong interpretation in the tests; the attributes belong to the
label, not to the statement.

Today in the morning, when I thought that the change in cgram.y 1.400
were innocent, I accidentally ran lint only with the options '-Sw' but
forgot the option '-g' for GNU mode. Without that option, the token
'__attribute__' is unknown, which unsurprisingly leads to lots of syntax
errors, and these didn't change with that commit. The actual change was
only visible in GNU mode.
 1.402  24-Apr-2022  rillig lint: error out on declarations with implicit int type
 1.401  24-Apr-2022  rillig lint: error out on missing type in declarations
 1.400  24-Apr-2022  rillig lint: resolve 4 shift/reduce conflicts in labeled_statement

The attributes are already parsed as part of the statement.

No functional change intended.
 1.399  24-Apr-2022  rillig lint: resolve 6 shift/reduce conflicts in type_direct_declarator

No functional change intended.
 1.398  24-Apr-2022  rillig lint: solve 6 shift/reduce conflicts in notype_direct_declarator

No functional change intended.
 1.397  24-Apr-2022  rillig lint: warn about anonymous struct in struct, in plain C99 mode
 1.396  24-Apr-2022  rillig lint: reduce shift/reduce conflicts in C grammar

Previously, direct_abstract_declarator allowed type attributes like
_Noreturn to be prepended and appended to a type without specifying any
order.

No functional change intended.
 1.395  16-Apr-2022  rillig lint: in C99 mode, allow trailing comma in enum declarations

Adjust the test to be run in C90 mode instead of traditional mode, since
traditional C didn't have enums.
 1.394  10-Apr-2022  rillig lint: fix assertion failure on duplicate qualifiers from __typeof__
 1.393  09-Apr-2022  rillig lint: distinguish between storage class and declaration kind

These types overlap but are not the same.

No functional change.
 1.392  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.391  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.390  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.389  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.388  09-Mar-2022  rillig lint: fix indentation in C grammar

No functional change.
 1.387  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.386  27-Feb-2022  rillig lint: concatenate string literals from left to right

Previously, the string literals "1" "2" "3" "4" were concatenated in the
order "23", "234", "1234". This influenced the location of the
diagnostics for traditional C (which doesn't know concatenation at all)
and for mixing regular strings and wide strings.

Now the diagnostics occur exactly where they are expected. The first
string literal defines whether the whole string is regular or wide, and
any further string literals must match it.

In traditional C mode, there are more diagnostics than before, but that
doesn't hurt since they are still correct and nobody uses lint in
traditional C mode anyway.
 1.385  27-Feb-2022  rillig lint: C99 has been released, so refer to it by its proper name
 1.384  27-Feb-2022  rillig lint: unabbreviate two more members of sym_t

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

No functional change.
 1.382  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.381  26-Feb-2022  rillig lint: fix memory corruption in statement expressions (since 2021-12-17)

The commit that introduced the assertion failure looks innocent, it only
adds a few predefined functions for GCC mode. Nevertheless, before that
commit, lint consistently complained about 'error: void type illegal in
expression [109]', which doesn't make sense either.

This fix also removes the creative use of the initialization stack to
store the type of the statement expression. Having a separate stack for
these statement expressions makes the code easier to understand.
 1.380  26-Feb-2022  rillig lint: extract code for handling statement expressions from the grammar

This prepares the fix of the memory corruption bug that is demonstrated
in t_integration.sh, test case assertion_failures.

No functional change.
 1.379  15-Jan-2022  rillig lint: warn about unreachable null statements

This warning flags the second semicolon of 'return;;' as being
unreachable. It does not warn about these superfluous semicolons in
general though.

Seen in usr.bin/make/bmake_malloc.c.
 1.378  26-Dec-2021  christos Add clang's optnone attribute.
 1.377  20-Dec-2021  rillig lint: add grammar rule for the beginning of a designation

This will be necessary to properly implement handling of initializers
and braced initializer-lists.

No functional change for now since the designation is already reset
after each expression and '}'. To handle initializations properly, the
designation must not be reset after each expression, it must advance to
the next member instead.
 1.376  18-Dec-2021  rillig lint: format grammar consistently

No binary change.
 1.375  16-Dec-2021  rillig lint: narrow down parameter of build_name

Passing an arbitrary tokenizer symbol left too much freedom and
uncertainty to the caller, and 0 was a magic number in this context.

No functional change.
 1.374  15-Dec-2021  christos Add more attributes
 1.373  14-Dec-2021  christos Improve restrict handling.
 1.372  28-Nov-2021  rillig lint: allow Bison debug functions to be unused

The grammar is only compiled using Bison during development time. In the
official builds, it is built with byacc.

No functional change.
 1.371  27-Nov-2021  christos Add target attribute
 1.370  16-Nov-2021  rillig lint: fix check for function calls in strict bool mode

Previously, if a function call occurred in the controlling expression,
its return type could be any scalar, not just bool. This was against
the goal of strict bool mode, which makes bool a separate and
incompabile type to all other types. For example, it would allow
controlling expressions like 'strcmp(a, b)' without the usual '!= 0',
but only if at least one of 'a' and 'b' came from a macro definition
from a system header.

The fix is that the decision of whether the type of the controlling
expression may be scalar is no longer based on the operand types but on
the main operator of the controlling expression.
 1.369  16-Nov-2021  rillig lint: fix wrong error message in strict bool mode

This fix only affects the last token before a macro, as well as the last
token in the expanded macro.
 1.368  16-Nov-2021  rillig lint: rename attron to in_gcc_attribute

No functional change.
 1.367  26-Sep-2021  rillig lint: fix Bison warnings

cgram.y:998.11-35: warning: type clash on default action: <y_sym> != <>
[-Wother]

No functional change.
 1.366  17-Sep-2021  christos Extra commit to fix the actual wrong comment before:
Add _Static_assert grammar and keyword
 1.365  17-Sep-2021  christos remove the lint kludges
 1.364  14-Sep-2021  rillig lint: allow [*] everywhere where [] and [integer] are allowed

It's a seldom used feature, but now it's at least consistent.
 1.363  14-Sep-2021  rillig lint: support int[*][3] from C99

No warning in pre-C99 mode since this declarator is not used in practice
anyway.
 1.362  13-Sep-2021  rillig lint: continue analysis of wrong type in abstract declaration

No functional change.
 1.361  10-Sep-2021  rillig lint: replace space followed by tab with simply tab

No functional change.
 1.360  04-Sep-2021  rillig lint: spell out abbreviations in comments

No functional change.
 1.359  28-Aug-2021  rillig lint: explicitly ignore return value of some function calls

This fixes the warning from lint2 that these functions return values
which are sometimes ignored.

The remaining calls to fprintf that ignore the return value come from
scan.c. Lint does not currently detect the auto-generated portions of
that file and the interesting ones since it assumes that scan.c is the
main filename, see expr_zalloc_tnode.

No functional change.
 1.358  25-Aug-2021  rillig lint: add __attribute__ regparm

Seen in libexec/ld.elf_so/rtld.h.
 1.357  21-Aug-2021  rillig lint: add missing newlines to grammar debug output
 1.356  19-Aug-2021  christos Add returns_nonnull attribute
 1.355  11-Aug-2021  rillig lint: allow GCC __attribute__ after array brackets

GCC accepts this, so should lint. Seen in pam_lastlog.c:115.
 1.354  01-Aug-2021  rillig lint: clean up debug logging in the C grammar
 1.353  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.352  31-Jul-2021  rillig lint: add debugging output for the grammar tokens

No functional change outside debug mode.
 1.351  27-Jul-2021  rillig lint: inline align_as in the grammar

This saves 500 bytes in the resulting binary.

No functional change.
 1.350  27-Jul-2021  rillig lint: provide a direct link to the documentation

No functional change.
 1.349  26-Jul-2021  rillig lint: fix parse error in conditional expression (since 2021-07-15)
 1.348  26-Jul-2021  rillig lint: fix parsing of chained assignments (since 2021-07-15)

The grammar rule for assignment_expression is quite different from those
of the other expressions, for 2 reasons: first, its precedence is
right-to-left. Second, its left-hand side must be an lvalue, which
rules out all binary operators. K&R C even had a grammar rule named
'lvalue' for this purpose. Later C standards made the kinds of
expressions more fine-grained and used 'unary_expression' in this place.
 1.347  26-Jul-2021  rillig lint: remove redundant associativity declarations

Since cgram.y 1.325 from 2021-07-15, these are not needed anymore.
Strangely, neither yacc nor Bison warned about this redundancy.

No functional change, the grammar rules are the same as before.
 1.346  25-Jul-2021  rillig lint: revert previous commit; it didn't improve readability

No functional change.
 1.345  25-Jul-2021  rillig lint: merge duplicate code for abstract_declaration

No functional change; same code coverage outside of cgram.y.
 1.344  25-Jul-2021  rillig lint: resolve conflicts in begin_type_specifier_qualifier_list

The 9 shift/reduce conflicts were all internal to the grammar rule
begin_type_specifier_qualifier_list. Previously, there were two
possible ways to parse '__attribute__(()) const int':

1. '__attribute__(())' 'const int'
2. '__attribute__(()) const' 'int'

Both ways would produce the same result since __attribute__ has almost
no observable effects on the resulting type.

No functional change.
 1.343  25-Jul-2021  rillig lint: reorder grammar rules

First the base cases, then the extensions, like in most other rules in
this file.

No functional change.
 1.342  25-Jul-2021  rillig lint: fix parsing of enumerators with __attribute__
 1.341  25-Jul-2021  rillig lint: fix parsing of __attribute__ before enum tag

The __attribute__ after the enumerators will be fixed in a follow-up
commit since lint exits after the 5th syntax error in a translation
unit, which up to now shadowed the error messages about the enumerators.
 1.340  25-Jul-2021  rillig lint: add citations for a few grammar rules

No functional change.
 1.339  25-Jul-2021  rillig lint: fix parsing of GNU __attribute__ after __asm

GCC only accepts them in the order __asm __attribute__, not the other
way round. So should lint.
 1.338  25-Jul-2021  rillig lint: wrap overly long lines

No functional change.
 1.337  25-Jul-2021  rillig lint: do not parse 'typeof(0)(void)' as function call

Previously, lint tried to parse 'typeof(0)(void)' as 'typeof'
'(0)(void)', which tries to call 0 as a function.
 1.336  25-Jul-2021  rillig lint: fix parsing of 'typeof(double(typeof(0.0)))'

By removing the misplaced grammar rule 'abstract_declarator: T_TYPEOF',
the type expression 'typeof(double(typeof(0.0)))' is no longer
interpreted as a declarator, but rather as a type specifier, just as in
the GCC parser.

This resolves 7 shift/reduce conflicts.
 1.335  23-Jul-2021  rillig lint: move single semicolon to external_declaration

This aligns more closely with the grammar from GCC's parser. The global
cleanup from the grammar rule 'external_declaration:
top_level_declaration' is not performed anymore, which doesn't matter
since there is nothing to clean up after a single semicolon.

No functional change.
 1.334  21-Jul-2021  rillig lint: move assignments to $$ at the end of the action

They are closely related to return statements.

While here, add some more remarks from reviewing the grammar.

No functional change.
 1.333  21-Jul-2021  rillig lint: rename grammar rules for specifier-qualifier-list

No functional change.
 1.332  21-Jul-2021  rillig lint: remove unnecessary assertion for type qualifier

If there is any new type qualifier that lint should support (such as
_Atomic from C11), the obvious place is to look in the grammar rule
type_qualifier, so there is no need to have an assertion.

No functional change.
 1.331  21-Jul-2021  rillig lint: rename ignore_up_to_rparen to match the grammar rule

No functional change.
 1.330  20-Jul-2021  rillig lint: use consistent naming scheme for functions that build nodes

No functional change.
 1.329  20-Jul-2021  rillig lint: split 'build' into build_binary and build_unary

No functional change.
 1.328  15-Jul-2021  rillig lint: remove message 66 about missing semicolon in struct-declaration
 1.327  15-Jul-2021  rillig lint: merge duplicate code in declarations

No functional change, code coverage outside cgram.y stays the same.
 1.326  15-Jul-2021  rillig lint: rename grammar rule 'declaration' to 'declaration_or_error'

This prepares for merging the duplicate code from top_level_declaration.
The code coverage outside cgram.y is exactly the same as before.

No functional change.
 1.325  15-Jul-2021  rillig lint: in the grammar, replace %prec with explicit rules

This way, in the arguments of __attribute__, where only constant
expressions are expected, a '=' leads to a syntax error. Previously,
this was not detected.

No noticeable change in practice since these cases are already handled
by the compilers.
 1.324  14-Jul-2021  rillig lint: in the grammar, rename 'decl' to 'declarator'

For a casual reader, the abbreviation 'decl' was ambiguous since C has
both declarations and declarators.

No functional change.
 1.323  14-Jul-2021  rillig lint: extract build_member_access from the grammar

No functional change.
 1.322  14-Jul-2021  rillig lint: rename grammar rule 'expr' to 'expression'

No functional change.
 1.321  14-Jul-2021  rillig lint: remove references to C18

The standard is called C17, not C18, and furthermore the section
numbering didn't change between C11 and C17.

No functional change.
 1.320  12-Jul-2021  rillig lint: order type declarations in grammar, group by C99 section

No functional change.
 1.319  12-Jul-2021  rillig lint: reorder grammar rules in the same way as in C99

The code coverage before and after this change is exactly the same,
except of course for cgram.y and cgram.c.

No functional change.
 1.318  11-Jul-2021  rillig lint: reorder grammar rules for expressions according to C18

No functional change.
 1.317  11-Jul-2021  rillig lint: make _Generic a primary-expression

C11 says so, and unless the _Generic expression was wrapped in
parentheses, it was not possible before to use it as a function call
expression.
 1.316  11-Jul-2021  rillig lint: rename grammar rule 'term' to 'cast_expression'

No functional change.
 1.315  11-Jul-2021  rillig lint: reorganize grammar rules for unary expressions

According to GCC, __builtin_offsetof is a primary-expression.

According to GCC, __real__, __imag__ and __extension__ are
unary-operator, just like '!' and '~'.

According to C11, _Alignof is a unary-operator.
 1.314  11-Jul-2021  rillig lint: remove grammar conflict for __real__ and __imag__

The rules were redundant since a term can be parenthesized by itself,
there is no need for an extra rule. The rules for '__real__(term)' and
'__imag__(term)' were never reduced since these cases were handled by
the rules '__real__ term' and '__imag__ term' a few lines above.

No functional change.
 1.313  11-Jul-2021  rillig lint: support __attribute__((hot))

The corresponding attribute 'cold' was already added in cgram.y 1.84
from 2016-12-29.
 1.312  11-Jul-2021  rillig lint: fix shift/reduce conflict for dangling else

The following line no longer occurs in the yacc output:
257: shift/reduce conflict (shift 427, reduce 270) on T_ELSE

No functional change.
 1.311  11-Jul-2021  rillig lint: resolve shift/reduce conflict in notype_direct_decl

When a notype_direct_decl was followed by a type_attribute_list, and the
next token was another type_attribute, the parser could either continue
the current type_attribute_list or start a new one. Either way has the
same effect since type_attribute_list has no associated action.

This reduces the conflicts by 4, one for each of T_ALIGNAS, T_ATTRIBUTE,
T_NORETURN, T_PACKED. There are several other conflicts involving these
4 tokens, but they are harder to fix.

No functional change.
 1.310  11-Jul-2021  rillig lint: use separate tokens for logical not and bitwise complement

The token T_UNARY was misleading since it only captured 2 of the 6
operators that C99 calls unary-operator. Make the grammar easier to
understand by explicitly listing these 2 operators.

No functional change.
 1.309  11-Jul-2021  rillig lint: remove redundant %prec from the grammar

Now that the precedence of the unary operators has been modeled via
separate rules, the precedence is no longer needed.

No change to the generated parser, with both yacc or Bison.
 1.308  11-Jul-2021  rillig lint: remove shift/reduce conflict for sizeof

According to the grammar, the expression 'sizeof(int)x' was ambiguous.
Since 'sizeof(int)' is a valid term, that could have been reduced,
which would have resulted in a parse error when trying to parse 'x'.

Now 'sizeof' takes a unary_expression instead of a term.

No functional change.
 1.307  11-Jul-2021  rillig lint: resolve shift/reduce conflicts for unary expressions

The grammar rule 'term' was ambiguous since both the prefix and postfix
increment operators were listed with the same precedence. The
expression '++x++' was parsed as '++ (x++)', as expected, since
conflicts resolve towards shift.

Resolve these conflicts by structuring the grammar as in C99, with the
GCC extension of statement-expressions. The resolved conflicts are:

134: shift/reduce conflict (shift 161, reduce 347) on T_LBRACK
134: shift/reduce conflict (shift 162, reduce 347) on T_LPAREN
134: shift/reduce conflict (shift 163, reduce 347) on T_POINT
134: shift/reduce conflict (shift 164, reduce 347) on T_ARROW
134: shift/reduce conflict (shift 165, reduce 347) on T_INCDEC
state 134
term : term . T_INCDEC (335)
term : term . T_LBRACK expr T_RBRACK (341)
term : term . T_LPAREN T_RPAREN (342)
term : term . T_LPAREN argument_expression_list T_RPAREN (343)
term : term . point_or_arrow T_NAME (344)
term : T_EXTENSION term . (347)

No functional change.
 1.306  11-Jul-2021  rillig lint: fix bug when parsing unused variable (since 2021-07-10)

Partially revert to cgram.y 1.248 from 2021-06-29.

This fixes the parse error for variables whose declaration starts with
__attribute__((unused)). In the many refactorings of the last days this
bug has slipped in, and since there were several refactorings in that
area, there may be have been further bugs that are not caught by the
current test suite. Revert for now and maybe apply them later again
when there are more tests.

Things kept from the current version are:

The names of most of the rules, as they correspond more closely to C99
and do not affect the behavior in any way.

In type_direct_decl, the replacement of type_attribute_list with
type_attribute since that nonterminal is already part of a repetition
(saves 4 conflicts).

In block_item, the order of the rules corresponds to C99. This has no
influence on the generated parser, except for the rule numbers, which
are informative.

The merge of the duplicate code for struct_tag, enum_tag and
enum_constant, as they all contained exactly the same code.
 1.305  10-Jul-2021  rillig lint: fix parsing of __attribute__ for member (since 2021-07-10)

Since cgram.y 1.280 from 2021-07-10, lint could not parse struct members
that have multiple __attribute__ in front of their type.
 1.304  10-Jul-2021  rillig lint: inline grammar rules declmod and qualifier_or_storage_class

The rule declmod had a confusing name since declmods was not exactly a
list of declmod.

Inlining the rules reduces the abstraction level. There are still some
shift/reduce conflicts in that area, so make the rules as simple as
possible, in order to resolve these conflicts.

No functional change.
 1.303  10-Jul-2021  rillig lint: merge duplicate code for struct and enum declarations

No functional change.
 1.302  10-Jul-2021  rillig lint: move type_attribute back into the main section

Type attributes are a standard feature since C11 and thus do not belong
in the GCC-specific section. Only the GCC __attribute__ belongs there.

No functional change.
 1.301  10-Jul-2021  rillig lint: merge duplicate code for struct and enum tags

This is a tricky area. Inlining identifier_sym did not work because of
the side-effects of getsym. In situations where two identifiers of
different kinds follow each other, such as 'enum id1 id2', the timing is
crucial, and inlining identifier_sym would have led to an internal error
in getsym. The symbol type has to be reset from FTAG to FVFT before
reading the next token.

No functional change.
 1.300  10-Jul-2021  rillig lint: rename grammar rules to align with C99

No functional change.
 1.299  10-Jul-2021  rillig lint: merge duplicate code for typespec and notype_typespec

No functional change.
 1.298  10-Jul-2021  rillig lint: rename func_arg_list to align with C99

No functional change.
 1.297  10-Jul-2021  rillig lint: rename y_sb to y_name

That buffer is only used for names of identifiers, so be more specific.

No functional change.
 1.296  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.295  10-Jul-2021  rillig lint: extract clrtyp from noclass_declspecs

Finally each clrtyp pairs up with its corresponding deftyp, which makes
the grammar much easier to understand. The many grammar rules that
contain these actions now all look the same.

No functional change.
 1.294  10-Jul-2021  rillig lint: extract clrtyp from declaration_specifiers

This makes the grammar more uniform and thereby easier to understand.
The actions clrtyp and deftyp now come in pairs almost everywhere.

No functional change.
 1.293  10-Jul-2021  rillig lint: split grammar rule clrtyp_declmods

By extracting clrtyp from that rule, clrtyp and deftyp pair up nicely in
most of the grammar rules. These two actions delimit the common part of
a declaration that declares multiple identifiers.

No functional change.
 1.292  10-Jul-2021  rillig lint: inline grammar rule clrtyp_typespec

No functional change.
 1.291  10-Jul-2021  rillig lint: merge duplicate code from grammar rule clrtyp_typespec

No functional change.
 1.290  10-Jul-2021  rillig lint: swap order in grammar rule clrtyp_typespec

It should not make a difference whether the rule says 'T_TYPENAME
clrtyp' or 'clrtyp T_TYPENAME'. The latter order is more consistent
with the name of the rule, though.

According to the code, these two tokens take completely distinct
actions. The code coverage outside of cgram.y and cgram.c stays exactly
the same, at least for lint's test suite.

No functional change intended.
 1.289  10-Jul-2021  rillig lint: rename grammar rule declmods to clrtyp_declmods

It wasn't obvious from the name 'declmods' that this rule starts a new
type declaration.

No functional change.
 1.288  10-Jul-2021  rillig lint: do not allow struct{const;}

In traditional C, a struct member was defined syntactically as
'type-specifier struct-declarator-list', the concept of a type-qualifier
was not known back then.

C90 invented the type-qualifier 'const' and relaxed the syntactic
requirement for struct member declarations by allowing 'const x'. Having
only a type-qualifier without an actual type may be regarded as an
"incomplete type", which would be forbidden by C90 and later.

Anyway, this doesn't occur in practice anyway, so there is no need for
lint to try to parse it. This removes a bit of dead code, since a
type-qualifier-list can never have type struct or union.
 1.287  10-Jul-2021  rillig lint: remove noclass_declmods from grammar

That rule was hard to understand since it contained clrtyp but not the
corresponding deftyp. It's easier to read when a grammar rule contains
both clrtyp and deftyp in the same line.

C99 does not mention the term 'decl-modifier' anywhere, and in fact the
only thing that this grammar rule allowed was a type-qualifier-list.
The new name better reflect this.

No functional change.
 1.286  10-Jul-2021  rillig lint: fix assertion failure for malformed member declaration
 1.285  10-Jul-2021  rillig lint: merge duplicate code in grammar for 'for' loops

No functional change.
 1.284  10-Jul-2021  rillig lint: clean up grammar for do-while statements

No functional change.
 1.283  10-Jul-2021  rillig lint: merge duplicate code in grammar for 'while' statements

No functional change.
 1.282  10-Jul-2021  rillig lint: do not allow __packed or _Alignas in statement

When the rule 'statement: type_attribute T_SEMI' was added in cgram.y
1.214 from 2021-04-14, type_attribute was the closest match since there
was no definition for gcc_attribute yet.
 1.281  10-Jul-2021  rillig lint: reduce shift/reduce conflicts in direct_abstract_declarator

No functional change.
 1.280  10-Jul-2021  rillig lint: remove 8 of the grammar conflicts, 142 remaining

No functional change.
 1.279  10-Jul-2021  rillig lint: merge duplicate code in declmods and declmod

No functional change.
 1.278  10-Jul-2021  rillig lint: remove duplicate code for parsing declarations

No functional change.
 1.277  09-Jul-2021  rillig lint: remove 6 conflicts from the grammar, in type_direct_decl

No functional change.
 1.276  09-Jul-2021  rillig lint: remove 6 of the remaining 162 conflicts from the grammar

No functional change.
 1.275  09-Jul-2021  rillig lint: indent grammar actions properly

No functional change.
 1.274  08-Jul-2021  rillig 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.
 1.273  08-Jul-2021  rillig lint: fix wrong check for enum constants in switch (since today)
 1.272  08-Jul-2021  rillig 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.
 1.271  08-Jul-2021  rillig 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.
 1.270  08-Jul-2021  rillig 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.
 1.269  08-Jul-2021  rillig lint: clean up grammar for member declarations

No functional change.
 1.268  08-Jul-2021  rillig lint: move optional grammar rules above their corresponding rules

No functional change.
 1.267  08-Jul-2021  rillig 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.
 1.266  08-Jul-2021  rillig 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.
 1.265  06-Jul-2021  rillig 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.
 1.264  06-Jul-2021  rillig lint: document the cause for 24 of the 162 grammar conflicts
 1.263  06-Jul-2021  rillig 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.
 1.262  06-Jul-2021  rillig lint: do not allow _Alignas (from C11) or __packed after a label
 1.261  06-Jul-2021  rillig lint: rename grammar rules for GCC __attribute__

No functional change.
 1.260  06-Jul-2021  rillig 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.
 1.259  06-Jul-2021  rillig lint: align grammar rules for enum-specifier with C99

No functional change.
 1.258  06-Jul-2021  rillig lint: document grammar rule that deviates from C99
 1.257  06-Jul-2021  rillig 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.
 1.256  06-Jul-2021  rillig 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.
 1.255  06-Jul-2021  rillig 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.
 1.254  06-Jul-2021  rillig lint: clean up style in grammar

No functional change.
 1.253  06-Jul-2021  rillig lint: rename type generic_association_types to generic_association

The word 'types' was misleading and unnecessary.

No functional change.
 1.252  05-Jul-2021  rillig lint: refer to documentation about the 'notype' rules in the grammar
 1.251  05-Jul-2021  rillig lint: rename message 340 to talk about "GCC extension", not "GNU"
 1.250  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.249  03-Jul-2021  rillig lint: guard against segmentation fault when parsing struct

Found by afl. The code that triggers this case is:

struct{const}
 1.248  29-Jun-2021  rillig 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.
 1.247  28-Jun-2021  rillig lint: fix parse error for type 'void (*)[*]'
 1.246  28-Jun-2021  rillig 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.
 1.245  28-Jun-2021  rillig lint: align grammar with C99

C99 uses type-qualifier-list_opt in section 6.7.5.
 1.244  28-Jun-2021  rillig lint: refrain from renaming the grammar rule 'pointer'

That rule is called 'pointer' by C99 as well.

No functional change.
 1.243  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.242  28-Jun-2021  rillig lint: only accept assignment-expression in _Generic

That's what C11 says.
 1.241  27-Jun-2021  rillig 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.
 1.240  27-Jun-2021  rillig 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.
 1.239  27-Jun-2021  rillig lint: reorder grammar rules from big to small

No functional change.
 1.238  27-Jun-2021  rillig 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.
 1.237  27-Jun-2021  rillig lint: fix result type of _Generic expressions
 1.236  27-Jun-2021  rillig 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".
 1.235  27-Jun-2021  rillig lint: sort and rename grammar rules for generic selection

No functional change.
 1.234  27-Jun-2021  rillig lint: fix uninitialized variable for declaration after statement
 1.233  27-Jun-2021  rillig 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.
 1.232  27-Jun-2021  rillig 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 '$$'.
 1.231  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.230  20-Jun-2021  rillig 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.
 1.229  20-Jun-2021  rillig lint: fix crash on semantically wrong code in ({...})

Found by afl.
 1.228  19-Jun-2021  rillig lint: fix assertion failure in struct with unnamed member

Found using afl.
 1.227  19-Jun-2021  rillig lint: replace undefined behavior with assertion failure

Triggered by this malformed code:

struct{int;
 1.226  03-May-2021  rillig lint: fix parsing of __typeof__ after statement in ({ ... })

Since C99, declarations and statements can be freely mixed, and GCC
supported this even before 1999.
 1.225  02-May-2021  rillig lint: sort GCC attributes alphabetically in the grammar

No functional change.
 1.224  01-May-2021  rillig lint: support all documented variants of __attribute__((nonnull))
 1.223  30-Apr-2021  christos - add nonstring attribute
- allow attributes after labels (for unused)
XXX: split the attributes into function, variable, etc attributes
so that we don't accept all attributes in all places (only where they make
sense)
 1.222  29-Apr-2021  christos Add constructor and destructor attribute priorities
 1.221  23-Apr-2021  rillig lint: merge duplicate code in grammar for GCC compound expressions

This increases the number of shift/reduce conflicts, once again. I
don't know why since the previous two grammar rules only differed in a
single detail. One of them had a declaration_list while the other
didn't. This difference is exactly what declaration_list_opt is for.

Anyway, the tests for both cases (with and without declarations) work
exactly as before.

Merging this duplicate code will probably make it easier to fix the
current limitation in lint regarding GCC compound expressions that a
statement followed by a declaration generates a syntax error.

Fixing this is not trivial, my first attempt failed either with
segmentation faults or with sym->s_type becoming NOSPEC during the
expression.
 1.220  20-Apr-2021  christos Add common attribute
 1.219  18-Apr-2021  rillig lint: fix strict bool mode errors in cgram.y

The code generated by yacc already adheres to strict bool mode, in
default mode as well as in debug mode.

Running lint on the generated cgram.c as well avoids most of the
"declared but not used" warnings from lint2.

The code generated by lex does not adhere to strict bool mode though.
Suppressing the errors from strict bool mode works, but then lint1 runs
into an assertion failure:

assertion "tn != NULL || nerr != 0" failed
in expr at tree.c:3610 near scan.c:822

This leaves several warnings about "declared but not used" for the
functions from lex.c.
 1.218  14-Apr-2021  rillig lint: remove stray semicolon from grammar, make empty rule visible

No functional change.
 1.217  14-Apr-2021  christos there is also an optional type qualifier list in the array size
 1.216  14-Apr-2021  rillig lint: add support for C11-isms such as int[static 3]
 1.215  14-Apr-2021  rillig lint: add test for newly added message about static array size
 1.214  14-Apr-2021  christos support parsing c99's static class for array size expressions.
 1.213  13-Apr-2021  christos Allow type attributes after function pointer parameters
 1.212  12-Apr-2021  christos Add attribute fallthrough
 1.211  02-Apr-2021  rillig lint: add parentheses after sizeof, as required by share/misc/style

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

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

No functional change.
 1.208  02-Apr-2021  rillig lint: rename getnode to expr_zalloc_tnode

The new name highlights that the returned memory is only valid in the
scope of the current expression. This was misleading before since the
other related functions all have a 't' (probably for 'temporary') in
their names.

Also encode in the function name that the returned memory is zeroed out
as that could not be inferred from the old name.

No functional change.
 1.207  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.206  29-Mar-2021  rillig lint: remove outdated comments, clean up style

No functional change.
 1.205  28-Mar-2021  rillig lint: rename public designator functions

Their previous names were too similar to the actual implementation
functions, which was confusing.

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

No functional change.
 1.203  26-Mar-2021  rillig lint: rename pushctrl and popctrl to be more expressive

While here, remove the magic number 0 that in this context means
"function body".

No functional change.
 1.202  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.201  26-Mar-2021  rillig lint: remove redundant '%prec' from grammar for compound literals

No change to the resulting binary.
 1.200  25-Mar-2021  rillig lint: fix names of functions dealing with designations

These functions modify the whole designation, not only a single
designator.

No functional change.
 1.199  23-Mar-2021  christos Add _Alignas()
 1.198  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.197  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.196  21-Mar-2021  rillig lint: rename functions for handling control statements

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

No functional change.
 1.194  21-Mar-2021  rillig lint: rename declspecs to declaration_specifiers, just as in C99

No functional change.
 1.193  21-Mar-2021  rillig lint: rename grammar rule 'data_def' to 'top_level_declaration'

No functional change.
 1.192  21-Mar-2021  rillig lint: remove redundant '%prec' declarations from the grammar

No change to the generated binary.
 1.191  21-Mar-2021  rillig lint: rename token T_XOR to T_BITXOR

For symmetry with the operator, which is named BITXOR.

No functional change.
 1.190  21-Mar-2021  rillig lint: in debug output, use uniform file location references

This makes it easy to click on the location in the IDE instead of having
to manually parse the location and navigate to it.

No functional change outside debug mode.
 1.189  21-Mar-2021  rillig lint: remove redundant operator information from the grammar

Several tokens can only ever map to a single operator and thus do not
need to encode the operator. Indeed, they already encoded it as NOOP,
and it was not used by any grammar rule.

No functional change.
 1.188  20-Mar-2021  rillig lint: rename ftflg to seen_fallthrough

One less abbreviation to remember when reading the code.

No functional change.
 1.187  20-Mar-2021  rillig lint: make the calls to clear_warning_flags stand out less

Even though clear_warning_flags and its companions are implemented as
macros, they act like ordinary functions. Do not distract the reader by
using uppercase names for them.

No functional change.
 1.186  20-Mar-2021  rillig lint: clean up grammar for declaration after statement

No functional change.
 1.185  20-Mar-2021  rillig lint: fix check for declaration after statement in pre-C99 mode

The new code may not be the most beautiful, but it fixes all bugs that
occurred while testing message 327. The grammar rules are taken from
C99 6.8.2, so it's no surprise they work well.
 1.184  20-Mar-2021  rillig lint: properly name C99 in message about declaration after statement

Now that C99 has been released and published, there is no reason anymore
to refer to it as C9X.
 1.183  20-Mar-2021  rillig lint: use proper boolean literals instead of 0/1

The code in the C grammar is generated by yacc and is not checked by
lint's strict bool mode, therefore the replacement was done manually.

No change to the resulting change.
 1.182  20-Mar-2021  rillig lint: remove unnecessary '%prec T_COMMA' from grammar

My previous commit message was wrong in saying that the '%prec' was
necessary. It is not necessary.

Most probably I misspelled the name of the grammar rule as opt_comma
instead of comma_opt, which would lead to the same number of conflicts
in the grammar plus a warning, but no build failure.
 1.181  20-Mar-2021  rillig lint: join grammar rules for initialization

The '%prec T_COMMA' is necessary to avoid lots of parse errors in the
lint1 unit tests. Curiously, further down in the grammar, for compound
literals, the '%prec T_COMMA' is not necessary, even though the context
looks very similar.

No functional change.
 1.180  20-Mar-2021  rillig lint: fix grammar for initialization

Previously, the grammar syntactically accepted the following code:

int var = .member = 12345;

The designation '.member =' can only be used with brace-enclosed
initializers.
 1.179  20-Mar-2021  rillig lint: align rule names in grammar with C99

No functional change.
 1.178  19-Mar-2021  rillig lint: add reminder that C99 does not allow '{}' in initializer

No functional change.
 1.177  19-Mar-2021  rillig lint: rename push_member and pop_member

These two functions are supposed to model the designator that is used
for initializing structs and arrays. The implementation is still buggy
and does not work at all for C99 designators with multiple names, see
d_init_pop_member.c.

For now, just rename the functions to head in the right direction.

No functional change.
 1.176  17-Mar-2021  rillig lint: add debug logging for C99-style initialization of arrays

No functional change outside debug mode.
 1.175  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.174  17-Mar-2021  rillig lint: move main part of idecl over to decl.c and rename it

No functional change.
 1.173  17-Mar-2021  rillig lint: replace a call to LERROR with lint_assert

No functional change.
 1.172  17-Mar-2021  rillig lint: rename 'toicon' to 'to_int_constant'

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

No functional change.
 1.170  17-Mar-2021  rillig lint: rename 'parn' to 'paren' in the grammar

No functional change.
 1.169  07-Mar-2021  rillig lint: do not allow assignment-expression for constant-expression

It's a funny idea to do something like 'case a = 13:', but since any
compiler will reject this code, there is no point in lint supporting it.

No functional change since everywhere the grammar allows a constant
expression, there is no ambiguity where an assignment could be
interpreted differently.
 1.168  07-Mar-2021  rillig lint: rename grammar rule 'constant'

C99 6.4.4 already defines a grammar rule named 'constant' for an number
literal or an enum constant, so don't use that name for something else.

No functional change.
 1.167  07-Mar-2021  rillig lint: align names of C grammar rules with C99

No functional change.
 1.166  07-Mar-2021  rillig lint: in strict C mode, warn about initialization with '[a ... b]'

https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html
 1.165  07-Mar-2021  rillig lint: fix off-by-one error in 'case 3...5'

According to the GCC documentation[1], the high end of the range is
inclusive as well, which makes sense since otherwise there would be no
way of specifying a range that includes the maximum representable
number.

Since the range is not used at all in the code, none of the tests could
possibly fail.

[1] https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html

No functional change.
 1.164  07-Mar-2021  rillig lint: inline 'case 3...5' in grammar

There was no point in having a separate grammar rule for the '3...' part
of a range expression, it just made the code more complicated than
necessary.

No functional change.
 1.163  20-Feb-2021  rillig lint: rename mkinit to init_using_expr

No functional change outside debug mode.
 1.162  19-Feb-2021  rillig lint: rename storage class constants to be more expressive

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

No functional change.
 1.160  31-Jan-2021  rillig lint: don't warn about constant condition in 'do { } while (0)'
 1.159  31-Jan-2021  rillig lint: add quotes to messages 1 and 19
 1.158  31-Jan-2021  rillig lint: be more precise in message 003 "tag in argument list"
 1.157  18-Jan-2021  rillig lint: clean up member names of control_structure and comments
 1.156  18-Jan-2021  rillig lint: rename grammar rule lorange

It looked too much like an orange.
 1.155  18-Jan-2021  rillig lint: rename grammar rules to align with C99 6.7.6
 1.154  18-Jan-2021  rillig lint: fix precedence of __builtin_offsetof

A previous version of the C grammar contained TBUILTIN_SIZEOF in this
place, which had two typos. Therefore it was handled as a separate
token that was otherwise ignored. Curiously, bison didn't warn about
this obvious inconsistency.
 1.153  18-Jan-2021  rillig lint: sort tokens in grammar
 1.152  18-Jan-2021  rillig lint: rename T_SOU to T_STRUCT_OR_UNION

This abbreviation occurred too seldom to be used.
 1.151  18-Jan-2021  rillig lint: don't treat restrict and _Thread_local as volatile anymore
 1.150  18-Jan-2021  rillig lint: align token names with the wording from C99
 1.149  18-Jan-2021  rillig lint: replace abort with lint_assert
 1.148  18-Jan-2021  rillig lint: expand abbreviations in function names
 1.147  18-Jan-2021  rillig lint: rename T_ELLIPSE to T_ELLIPSIS

The 3 dots have nothing to do with geometry.
 1.146  18-Jan-2021  rillig lint: rename T_STROP to T_MEMBACC

The 'STR' was misleading since it is the abbreviation for 'string' in
many other programs. Member access not only happens in structs, it also
happens in unions.
 1.145  17-Jan-2021  rillig lint: rename T_AND to T_AMPER

When parsing a text into a C program, the character '&' does not yet
mean 'bitwise and', it could also be the address operator.
 1.144  17-Jan-2021  rillig lint: rename bitwise operators

When there are several variants of the AND operator, both of them should
get a distinguishing prefix, otherwise it's not clear which of the two
possible operators is meant by the plain AND.
 1.143  17-Jan-2021  rillig lint: rename operator STAR to INDIR

C99 calls this operator the "indirection operator". The word "star"
does not occur in the index of that standard.
 1.142  17-Jan-2021  rillig lint: rename operator AMPER to ADDR

There is no operator called 'ampersand'. The ampersand sign is merely
the textual representation of both the operator ADDR and the operator
BITAND.
 1.141  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.140  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.139  12-Jan-2021  rillig lint: add new check for strict bool mode

In strict bool mode, bool is considered incompatible with all other
scalar types, just as in Java, C#, Pascal.

The controlling expressions in if statements, while loops, for loops and
the '?:' operator must be of type bool. The logical operators work on
bool instead of int, the bitwise operators accept both integer and bool.
The arithmetic operators don't accept bool.

Since <stdbool.h> implements bool using C preprocessor macros instead of
predefining the identifiers "true" and "false", the integer constants 0
and 1 may be used in all contexts that require a bool expression.
Except from these, no implicit conversion between bool and scalar types
is allowed.

See usr.bin/tests/xlint/lint1/d_c99_bool_strict.c for more details.

The command line option -T has been chosen because all obvious choices
(-b or -B for bool, -s or -S for strict) are already in use. The -T may
stand for "types are checked strictly".

The default behavior of lint doesn't change. The strict bool check is
purely optional.

An example program for strict bool mode is usr.bin/make, which has been
using explicit comparisons such as p != NULL, ch != '\0' or n > 0 in
most places for a long time now, even before the refactoring in 2020.
 1.138  10-Jan-2021  rillig lint: rename functions with short names
 1.137  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.136  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.135  09-Jan-2021  rillig lint: rename ename to enumeration_constant
 1.134  09-Jan-2021  rillig lint: align grammar rules with C99
 1.133  09-Jan-2021  rillig lint: expand abbreviations in grammar rules

stmnt -> statement
comp -> compound

The abbreviation "stmnt" was non-standard, and "comp" was ambiguous
since it is used for "comparison" as well.
 1.132  09-Jan-2021  rillig lint: rename T_MULT to T_ASTERISK

In the early phase of lexical analysis, the '*' does not mean
multiplication, therefore its name should not suggest that. It is only
an asterisk, and depending on the surrounding context, it will only
later turn into a pointer dereference or a multiplication.

The call operator(T_MULT, MULT) was misleading since the MULT was not
used at all.
 1.131  05-Jan-2021  rillig lint: remove unused TBUILTIN_SIZEOF from the C grammar

This token is not generated by the lexer, and it was misspelled anyway.
All other token names start with "T_", this one was missing the
underscore.
 1.130  03-Jan-2021  rillig lint: use consistent indentation for C grammar
 1.129  03-Jan-2021  rillig lint: rename funcarg and funccall to longer names

From the previous short names, it was no obvious that these functions
create a new tree node.

The function named funccall in lint2 has been left as-is, since it has a
completely different prototype.
 1.128  03-Jan-2021  rillig lint: rename functions that create nodes
 1.127  01-Jan-2021  rillig lint: add missing redundant messages in source code
 1.126  01-Jan-2021  rillig lint: rename tokens for left and right parentheses
 1.125  01-Jan-2021  rillig lint: split label handling into separate functions

The only thing these cases have in common is the name "label" and the
"reached = 1" assignment. That's not reason enough to combine
completely unrelated functions.
 1.124  01-Jan-2021  rillig lint: replace simple LERROR with lint_assert
 1.123  01-Jan-2021  rillig lint: align comments with actual message, in the lexer and parser
 1.122  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.121  30-Dec-2020  rillig lint: un-abbreviate parenthesized and _strg
 1.120  30-Dec-2020  rillig lint: rename symt_t constants

There's no need to abbreviate them, furthermore FMOS was imprecise.
 1.119  30-Dec-2020  rillig lint: rename s_nxt to s_next
 1.118  30-Dec-2020  rillig lint: reduce nesting of function calls
 1.117  30-Dec-2020  rillig lint: add debug logging to the parser

Even with -DDEBUG and -DYYDEBUG, the debug output is not detailed enough
to clearly see what happens.

Add some custom debug logging to the parser, mainly for demonstration
purposes, and also to find out how to fix the test d_struct_init_nested.
 1.116  29-Dec-2020  rillig lint: split complete_tag into separate functions
 1.115  29-Dec-2020  rillig lint: rename functions for handling the initialization stack
 1.114  29-Dec-2020  rillig lint: rename functions with very short names
 1.113  29-Dec-2020  rillig lint: fix indentation and alignment that used space-tab
 1.112  29-Dec-2020  rillig lint: remove redundant parentheses around return value
 1.111  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.110  28-Dec-2020  rillig lint: spell check
 1.109  28-Dec-2020  rillig lint: remove trailing whitespace
 1.108  28-Dec-2020  rillig lint: sort includes
 1.107  28-Dec-2020  rillig lint: rename tspec macros
 1.106  04-Dec-2020  christos __sentinel__ = __sentinel__(0)
 1.105  18-Sep-2020  christos add optimize attribute
 1.104  04-Mar-2019  christos Add __thread/tls_model attribute
 1.103  04-Mar-2019  christos add a two argument version of alloc_size
 1.102  04-Mar-2019  christos add gnu_printf
 1.101  03-Mar-2019  christos Add more gnu attributes
 1.100  04-Jan-2019  christos recognize destructor attribute.
 1.99  24-Nov-2018  christos add warn_unused_result.
 1.98  03-Sep-2018  christos support deprecated("string") for libpcap
 1.97  08-Jul-2018  christos recognize noinline attribute
 1.96  29-Jun-2018  christos Add our syslog format.
 1.95  15-Jan-2018  christos branches: 1.95.2; 1.95.4;
Add a _Noreturn token
 1.94  06-Mar-2017  christos fix typeof, add __builtin_offsetof
 1.93  06-Mar-2017  christos handle typeof in casts
 1.92  07-Jan-2017  christos branches: 1.92.2;
add pcs
 1.91  30-Dec-2016  christos - add buffer bounded attribute
- allow empty attributes
 1.90  30-Dec-2016  christos sort, kill typo
 1.89  30-Dec-2016  christos add bounded, fix nonnull
 1.88  29-Dec-2016  christos handle __ symbols differently (so we don't duplicate entries in the table)
and add non_null.
 1.87  29-Dec-2016  christos allow cascaded attributes
 1.86  29-Dec-2016  christos Add alias attribute
 1.85  29-Dec-2016  christos Add always_inline
 1.84  29-Dec-2016  christos Add more attributes.
 1.83  29-Dec-2016  christos accept optional type attributes after struct/union members
 1.82  27-Dec-2016  christos teach lint __attribute__((__unused__))
 1.81  05-Nov-2016  christos Add _Generic C11 support.
 1.80  19-Aug-2016  christos be less aggressive in clearing blocks to protect against:

int
main(int argc, char *argv[])
{
int rv;

if ((rv = ({ int _ret = 1; if (argc == 1) {} _ret; })) != 0)
printf("%d\n", rv);
return 0;
}
 1.79  31-Jul-2016  dholland Don't allow initializers of the form { .a = .b = expr } as this is not
valid. Helps a bit with PR 22500.
 1.78  20-Jul-2016  christos accept attributes in param decls
 1.77  20-Jul-2016  christos handle "extern __attribute__((__gnu_inline__)) __inline"
 1.76  27-Feb-2016  christos branches: 1.76.2;
Add visibility and weak
 1.75  02-Jan-2016  christos Handle function symbol renames.
 1.74  13-Oct-2015  christos the next symbol should be a type.
 1.73  13-Oct-2015  christos handle anonymous struct/union members.
 1.72  13-Oct-2015  christos more descriptive aborts
 1.71  28-Jul-2015  christos handle c99 nested struct initialization { .data.foo[0] = 1 }
 1.70  01-Jul-2015  christos Fix segmentation fault caused by freeing prematurely function parameter types
inside cast expressions.
 1.69  11-May-2015  christos handle compound literals with a trailing comma
 1.68  03-Apr-2015  christos accept typenames in param decls.
 1.67  26-Sep-2014  christos oops I terminated the block too early (thanks unit tests!)
 1.66  26-Sep-2014  christos make for introduce a new block level for c99 decls.
 1.65  21-Apr-2014  christos add more attributes
 1.64  21-Apr-2014  christos add asm function renames
 1.63  18-Apr-2014  christos add more places where attribute is valid.
 1.62  18-Apr-2014  christos handle constant attribute
 1.61  18-Apr-2014  christos Handle the rest of gcc __attribute__ s.
 1.60  17-Apr-2014  christos typeof and extension don't need parens
 1.59  23-Mar-2014  dholland branches: 1.59.2;
typo in comment
 1.58  18-Feb-2014  christos add __extension__ and typeof
 1.57  04-Feb-2014  njoly Handle another declaration after statement case for lint in c99 mode.
Add the corresponding testcase.
 1.56  16-Jan-2014  christos empty init_decl {} is valid
 1.55  19-Apr-2013  christos Allow linted comments to take an argument that defines which error to suppress.
 1.54  27-Mar-2012  christos branches: 1.54.2;
more cross lint friendlyness
XXX: needs more constants converted double/float
 1.53  25-Dec-2011  christos fix the grammar conflict differently.
 1.52  25-Dec-2011  christos PR/45666: Nicolas Joly: lint(1) wrong 'syntax error' message
 1.51  19-Dec-2011  njoly c99: do not warn about trailing comma in enum declaration.
 1.50  04-Oct-2011  christos branches: 1.50.2;
Handle c99 declarations in the middle of blocks.
 1.49  09-Feb-2010  wiz Fix typo in comment.
 1.48  03-Oct-2009  christos add type attributes in a few more places.
 1.47  03-Oct-2009  christos accept struct { ... } __packed name;
 1.46  02-Oct-2009  christos recognize struct __packed x { }; in addition to struct x { } __packed;
 1.45  02-Oct-2009  christos understand __attribute__((__packed__)) and __packed.
 1.44  02-May-2009  christos Add __alignof__.
 1.43  01-May-2009  christos add variable declarations in for loops for c99
 1.42  16-Nov-2008  dholland branches: 1.42.2;
WARNS=4
 1.41  25-Apr-2008  christos preliminary _Complex support.
NB: Does not really understand type conversions between complex and doubles.
 1.40  25-Apr-2008  christos handle case C1 ... C2:
 1.39  08-Nov-2006  christos branches: 1.39.16;
- add debugging to track nowarns
- make /*LINTED*/ take effect on unused functions
 1.38  17-Oct-2006  he Use __inline instead of inline, to allow linting of ourselves...
 1.37  12-Jul-2006  christos PR/33984: YAMAMOTO Takashi: lint complains about typedef
The grammar for c99 initializers only looked for name tokens, so if there
was a typedef'ed name it failed. Fixed by looking at all identifier tokens.
 1.36  24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.35  17-Jul-2005  christos Handle C99 array range initializers:

type a[] = { [lo ... hi] = c }:
 1.34  03-Aug-2004  yamt recognize C99 array initializer designators. PR/18896.
 1.33  24-May-2003  christos handle void ({ })
 1.32  20-May-2003  christos Better implementation of ({}) gcc extension.
 1.31  18-May-2003  kristerw Prevent use of stale pointer for determining return type of ({ })
expressions.

Details:
lint did fail on constructs like

struct foo *x;
x = ({ struct foo *y; /* do stuff */; y;});

since it gave the whole ({ }) the same structure representing the
type as y, but that structure is reclaimed when y goes out of scope.
 1.30  23-Oct-2002  christos mention what is wrong with the ({}) productions.
 1.29  22-Oct-2002  christos add support for ({}) gcc shit.
 1.28  22-Oct-2002  christos add C9X/GCC compound literal expressions.
 1.27  22-Oct-2002  christos add variable array dimension.
 1.26  21-Oct-2002  christos support for c99 style and gnu style structure and union named initializers.
 1.25  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.24  05-Feb-2002  thorpej Replace u_quad_t with uint64_t and quad_t with int64_t, and use
<inttypes.h> to get those type definitions. These types are more
portable, and a little more sane to do autoconf tests for.
 1.23  31-Jan-2002  tv Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.22  30-Jan-2002  thorpej Add a missing "static" on a function decl.
 1.21  26-Jul-2001  wiz Various typos in comments (neccessary, sceme, choise, ...).
 1.20  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.19  24-May-2001  lukem oops! delint previous
 1.18  24-May-2001  lukem allow trailing , in enum if -g
 1.17  24-Feb-2001  cgd fix broken NetBSD RCS id tags
 1.16  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.15  23-Nov-1998  christos branches: 1.15.8;
Unfortunately lint uses c-style comments as directives and these get parsed
at the lexical analysis stage not at the syntax parsing stage. The upshot
is that:
if (expr) {
stmt1;
}
/* LINTED */
stmt2;

stmt2 is the look-ahead token for the parser to choose between and if-then-else
statement as opposed to an if-then statement. Unfortunately the side effect
is that the LINTED directive gets reset before stmt2 gets parsed. We fix this,
by remembering the the linted directive during the if statement parsing and
restoring it at the appropriate time.
 1.14  13-Nov-1998  christos Fix problems with LINTED comment:

if (a) b;
/*LINTED*/
c;

if (a) { b; }
/*LINTED*/
c;

do { b; }
/*LINTED*/
while (c);

Produced warnings for c.
 1.13  22-Feb-1998  christos WARNSify
 1.12  06-Nov-1997  cjs I do wish people would start including <string.h> when they use memcpy.
 1.11  03-Nov-1997  cgd implement (hack in) symbol (function and variable) renaming, so that
the function renaming tricks currently needed by libc can be tolerated
by lint. This needs some cleanup, but it appears to work.
 1.10  09-May-1997  mycroft branches: 1.10.2;
Hack to work around compiler bug for now.
 1.9  22-Dec-1996  cgd * Accept asm statements at any place where you could see a function or
variable declaration, in addition to within function & variable
declarations and function bodies. I think this comes close enough
to what gcc does to be considered "correct enough." Certainly, it
fixes the problem for the couple of cases where this is a problem
in our tree.
 1.8  02-Oct-1995  jpo don't print warnings about unused variables or arguments in compound
statements which contain asm statements.
 1.7  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.6  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.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.10.2.2  12-Nov-1997  mellon Pull rev 1.12 up from trunk (cjs)
 1.10.2.1  04-Nov-1997  thorpej Pull up from trunk: make renaming work and other minor fixes.
 1.15.8.1  23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.39.16.1  18-May-2008  yamt sync with head.
 1.42.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.50.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.50.2.1  17-Apr-2012  yamt sync with head
 1.54.2.2  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.54.2.1  23-Jun-2013  tls resync from head
 1.59.2.1  10-Aug-2014  tls Rebase.
 1.76.2.4  20-Mar-2017  pgoyette Sync with HEAD
 1.76.2.3  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.76.2.2  06-Aug-2016  pgoyette Sync with HEAD
 1.76.2.1  26-Jul-2016  pgoyette Sync with HEAD
 1.92.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.95.4.1  10-Jun-2019  christos Sync with HEAD
 1.95.2.4  18-Jan-2019  pgoyette Synch with HEAD
 1.95.2.3  26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.95.2.2  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.95.2.1  28-Jul-2018  pgoyette Sync with HEAD
 1.506.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed