Commit Graph

1776 Commits

Author SHA1 Message Date
rillig 681c37d9da lint: in strict bool mode, allow do-while-0
Even though 0 is not a boolean constant, allow this common idiom, to
help in those cases where the C preprocessor used by lint does not mark
tokens as coming from system headers (Clang).
2024-05-12 12:28:34 +00:00
rillig 37d5546d18 tests/lint: clean up tests for strict bool mode 2024-05-12 11:46:14 +00:00
rillig 4bd7e6e13f 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.
2024-05-11 16:12:28 +00:00
rillig 9cfc443f88 lint: warn when comparing an integer to a floating point constant 2024-05-11 15:53:38 +00:00
riastradh 2173c07c84 tests/usr.bin/mtree/t_sets: Add base32, base64, debug32, debug64. 2024-05-10 03:29:47 +00:00
rillig 64ab641533 lint: in C23 mode, allow storage classes in compound literals 2024-05-09 20:56:41 +00:00
rillig 2d37fed27b lint: add details to message about too many initializers 2024-05-09 20:53:13 +00:00
rillig 151775b8cf lint: in C23 mode, support the nullptr constant 2024-05-09 11:08:07 +00:00
rillig 1cdc580354 lint: in C23 mode, support the keywords 'bool', 'false' and 'true' 2024-05-07 21:13:26 +00:00
rillig fe6f732478 tests/lint: show that in C23 mode, bool is not yet defined
The tests in C11 and C23 mode look the same right now but will change
soon.

The warnings in the C11 test disappeared because after the first error,
warnings about unused variables are suppressed by check_variable_usage,
as they are often wrong.
2024-05-07 19:32:35 +00:00
martin ce6107da93 Add manhtml set 2024-05-07 14:53:59 +00:00
riastradh 9263853839 tests/usr.bin/mtree/t_sets.sh: atf_fail, not atf_tc_fail 2024-05-06 14:38:28 +00:00
riastradh cd71d51811 tests/usr.bin/mtree: Fail gracefully with unknown sets.
Rather than `bogus test program', make a test fail.

PR misc/57877
2024-05-04 20:24:37 +00:00
rillig 1772ff8ac7 lint: increase debug logging for declarations
All changes to the global variable 'dcs' are tracked now, to help
identify the cause of the failing tests in expr_sizeof and
gcc_attribute_aligned.

While here, test more invalid type combinations in typedefs.
2024-05-04 06:52:16 +00:00
rillig cbe2532061 tests/lint: fix supposedly platform-independent type definitions
No idea where I got the previous type definitions from.  The typedef
names looked just too convincing to actually check the underlying types.
2024-05-03 19:16:13 +00:00
rillig 0b487d0915 tests/lint: skip test for sizeof struct on 32-bit platforms
Even though the test only uses fixed-size types, lint's computed size of
the resulting struct differs between i386 (80) and x86_64 (112).  Both
are wrong, probably due to the unrelated struct declaration above, as
already mentioned in the comments.
2024-05-03 15:32:37 +00:00
rillig 2e8fec16de tests/lint: demonstrate wrong struct size calculation 2024-05-02 20:03:33 +00:00
rillig 571b49008c lint: make 'offsetof(t, array-member)' a constant expression
The macro 'offsetof(t, m)' already expanded to a constant expression for
scalar members but not for arrays.  This was because the macro expanded
to '(size_t)(((t *)0)->m)', which lint internally represents as
'addr(indir(ptr(0) + offset(m)))', and build_address simplifies
'addr(indir(x))' to 'x' if the types match.  The types only match for
scalar types though, but not for arrays.

When build_address happens, the type information is incomplete,
therefore 'offsetof(t, array)' has to be simplified at a later point.
2024-05-01 17:42:57 +00:00
rillig b636d70fb7 tests/lint: test large enum constants and offsetof with array members 2024-05-01 12:36:56 +00:00
rillig d69057212d lint: fix size of struct with large alignment
Lint now successfully passes all compile-time assertions in the amd64
kernel that deal with struct sizes.
2024-05-01 10:30:56 +00:00
rillig 313458bc0b lint: support _Alignas and __attribute__((__aligned(4))) 2024-05-01 07:40:11 +00:00
rillig de44edfce0 lint: fix warning about out-of-bounds bit-field value 2024-05-01 05:49:33 +00:00
rillig ce8bf3c377 lint: demonstrate wrong warning about out-of-range bit-field 2024-05-01 05:38:11 +00:00
rillig d8f5b04c09 tests: replace deprecated '-s eq:...' with '-s exit:...' 2024-04-28 07:27:40 +00:00
rillig fc7f5da782 lint: converting a null pointer to another pointer type is not narrowing 2024-04-27 12:46:37 +00:00
rillig 96381692fe lint: add query for conversion from void pointer to other pointer 2024-04-27 10:08:54 +00:00
rillig 6e59c25695 tests/lint: show how to trigger message 207 2024-04-19 20:59:18 +00:00
rillig dae6022bba lint: in snprintb, warn about all escaped characters in descriptions 2024-04-12 05:17:48 +00:00
rillig 0382e641fc lint: in the query about implicit conversions, ignore casts 2024-03-30 19:12:37 +00:00
rillig 370056d3b9 lint: add query for implicit integer-to-floating conversion 2024-03-30 17:23:13 +00:00
rillig def8e1797a lint: do not convert array subscripts from size_t to ptrdiff_t
The C standards do not specify a fixed type for an array subscript, it
just has to be an integer type.  Previously, query 4 fired for the
ubiquitous expression 'ptr[sz]' when sz had type 'size_t'.

The test platform_ilp32_long is unaffected by this change, as the
integer constant 0x80000000 has type 'unsigned int', while size_t is
'unsigned long' on those platforms, and even though the types 'unsigned
int' and 'unsigned long' have the same value space, there's still a
conversion, at least for now.
2024-03-30 17:12:26 +00:00
rillig c6466ed0f7 lint: reword messages about array subscripts to sound more natural 2024-03-30 16:47:44 +00:00
rillig 55398a9a51 lint: fix wording of warning about bit-field initializer 2024-03-29 07:35:45 +00:00
rillig 134116ce30 lint: clean up 2024-03-28 21:04:48 +00:00
rillig 8910413e27 lint: clean up; extend overflow test 2024-03-27 20:09:43 +00:00
rillig e57698da95 lint: don't use 'long' in diagnostics
The size of 'long' differs between 64-bit and 32-bit platforms.
Eliminate this possible platform-dependency.
2024-03-27 19:28:20 +00:00
rillig 216c89c02b lint: fix warnings about loss of accuracy on bit-field operations 2024-03-25 23:39:13 +00:00
rillig 6167e0cc12 tests/lint: demonstrate wrong warnings about lossy bit field operations 2024-03-25 22:46:23 +00:00
rillig 64230f3217 lint: rename snprintb 'directives' to 'conversions'
This aligns the terminology with the snprintf function.
2024-03-25 22:37:43 +00:00
rillig 083828859c stat: don't allow numeric formatting flags on strings
Calling snprintf with "%+s" invokes undefined behavior.
2024-03-14 21:17:54 +00:00
rillig 897cdf26ba tests/stat: test the left-aligned and right-aligned 'S' format 2024-03-14 21:00:32 +00:00
rillig 9ca08a6937 tests/lint: ensure that lint correctly decays array parameter types 2024-03-13 06:56:24 +00:00
rillig 9ed4dea22d tests/lint: extend test for previously wrong warning about bit-fields 2024-03-12 20:35:29 +00:00
rillig 9b239cc71c lint: fix warning about loss of conversion for unsigned bit-fields
Since decl.c 1.180 from 2021-05-02.
2024-03-12 07:56:08 +00:00
rillig fc2f5e14be tests/lint: demonstrate wrong warning when comparing a bit-field
Since decl.c 1.180 from 2021-05-02, which allowed arbitrary integer
types to be used as the underlying type for bit-fields in GCC mode.
2024-03-12 07:29:39 +00:00
rillig dd848dec1a lint: add details to the message about integer overflow
Having only the operator was too unspecific to be actionable, so add the
actual numbers and the data type.
2024-03-10 19:45:14 +00:00
rillig bd9743d3db lint: saturate signed integer overflow
In array address calculations, this prevents a 'array subscript cannot
be negative' for large array subscripts.
2024-03-10 16:06:13 +00:00
rillig 08d1bd5c72 lint: fix integer overflow detection
Previously, an unsigned operation that had a negative result went
undetected in a few cases. Now, all results that are not representable
by their type are considered overflows.

The implementation of signed shift-right had been wrong for a few
commits.
2024-03-10 15:49:12 +00:00
rillig 51858eeb3e lint: detect more cases of integer overflow in constant expressions
For unsigned integers, detect when 'a + b' wraps around.
2024-03-10 14:32:30 +00:00
rillig 7d57e750b8 tests/lint: enable test for integer overflow in array index 2024-03-10 10:39:19 +00:00