Commit Graph

17831 Commits

Author SHA1 Message Date
rillig
24351504d4 lint: do not error out of a struct is initialized without braces
This allows to process lib/libc/gen/sysctl.c 1.38 from 2021-03-30, as
well as its precedessor 1.37, which had a workaround just for lint.

While unusual, C99 allows these.
2021-04-01 14:20:30 +00:00
simonb
2498171cf2 Use kernel sysctl hashstat collection instead of kmem grovelling
directly.  Also GC a few old hash nlist entries that no longer exist.
2021-04-01 06:23:14 +00:00
simonb
a892c37c69 Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".
2021-04-01 05:33:50 +00:00
rillig
a391e62ebd lint: clean up duplicate code in handling of initialization
No functional change.
2021-03-30 20:23:30 +00:00
rillig
ea90fdfcdd lint: add error about out-of-bounds array subscripts
This check is not strictly necessary since any C99 compiler must
diagnose them as well, it is rather meant for demonstrating how to do
the check in lint, and for symmetry with the 'unknown member' error
message.  These provide insight into how the data structures in init.c
are meant to be accessed.
2021-03-30 16:07:07 +00:00
rillig
94c797a88b lint: add type information for message about unknown member name 2021-03-30 15:18:19 +00:00
rillig
ee9d2e6631 lint: reword message for very unlikely .member in array initialization 2021-03-30 15:10:46 +00:00
rillig
47d84fb81e lint: add type information to message 175 2021-03-30 15:07:53 +00:00
rillig
58c739af66 make: remove workaround for bug in lint
The bug has been fixed in lint.

No functional change.
2021-03-30 14:58:17 +00:00
rillig
65a86d028a 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.
2021-03-30 14:25:28 +00:00
rillig
bcdf6c3e99 lint: rename variable 'level' to 'bl'
For consistency with its type prefix and the other variables.  This
variable is used so often that it makes sense to abbreviate it.

No functional change.
2021-03-29 21:34:17 +00:00
rillig
3915aeb0e8 lint: add helper functions
No functional change.
2021-03-29 21:09:21 +00:00
rillig
2bc143b2cb lint: rename struct members in init.c
No functional change.
2021-03-29 20:52:00 +00:00
rillig
53e378632b lint: remove outdated comments, clean up style
No functional change.
2021-03-29 20:39:18 +00:00
rillig
b60c67330a lint: add assertions for aggregate initialization
No functional change.
2021-03-28 20:35:58 +00:00
rillig
af1032a21b lint: add test for assertion failure in initialization
The 'cnt = level->bl_type->t_tspec == STRUCT ? 2 : 1;' in
initialization_push_struct_or_union is obviously wrong since not every
struct has exactly 1 remaining member after the first member that has an
initializer with designation.

This bug started its life in init.c 1.12 from 2002-10-21, a little over
18 years ago.
2021-03-28 19:53:58 +00:00
rillig
42f643d6d2 lint: split complicated function for looking up struct members
No functional change.
2021-03-28 19:30:08 +00:00
rillig
43bbce9d8f lint: inline variable in initialization_init_array_using_string
No functional change.
2021-03-28 18:33:27 +00:00
rillig
fe38660a11 lint: clean up initialization_init_array_using_string
No functional change.
2021-03-28 18:28:22 +00:00
rillig
6194e85bdd lint: clean up initialization_expr
No functional change.
2021-03-28 18:21:28 +00:00
rillig
966105efc7 lint: extract duplicate code to is_string_array
No functional change.
2021-03-28 18:18:22 +00:00
rillig
ff8ca4b11c lint: add is_struct_or_union
No functional change.
2021-03-28 18:01:57 +00:00
rillig
ef0f1616fd lint: extract brace_level_subtype
No functional change.
2021-03-28 16:28:15 +00:00
rillig
2a57740d57 lint: extract initialization_end_brace_level
No functional change.
2021-03-28 16:19:21 +00:00
rillig
17b8bb349c lint: extract check_no_auto_aggregate
No functional change.
2021-03-28 15:39:25 +00:00
rillig
94f17677cf lint: only define GCC builtins if -g is given
This removes 7 wrong warnings when running lint in -t mode.

Surprisingly, this added a warning that had not been there before in
msg_189.c.  This is because check_variable_usage skips the checks when
an error occurred before.  All diagnostics that happened were warnings,
but the -w option treats them as errors, see vwarning.
2021-03-28 15:36:37 +00:00
rillig
1ecca4fb87 lint: clean up type handling in initialization
No functional change.
2021-03-28 14:13:18 +00:00
rillig
034864b5d3 lint: remove wrong warning about wrong initializer type
The following code is valid:

	int valid = {{{ 3 }}};

C90 3.5.7 and C99 6.7.8 both say that the "initializer for a scalar
shall be a single expression, optionally enclosed in braces".  They
don't put any upper bound on the amount of braces, not even in the
"Translation limits" section.
2021-03-28 14:01:49 +00:00
rillig
3bd18ec06c lint: sprinkle const on function declarations
No functional change.
2021-03-28 13:09:43 +00:00
rillig
a97ec4c8f0 lint: move code for extending an array of unknown size further up
No functional change.
2021-03-28 11:08:01 +00:00
rillig
21b415bd4d lint: move code for checking init expressions further up
It did not make sense to have this code between the code for the
designation and the brace level.  Since it is independent of all these
types, move it to the top.

No functional change.
2021-03-28 10:58:18 +00:00
rillig
ab203ec18a lint: group functions according to their main object
No functional change.
2021-03-28 10:52:41 +00:00
rillig
bed16d6c94 lint: rename public designator functions
Their previous names were too similar to the actual implementation
functions, which was confusing.

No functional change.
2021-03-28 10:09:34 +00:00
rillig
8d56fa8a62 lint: inline initsym
No functional change.
2021-03-28 10:05:19 +00:00
rillig
9d93c87b1f lint: replace initstack_push_array with brace_level_push_array
The designator is no longer logged at this point because it is
irrelevant.

No functional change.
2021-03-28 10:03:02 +00:00
rillig
efa03aa3f8 lint: clean up debug logging, use consistent variable names
No functional change.
2021-03-28 09:57:31 +00:00
rillig
113c2810b6 lint: omit unnecessary calls to current_init
No functional change.
2021-03-28 09:51:16 +00:00
rillig
d983f2b76b lint: move brace level functions further up
No functional change.
2021-03-28 09:46:55 +00:00
rillig
77e6be55c1 lint: clean up debug logging for initialization
No functional change.
2021-03-28 09:43:28 +00:00
rillig
d868ac1eab lint: inline initerr in code for handling initializations
No functional change.
2021-03-28 09:39:04 +00:00
rillig
f7466f5c66 lint: inline brace level in initialization
No functional change.
2021-03-28 09:34:45 +00:00
rillig
a67ebcf1f2 lint: replace global variables with function parameters
No functional change.
2021-03-28 09:20:51 +00:00
rillig
403d5c8a72 lint: move more functions to the global-variables-free section
No functional change.
2021-03-28 09:08:13 +00:00
rillig
8d7ac35e4f lint: reorder code for handling initializations
First the primitives for debug logging, then the functions that do not
access any global variables, finally everything else.

No functional change.
2021-03-28 08:30:22 +00:00
rillig
18eeb7dffa lint: move debug primitives to the top of the code
No functional change.
2021-03-28 07:59:09 +00:00
rillig
713cdeb737 lint: extract brace_level_next_member from initstack_pop_item_unnamed
No functional change.
2021-03-27 23:18:37 +00:00
rillig
a638669c26 lint: extract brace level code into separate functions
No functional change.
2021-03-27 22:53:10 +00:00
rillig
e8a58a4a0e lint: prepare support for adding array designators
No functional change.
2021-03-27 22:35:10 +00:00
rillig
ef9afa2e18 lint: move handling of function renaming over to declare_extern
No functional change.
2021-03-27 22:13:55 +00:00
rillig
1eacbd0104 lint: rename decl1ext, reduce visibility
No functional change.
2021-03-27 22:04:39 +00:00
rillig
ba16517256 lint: add function for setting the initialization error
No functional change.
2021-03-27 21:56:51 +00:00
rillig
ccfb8928c0 lint: remove unnecessary typedefs
No functional change.
2021-03-27 19:59:22 +00:00
rillig
fe9fcc3850 lint: rename initstack_element to brace_level
No functional change.
2021-03-27 19:48:00 +00:00
rillig
4b2a451006 lint: extract look_up_member from initstack_push_struct_or_union
No functional change.
2021-03-27 16:37:12 +00:00
rillig
6ff83f9559 lint: clean up initstack_pop_item_named_member
Previously, the code accessed the global variable for the designator
several times, even though the designator cannot change during this part
of the code.  Make this obvious by passing this designator as a
parameter instead.

No functional change.
2021-03-27 16:24:21 +00:00
rillig
5787cf077c lint: fix and update comments about initialization 2021-03-27 13:17:42 +00:00
rillig
ebecd520af lint: merge duplicate code in initialization
No functional change.
2021-03-27 13:08:20 +00:00
rillig
ae661a2bff lint: rename LERROR to INTERNAL_ERROR
The '#ifndef' in tyname.c is meant to distinguish between lint1 and
lint2, it is not meant to be defined from anywhere outside the lint code
itself.

No functional change.
2021-03-27 12:42:22 +00:00
rillig
a71c5054a7 lint: rename filename management functions
No functional change.
2021-03-27 12:32:19 +00:00
rillig
23f85da8c6 lint: clean up code for filename management
In add_directory_replacement, the expression 'r->repl - r->orig' looked
strange, as if two pointers into separate objects were subtracted.

The code was probably optimized to a particular compiler on a particular
platform to generate fast and simple code.  Since compilers have made
considerable progress over the last 25 years, optimize the code for
human legibility instead.  The compilers will somehow cope with that.

No functional change.
2021-03-27 12:24:43 +00:00
rillig
993e4d3b00 lint: rename filename_replacement.len to orig_len
No functional change.
2021-03-27 12:17:22 +00:00
rillig
7b6e605eda lint: rename global variables in filename management
No functional change.
2021-03-27 12:14:49 +00:00
rillig
625ccc15a1 lint: rename srchfn to search_filename, return const value
No functional change.
2021-03-27 12:10:41 +00:00
rillig
054e76c5e6 lint: rename types in filename management
No functional change.
2021-03-27 12:01:49 +00:00
rillig
95991669ee lint: reduce indentation in fnnalloc
No functional change.
2021-03-27 11:54:35 +00:00
rillig
414d96f2ad lint: rename fnaddreplsrcdir to something less cryptic
No functional change.
2021-03-27 11:50:34 +00:00
rillig
e19973139d lint: remove unused fnalloc 2021-03-27 11:47:59 +00:00
rillig
5e491b8d10 lint: remove space between 'sizeof ('
No functional change.
2021-03-27 11:08:00 +00:00
rillig
13262e443a lint: add quotes around placeholder in message about undefined variable
Before: error: expected undefined [99]
After:  error: 'expected' undefined [99]

Seen in external/mpl/bind, which for Clang defines in stdatomic.h:
> #define atomic_exchange_explicit(obj, desired, order) \
>     __c11_atomic_exchange_explicit(obj, expected, order)
Note the mismatch between 'desired' and 'expected'.
2021-03-26 23:17:33 +00:00
rillig
c162536975 indent: don't claim that indent is "the nicest C pretty printer around"
That statement may have been true in 1993, but definitely is not true
anymore, as of 2021.

The part about "needs to be completely redone" is still true though
since indent cannot even format its own source code in an acceptable
way.
2021-03-26 22:33:54 +00:00
rillig
0554da173f indent: remove workaround for array initialization bug in lint
The bug has been fixed in init.c 1.133 from 2021-03-25.
2021-03-26 22:27:43 +00:00
rillig
f8d94ead78 indent: fix Clang build everywhere but on amd64
No idea why Clang didn't complain about this on amd64, only on all other
platforms.
2021-03-26 22:02:00 +00:00
rillig
e355d71d52 lint: improve output format for internal errors
The new format follows the common conventions for file locations and
allows quick navigation in IDEs.

To trigger an internal error, it suffices to have 2 tokens in lint1's
input, after preprocessing: 'void __pure'.
2021-03-26 21:05:27 +00:00
christos
2fe32f22d3 use __func__ 2021-03-26 20:51:34 +00:00
rillig
2e0a622386 lint: in malloc calls, use 'sizeof *ptr' instead of 'sizeof(type)'
No functional change.
2021-03-26 20:31:07 +00:00
rillig
48d931bdcb lint: rename members of struct control_statement to be more expressive
C99 does not define names for the head parts of the 'for' statements, it
just calls them clause-1, expression-2 and expression-3.  Therefore the
rather abstract name 'expr3'.

No functional change.
2021-03-26 19:17:58 +00:00
rillig
c9fcf5c0ae 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.
2021-03-26 18:54:39 +00:00
rillig
108d85da05 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.
2021-03-26 17:44:52 +00:00
rillig
aead5d0dd4 lint: allow pointer cast to 'char *' and 'unsigned char *'
This reduces the number of warnings in the regular NetBSD build by 5560.
2021-03-26 16:59:18 +00:00
rillig
9c1785fdab lint: rename variables in check_pointer_conversion
No functional change.
2021-03-26 16:53:19 +00:00
rillig
3f6cb883b6 lint: extract decision for warning about pointer cast
This makes the code several lines longer but way more readable.  In the
previous dense expression it was hard to see what was going on at all
and that there are two completely separate situations in which this
warning applies.

No functional change.
2021-03-26 16:45:06 +00:00
rillig
280dddc0f6 lint: remove redundant '%prec' from grammar for compound literals
No change to the resulting binary.
2021-03-26 16:05:19 +00:00
rillig
f829424df6 lint: fix initialization for arrays with designators
From the previous commit, there was an off-by-one error left, which was
due to the interaction between designation_add_subscript and
extend_if_array_of_unknown_size.

The other crucial point was to call initstack_pop_nobrace before
accessing the "current initialization stack element".  Without this
call, in msg_168.c the "current element" would point to the initializer
level for 'const char *' instead of the one for 'array of const char *'.

One more step towards supporting C99.
2021-03-25 22:53:05 +00:00
rillig
23e30dfb46 lint: improve initialization of arrays with designators
Initialization is still buggy but better than before.  The remaining bug
is that only the first designator determines the array size, and after
that, the array is no longer considered of unknown size.  This
contradicts C99.  More improvements to come.
2021-03-25 22:15:38 +00:00
rillig
35601c2713 lint: fix names of functions dealing with designations
These functions modify the whole designation, not only a single
designator.

No functional change.
2021-03-25 21:51:55 +00:00
rillig
dda1a9e968 lint: free the designator as soon as it is no longer needed
One of the latest "refactorings" introduced a small and practically
unimportant memory leak.  If the last initializer in an initialization
had a designator, that designator was not freed.

When the "current initialization" was still a global variable with
unlimited lifetime, it was freed at the beginning of the next
initialization.  After the refactorings, this "next initialization"
could no longer see anything from the previous initialization since all
references have been cleaned up at that point.  Freeing the memory so
late and in an almost totally unrelated place was a bad idea anyway.
2021-03-25 21:45:10 +00:00
rillig
34b6d8b796 lint: distinguish between read and write access to initstk
There are far too many places that modify the top element of the
initializer stack.  Each of these places should get its own logging, as
long as the code is still complicated.  These places are now clearly
marked with initstk_lvalue.

No functional change.
2021-03-25 21:36:41 +00:00
rillig
b7a27c9e27 lint: replace namlist with designation and designator
This makes it possible to accurately model C99 initializers, including
their optional designators.  Previously, array subscripts had not been
modeled at all.

In the previous commit, debug_designation crashed immediately since I
had not run the code in debug mode even once.  The condition 'name !=
head' was a left-over from the old times where the designator was still
a circular list.

No functional change outside debug mode.
2021-03-25 21:07:52 +00:00
rillig
4cc73421be lint: remove over-engineered doubly-linked circular list
The designation only needs to be navigated from head to tail, not the
other way round.

No functional change.
2021-03-25 20:38:16 +00:00
rillig
4a688eae44 lint: rename debug_named_member to debug_designation
No functional change outside debug mode.
2021-03-25 20:11:18 +00:00
rillig
182cc5aa66 lint: rename i_current_object to i_next_member
No functional change outside debug mode.
2021-03-25 19:48:25 +00:00
rillig
1c9e647c42 lint: rename the few remaining instances of 'namedmem'
No functional change.
2021-03-25 19:33:44 +00:00
rillig
a58d119dde lint: split current_namedmem into lvalue and rvalue form, rename them
This is a small step towards using the terminology from C99.

No functional change.
2021-03-25 19:20:15 +00:00
rillig
0cb32f4608 lint: inline macro 'namedmem' for C99 designators
No functional change.
2021-03-25 19:11:18 +00:00
rillig
e44d626769 lint: free memory at the end of an initialization
No functional change, just more clarity in the code.
2021-03-25 16:43:51 +00:00
rillig
7d8ec13de2 lint: condense debug output for initializations
This way it does not look more impressive than it really is.

No functional change outside debug mode.
2021-03-25 16:30:23 +00:00
rillig
6d41f06e4c lint: add comments about things left to do, from code review
No functional change.
2021-03-25 13:10:19 +00:00
nia
e11a27e948 Add an example for recording CD quality audio 2021-03-25 10:03:26 +00:00
rillig
aadb627a71 lint: fix C99 initialization with expression of type 'struct'
This has been a long-standing limitation of lint.  Now it is almost
ready for C99, see the list of "major changes" in the foreword of C99.

One known remaining bug in the area of initialization is designators
with several levels, such as '.member[2].member.member'.  Oh, and
designators for arrays are only supported in the parser but not in the
type checker.  There's still some work to do.
2021-03-25 01:42:53 +00:00
rillig
586d0a84e9 lint: remove outdated comment from init_using_expr
Since C99, an aggregate type can be initialized without braces.

No functional change.
2021-03-25 00:48:58 +00:00
rillig
9d0a894bfa lint: extract check_init_expr from init_using_expr
No functional change.
2021-03-25 00:35:16 +00:00
rillig
e92d4ad150 lint: fix wrong warning about initialization using string literal
Missing braces after 'if', since init.c 1.68 from 2021-02-20.

GCC 10 doesn't complain about this even with -Wmisleading-indentation
since at least one of the involved lines is a macro invocation (in this
case both lines).  GCC 11 will warn about this.

Clang warns about this, but the regular Clang build currently fails for
other reasons, so this problem didn't show up there either.
2021-03-23 22:58:08 +00:00
christos
cf91e4bb2b Add _Alignas() 2021-03-23 20:57:40 +00:00
rillig
c40f4a5057 lint: extract init_using_assign from init_using_expr
No functional change.
2021-03-23 20:21:07 +00:00
rillig
7c67467864 lint: merge duplicate code in init_using_expr
No functional change.
2021-03-23 20:14:55 +00:00
rillig
49b3d03d05 lint: fix documentation about optional braces in initializers 2021-03-23 18:51:43 +00:00
rillig
131c7001fe 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.
2021-03-23 18:40:50 +00:00
rillig
19b0e62cf4 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.
2021-03-23 17:36:55 +00:00
rillig
a2e7847c63 lint: reduce visibility of variables for initializations
No functional change.
2021-03-22 19:29:43 +00:00
rillig
cb3c7a45cf lint: reduce visibility of global variable for getopt check
No functional change.
2021-03-22 19:25:08 +00:00
rillig
771299944e lint: use precise type information in message about type mismatch
While here, reword the message, avoiding operators and parentheses.

Since 2021-01-02, providing the precise type name is as easy as the
broad type classification (just replace tspec_name with type_name), and
it's definitely more useful to the human readers.
2021-03-22 15:29:43 +00:00
rillig
490538eb4d make: fix typos in documentation of ModChain 2021-03-21 23:03:33 +00:00
rillig
ab16413a62 lint: prefix error messages with 'error:'
This makes it easier to find these errors in the build logs.
2021-03-21 20:44:59 +00:00
rillig
494aa35c5b lint: remove redundant prototypes
No functional change.
2021-03-21 20:30:19 +00:00
rillig
f838b057fa lint: adjust type in documentation of add_array
No functional change.
2021-03-21 20:18:45 +00:00
rillig
ac846d67c2 lint: warn about unreachable statement after joining the 'if' branches 2021-03-21 19:14:40 +00:00
rillig
f32d16fd5a lint: invert 'rchflag', call it warn_about_unreachable instead
No functional change.
2021-03-21 19:08:10 +00:00
rillig
5db61676e0 lint: reduce number of places where 'reached' is set
When determining the reachability of a statement, the idea was that
whenever 'reached' was set to false, 'rchflg' (the abbreviation for "do
not warn about unreachable statements") would be reset as well.

In some (trivial) cases, this was done, but many more interesting cases
simply forgot to set this second variable.  To prevent this in the
future, encapsulate this in a simple helper function.

Now even if a statement is reachable, 'rchflg' gets reset.  This does
not hurt since as long as the current statement is reachable, the value
of 'rchflg' does not matter.

No functional change.  There would be quite a big functional change
though if check_statement_reachable were to reset 'rchflg' instead of
'reached', as the comment already suggests.  In that case, with the
current code, many legitimate warnings about unreachable statements
would be skipped, especially those involving 'if' statements, since
these didn't reset 'rchflg' properly before.
2021-03-21 18:58:34 +00:00
rillig
792d6541e8 lint: fix reachability for while (0) 2021-03-21 15:44:57 +00:00
rillig
62b887ae9d lint: fix reachability for constant controlling expression in for loop 2021-03-21 15:34:13 +00:00
rillig
352b5b3b4b lint: fix reachability for if-then-else statements 2021-03-21 15:24:55 +00:00
rillig
f23731fc8b lint: rename functions for handling control statements
No functional change.
2021-03-21 14:49:21 +00:00
rillig
97e5c72af7 lint: fix reachability computation in if statements
Previously, only loop statements were considered for reachability.  This
ignored the possibility of an early return in an if statement, or
unreachable branches.
2021-03-21 14:36:59 +00:00
rillig
65ab73b7c4 lint: add missing space when adding a new test case 2021-03-21 13:10:58 +00:00
rillig
4e6f02877c lint: rename c_rchif to c_reached_end_of_then
No functional change.
2021-03-21 13:03:42 +00:00
rillig
d19f53645a lint: document why an unreachable statement is set to reachable
No functional change.
2021-03-21 12:10:27 +00:00
rillig
2703dc53ce lint: rename c_cont to c_continue
No functional change.
2021-03-21 12:08:34 +00:00
rillig
20bc44c056 lint: document the precise meaning of control_statement.c_break
No functional change.
2021-03-21 12:06:10 +00:00
rillig
6c32983dfe lint: rename i_infinite to i_maybe_endless
Not every loop that has 'while (1)' is an endless loop.  It may still
contain a 'return' somewhere.
2021-03-21 12:03:56 +00:00
rillig
8c4298c341 lint: fix wrong 'falls off bottom' after return in do-while 2021-03-21 11:55:59 +00:00
rillig
85a09d20fa lint: fix wrong 'statement not reached' in do-while loop 2021-03-21 11:48:04 +00:00
rillig
299565f1d9 lint: remove redundant braces in doreturn
No functional change.
2021-03-21 11:38:24 +00:00
nia
bc9df35069 audioctl.1: describe foibles 2021-03-21 10:50:08 +00:00
rillig
07746a75ad lint: rename d_fargs, d_fdpos and d_fpsyms to be less abbreviated
No functional change.
2021-03-21 10:30:28 +00:00
rillig
4baf940241 lint: rename d_nedecl to d_nonempty_decl
No functional change.
2021-03-21 10:25:40 +00:00
rillig
b7e78ec23d lint: rename d_rdcsym to d_redeclared_symbol
No functional change.
2021-03-21 10:21:07 +00:00
rillig
94e7a0615e lint: inline local variable in declarator_1_struct_union
No functional change.
2021-03-21 10:16:12 +00:00
rillig
c509e4baa5 lint: rename clst to case_labels
No functional change.
2021-03-21 10:08:01 +00:00
rillig
7dc34efc1f lint: rename declspecs to declaration_specifiers, just as in C99
No functional change.
2021-03-21 09:54:02 +00:00
rillig
7e6909cce4 lint: rename grammar rule 'data_def' to 'top_level_declaration'
No functional change.
2021-03-21 09:49:34 +00:00
rillig
6474e49f87 lint: remove redundant '%prec' declarations from the grammar
No change to the generated binary.
2021-03-21 09:22:35 +00:00
rillig
4629487630 lint: rename token T_XOR to T_BITXOR
For symmetry with the operator, which is named BITXOR.

No functional change.
2021-03-21 08:55:59 +00:00
rillig
63f810f095 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.
2021-03-21 08:52:05 +00:00
rillig
389a384e79 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.
2021-03-21 08:46:26 +00:00
cheusov
d7beb5fa1a seq.c: replace non-standard \e with standard compliant \x1B 2021-03-20 22:10:17 +00:00
rillig
b48597d41d lint: clean up new_name_node
No functional change.
2021-03-20 21:08:09 +00:00
rillig
440cc62809 lint: move getopname over to tree.c
Except for the one use in print_tnode, the name of the operator is only
used in tree.c.

No functional change.
2021-03-20 20:56:58 +00:00
rillig
ea582d3e24 lint: remove redundant operator properties table
It's enough to have modtab, which describes the properties of the
various operators.  There is no need to have a second table imods that
holds the same content.  Rather make modtab constant as well.

The only possible functional change is that the names of the internal
operators 'no-op', '++', '--', 'real', 'imag' and 'case' may appear in
diagnostics, where previously lint invoked undefined behavior by passing
a null pointer for a '%s' conversion specifier.
2021-03-20 20:39:35 +00:00
rillig
d6f490fd83 lint: fix argument names and table headings for operator definitions
The abbreviations in the table of operator properties had been wrong
since ops.def 1.10 from 2021-01-12, when strict bool mode was added.  In
an earlier working draft, I had named that column 'takes_others' instead
of 'requires_bool', that's where the 'o' came from.

The names of the macro arguments had been wrong since op.h 1.11 from
2021-01-09, when the order of the columns changed and the macros were
not adjusted accordingly.  Since all the properties of the operator
table are uniform, this didn't result in any bugs, it was just confusing
for human readers.

Clang-tidy suggests to enclose the macro arguments in oper.c in
parentheses but that is not possible since the arguments are either
empty or 1, and the syntactical ambiguity of the '+ 0' being either a
unary or a binary operator is needed here.

No change to the resulting binary.
2021-03-20 20:15:37 +00:00
rillig
5019ab66ba lint: make lint's own code pass the strict bool mode
No functional change.
2021-03-20 19:33:25 +00:00
rillig
7ccd7b1468 lint: use macro for initializing keywords table
Since today, lint's strict bool mode requires initializers to have the
correct type.  The flags in kwtab are of type bool and were initialized
with an int, for brevity.  Keep the brevity and do the conversion from
int to bool in a macro.

By defining several macros for the different kinds of keywords, reduce
the clutter of having 2 additional zeroes per line.  The macros also
remove the redundancy and thereby the possible inconsistency of filling
the wrong fields since these depend on the token type.

No functional change.  The only change to the binary is due to the
changed line numbers in the calls to lint_assert.
2021-03-20 19:24:56 +00:00
rillig
e18860fa07 lint: use macro for encoding type information
In lint's strict bool mode, initialization must be of the correct type.
This affects the bool fields in ttab_t, which are initialized with int.
To keep the code brief, preserve these ints and let a macro do the
actual work of converting them to bool.

No change to the generated binary.
2021-03-20 18:59:00 +00:00
rillig
6a451d6268 lint: inline access to type properties in check_bad_enum_operation
No functional change.
2021-03-20 18:38:25 +00:00
rillig
10736dfe07 lint: in strict bool mode, check initialization as well
C99 6.7.8p11 says for initialization that "the same type constraints and
conversions as for simple assignments apply", so actually apply them.
(I had just forgotten this "operator" when I first implemented strict
bool mode.)
2021-03-20 17:18:50 +00:00
rillig
87876a2355 lint: rename ftflg to seen_fallthrough
One less abbreviation to remember when reading the code.

No functional change.
2021-03-20 16:16:32 +00:00
rillig
73790b7671 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.
2021-03-20 16:11:12 +00:00
rillig
f5c815bc77 lint: clean up grammar for declaration after statement
No functional change.
2021-03-20 15:30:58 +00:00
rillig
fb9b10bc8d 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.
2021-03-20 15:28:07 +00:00
cheusov
736f809ed1 cmp.c: use C99 strtoll(3) instead of legacy strtoq(3) 2021-03-20 14:27:47 +00:00
rillig
daef7ea921 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.
2021-03-20 14:17:56 +00:00
rillig
b925668ec9 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.
2021-03-20 13:53:28 +00:00
rillig
e4fa7e61a5 lint: update comment on setasm for C99
No functional change.
2021-03-20 13:25:31 +00:00
rillig
4f4415984d lint: reduce indentation and braces in merge_type_specifiers
No functional change.
2021-03-20 13:22:06 +00:00
rillig
e305d7be33 lint: extract adjusting of the storage class into separate function
No functional change.
2021-03-20 13:06:05 +00:00
rillig
1cf2c45884 lint: document the struct for declarations more precisely
No functional change.
2021-03-20 13:00:43 +00:00
rillig
d37415b4e9 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.
2021-03-20 11:33:50 +00:00
rillig
941875ba2d 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.
2021-03-20 11:24:49 +00:00
rillig
5f7e254669 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.
2021-03-20 11:05:16 +00:00
rillig
b61f069794 lint: align rule names in grammar with C99
No functional change.
2021-03-20 10:32:43 +00:00
rillig
80b7b20b36 lint: fix assertion failure after error in designation
In d_c99_init.c, the initialization of array_with_designator failed.
The designator '.member' from that initialization was not cleaned up
before starting the next initialization.
2021-03-20 08:54:27 +00:00
rillig
88e315e145 lint: replace segmentation fault with assertion failure 2021-03-20 08:16:30 +00:00
rillig
1a007aec0b lint: improve debug loggin for initialization 2021-03-19 18:17:46 +00:00
rillig
a8fb7d4818 lint: rename designator_pop_name to designator_shift_name
The entries are removed from the beginning, not from the end.

No functional change.
2021-03-19 17:37:57 +00:00
rillig
4c27df2433 lint: use standard form of statement macro for debug_node
No functional change.
2021-03-19 08:23:39 +00:00
rillig
5acb533d3d lint: rename in_bit to in_bits
No functional change.
2021-03-19 08:21:26 +00:00
rillig
527774e33b lint: rename tsize to type_size_in_bits
The shorter name size_in_bits was already taken by the function-like
macro with argument type tspec_t.

No functional change.
2021-03-19 08:19:24 +00:00
rillig
19ff95ceea lint: add reminder that C99 does not allow '{}' in initializer
No functional change.
2021-03-19 07:54:13 +00:00
rillig
0b45cbea90 lint: replace assertion in initialization with proper error message 2021-03-19 01:02:52 +00:00
rillig
674baf6361 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.
2021-03-19 00:55:02 +00:00
rillig
bde88c228c lint: extend documentation about initialization
No functional change.
2021-03-19 00:39:17 +00:00
rillig
89239b6de5 lint: split initstack_pop_item into separate functions
No functional change.
2021-03-19 00:19:32 +00:00
rillig
e2bce8130d lint: improve debug logging in initstack_push
No functional change outside debug mode.
2021-03-19 00:08:13 +00:00
rillig
dc7202e285 lint: split initstack_push into smaller functions
No functional change.
2021-03-18 23:45:20 +00:00
rillig
d68805fd28 lint: clean up control flow in initstack_push
No functional change.
2021-03-18 23:37:31 +00:00
rillig
77fa05a23f lint: extract extend_if_array_of_unknown_size from initstack_push
No functional change.
2021-03-18 23:23:40 +00:00
rillig
d30c5846db lint: replace undefined behavior during initialization with assertion
This only affects code that is already rejected by the compiler.
2021-03-18 22:51:32 +00:00
rillig
b4cc35448b lint: improve debug logging during initialization
No functional change outside debug mode.
2021-03-18 22:08:05 +00:00
rillig
5f25f85e8f lint: make the debug log for nodes more readable
The operator NAME has the name 'name', therefore no special case is
needed.

Having the words 'with type' in the message makes the message easier to
find from the debug log.  Given that the operator name is used unquoted,
the log message 'name: int value=111' was nearly impossible to find in
the code.

Replace the '()' with an actual word, to avoid any confusion about
whether the type name might be a function type without prototype.

Reduce the amount of '=' signs, instead use commas to separate the
properties of the node.

No functional change outside debug mode.
2021-03-18 22:05:33 +00:00
rillig
b1117d0cb9 lint: rename operator 'const' to 'constant'
The previous name could be too easily confused with the type qualifier
'const'.  The operator name is mainly used in the debug log, only
occasionally in the output.  Since 'constant' is not a "real" operator,
it probably doesn't occur in messages at all.
2021-03-18 21:56:34 +00:00
rillig
ebe3bde9bf lint: reword message about type mismatch in initialization
Using parentheses for quotes is unusual, furthermore the previous
message didn't follow proper grammar rules, sacrificing clarity for
brevity.
2021-03-18 21:26:56 +00:00
rillig
e82f0a6950 lint: reduce debug logging for initialization, update documentation
No functional change outside debug mode.
2021-03-18 20:55:58 +00:00
rillig
ce64b8cc18 lint: document how initialization works, improve debug logging
No functional change outside debug mode.
2021-03-18 20:22:50 +00:00
cheusov
37e902b261 join.c: print usage after warning "illegal option..." as it was originally intended 2021-03-18 19:47:41 +00:00
cheusov
47b5db6ce5 join.c: explicitly convert -1 to u_long in order to fix compiler warnings 2021-03-18 19:41:54 +00:00
cheusov
61b08b6410 ipcs.c: do not #include sys/inttypes.h header which is not necessary 2021-03-18 19:34:05 +00:00
cheusov
93a814dc9d find: use POSIX strtoll(3) instead of legacy strtoq(3) 2021-03-18 18:24:14 +00:00
cheusov
4e50b167d1 find: use POSIX type uint32_t instead of u_int32_t 2021-03-18 18:21:18 +00:00
cheusov
0dc4923bc1 cksum: use POSIX type uint32_t instead of u_int32_t 2021-03-18 18:12:35 +00:00
rillig
1250e70dfe lint: document the initialization of an object in more detail
This will help fixing the bugs that are currently demonstrated in
msg_168.c and d_struct_init_nested.c.
2021-03-18 14:58:44 +00:00
rillig
d8304c1dc3 lint: add debug logging for C99-style initialization of arrays
No functional change outside debug mode.
2021-03-17 15:45:30 +00:00
rillig
59329564e5 lint: move debug logging for the designator to the top of the code
The debugging code is needed by the soon-to-be-added proper handling of
array subscript initializers such as '.member[123].member = 12345'.

No functional change.
2021-03-17 15:37:42 +00:00
rillig
d07ef6733f lint: clean up documentation of dinfo_t
No functional change.
2021-03-17 02:24:06 +00:00
rillig
c026af7a30 lint: rename dinfo_t members to be more expressive
While here, sync redundant but diverging comments, split
multi-assignments and initialize the members in declaration order.

No functional change.
2021-03-17 02:18:03 +00:00
rillig
16ce4325a7 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.
2021-03-17 01:53:21 +00:00
rillig
e61595b13a lint: move main part of idecl over to decl.c and rename it
No functional change.
2021-03-17 01:38:31 +00:00
rillig
ce90f2b2d5 lint: replace a call to LERROR with lint_assert
No functional change.
2021-03-17 01:22:55 +00:00
rillig
068b6bffae lint: rename 'toicon' to 'to_int_constant'
No functional change.
2021-03-17 01:19:50 +00:00
rillig
0351b7e6cb lint: rename 'blklev' to 'block_level'
No functional change.
2021-03-17 01:15:31 +00:00
rillig
923306e4b7 lint: rename 'parn' to 'paren' in the grammar
No functional change.
2021-03-17 01:07:33 +00:00
rillig
5850837c3b make: fix documentation for ModChain
The outer ModChain can be interrupted by an inner ModChain, but it
continues to exist.

No functional change.
2021-03-16 16:21:27 +00:00
rillig
ebbd921098 make: rename ApplyModifiersState to ModChain
The new name accurately describes the structural element that holds such
properties as the separator character and whether the expression value
is considered a single word.  The old name ApplyModifiersState was too
long and was meant as a placeholder anyway, when I introduced it in
var.c 1.236 from 2020-07-03.
2021-03-15 20:00:50 +00:00
rillig
ac07af747c make: improve documentation of ApplyModifiersState
No functional change.
2021-03-15 19:15:04 +00:00
rillig
a05498199d make: document an example for a 'chain of modifiers'
No functional change.
2021-03-15 19:02:57 +00:00
rillig
507bcc82b8 make: fix double varname expansion in the variable modifier '::='
This is an edge case that doesn't occur in practice since pretty much
nobody dares to use variable names that contain an actual '$' in their
name.  This is not about the fairly common VAR.${param} (as written in
the makefile), but instead about the variable whose name is literally
'VAR.${param}'.

The test demonstrates that after the fix, the variable name is taken
exactly as-is for the simple assignment modifier '::='.  There are no
such tests for the modifiers '::+=', '::!=' and '::?=', but that's ok.
The code in ApplyModifier_Assign would look assymetrical and suspicious
enough if one of these modifiers would expand its variable name and the
others wouldn't.
2021-03-15 18:56:37 +00:00
rillig
7eea180375 tests/make: demonstrate that the modifier '::=' expands the varname 2021-03-15 18:46:05 +00:00
rillig
87c62a5243 tests/make: convert varmod-loop to parse-time
In case of unexpected failures, this provides the line number of the
'.error' directive.
2021-03-15 17:54:49 +00:00
rillig
8d27738a97 tests/make: add position marker in test 'varmod-loop' 2021-03-15 17:11:08 +00:00
rillig
e9a9d1718c make: clean up documentation of ApplyModifiersState
No functional change.
2021-03-15 16:51:14 +00:00
rillig
c066baf306 make: fix documentation of Lst_MoveAll
In CLEANUP mode, was originally meant to track memory allocations but is
useful during debugging as well, initialize the list.  There is no
distinct constant representing an invalid pointer, otherwise that would
have been an even better choice.
2021-03-15 16:45:30 +00:00
rillig
c175751478 make: indent inline functions for lists
No functional change.
2021-03-15 16:06:05 +00:00
rillig
0983b9b566 make: clean up header for runtime type information for enums
An enum with 32 bits would lead to signed integer overflow anyway, so
that definition is not worth keeping even if it works on typical
2-complement platforms.

The definitions for 2, 4 and 8 enum have been unused for several months
now.

No functional change.
2021-03-15 16:00:05 +00:00
rillig
4a38bf21f4 make: change debug log for variable evaluation flags to lowercase
This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
2021-03-15 15:39:13 +00:00
rillig
2f8026b0e5 make: replace enum bit-field with struct bit-field for VarEvalFlags
This makes the code easier to read, especially in var.c.  It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases.  Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly.  This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
2021-03-15 12:15:03 +00:00
rillig
4fd3cf6eed make: rename VARE_NONE to VARE_PARSE_ONLY
The name 'NONE' described the bit pattern, which was not useful to
understand its meaning.  Omitting VARE_WANTRES only parses the
expression, without evaluating any part of it.

No functional change, not even in debug mode since Enum_FlagsToString
always returns "none" for all-bits-unset.
2021-03-15 11:41:07 +00:00
rillig
8699d6553b tests/make: document today's bug fixes in the test 2021-03-14 20:41:39 +00:00
rillig
3042e42091 make: fix documentation of VarFreeEnv
No functional change.
2021-03-14 20:23:29 +00:00
rillig
259019554f make: skip variable lookup for '::=' modifiers in parse-only mode
This is just to keep the code consistent among the various variable
modifiers.  The performance gain is negligible.

The actual assignment to the variable had already been skipped
previously.

No functional change.
2021-03-14 20:18:33 +00:00
rillig
96491d26ea make: separate parsing and evaluating for modifier '::='
No functional change.
2021-03-14 20:12:16 +00:00
rillig
d4faf73862 make: in parse-only mode, do not update the expression value in ':sh'
No functional change outside debug mode.  The other variable modifiers
behave in the same way.
2021-03-14 20:09:26 +00:00
rillig
96faeb06ee make: do not evaluate the ':O' modifiers in parse-only mode
No functional change in practical usage.  Theoretically this change can
be observed by looking at the generated random numbers for the ':Ox'
modifier, but the quality or exact sequence of these random numbers is
not guaranteed anyway.
2021-03-14 20:03:56 +00:00
rillig
f7a4d3a3e0 make: separate parsing and evaluating in the ':O' modifiers
No functional change.
2021-03-14 20:00:48 +00:00
rillig
812ef981d6 make: do not evaluate modifier ':[...]' in parse-only mode
In parse-only mode, variable expressions in the argument to that
modifier are not resolved.  This led to the error message about the 'Bad
modifier' in var-eval-short.mk.
2021-03-14 19:29:37 +00:00
rillig
ef2d559187 make: do not evaluate modifiers ':M' and ':N' in parse-only mode
No functional change outside debug mode (-dv for ModifyWord_Match).
2021-03-14 19:25:05 +00:00
rillig
aaaf8460b3 make: do not return unevaluated 'else' part from the ':?' modifier
No functional change outside debug mode.
2021-03-14 19:21:28 +00:00
rillig
91f10d43f6 tests/make: add test for the ':?' modifier in parse-only mode
The debug output for this scenario will change a bit in an upcoming
commit, but that will not affect anything outside the debug log.
2021-03-14 19:16:41 +00:00
rillig
c8091d0b16 make: do not evaluate ':gmtime' and ':localtime' in parse-only mode
No functional change.
2021-03-14 18:30:24 +00:00
rillig
99e5bcf513 make: don't evaluate several simple modifiers in parse-only mode
This affects the modifiers ':E', ':H', ':P', ':Q', ':R', ':T', ':hash',
':q', ':range', ':tl', ':ts', ':tu', and ':u'.  All these modifiers are
side-effect free.

Skipping the evaluation for these modifiers is purely for code
consistency and performance.

No functional change.
2021-03-14 18:23:44 +00:00
rillig
a1837566a4 make: skip strdup when parsing an irrelevant ':L' modifier
No functional change.
2021-03-14 18:10:57 +00:00
rillig
ae0a762a50 make: skip memcpy when parsing but not evaluating ':D' and ':U'
No functional change, just a tiny bit of performance improvement,
probably not even measurable.  Having the code nevertheless serves as a
copy-and-paste template for implementing other modifiers that might
perform more costly tasks.
2021-03-14 18:08:25 +00:00
rillig
a1747f17a6 make: only evaluate the ':@' modifier if the result is actually used
The test 'var-eval-short' had produced the output 'unexpected' before,
on stderr.  It had been generated by '${:Uword:@${FAIL}@expr@}' by
combining the following obscure "features" of make:

1.  the ':@' modifier loops over the words of the variable.  This
    modifier is not really obscure, it still takes some time to get used
    to it.

2.  the ':@' modifier allows a '$' sign in the variable name, which is
    useless in practice.

3.  the ':@' modifier creates a temporary loop variable in the global
    namespace.  Luckily there are only few collisions with other
    variable names since their naming conventions differ.

4.  after looping over the words of the expression, the temporary global
    loop variable is deleted, and at that point the '$' is expanded,
    being interpreted as the start of a variable expression.

5.  The ':@' modifier deleted the global variable even when it was
    called in parse-only mode (without VARE_WANTRES).

When the modifier ':@' was initially added to make in var.c 1.40 from
2000-04-29, Var_Delete didn't expand the variable name.  That feature
was added in var.c 1.174 from 2013-05-18, probably without thinking of
this very edge-casey combination of features.

This commit fixes item 5 from the above list.  The other obscurities
remain for now.
2021-03-14 18:02:44 +00:00
rillig
9ac0661025 make: eliminate common subexpression in ApplyModifier_Remember
No functional change.
2021-03-14 17:38:24 +00:00
rillig
71128ca3aa make: merge duplicate code in ApplyModifier_Remember
This way, parsing and evaluating the modifier is only written once in
the code.  The downside is that the variable name is allocated even if
VARE_WANTRES is not set, but since this modifier is so obscure and
seldom used this doesn't matter in practice.
2021-03-14 17:34:50 +00:00
rillig
0fc517c113 make: do not expand the variable name in the ':_' modifier
This edge case had been so obscure that even discovering this takes
quite some time and requires reading the source code of make.

The manual page doesn't document whether the variable name is expanded
or not, it doesn't even give an example.  When this obscure modifier was
initially added in var.c 1.210 from 2017-01-30, Var_Set always expanded
the variable name once, and there was no way around it.  Therefore this
expansion has probably been unintentional.
2021-03-14 17:27:27 +00:00
rillig
a442584d73 tests/make: demonstrate unintended edge case for the ':_' modifier 2021-03-14 17:14:15 +00:00
rillig
d905f14720 tests/make: convert test for ':_' modifier to parse time 2021-03-14 17:07:11 +00:00
rillig
64a393d8af make: only evaluate the ':_' modifier if the expression is needed
See var-eval-short.mk:46 for the test demonstrating this change.
Previously, the expression ${:Uword:_=VAR} was evaluated including all
its side effects even though it was in an irrelevant branch of the
condition.
2021-03-14 16:43:30 +00:00
rillig
c361e1ef2f make: return failure in TryParseIntBase0 for empty string
No functional change since the only caller of TryParseIntBase0 already
handles all possible parse errors.  Without this check, the code just
looked wrong though.
2021-03-14 16:03:04 +00:00
rillig
f3e066bf1b make: add test for edge case in modifier ':[...]'
TryParseIntBase0 wrongly returns successful for a string that does not
start with a number at all.  Its only caller, ApplyModifier_Words,
already handles all error cases properly.

No functional change.
2021-03-14 16:00:07 +00:00
rillig
c9c8cb6d43 make: separate parsing from evaluating for several modifiers
This aligns the implementation of these modifiers with the requirements
in the long comment starting with 'The ApplyModifier functions'.

No functional change.
2021-03-14 15:43:31 +00:00
rillig
54f9178de3 make: reduce indentation in ApplyModifier_SunShell
No functional change.
2021-03-14 15:24:37 +00:00