Commit Graph

17570 Commits

Author SHA1 Message Date
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