From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=lspYEw/N; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 20B8F5A0262 for ; Sat, 16 May 2026 13:12:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1778929960; bh=LQ5AbthlziRWXlgPkXGM5LqKE8U/WUJW6mty4+yyf+E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lspYEw/N44oGFzkypNpzho+jCTiK0n8u+fnipSE/VNGftRf4WitEpjWG+JQamOij6 juoBcU0PsaxdZk4QWww9VFSUQUKbB0wZPlynmR6OSPn0uLjWjpZFo3Y34AuKMrkqSw +Z2PpoDq+L9gBBz8FSMJPFueN7AI9vQTBv82WCDNICMdsLuSF5ruwmfP2sLGdLK9OA CVyCwy0S7HKdhBFej94OCKgK9wcWoQqkJJG1mMx8cW1Trh3EJDUzDQOVtGOqe9ZQ0U RY7C9vHt7IzaSDM9M61N+VeEVAwl/KpNvELM5tlYKf7lkwx/gtfBUjcnnbxMqUzTph beoYD4qejYujg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gHhHX4WDSz4x1h; Sat, 16 May 2026 21:12:40 +1000 (AEST) Date: Sat, 16 May 2026 21:12:32 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 2/3] Fix build with -DNDEBUG Message-ID: References: <20260515041312.317644-1-david@gibson.dropbear.id.au> <20260515041312.317644-3-david@gibson.dropbear.id.au> <20260516112715.6e3d2730@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="aGz3Jfe/e4w1i4xR" Content-Disposition: inline In-Reply-To: <20260516112715.6e3d2730@elisabeth> Message-ID-Hash: R7X2GTJVKZIGJ76D25FD42MH5UPSY4RX X-Message-ID-Hash: R7X2GTJVKZIGJ76D25FD42MH5UPSY4RX X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Jan Palus , passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --aGz3Jfe/e4w1i4xR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, May 16, 2026 at 11:27:16AM +0200, Stefano Brivio wrote: > On Sat, 16 May 2026 16:28:52 +1000 > David Gibson wrote: >=20 > > On Fri, May 15, 2026 at 01:05:50PM +0200, Jan Palus wrote: > > > On 15.05.2026 14:13, David Gibson wrote: =20 > > > > Since bc872d91765d, our assert() statements are omitted if we compi= le with > > > > -DNDEBUG, like the standard library assert(3). Unfortunately a tri= vial but > > > > embarrassing mistake in that patch means that instead of never abor= ting in > > > > this case, assert_with_msg() *always* aborts, breaking pretty much > > > > everything. > > > >=20 > > > > There's also a missing #include that breaks the build with -DNDEBUG= on at > > > > least some library versions. > > > >=20 > > > > Reported-by: Jan Palus > > > > Fixes: bc872d91765d ("treewide: Spell ASSERT() as assert()") > > > > Signed-off-by: David Gibson > > > > --- > > > > util.h | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > >=20 > > > > diff --git a/util.h b/util.h > > > > index 70aadeba..11f71d45 100644 > > > > --- a/util.h > > > > +++ b/util.h > > > > @@ -6,6 +6,7 @@ > > > > #ifndef UTIL_H > > > > #define UTIL_H > > > > =20 > > > > +#include > > > > #include > > > > #include > > > > #include > > > > @@ -60,7 +61,7 @@ void abort_with_msg(const char *fmt, ...) > > > > __func__, __FILE__, __LINE__, STRINGIFY(expr)) > > > > #else > > > > #define assert_with_msg(expr, ...) \ > > > > - ((void)(expr), 0 ? (void)0 : abort_with_msg(__VA_ARGS__)) > > > > + ((void)(expr), 1 ? (void)0 : abort_with_msg(__VA_ARGS__)) =20 > > >=20 > > > There is a slight semantic difference between assert() and > > > assert_with_msg() when building with -DNDEBUG -- `expr` is still being > > > evaluated in abort_with_msg() although likely optimized out in most > > > builds. =20 > >=20 > > Right, I'm expecting the compiler to optimise this away. That won't > > be the case if the expression has side effects, but side effects in an > > assert() expression is already a bug, precisely because of the > > possibility NDEBUG. > >=20 > > > I'm assuming you'd prefer to avoid cppcheck suppressions. =20 > >=20 > > cppcheck suppressions would be acceptable if we could put them inside > > the macro. But these are unused variable warnings, which show up at > > the site of variable declaration not (obviously) at the place the > > variable... isn't used. Putting suppressions on variables because > > they might become unused depending on a macro definition certainly > > isn't acceptable. Both for aesthetics, and because it means if we > > removed the assert we'd no longer get a warning that the variable now > > really isn't used. > >=20 > > > How > > > about moving `expr` into branch which is never evaluated then? Would = it > > > keep cppcheck happy? > > >=20 > > > + (1 ? (void)0 : ((void)(expr), abort_with_msg(__VA_ARGS__))) =20 > >=20 > > That does work. Not sure if it's worth the bother of a respin. > > Stefano, any opinion? >=20 > I think it would be worth changing that given that the only reason why > PLD Linux enables NDEBUG is to avoid evaluating those expressions. I guess. But I'm pretty sure it will come to the same thing unless you used both -DNDEBUG *and* -O0, which seems a perverse combination. > I can also change it on merge though, it's trivial enough. I'll do that > if everybody is fine with it. Fine by me. --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --aGz3Jfe/e4w1i4xR Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoIURsACgkQzQJF27ox 2Ge0HRAAqfLO5uTGiLwj3Cf7mbY22ue+8P0iZrCZ02+FpkgLNt76ErU1NRiZ4/DD OAopYx86SlLCyPHSHm0scTqJNs6FNk8vGuqRyFWvNH7sPcEkCn1FSrq8kT/Xfcdw Q6a9lGzPrEWTAJOX9Fcg3pQQ8T01eXFOUCmxigVx4x3SB9Fps+yxYQvuFMGYlEFl FUJVBMmcA1tI1bzuuLObRcTeVc20++jk4VdMDVtULyCwJIM6Ibwo3VGrcqoREG9j SBMrnkOq76eGQn97J8FCFiV8JZ97tZkNw/hfxc3cGwQ5w1AHI8JRCgpFgFFP3EhU gchFyZT3KKaK4kaZFDZjl/iawZyCNmVutIB9VMgIWhkh489MmMR1x59+VsssOI4k E5MLQCWk4REzG3+f1+on1Qcezu9c5Db/PY2PxLoK2KHmBzdch9F9fZkFM5VMcTZ3 2Skuk4U5zKwW5TVJlBUO4tDBn4hs1/NCx/l1ntCSq6xcnBHnkzejWIgvDJ9iwxgn Qrkxn2/peRs0juJzcXYzxlDF+ifazLB3nXXZzLaMooEhK65cnJLGW5TxSdRo9BeP i5VClPHgjUKZDNcGR91tH395C4NLW8wIerQRZUx5RW3bR8MQyYOhFUWSdiA/JgF1 uBtqQ3hH0kzGD1tpuVShTrZusA0iIvLz+O7P+T2tKm5a3T9bxYo= =USrv -----END PGP SIGNATURE----- --aGz3Jfe/e4w1i4xR--