Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Alex Williamson <alex@shazbot.org>
Cc: David Matlack <dmatlack@google.com>, Kees Cook <kees@kernel.org>,
	Shuah Khan <shuah@kernel.org>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	llvm@lists.linux.dev, Andy Lutomirski <luto@amacapital.net>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
	Raghavendra Rao Ananta <rananta@google.com>,
	Vipin Sharma <vipinsh@google.com>, Will Drewry <wad@chromium.org>,
	Aaron Lewis <aaronlewis@google.com>
Subject: Re: [PATCH] selftests: harness: Mark test fixture objects __maybe_unused
Date: Tue, 30 Jun 2026 19:49:06 -0700	[thread overview]
Message-ID: <20260701024906.GA3960633@ax162> (raw)
In-Reply-To: <20260630165244.0d013bbc@shazbot.org>

On Tue, Jun 30, 2026 at 04:52:44PM -0600, Alex Williamson wrote:
> On Tue, 30 Jun 2026 21:33:41 +0000
> David Matlack <dmatlack@google.com> wrote:
> 
> > Mark test fixture objects __maybe_unused since they will not be used
> > when there are fixture variants (the variants will be used instead).
> > 
> > This fixes the VFIO selftest build with clang and -Werror:
> > 
> > vfio_dma_mapping_mmio_test.c:106:1: error: variable '_vfio_dma_mapping_mmio_test_map_full_bar_object' set but not used [-Werror,-Wunused-but-set-global]
> >   106 | TEST_F(vfio_dma_mapping_mmio_test, map_full_bar)
> >       | ^
> > ./../kselftest_harness.h:398:2: note: expanded from macro 'TEST_F'
> >   398 |         __TEST_F_IMPL(fixture_name, test_name, -1, TEST_TIMEOUT_DEFAULT)
> >       |         ^
> > ./../kselftest_harness.h:470:33: note: expanded from macro '__TEST_F_IMPL'
> >   470 |         static struct __test_metadata *_##fixture_name##_##test_name##_object; \
> >       |
> > 
> > Fixes: ff556bd98348 ("vfio: selftests: Add -Wall and -Werror to the Makefile")
> > Reported-by: Aaron Lewis <aaronlewis@google.com>
> > Signed-off-by: David Matlack <dmatlack@google.com>
> > ---
> >  tools/testing/selftests/kselftest_harness.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> > index 261e4df94d9d..29a19bc87084 100644
> > --- a/tools/testing/selftests/kselftest_harness.h
> > +++ b/tools/testing/selftests/kselftest_harness.h
> > @@ -467,7 +467,7 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
> >  				!__atomic_test_and_set(_metadata->no_teardown, __ATOMIC_RELAXED)) \
> >  			fixture_name##_teardown(_metadata, self, variant); \
> >  	} \
> > -	static struct __test_metadata *_##fixture_name##_##test_name##_object; \
> > +	static struct __test_metadata *_##fixture_name##_##test_name##_object __maybe_unused; \
> >  	static void __attribute__((constructor(KSELFTEST_PRIO_TEST))) \
> >  			_register_##fixture_name##_##test_name(void) \
> >  	{ \
> > 
> > base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
> 
> Reviewed-by: Alex Williamson <alex@shazbot.org>
> 
> Kees/Shuah, I can take this through the vfio tree if you prefer, it
> fixes a commit that entered through vfio selftests.  Thanks,

Not that it is a big deal or matters all too much but I do not think
this fixes tag is entirely accurate. The blamed commit may have
introduced the build warning/error in the VFIO code but that same
warning could occur in any selftest code, as evidenced by the exact same
patch submitted a month ago:

  https://lore.kernel.org/20260530054722.271157-1-kuniyu@google.com/

clang made a change to -Wunused-but-set-variable (split out into its own
subwarning, -Wunused-but-set-global) that exposes this. Personally, I
find that change explains the problem better but this one makes it clear
that it can become fatal with -Werror.

-- 
Cheers,
Nathan

      reply	other threads:[~2026-07-01  2:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 21:33 [PATCH] selftests: harness: Mark test fixture objects __maybe_unused David Matlack
2026-06-30 22:52 ` Alex Williamson
2026-07-01  2:49   ` Nathan Chancellor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260701024906.GA3960633@ax162 \
    --to=nathan@kernel.org \
    --cc=aaronlewis@google.com \
    --cc=alex@shazbot.org \
    --cc=dmatlack@google.com \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=luto@amacapital.net \
    --cc=morbo@google.com \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=rananta@google.com \
    --cc=shuah@kernel.org \
    --cc=vipinsh@google.com \
    --cc=wad@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox