Skip to content

Conversation

arichardson
Copy link
Contributor

I uploaded many of these to phabricator, but for a lot of these small ones it seems like a lot of overhead, so I'm just pushing the full set of required changes here.

@arichardson arichardson force-pushed the clang-head-warning-fixes branch 3 times, most recently from 3b547bf to a9ada86 Compare September 15, 2025 23:33
Summary:
This ensures this header can be included without an explicit or implicit
sys/types.h include first. This causes issues building SPEC2017 which
includes sys/rtprio.h and then we get an error due to missing u_char
definition.

Reviewers: emaste, imp

Differential Revision: https://reviews.freebsd.org/D52041
Summary:
glibc defines two versions of strerror_r, the char* returning one is used
when _GNU_SOURCE is defined. This triggers a -Wint-conversion error in
the krb5 strerror_r wrapper, but until clang 19 this was just a normal
warning, now it defaults to being an error.

/home/runner/work/freebsd-src/freebsd-src/crypto/krb5/src/util/support/strerror_r.c: In function ‘k5_strerror_r’:
/home/runner/work/freebsd-src/freebsd-src/crypto/krb5/src/util/support/strerror_r.c:94:12: warning: returning ‘char *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
   94 |     return strerror_r(errnum, buf, buflen);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This was not caught by the GitHub CI since it still builds with clang 18
on the Linux runners. Add -Werror=int-conversion to the build flags to
catch errors like this in the future.

MFC after:	3 days

Reviewers: jrtc27, emaste

Subscribers: imp
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D52526
Summary:
The init function does not need to aquire a lock for TAILQ_INIT, so just
add __no_lock_analysis. We could also acquire the lock to silence the
analysis but that is unnecessary.

Reviewers: imp
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D52533
Summary:
This attribute can be used to annotate char arrays that are not supposed to
be terminated with a NUL char and is needed to silence clang's new
-Wunterminated-string-initialization warning. The name matches linuxkpi.

Reviewers: emaste, imp, jhb, jrtc27

Differential Revision: https://reviews.freebsd.org/D52565
Summary:
Use the new __nostring attribute since the signature is not NUL-terminated.

Reviewers: imp, emaste, jhb

Subscribers: bdragon
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D52535
Reviewers: jhb, emaste

Subscribers: imp
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D52528
Fixes build failure with latest clang HEAD:
error: initializer-string for character array is too long, array size is
2 but initializer has size 3 (including the null terminating character)

MFC after:	3 days
Found by the latest clang HEAD analysis. This is not a false positive.
MFC after:	3 days
Found building with latest clang

MFC after:	3 days
Fix `passing 'printf' format string where 'freebsd_kprintf' format string is expected [-Werror,-Wformat]`
by using __printf__ which is remapped to __freebsd_kprintf__.

MFC after:	3 days
This is only used in memcmp() calls, so the missing NUL is safe.

MFC after:	3 days
These are not used as strings, don't warn about missing NUL terminator.

MFC after:	3 days
This is not used as a string, don't warn about missing NUL terminator.

MFC after:	3 days
This is not used as a string, don't warn about missing NUL terminator.

MFC after:	3 days
This is not used as a string, don't warn about missing NUL terminator.

MFC after:	3 days
Summary:
This defaults to an error in clang HEAD, use a char-by-char
initializer instead.

Reviewers: emaste, jhb, jrtc27

Subscribers: imp
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D52532
This is not used as a string, don't warn about missing NUL terminator.

MFC after:	3 days
Use a normal string and strlen() instead of a fixed-size char[].

MFC after:	3 days
This was fixed in upstream ncurses (https://ncurses.scripts.mit.edu/?p=ncurses.git;a=commitdiff;h=64afa9627b292b87c8473928854f3dd8c463d833),
but for now only pull in the minimal fix that avoids reading
beyond the end of the buffer during strlen().

MFC after:	3 days
Summary:
This is not used as a string, don't warn about missing NUL terminator.
Silence -Wunterminated-string-initialization warning by adding 1 to
size. We can't use __nonstring unconditionally in bmake since the bmake
bootstrap headers don't define it.

MFC after:	1 week

Test Plan: compiles with clang HEAD

Reviewers: sjg

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D52563
This is triggered by every file that uses gtest-printers.h.
See google/googletest#4762.

MFC after:	3 days
The __printflike macro sets the format to freebsd_kprintf which recent
clang understands and warns about. Fixes the following error:
`passing 'printf' format string where 'freebsd_kprintf' format string is expected [-Werror,-Wformat]`

MFC after:	1 week
The __printflike macro sets the format to freebsd_kprintf which recent
clang understands and warns about. Fixes the following error:
`passing 'printf' format string where 'freebsd_kprintf' format string is expected [-Werror,-Wformat]`

MFC after:	1 week
The native_to_linux_itimerspec() call should have used l_oval as the
output parameter here.
Summary:
The netmap_ring struct starts with various const members and rencent
clang warns about leaving them uninitialized. Having them const in the
first place is highly suspicious since they are updated with various
macros but using hand-coded __DECONST(). But fixing that is a more
invasive change that I am unable to test.

```
.../freebsd/sys/dev/netmap/netmap_kloop.c:320:21: error: default initialization of an object of type 'struct netmap_ring' with const member leaves the object uninitialized [-Werror,-Wdefault-const-init-field-unsafe]
  320 |         struct netmap_ring shadow_ring; /* shadow copy of the netmap_ring */
      |                            ^
.../freebsd/sys/net/netmap.h:290:16: note: member 'buf_ofs' declared 'const' here
  290 |         const int64_t   buf_ofs;
      |                         ^
```

Test Plan: Compiles

Reviewers: vmaffione, jhb

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D52568
@arichardson arichardson force-pushed the clang-head-warning-fixes branch from a9ada86 to 71ae6c7 Compare September 16, 2025 05:35
@arichardson
Copy link
Contributor Author

This should be ready now, I've built it locally targeting amd64 and risc64

Use the latest Clang packages available for macos and Ubuntu 24.04 to
ensure we also test newer versions in addition to the oldest supported
version.
@arichardson arichardson force-pushed the clang-head-warning-fixes branch from d17474f to 70633bc Compare September 16, 2025 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant