git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,
	"brian m. carlson" <sandals@crustytoothpaste.net>,
	Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH v2 2/3] ci: add build checking for side-effects in assert() calls
Date: Mon, 17 Mar 2025 18:30:53 -0400	[thread overview]
Message-ID: <Z9iinbyrn4PeFmCl@nand.local> (raw)
In-Reply-To: <58cb8f6a1609b10d761e86bdad541d1c018cb582.1742107322.git.gitgitgadget@gmail.com>

On Sun, Mar 16, 2025 at 06:42:01AM +0000, Elijah Newren via GitGitGadget wrote:
> We have roughly 566 assert() calls in our codebase (my grep might have
> picked up things that aren't actually assert() calls, but most appeared
> to be).  All but 9 of them can be determined by gcc to be free of side
> effects with a clever redefine of assert() provided by Bruno De Fraine
> (from
> https://stackoverflow.com/questions/10593492/catching-assert-with-side-effects),
> who upon request has graciously placed his two-liner into the public
> domain without warranty of any kind.  The current 9 assert() calls
> flagged by this clever redefinition of assert() appear to me to be free
> of side effects as well, but are too complicated for a compiler/linker
> to figure that since each assertion involves some kind of function call.
> Add a CI job which will find and report these possibly problematic
> assertions, and have the job suggest to the user that they replace these
> with BUG_IF_NOT() calls.

Very nice, and thank you Bruno for placing your very clever assert() in
the public domain :-).

I wonder if it might be useful to explain this in
Documentation/CodingGuidelines as a follow-up to this series. I was
thinking of a scenario where someone either writes a side-effecting
assert(), or a non-side-effecting one that is too complicated to prove
otherwise.

If that person runs 'make test' locally, they might not see any
failures, but then be surprised when CI fails on the new step. It may be
worth mentioning that we have such a check, and that we expect all
assert() statements to be side effect-free, and that developers can
verify this by ci/check-unsafe-assertions.sh.

But that may bring us into an assert() versus BUG_IF_NOT() debate, which
may be somewhat counterproductive, so I'm just as happy if you did
nothing here :-).

Thanks,
Taylor

  reply	other threads:[~2025-03-17 22:30 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14  0:20 [PATCH 0/3] Add a static analysis job to prevent assertions with side effects Elijah Newren via GitGitGadget
2025-03-14  0:20 ` [PATCH 1/3] git-compat-util: introduce BUG_IF_NOT() macro Elijah Newren via GitGitGadget
2025-03-14  0:20 ` [PATCH 2/3] ci: add build checking for side-effects in assert() calls Elijah Newren via GitGitGadget
2025-03-14  1:06   ` Junio C Hamano
2025-03-14  1:18     ` brian m. carlson
2025-03-14  1:20       ` Junio C Hamano
2025-03-14  1:27         ` Elijah Newren
2025-03-14 17:29           ` Junio C Hamano
2025-03-16  6:38             ` Elijah Newren
2025-03-17 15:45               ` Elijah Newren
2025-03-17 22:27               ` Junio C Hamano
2025-03-14  0:20 ` [PATCH 3/3] treewide: replace assert() with BUG_IF_NOT() in special cases Elijah Newren via GitGitGadget
2025-03-16  6:41 ` [PATCH v2 0/3] Add a static analysis job to prevent assertions with side effects Elijah Newren via GitGitGadget
2025-03-16  6:42   ` [PATCH v2 1/3] git-compat-util: introduce BUG_IF_NOT() macro Elijah Newren via GitGitGadget
2025-03-17 22:33     ` Junio C Hamano
2025-03-17 22:36       ` Taylor Blau
2025-03-16  6:42   ` [PATCH v2 2/3] ci: add build checking for side-effects in assert() calls Elijah Newren via GitGitGadget
2025-03-17 22:30     ` Taylor Blau [this message]
2025-03-19 16:21       ` Elijah Newren
2025-03-19 22:26         ` Taylor Blau
2025-03-17 22:37     ` Junio C Hamano
2025-03-16  6:42   ` [PATCH v2 3/3] treewide: replace assert() with BUG_IF_NOT() in special cases Elijah Newren via GitGitGadget
2025-03-17 22:33     ` Taylor Blau
2025-03-17 22:34   ` [PATCH v2 0/3] Add a static analysis job to prevent assertions with side effects Taylor Blau
2025-03-19 16:22   ` [PATCH v3 " Elijah Newren via GitGitGadget
2025-03-19 16:22     ` [PATCH v3 1/3] git-compat-util: introduce ASSERT() macro Elijah Newren via GitGitGadget
2025-03-19 16:22     ` [PATCH v3 2/3] ci: add build checking for side-effects in assert() calls Elijah Newren via GitGitGadget
2025-03-19 16:22     ` [PATCH v3 3/3] treewide: replace assert() with ASSERT() in special cases Elijah Newren via GitGitGadget
2025-03-19 22:27       ` Taylor Blau
2025-03-19 22:27     ` [PATCH v3 0/3] Add a static analysis job to prevent assertions with side effects Taylor Blau

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=Z9iinbyrn4PeFmCl@nand.local \
    --to=me@ttaylorr.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=newren@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    /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;
as well as URLs for NNTP newsgroup(s).