[all-commits] [llvm/llvm-project] 5a530a: [libc] Reimplement IN6_IS_ADDR_* macros using stat...
Pavel Labath via All-commits
all-commits at lists.llvm.org
Wed Jul 15 23:36:15 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 5a530a22fae4aaa41da79779cd56db57f8de55f8
https://github.com/llvm/llvm-project/commit/5a530a22fae4aaa41da79779cd56db57f8de55f8
Author: Pavel Labath <pavel at labath.sk>
Date: 2026-07-16 (Thu, 16 Jul 2026)
Changed paths:
M libc/include/llvm-libc-macros/netinet-in-macros.h
M libc/test/include/netinet_in_test.cpp
Log Message:
-----------
[libc] Reimplement IN6_IS_ADDR_* macros using statement expressions (#209772)
This patch fixes three issues with the previous implementation:
- the macro argument was being evaluated more than once
- casting to other types (uint32_t in particular) was an aliasing
violation
- it was casting to non-const pointers, resulting in compiler errors in
cases where the user passes a const ptr.
A statement expression fixes the first issue by using a temporary
variable. The second issue is fixed by using the appropriate members of
struct in6_addr. The last issue is fixed by dropping the cast
completely. This requires the user to pass a correctly types pointer (as
POSIX requires). Implementations keep it for compatibility with old code
passing void * and similar, but a quick survey shows that most modern
code passes the correct types. If this turns out to be an issue, we can
easily add the cast (to a const type) back.
Implementation notes:
- IN6_IS_ADDR_MULTICAST doesn't use the statement expression because the
argument is evaluated only once
- I use private helper macros (__IN6_IS_ADDR_UNSPECIFIED and
__IN6_IS_ADDR_LOOPBACK) so IN6_IS_ADDR_V4COMPAT does not nest statement
expressions
- I considered using private entrypoints (like we do with cpuset macros)
instead of statement expressions, but decided against it because these
macros are simpler and would thus result in a higher
boilerplate-to-useful-code ratio (particularly given our restriction on
calling other entrypoints)
Assisted by Gemini.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list