From: Junio C Hamano Date: Tue, 8 Apr 2025 18:43:12 +0000 (-0700) Subject: Merge branch 'en/assert-wo-side-effects' X-Git-Tag: v2.50.0-rc0~141 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b97b360c514acd0f5a148524a85bcdb583dbe914;p=thirdparty%2Fgit.git Merge branch 'en/assert-wo-side-effects' Ensure what we write in assert() does not have side effects, and introduce ASSERT() macro to mark those that cannot be mechanically checked for lack of side effects. * en/assert-wo-side-effects: treewide: replace assert() with ASSERT() in special cases ci: add build checking for side-effects in assert() calls git-compat-util: introduce ASSERT() macro --- b97b360c514acd0f5a148524a85bcdb583dbe914 diff --cc git-compat-util.h index cf733b38ac,5891efaeb1..f8562996ed --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -1583,13 -1585,10 +1585,20 @@@ static inline void *container_of_or_nul ((uintptr_t)&(ptr)->member - (uintptr_t)(ptr)) #endif /* !__GNUC__ */ +/* + * Prevent an overly clever compiler from optimizing an expression + * out, triggering a false positive when building with the + * -Wunreachable-code option. false_but_the_compiler_does_not_know_it_ + * is defined in a compilation unit separate from where the macro is + * used, initialized to 0, and never modified. + */ +#define NOT_CONSTANT(expr) ((expr) || false_but_the_compiler_does_not_know_it_) +extern int false_but_the_compiler_does_not_know_it_; ++ + #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