Skip to content

Commit

Permalink
net: Build assert issue with llvm
Browse files Browse the repository at this point in the history
Remove the build assert from NET_L3_REGISTER() macro as that
is causing an issue with llvm. Add runtime check of the handler
pointer value.

subsys/net/l2/ethernet/arp.c:1044:1: error: static_assert expression
is not an integral constant expression

ETH_NET_L3_REGISTER(ARP, NET_ETH_PTYPE_ARP, arp_recv);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/zephyr/net/ethernet.h:1272:2: note: expanded from
macro 'ETH_NET_L3_REGISTER'
        NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/zephyr/net/net_core.h:190:2: note: expanded from
macro 'NET_L3_REGISTER'
        BUILD_ASSERT((_handler) != NULL, "Handler is not defined")
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/zephyr/toolchain/gcc.h:87:51: note: expanded from
macro 'BUILD_ASSERT'
define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG)
                                                  ^~~~~~
subsys/net/l2/ethernet/arp.c:1044:1: note: cast from 'void *' is not
allowed in a constant expression
include/zephyr/net/ethernet.h:1272:2: note: expanded from
macro 'ETH_NET_L3_REGISTER'
        NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
        ^
include/zephyr/net/net_core.h:190:29: note: expanded from
macro 'NET_L3_REGISTER'
        BUILD_ASSERT((_handler) != NULL, "Handler is not defined")
                                   ^
/usr/lib/llvm-14/lib/clang/14.0.0/include/stddef.h:89:16: note: expanded
from macro 'NULL'
  define NULL ((void*)0)

Signed-off-by: Jukka Rissanen <[email protected]>
  • Loading branch information
jukkar authored and kartben committed Jan 21, 2025
1 parent 04205ae commit ab9b85b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 1 addition & 2 deletions include/zephyr/net/net_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ struct net_l3_register {
.handler = _handler, \
.name = STRINGIFY(_name), \
.l2 = _l2_type, \
}; \
BUILD_ASSERT((_handler) != NULL, "Handler is not defined")
};

/* @endcond */

Expand Down
3 changes: 2 additions & 1 deletion subsys/net/l2/ethernet/ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
net_buf_pull(pkt->frags, hdr_len);

STRUCT_SECTION_FOREACH(net_l3_register, l3) {
if (l3->ptype != type || l3->l2 != &NET_L2_GET_NAME(ETHERNET)) {
if (l3->ptype != type || l3->l2 != &NET_L2_GET_NAME(ETHERNET) ||
l3->handler == NULL) {
continue;
}

Expand Down

0 comments on commit ab9b85b

Please sign in to comment.