Home | History | Annotate | Download | only in lint1
History log of /src/usr.bin/xlint/lint1/debug.c
RevisionDateAuthorComments
 1.84  11-Jul-2025  rillig lint: fix warning about enum array index

Seen in openssh/fmt_scaled.c, scale_chars.
 1.83  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.82  13-Nov-2024  rillig lint: handle _Noreturn, [[noreturn]] and __attribute__((__noreturn__))
 1.81  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.80  24-Sep-2024  rillig lint: exclude the GCC builtins from debug logging

Their source code is parsed for simplicity, and since the text is fixed,
there is nothing surprising to be expected there. Instead, start
debugging when the actual code begins.
 1.79  11-May-2024  rillig branches: 1.79.2;
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.78  09-May-2024  rillig lint: in C23 mode, support the nullptr constant
 1.77  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.76  01-May-2024  rillig lint: support _Alignas and __attribute__((__aligned(4)))
 1.75  31-Mar-2024  rillig lint: merge function call operators 'CALL' and 'ICALL'
 1.74  19-Mar-2024  rillig lint: keep invalid arguments in function calls

Previously, arguments of incomplete type or 'void' cleared all arguments
of the function call expression, requiring extra checks in later checks.

Invalid function calls are now exported to the .ln files, but that's
irrelevant in practice as these invalid function calls make lint1 fail,
after which xlint removes the .ln file.
 1.73  09-Mar-2024  rillig lint: inline accessor macros for tnode_t
 1.72  09-Mar-2024  rillig lint: inline accessor macros for type_t
 1.71  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.70  03-Feb-2024  rillig lint: keep strings in their source representation

This allows further analysis depending on whether individual characters are
escaped as octal, hexadecimal or not at all.
 1.69  02-Feb-2024  rillig lint: fix debug output for strings, reduce code size

The debug output contained too many newlines.

The buffer functions were built into lint2 even though they weren't
used.

Enable the query for invisible characters in string literals, to make
sure that a newline in a string literal does not trigger that query.
 1.68  01-Feb-2024  rillig lint: use standard buffer for storing string values

No functional change.
 1.67  29-Jan-2024  rillig lint: do not remember content of wide string literals

The plain char literals are needed for checking printf/scanf format
strings; lint has no similar check for wide strings. These format
strings are checked by modern compilers, making this check less
relevant.
 1.66  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.65  03-Dec-2023  rillig lint: indent statement continuations consistently

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

For symmetry with NO_TSPEC. No functional change.
 1.63  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.62  13-Sep-2023  rillig lint: prevent invalid memory access when checking an expression

In check_expr_misc, the left and right operands of an expression were
accessed even in the case of CON (constant), STRING (string literal) and
NAME (identifier), which led to invalid values in pointer variables.
These invalid values were not used though, but technically they invoked
undefined behavior.

Precede each access to the operands with a check that the expression
indeed has operands, except in those cases where the operand is known to
have operands by only looking at the code of the current function.
 1.61  02-Aug-2023  rillig lint: remove unused string literals
 1.60  02-Aug-2023  rillig lint: distinguish between arguments and parameters
 1.59  01-Aug-2023  rillig lint: improve debug logging for declarators
 1.58  30-Jul-2023  rillig lint: in debug mode, default to indenting the debug log

Only the 'parsing' lines are not indented, as line breaks are
independent from the structure of the code.
 1.57  30-Jul-2023  rillig lint: in memory debug mode, log the type of the nodes

First log all objects to be freed, then free them all at once. This
allows cross references from the objects of a block independent of their
allocation order.
 1.56  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.55  13-Jul-2023  rillig lint: merge duplicate code for checking duplicate type qualifiers
 1.54  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.53  13-Jul-2023  rillig lint: _Thread_local is a storage class, not a type qualifier
 1.52  12-Jul-2023  rillig lint: clean up handling of __real__ and __imag__

These two operatos are not binary, therefore they don't need a right
operand. The questionable operands were a copy-and-paste mistake, as
the code was taken from the ++ and -- operands (tree.c 1.46 from
2008-04-25). The ++ and -- operands aren't binary either, but since
lint represents address calculations in their premultiplied form, the
expression ptr++ contains a hidden right operand specifying the number
of bytes by which to increment the pointer.

Creating an integer-constant-expression node with type 'long double'
didn't make sense either. Luckily, these expressions are only built but
not analyzed any further.
 1.51  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.50  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.49  10-Jul-2023  rillig lint: merge duplicate code for getting the name of an operator
 1.48  10-Jul-2023  rillig lint: improve debug output when debugging the grammar parser
 1.47  08-Jul-2023  rillig lint: clean up

PUSH nodes are not marked as binary, yet they have a left and a right
operand.

If none of the queries is enabled, omit the query from the debug log.
 1.46  02-Jul-2023  rillig lint: clean up variable names relating to structure padding
 1.45  02-Jul-2023  rillig lint: rename 'quad' to 'signed int' or 'unsigned int'

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

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

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

Indent the debug logging according to the declaration level.

Since there are a few cases where the enclosing declaration levels are
modified, log the whole declaration level stack whenever a level begins
or ends.
 1.42  02-Jul-2023  rillig lint: clean up variable names
 1.41  01-Jul-2023  rillig lint: clean up typos
 1.40  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.39  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.38  30-Jun-2023  rillig lint: clean up packing of structs and unions

No functional change outside debug mode.
 1.37  29-Jun-2023  rillig lint: clean up member names of declaration levels

No functional change outside debug mode.
 1.36  24-Jun-2023  rillig lint: reduce memory allocations

The type val_t has the same size as the tn_s member in the same union.

No functional change.
 1.35  24-Jun-2023  rillig lint: add query for comparing 'char' with plain integers
 1.34  23-Jun-2023  rillig lint: remove redundant printflike declarations from debugging code
 1.33  03-Jun-2023  rillig lint: loosen assertion that unary operators have only a single operand
 1.32  03-Jun-2023  rillig lint: use consistent and configurable stream for debug output
 1.31  22-May-2023  rillig lint: rename constant NOTSPEC to NO_TSPEC

It was too easy to misread the old name as NOT_SPEC instead of the
intended NO_TSPEC.
 1.30  22-Apr-2023  rillig lint: fix missing initialization for cast to union

The left operand of a unary AST node must not be NULL.

The previous code crashed lint when run with some query enabled, as
is_cast_redundant assumes that a non-null AST node has valid operands.

$ cat <<EOF > crash.c
double
demo(void) {
union u {
double *num;
} u;
u = (union u)&((double) { 0.0 });
return *u.num;
}
EOF
$ /usr/libexec/lint1 -w -S -g -q8 crash.c /dev/null
 1.29  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.28  11-Apr-2023  rillig lint: in debug mode, use different names for macro and function

No functional change.
 1.27  10-Apr-2023  rillig lint: add debug logging for values that differ between trad and C90
 1.26  28-Mar-2023  rillig lint: condense debugging code

No functional change.
 1.25  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.24  08-Jan-2023  rillig lint: unclutter debug logging for nodes

No functional change.
 1.23  16-Jul-2022  rillig lint: add missing space before func_proto_sym in debug mode
 1.22  03-Jul-2022  rillig lint: add debug logging for struct and enum details
 1.21  26-May-2022  rillig lint: fix spacing and line breaks in debug logging

The spacing between function arguments in a declaration info was too
big, it was the indentation level instead of a single space.

The function debug_sym is used for two purposes: own-line and in-line,
which coincidentally are distinguished by whether the suffix string is
"\n".
 1.20  26-May-2022  rillig lint: improve debug logging for NAME expressions

In a NAME expression, the name is an essential part, so put it to the
front, in natural reading order.
 1.19  26-May-2022  rillig lint: add missing newlines in debug_node
 1.18  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.17  09-Apr-2022  rillig lint: distinguish between storage class and declaration kind

These types overlap but are not the same.

No functional change.
 1.16  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.15  09-Apr-2022  rillig lint: extract is_member into separate function

No functional change.
 1.14  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.13  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.12  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.11  02-Apr-2022  rillig lint: rename dinfo_t.d_next to d_enclosing

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

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

To track down the wrong edge cases in decl_direct_abstract.c.
 1.9  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.8  27-Feb-2022  rillig lint: merge duplicate code for handling plain and wide strings

No functional change. As before, the string literals "1" "2" "3" are
not concatenated from left to right, instead concatenation starts with
"23" and then proceeds to "123".
 1.7  21-Dec-2021  rillig lint: rename debug_indent to debug_print_indent

The previous name could be mistaken to mean "increase the indentation of
the debug output". Instead, the function prints the current indentation.

In externs1.h, the macro definition was a duplicate, the macros were
sorted differently than the functions a few lines above.

No binary change.
 1.6  20-Dec-2021  rillig lint: in debug mode, output value of boolean expressions
 1.5  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.4  16-Nov-2021  rillig tests/lint: explain the missing error message in strict bool mode

There are 2 separate bugs that lead to the missing error message.

The first bug is that when parsing a name, the information about whether
that name comes from a system header is not properly recorded for the
last token before switching from or to a system header.

The second bug is that for determining whether the type of a function
call expression is relaxed, the types of the function call arguments are
taken into account, even though the type only depends on the function
itself. The same idea applies to the operators '<<' and '>>', as their
result type only depends on the left operand, at least since C90.
 1.3  22-Aug-2021  rillig lint: merge duplicate code for binary operator

No functional change.
 1.2  01-Aug-2021  rillig lint: merge duplicate debugging code

The functions 'debug_node' and 'display_expression' were similar enough
to be merged.

Migrate debug_node to use the existing debug logging functions.

Remove the now unused option 'd' from the options string.
 1.1  31-Jul-2021  rillig lint: extract debug logging to separate file

Lint currently has several different kinds of debug log:

* The -DDEBUG log is controlled at compile time.
* The -d command line options enables some other debug logging.
* The -DYYDEBUG log for parsing is controlled at compile time.
* The -y command line option only has an effect in -DYYDEBUG mode.

Extracting the logging into a separate file is a first step towards
unifying these logs and making the code for debug logging stand out less
than the current #ifdef DEBUG.

No functional change.
 1.79.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed