From patchwork Sun Mar 16 06:42:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 14018364 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 2092D1514E4 for ; Sun, 16 Mar 2025 06:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742107328; cv=none; b=gpSfICe7dmeWA7r1GrUc3YyfKs2djOQj/xmTMg57qRW9FbwHgzxSSJ5fmfvi0CHh5ntACjeLKNiDuYwgCzwI5lz9h4I8VS40t1Sy90G17kLv9JdJB+dVbCPA+aCBh1lZisK4rno0x2p+e57jHQy+AKKF5omS6nZQXVesBBjUTpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742107328; c=relaxed/simple; bh=9jjz5F1a8/dNZiM277C1aeXpMRBIIEehRF47/i0JKOs=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=GVUrVTuaKmq4o+fIvq48VJBiPRF/XqODHOKwyvsYr7L6H1HrrtzwPC1mfVZJuczico+TrP7o081IL0w12D27Cpj0HRM1RZNZvt8K7Wo3RHeeyTbLWidXtzVSnNxNOkx9GxVhLiIIUEhj8it/aM3k//3ltdnJwXZDGZR+r3MA7kw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Kyw3QqZh; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Kyw3QqZh" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-43d0359b1fcso6210575e9.0 for ; Sat, 15 Mar 2025 23:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742107325; x=1742712125; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=3ZpoFSg52lF4whc6ZSEX42NfZUMdvuxvhsh6l6nJHN0=; b=Kyw3QqZhp6mySnmzpAqQLe6WewIgCBw0cvyXqFRAXTEE037rz8jpxd4RbCVRRDxSiJ eMUKtmHhZEO+47H6Tgym2+7B62jWLbgfwtwsHNLL3beol9WGlYme3R/to/2stWJeWXUV /XH4bvThArwA0W+O8NiM5G7LWY09pjBZdTUaU5ikbU1VfA/+5OksVewqT40I17UysVw2 vwD5PG6aZZIIS8NG8G25JVonDx1M3oV27OetBMfQhjOQC4ysh2N49FiG43z/zH2zcSjZ eUtkYZUq7uN9IxIrgZQ20a353YvmD0szpopCRWE00783a1SkH5Ie787YlfL3WBTnoNpL yDYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742107325; x=1742712125; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3ZpoFSg52lF4whc6ZSEX42NfZUMdvuxvhsh6l6nJHN0=; b=rrS4Gm2c0kF3jWLbD1mW3xjbaU7s78dKlbgNEOzDiNYJ6R/Nz4gb9583jTJ3x5J9Wa fKK/Kvbjommvi4fOi+fueSedEmtesOrP4ipHG3A1XJWo/ymou4I4xSU8B5UMjFcXRbcP KHsFrlP4Ayru1Xh9jZqfRpvsqL2HtN25/w3xtTjT+SKzbI2Dh0wZj4KksGsjvr8KTPaA aUbwYAxnbGaIVWLA7kKj2gDi9zQqk2Te1HrtQYwxM6BSZOq9TLtWmVIFitHrtNImIRZX Veq9iTvGyuAggjLWJs/pSyiQ9nfTosgPC5Of02RA+Cr4fSGXXorInsUrLDcefnsLjoch FCkQ== X-Gm-Message-State: AOJu0YyBdOe9lVv5l/1LXivtRgfFcVvc+WByqXt/kMgiYIGHsJTnx2dr BR2fVu+0CDdf+i9ZVYVWSn40OyIScIe/Imf7esPWLmSZ3D1IT0GPEi3QSQ== X-Gm-Gg: ASbGncs5EFLKqypDAX0x19RSRJXOMfV6hnno2EPB49ogWV3gKSaZIHGUFPuQPiH9OXO Er0KA0KelP6fzHf51VQAghCoc8kOg2cMhj5yup61/Dv81ABvaUNvfpqfE5mOI2VxQ+Y4C67Fodu GRYgF7Jxslc68k5aGFMLpkh0PKsrfPL5u2XtRCtjS8uByUUCTRwiBHUg4t9iG/O2jjM3pzpd3Mx EWPtjhICFHn2r6lbxfjGiBWZ/IFwRMAHyfWZ1GznqeV+KcZBN3vuLSAbSAkoPm+0MXGNPQwSuRP KaWnRPZ1ETwJZMUrVt6G0Q482F44lK/O/Haib/3/fyC3TA== X-Google-Smtp-Source: AGHT+IFOZYpMUIQMlCghi6MXURMtKqUYmiY0YtnnfwtWa5WHLczw+EEOLk9ndNcZyNZU2JnPN7wV1g== X-Received: by 2002:a05:600c:1550:b0:43d:1bf6:15e1 with SMTP id 5b1f17b1804b1-43d1f1d2bc1mr92684015e9.1.1742107324654; Sat, 15 Mar 2025 23:42:04 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d2010e2d6sm69236775e9.38.2025.03.15.23.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Mar 2025 23:42:04 -0700 (PDT) Message-Id: <109060ccb8665c73aa0c4f73e3cbbddcd135bde4.1742107322.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 16 Mar 2025 06:42:00 +0000 Subject: [PATCH v2 1/3] git-compat-util: introduce BUG_IF_NOT() macro Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Elijah Newren , Elijah Newren , Elijah Newren From: Elijah Newren From: Elijah Newren Create a BUG_IF_NOT() macro which is similar to assert(), but will not be compiled out when NDEBUG is defined, and is thus safe to use even if its argument has side-effects. We will use this new macro in a subsequent commit to convert a few existing assert() invocations to BUG_IF_NOT(). In particular, we'll convert the handful of invocations which cannot be proven to be free of side effects with a simple compiler/linker hack. Signed-off-by: Elijah Newren --- git-compat-util.h | 1 + 1 file changed, 1 insertion(+) diff --git a/git-compat-util.h b/git-compat-util.h index e123288e8f1..c3415ad7e0a 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -1460,6 +1460,7 @@ extern int bug_called_must_BUG; __attribute__((format (printf, 3, 4))) NORETURN void BUG_fl(const char *file, int line, const char *fmt, ...); #define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__) +#define BUG_IF_NOT(a) if (!(a)) BUG("Assertion `" #a "' failed.") __attribute__((format (printf, 3, 4))) void bug_fl(const char *file, int line, const char *fmt, ...); #define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__) From patchwork Sun Mar 16 06:42:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 14018365 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 1B70F16F282 for ; Sun, 16 Mar 2025 06:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742107329; cv=none; b=Jfg3DAvfHDtPmhpJrbjBt1mbnliGqCrA8D1y6npToV1PV4IB6pzyao8sELRbpLIaJJ48iUX4yQsj+d8irJqRwhd7Ros9ZKQL7yS+PwjHZQZVDEEBveOqwvWI6ThpJncq6ySvicxqt0OfHmNQKGBMyS1lJHbANLfuawZGngoNZOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742107329; c=relaxed/simple; bh=ZGogjwM/0atSSLaghuPJkK5zqZ1S/YH6MludFo/IKXU=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ILt5zPcbTgA2GIluBm49taX1aiV44wMqXPNssnnTXSoi0594oPHA+b1txfeC1bZBZ2VHHs8VXOqXc78ZgqbXw/9NO0LNmXaT0QC70oVWhEx+I9kqmHAW0houyXWbZSNE84gLK+D+z1KvaPZZmhvjMWehVN3TXrSRn5qctSpXaKk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KhGjoBWT; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KhGjoBWT" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-43cebe06e9eso7363035e9.3 for ; Sat, 15 Mar 2025 23:42:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742107325; x=1742712125; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=pcvlNJLPB1uWY32mUCNxzjxUYDnX2VNOB3ObzhubuxQ=; b=KhGjoBWTlHWjMk68U+7s414dIId+zvxa7cKRFGNnPfzz8qrT5NpQ+MGv0mAKhRisKW 7ZfF+H7BmybvZ6TDF4NF7b/bLtEcNB42poFGi+uDll3U6UDXNUO2IP6rXC5cGwnfaMln KRHqduWHXSmFuTbBXdrasxyqNWC+VuNHJ7D1Nb+PUR0DQ8rvJ/uqiGpPF1FRvoi0hCuC FLOJKqaQZ3RLk3xf3LbZCAXaN/XzRNijo1Y/9BMQhR3be/pvSIBcoIE5fXz2nJ0w7NLE XeN0BApuGvJSA0LIrceCbOJTbr2DT4JBoptPhibkfI4WclouFJSpfyZhtPazUzUMUmsN Yy+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742107325; x=1742712125; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pcvlNJLPB1uWY32mUCNxzjxUYDnX2VNOB3ObzhubuxQ=; b=GdNl+pagl2R9BYgUGnVuPQXnrDaYQPRlrRU6cSPRHhrVGbcywkPGwpWsbylycotJmt xgzZP4ecH032lCY4QMgTTuIbAND+PLi+hJuWOpqQ4K9FBvIa/WcnH6YydOyIoSFwaRLd weDdSddZPHAslFOHUelSVnLL0OSlCa+MWNWHV0UtoupdGCU+fHO4H+7zIyOf1f5NOw/h pVbSjisSSvaiBPTw5eL8BTeg59ZsVB59GElD9W6a1ebT3Rp2361fZ8yBJwTue7Bat1D0 jAdwZLyYdehhroGNQjUOySNDc7wfLt3sk8SZ0b4toqKdeRfoHiUqhjpWqAx/CNDNaAIC l8PA== X-Gm-Message-State: AOJu0YykxEslo16KX2jAl4yicfEy8qode1tNLLN3P0O3qzP2iyptmzAl wn/HMBYzOKjO+1ewLZCeXvRlNKWpbk1JGehcgAQHl7Mvvvd9Ik89BjRbIA== X-Gm-Gg: ASbGnctzinDqpUJHt6wx4c5Bc/dJIGqAxb6JZdjrA7qvgDvVM6Gro8mm+S92dg+BL/x R7xNYEV1fByPIiTkE9iwIv+bOe5DOZFcqw4GCQ+5xgjlNulIKSgZUpjKSEsPmcqG/Jk13/FJB85 Wj8t8npJRXeVCWk9MYqbWpEKK2SNZhNwOQJsRxgbe1guYQQSyzvYKn8bP27a1XVP1+gV4/XSBIF BMZ7Vn4B+vvtqZ7BRwHoo7gbkSVXU7Mv5dXqsQQBS95R3ciYLK2S2DHBbcfuQwDvtjbId5r2ygD N3iXKwdi3eEuY+sqa+W9jdkJpJKyna53EkXQ/XiyGcr94w== X-Google-Smtp-Source: AGHT+IFOAZ7uJMS84Xrw1kaVE+dBRhFQSdAiRCThx9pizUem/q++mMIsRdnZvVA+JRUvMyrtJ9t3oA== X-Received: by 2002:a05:6000:1fa5:b0:390:f55b:ba94 with SMTP id ffacd0b85a97d-3971d3336e4mr10862251f8f.13.1742107325530; Sat, 15 Mar 2025 23:42:05 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-395cb318a96sm11348945f8f.69.2025.03.15.23.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Mar 2025 23:42:05 -0700 (PDT) Message-Id: <58cb8f6a1609b10d761e86bdad541d1c018cb582.1742107322.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 16 Mar 2025 06:42:01 +0000 Subject: [PATCH v2 2/3] ci: add build checking for side-effects in assert() calls Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Elijah Newren , Elijah Newren , Elijah Newren From: Elijah Newren From: Elijah Newren It is a big no-no to have side-effects in an assertion, because if the assert() is compiled out, you don't get that side-effect, leading to the code behaving differently. That can be a large headache to debug. 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. Example output from running: ``` ERROR: The compiler could not verify the following assert() calls are free of side-effects. Please replace with BUG_IF_NOT() calls. /home/newren/floss/git/diffcore-rename.c:1409 assert(!dir_rename_count || strmap_empty(dir_rename_count)); /home/newren/floss/git/merge-ort.c:1645 assert(renames->deferred[side].trivial_merges_okay && !strset_contains(&renames->deferred[side].target_dirs, path)); /home/newren/floss/git/merge-ort.c:794 assert(omittable_hint == (!starts_with(type_short_descriptions[type], "CONFLICT") && !starts_with(type_short_descriptions[type], "ERROR")) || type == CONFLICT_DIR_RENAME_SUGGESTED); /home/newren/floss/git/merge-recursive.c:1200 assert(!merge_remote_util(commit)); /home/newren/floss/git/object-file.c:2709 assert(would_convert_to_git_filter_fd(istate, path)); /home/newren/floss/git/parallel-checkout.c:280 assert(is_eligible_for_parallel_checkout(pc_item->ce, &pc_item->ca)); /home/newren/floss/git/scalar.c:244 assert(have_fsmonitor_support()); /home/newren/floss/git/scalar.c:254 assert(have_fsmonitor_support()); /home/newren/floss/git/sequencer.c:4968 assert(!(opts->signoff || opts->no_commit || opts->record_origin || should_edit(opts) || opts->committer_date_is_author_date || opts->ignore_date)); ``` Note that if there are possibly problematic assertions, not necessarily all of them will be shown in a single run, because the compiler errors may include something like "ld: ... more undefined references to `not_supposed_to_survive' follow" instead of listing each individually. But in such cases, once you clean up a few that are shown in your first run, subsequent runs will show (some of) the ones that remain, allowing you to iteratively remove them all. Helped-by: Bruno De Fraine Signed-off-by: Elijah Newren --- Makefile | 4 ++++ ci/check-unsafe-assertions.sh | 18 ++++++++++++++++++ ci/run-static-analysis.sh | 2 ++ git-compat-util.h | 6 ++++++ 4 files changed, 30 insertions(+) create mode 100755 ci/check-unsafe-assertions.sh diff --git a/Makefile b/Makefile index 7315507381e..57774912f18 100644 --- a/Makefile +++ b/Makefile @@ -2261,6 +2261,10 @@ ifdef WITH_BREAKING_CHANGES BASIC_CFLAGS += -DWITH_BREAKING_CHANGES endif +ifdef CHECK_ASSERTION_SIDE_EFFECTS + BASIC_CFLAGS += -DCHECK_ASSERTION_SIDE_EFFECTS +endif + ifdef INCLUDE_LIBGIT_RS # Enable symbol hiding in contrib/libgit-sys/libgitpub.a without making # us rebuild the whole tree every time we run a Rust build. diff --git a/ci/check-unsafe-assertions.sh b/ci/check-unsafe-assertions.sh new file mode 100755 index 00000000000..d66091efd22 --- /dev/null +++ b/ci/check-unsafe-assertions.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +make CHECK_ASSERTION_SIDE_EFFECTS=1 >compiler_output 2>compiler_error +if test $? != 0 +then + echo "ERROR: The compiler could not verify the following assert()" >&2 + echo " calls are free of side-effects. Please replace with" >&2 + echo " BUG_IF_NOT() calls." >&2 + grep undefined.reference.to..not_supposed_to_survive compiler_error \ + | sed -e s/:[^:]*$// | sort | uniq | tr ':' ' ' \ + | while read f l + do + printf "${f}:${l}\n " + awk -v start="$l" 'NR >= start { print; if (/\);/) exit }' $f + done + exit 1 +fi +rm compiler_output compiler_error diff --git a/ci/run-static-analysis.sh b/ci/run-static-analysis.sh index 0d51e5ce0e7..ae714e020ae 100755 --- a/ci/run-static-analysis.sh +++ b/ci/run-static-analysis.sh @@ -31,4 +31,6 @@ exit 1 make check-pot +${0%/*}/check-unsafe-assertions.sh + save_good_tree diff --git a/git-compat-util.h b/git-compat-util.h index c3415ad7e0a..0aefd763751 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -1584,4 +1584,10 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset) ((uintptr_t)&(ptr)->member - (uintptr_t)(ptr)) #endif /* !__GNUC__ */ +#ifdef CHECK_ASSERTION_SIDE_EFFECTS +#undef assert +extern int not_supposed_to_survive; +#define assert(expr) ((void)(not_supposed_to_survive || (expr))) +#endif /* CHECK_ASSERTION_SIDE_EFFECTS */ + #endif From patchwork Sun Mar 16 06:42:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 14018366 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 07F73187FFA for ; Sun, 16 Mar 2025 06:42:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742107330; cv=none; b=LPu/C/ho6t2Ki2MxCc5GaZxAt+k3uY+2KudYkxBf2NYSRt4rpwOLBVI3pecqFZkS6qlLZHKEYXbNWmybxNy+IlZagRfrVZ1XM655l+tono5ZDel+VcCdQh8ZjX3Z/hMsX+dHTLcPI+pIhMxLrbrEZ/M+5SkojIMMmQTotZoMlhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742107330; c=relaxed/simple; bh=wRQMfDQaX62xU9Sa5VNd1pS6SPdoVx6yFQicuRK5kr8=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ESbdNLPIjwNJqr/JeAad/65UtI/S249aHirS4U2ltR7g6irQA76/6MlFjG0JcBs/UyQ2dbGp4yTInoopTGaZk9ca5GLSHB616aX61O4RoJ+EV+vaq7UXJlX8rRzEavr3Sf2o63/tQIifWapoOLzbGc+8jqgZr6AW9C100y5TS5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l/dactuT; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l/dactuT" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4394345e4d5so7168815e9.0 for ; Sat, 15 Mar 2025 23:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742107327; x=1742712127; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=WXA3TRQ/r5/vvweHdjLi9mt0grtT7hlGaEAEogCoozw=; b=l/dactuTxaenl9RhIQz28+rmiuVgpp2YUI+adaQyFU+SDEQZ9j5SzTNCFNKxkh+3wD WGLtpKdOhf0q3a4DGvaBhiZn7xDLEA3CjjVvrlRItZmpNIASRyejft6PRpG5827TgbDP ZpN4vYk3VIBT6Lk9X5KWzk93+C0ZYh/UlO7YAApfLAc9yR1j2Z9w6ZNW5NWtLSGNSfH7 AnyYt9kXIY6UrJ6tSbcydU3oNa4aI49MrpPu284JFv6Wg9dt622tlyVfQBkO5+RauSPt OAzvni+1TyKVr9Xw6k62Lw1+jUwSES7MelUNhV7i40M4cSpH6z36gBVzJNQm+CyUg1xt FQyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742107327; x=1742712127; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WXA3TRQ/r5/vvweHdjLi9mt0grtT7hlGaEAEogCoozw=; b=LzB9gU9oFdhwl/XoBLbQ0FtgIkY+yS8F268Pey4k0YdWoSfV2kgfDkiGrKfIojXfQ8 hAFFnhCwTMjYsTZ7/wjB2BvF4g7kSpY66TAVk7rm+XQEBKbMIeaE2I2VfAPBV3LaXvn3 U25PJNY7ILDcGwzCjbReeKcaq9NpKvvQVN8pUVueKK4YeWVGiJMM2uRXpzJ9qz0Iw+tk XMEwLKa5XXVbEvqRF72l5siX9na1tbYcIC8nVrJGZt3EGNmbfQHBqmhdXnek42yiz6uf mij2crQvyL6goY5cq8m9dBQTf5NgFjkWUYy2Rj5SL/07E56bo0Lr+ZR8PpVfpvWg+OXi Zcdg== X-Gm-Message-State: AOJu0YwXCjbzUrAObSYjHMDt9nEj4rpcrNFyXbqztyxi3eKCTzJKAJPf IflkYenDvBV0sB2JCAgQkrfdI1sGkIniUB8iBExZMeako2WYhJLJpbnb9A== X-Gm-Gg: ASbGncu+8nPwIe8t3Et7zbS5XwDFFjurKHTV24n+Vr628+JXjK8W5Ako0VLbYpO+FrN rvMYystDJCrx+nXOdg5NVZuz1I4khZqifUHzCFuLCswVAlhvVZTMYS0agjmz9w93JA/EN2wKR8S rLl+sAVQb6OY4iw/MBriy5xswtCw+qmcJ/PnHtL9qw5HYTKe4DkkNeLvVQ7h7SZaZtruISiJVkf 9Fi10vo4UnDpIYaFOKGjHumnlwLdJgVlYjUJdfaLOE5oWFmyGH4dPa9T3KcDUHH9gv7bxWgCjGr yPdaOhYJE3/YSd6e/uVIfwEKXnYshh7UuFH1UYMJpMP1SsHFp292DcDD X-Google-Smtp-Source: AGHT+IGIe4AfQA/zzZeAVJ7FHPmVcLrGjlfLJuuBIW+6oeAsmdbSVfB9CI//hYK/kTNK7bmYWNiT0A== X-Received: by 2002:a05:600c:548e:b0:43d:683:8ca3 with SMTP id 5b1f17b1804b1-43d1ec62c5fmr102497635e9.5.1742107326857; Sat, 15 Mar 2025 23:42:06 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1ffc49adsm69623995e9.24.2025.03.15.23.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Mar 2025 23:42:05 -0700 (PDT) Message-Id: <20c763f295105bda9a701b9bf5b9aa47af5bf1e1.1742107322.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 16 Mar 2025 06:42:02 +0000 Subject: [PATCH v2 3/3] treewide: replace assert() with BUG_IF_NOT() in special cases Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Elijah Newren , Elijah Newren , Elijah Newren From: Elijah Newren From: Elijah Newren When the compiler/linker cannot verify that an assert() invocation is free of side effects for us (e.g. because the assertion includes some kind of function call), replace the use of assert() with BUG_IF_NOT(). Signed-off-by: Elijah Newren --- diffcore-rename.c | 2 +- merge-ort.c | 4 ++-- merge-recursive.c | 2 +- object-file.c | 2 +- parallel-checkout.c | 2 +- scalar.c | 4 ++-- sequencer.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/diffcore-rename.c b/diffcore-rename.c index 91b77993c78..1a945945fab 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -1406,7 +1406,7 @@ void diffcore_rename_extended(struct diff_options *options, trace2_region_enter("diff", "setup", options->repo); info.setup = 0; - assert(!dir_rename_count || strmap_empty(dir_rename_count)); + BUG_IF_NOT(!dir_rename_count || strmap_empty(dir_rename_count)); want_copies = (detect_rename == DIFF_DETECT_COPY); if (dirs_removed && (break_idx || want_copies)) BUG("dirs_removed incompatible with break/copy detection"); diff --git a/merge-ort.c b/merge-ort.c index 46e78c3ffa6..3db7a911f81 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -791,7 +791,7 @@ static void path_msg(struct merge_options *opt, struct strbuf tmp = STRBUF_INIT; /* Sanity checks */ - assert(omittable_hint == + BUG_IF_NOT(omittable_hint == (!starts_with(type_short_descriptions[type], "CONFLICT") && !starts_with(type_short_descriptions[type], "ERROR")) || type == CONFLICT_DIR_RENAME_SUGGESTED); @@ -1642,7 +1642,7 @@ static int handle_deferred_entries(struct merge_options *opt, ci = strmap_get(&opt->priv->paths, path); VERIFY_CI(ci); - assert(renames->deferred[side].trivial_merges_okay && + BUG_IF_NOT(renames->deferred[side].trivial_merges_okay && !strset_contains(&renames->deferred[side].target_dirs, path)); resolve_trivial_directory_merge(ci, side); diff --git a/merge-recursive.c b/merge-recursive.c index 884ccf99a58..ab888689ae4 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1197,7 +1197,7 @@ static void print_commit(struct repository *repo, struct commit *commit) struct pretty_print_context ctx = {0}; ctx.date_mode.type = DATE_NORMAL; /* FIXME: Merge this with output_commit_title() */ - assert(!merge_remote_util(commit)); + BUG_IF_NOT(!merge_remote_util(commit)); repo_format_commit_message(repo, commit, " %h: %m %s", &sb, &ctx); fprintf(stderr, "%s\n", sb.buf); strbuf_release(&sb); diff --git a/object-file.c b/object-file.c index 726e41a0475..8ef4813eb63 100644 --- a/object-file.c +++ b/object-file.c @@ -2706,7 +2706,7 @@ static int index_stream_convert_blob(struct index_state *istate, struct strbuf sbuf = STRBUF_INIT; assert(path); - assert(would_convert_to_git_filter_fd(istate, path)); + BUG_IF_NOT(would_convert_to_git_filter_fd(istate, path)); convert_to_git_filter_fd(istate, path, fd, &sbuf, get_conv_flags(flags)); diff --git a/parallel-checkout.c b/parallel-checkout.c index 7cc6b305281..4d2fa6d7374 100644 --- a/parallel-checkout.c +++ b/parallel-checkout.c @@ -277,7 +277,7 @@ static int write_pc_item_to_fd(struct parallel_checkout_item *pc_item, int fd, ssize_t wrote; /* Sanity check */ - assert(is_eligible_for_parallel_checkout(pc_item->ce, &pc_item->ca)); + BUG_IF_NOT(is_eligible_for_parallel_checkout(pc_item->ce, &pc_item->ca)); filter = get_stream_filter_ca(&pc_item->ca, &pc_item->ce->oid); if (filter) { diff --git a/scalar.c b/scalar.c index da42b4be0cc..173286110ea 100644 --- a/scalar.c +++ b/scalar.c @@ -241,7 +241,7 @@ static int add_or_remove_enlistment(int add) static int start_fsmonitor_daemon(void) { - assert(have_fsmonitor_support()); + BUG_IF_NOT(have_fsmonitor_support()); if (fsmonitor_ipc__get_state() != IPC_STATE__LISTENING) return run_git("fsmonitor--daemon", "start", NULL); @@ -251,7 +251,7 @@ static int start_fsmonitor_daemon(void) static int stop_fsmonitor_daemon(void) { - assert(have_fsmonitor_support()); + BUG_IF_NOT(have_fsmonitor_support()); if (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING) return run_git("fsmonitor--daemon", "stop", NULL); diff --git a/sequencer.c b/sequencer.c index ad0ab75c8d4..98a7657b398 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4965,7 +4965,7 @@ static int pick_commits(struct repository *r, ctx->reflog_message = sequencer_reflog_action(opts); if (opts->allow_ff) - assert(!(opts->signoff || opts->no_commit || + BUG_IF_NOT(!(opts->signoff || opts->no_commit || opts->record_origin || should_edit(opts) || opts->committer_date_is_author_date || opts->ignore_date));