Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

compiler_types.h: fix "unused variable" in __compiletime_assert()

This refines commit c03567a8e8d5 ("include/linux/compiler.h: don't perform
compiletime_assert with -O0") and restores #ifdef __OPTIMIZE__ symmetry by
evaluating the 'condition' variable in both compile-time variants of
__compiletimeassert().

As __OPTIMIZE__ is always true by default, this commit does not change
anything by default. But it fixes warnings with _non-default_ CFLAGS like
for instance this:

make CFLAGS_tcp.o='-Og -U__OPTIMIZE__'

from net/ipv4/tcp.c:273:

include/net/sch_generic.h: In function `qdisc_cb_private_validate':
include/net/sch_generic.h:511:30:
error: unused variable `qcb' [-Werror=unused-variable]

{
struct qdisc_skb_cb *qcb;

BUILD_BUG_ON(sizeof(skb->cb) < sizeof(*qcb));
...
}

[akpm@linux-foundation.org: regularize comment layout, reflow comment]
Link: https://lkml.kernel.org/r/20250424194048.652571-1-marc.herbert@linux.intel.com
Signed-off-by: Marc Herbert <Marc.Herbert@linux.intel.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Jan Hendrik Farr <kernel@jfarr.cc>
Cc: Macro Elver <elver@google.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Tony Ambardar <tony.ambardar@gmail.com>
Cc: Uros Bizjak <ubizjak@gmail.com>
Cc: Kees Cook <kees@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Marc Herbert and committed by
Andrew Morton
9c7b53b2 3dc32adf

+7 -1
+7 -1
include/linux/compiler_types.h
··· 525 525 sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) 526 526 527 527 #ifdef __OPTIMIZE__ 528 + /* 529 + * #ifdef __OPTIMIZE__ is only a good approximation; for instance "make 530 + * CFLAGS_foo.o=-Og" defines __OPTIMIZE__, does not elide the conditional code 531 + * and can break compilation with wrong error message(s). Combine with 532 + * -U__OPTIMIZE__ when needed. 533 + */ 528 534 # define __compiletime_assert(condition, msg, prefix, suffix) \ 529 535 do { \ 530 536 /* \ ··· 544 538 prefix ## suffix(); \ 545 539 } while (0) 546 540 #else 547 - # define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0) 541 + # define __compiletime_assert(condition, msg, prefix, suffix) ((void)(condition)) 548 542 #endif 549 543 550 544 #define _compiletime_assert(condition, msg, prefix, suffix) \