diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-10-30 12:30:50 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-30 12:30:50 +0000 |
commit | ca0b06f86fd44bd6067563dcbf4a2c021f2a79a5 (patch) | |
tree | a79768a42ca7543bd5e078243ebf4e3a23b14e0e /gcc/rust/parse/rust-parse-impl.h | |
parent | a9daecd2a35f7caebb02feb4dbb2dc89f3165cdb (diff) | |
parent | f569984bb80c7b7b15baccdc596c71938f49315a (diff) | |
download | gcc-ca0b06f86fd44bd6067563dcbf4a2c021f2a79a5.zip gcc-ca0b06f86fd44bd6067563dcbf4a2c021f2a79a5.tar.gz gcc-ca0b06f86fd44bd6067563dcbf4a2c021f2a79a5.tar.bz2 |
Merge #780
780: No side effects in 'assert' expressions r=philberty a=tschwinge
Usually, if 'assert'ions are disabled, 'assert' expressions are not evaluated,
so in that case won't effect any side effects.
Via spurious ICEs/test suite FAILs, this may be observed in GCC/Rust, for
example, if configuring with '--enable-checking=no' and disabling a "more
forgiving" 'gcc/system.h:gcc_assert' definition, so that '0 && (EXPR)' gets
used:
/* Use gcc_assert(EXPR) to test invariants. */
#if ENABLE_ASSERT_CHECKING
#define gcc_assert(EXPR) \
((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0 : 0))
-#elif (GCC_VERSION >= 4005)
+#elif (0) //GCC_VERSION >= 4005)
#define gcc_assert(EXPR) \
((void)(__builtin_expect (!(EXPR), 0) ? __builtin_unreachable (), 0 : 0))
#else
/* Include EXPR, so that unused variable warnings do not occur. */
#define gcc_assert(EXPR) ((void)(0 && (EXPR)))
#endif
As that one does cause some issues in GCC proper (that I shall fix separately),
may use this change to 'gcc/rust/rust-system.h:rust_assert' instead:
+#if 0
#define rust_assert(EXPR) gcc_assert (EXPR)
+#else
+#define rust_assert(EXPR) ((void) (0 && (EXPR)))
+#endif
To fix these, use the same pattern as is already used in a lot of existing
GCC/Rust code:
bool ok = [expression with side effects];
rust_assert (ok);
I've only done a quick manual review; maybe there is a tool for doing this?
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
0 files changed, 0 insertions, 0 deletions