]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'en/assert-wo-side-effects'
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2025 18:43:12 +0000 (11:43 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2025 18:43:12 +0000 (11:43 -0700)
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

1  2 
Makefile
diffcore-rename.c
git-compat-util.h
merge-ort.c

diff --cc Makefile
Simple merge
Simple merge
index cf733b38acdea071644c0f9181cd69e7416bf89d,5891efaeb1889087b6b1cf8be56a9c1886506f83..f8562996edeefcb40fb11bcf6595c5671f221295
@@@ -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
diff --cc merge-ort.c
Simple merge