From nobody Tue Dec 2 02:06:43 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E59823081D0 for ; Thu, 20 Nov 2025 15:02:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763650984; cv=none; b=uRJxOGZCfayypyqTm0GfMWoHN/srfIMb+oTrN6VOy+VgrKH4XJtDfI41FzIG8kvnYq2ZBdzp6JAYjPWVSoLPX84OtbL/GzGsAtfv6dTVP/V1/U21i5oG/7U6j89JmufRjD1jt//gcbiCw96MSWJ1RfYjcBZ6hVbNZvXFdDLBb6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763650984; c=relaxed/simple; bh=eBDUdyy/+hf0zNW0yP0X5FX5kRPqZGLn6VJLXyEfqFo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VU1fpyp1HmPTGfd6HZ7xfzNMBlPvCGFmRvBflgJ0enVE/zELTynVkuEnk+QQRLVjdbjBGdWaMObfc6jRjuNU2VsIDRX2pqntC64rg+URjyRIVuPayMEFV+Gva9LNTZFs+DY5bGsEm9apejuR5T9jL+gzRcdgepoJA4CbYbvdDpM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elver.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Us7Hk1RS; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--elver.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Us7Hk1RS" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4779da35d27so12323995e9.3 for ; Thu, 20 Nov 2025 07:02:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763650973; x=1764255773; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lIkqaT4GZQQ8I2xtRoztfiZr8q25ife+cBqIcslh3gQ=; b=Us7Hk1RShmc30uTXgR3INbaySaUA9KT4NJoXfduOpGY5/u6z9cFYcnISLbRnpNGSoQ ukqj/IdxlwM3BH1e9bRcTdHml126/z8CSQz0dBIoMvPIndNOXza7ixlzGoLVU/lu65DP +S9QkcHuNDE/jFRymy726C7ppg2/z/8OZkLsUdIqwWZW5gredZsdEl6FArODeVX0UKEF 94mtGLrEpzVssD8/VuNbqjIbAjESlJkNKruoDlQpTOC+eFJFsRyNyOqtynus0EIWaBIo ur6w8p+4BW6lMDP10IFNwMtgF0YMNLP+nJjqg0UmdstSiSiIOfrDG2ZHNnmoWgMhWDLK Ug+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763650973; x=1764255773; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lIkqaT4GZQQ8I2xtRoztfiZr8q25ife+cBqIcslh3gQ=; b=EG6iUKS9xQ33xzWIoeeG7wyg99nPuCy+jDMGOLtzD23dZuILvdXSuFXIiSQf9/6MMv z2kO+OCOqY19CfyjWsxu2KadoIH5vWby8a27xNuffNOxLkbryhY5uyv5lOl/+SHDk86p 4e9bXZWEppWYpzXoznYl5Pag5DgsoVo8+SGnA3b1tsdhYagJTxHFQGCRJGlpn0e6gefq Gf1Eo4IVeWa2R8URM/c8oFilAAdsEVmIJAgoYtBjFMoCwHVskYBJHK6U8mRrcBwn8peA rEHL3Ro2wwBZLtcBNdSMMG1ZtyFwXsaZCPkAZ9qXhq9XbJosCDhgGhF41CHlk7Q93uhj N/KA== X-Forwarded-Encrypted: i=1; AJvYcCW1gwOmcFfh1f/aZHFw7ajFo29H5EenG+EDLFx3H2wA7fb/ptk/B/yu8gxcubEefZpnQ00AMnyJSQ6iXd8=@vger.kernel.org X-Gm-Message-State: AOJu0YzXmChouJgaGcIH8E08Twiv9hQi+y3nLTz1EVgax+lzboAaExFk LVQMJJtIWEvTx3d+Uj3FMM1uH4XihwlKJASKbYQwf61Vut3r9/wdyOYQFi4UH1SVoTm+jscMxjj lPw== X-Google-Smtp-Source: AGHT+IE7SKgiCw/02hArGI9zujP0xPyrpw65qFKPWhHBeestq9lQVOSID1Bw6HemoDi2xS2ktBePcnke9A== X-Received: from wmrm14.prod.google.com ([2002:a05:600c:37ce:b0:46e:4c7c:5162]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:470d:b0:477:9cdb:e32e with SMTP id 5b1f17b1804b1-477b8a50e80mr28447795e9.9.1763650973180; Thu, 20 Nov 2025 07:02:53 -0800 (PST) Date: Thu, 20 Nov 2025 15:49:05 +0100 In-Reply-To: <20251120145835.3833031-2-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251120145835.3833031-2-elver@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251120145835.3833031-5-elver@google.com> Subject: [PATCH v4 03/35] compiler-context-analysis: Add test stub From: Marco Elver To: elver@google.com, Peter Zijlstra , Boqun Feng , Ingo Molnar , Will Deacon Cc: "David S. Miller" , Luc Van Oostenryck , Chris Li , "Paul E. McKenney" , Alexander Potapenko , Arnd Bergmann , Bart Van Assche , Christoph Hellwig , Dmitry Vyukov , Eric Dumazet , Frederic Weisbecker , Greg Kroah-Hartman , Herbert Xu , Ian Rogers , Jann Horn , Joel Fernandes , Johannes Berg , Jonathan Corbet , Josh Triplett , Justin Stitt , Kees Cook , Kentaro Takeda , Lukas Bulwahn , Mark Rutland , Mathieu Desnoyers , Miguel Ojeda , Nathan Chancellor , Neeraj Upadhyay , Nick Desaulniers , Steven Rostedt , Tetsuo Handa , Thomas Gleixner , Thomas Graf , Uladzislau Rezki , Waiman Long , kasan-dev@googlegroups.com, linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-sparse@vger.kernel.org, linux-wireless@vger.kernel.org, llvm@lists.linux.dev, rcu@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a simple test stub where we will add common supported patterns that should not generate false positive of each new supported context guard. Signed-off-by: Marco Elver --- v4: * Rename capability -> context analysis. --- lib/Kconfig.debug | 14 ++++++++++++++ lib/Makefile | 3 +++ lib/test_context-analysis.c | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 lib/test_context-analysis.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 696e2a148a15..0c499d22407c 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2833,6 +2833,20 @@ config LINEAR_RANGES_TEST =20 If unsure, say N. =20 +config CONTEXT_ANALYSIS_TEST + bool "Compiler context-analysis warnings test" + depends on EXPERT + help + This builds the test for compiler-based context analysis. The test + does not add executable code to the kernel, but is meant to test that + common patterns supported by the analysis do not result in false + positive warnings. + + When adding support for new context guards, it is strongly recommended + to add supported patterns to this test. + + If unsure, say N. + config CMDLINE_KUNIT_TEST tristate "KUnit test for cmdline API" if !KUNIT_ALL_TESTS depends on KUNIT diff --git a/lib/Makefile b/lib/Makefile index 1ab2c4be3b66..59ed5f881bcb 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -329,4 +329,7 @@ obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) +=3D devmem= _is_allowed.o =20 obj-$(CONFIG_FIRMWARE_TABLE) +=3D fw_table.o =20 +CONTEXT_ANALYSIS_test_context-analysis.o :=3D y +obj-$(CONFIG_CONTEXT_ANALYSIS_TEST) +=3D test_context-analysis.o + subdir-$(CONFIG_FORTIFY_SOURCE) +=3D test_fortify diff --git a/lib/test_context-analysis.c b/lib/test_context-analysis.c new file mode 100644 index 000000000000..68f075dec0e0 --- /dev/null +++ b/lib/test_context-analysis.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Compile-only tests for common patterns that should not generate false + * positive errors when compiled with Clang's context analysis. + */ + +#include + +/* + * Test that helper macros work as expected. + */ +static void __used test_common_helpers(void) +{ + BUILD_BUG_ON(context_unsafe(3) !=3D 3); /* plain expression */ + BUILD_BUG_ON(context_unsafe((void)2; 3) !=3D 3); /* does not swallow semi= -colon */ + BUILD_BUG_ON(context_unsafe((void)2, 3) !=3D 3); /* does not swallow comm= as */ + context_unsafe(do { } while (0)); /* works with void statements */ +} --=20 2.52.0.rc1.455.g30608eb744-goog