aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-item.h
diff options
context:
space:
mode:
authorThomas Schwinge <thomas@codesourcery.com>2021-10-28 21:36:34 +0200
committerThomas Schwinge <thomas@codesourcery.com>2021-10-30 00:11:25 +0200
commitf569984bb80c7b7b15baccdc596c71938f49315a (patch)
tree323a35da20d509a7a76fda78d2dc8f979a4c6e0b /gcc/rust/backend/rust-compile-item.h
parentcba61d8dcbe1ac0fb23a96b2974541b201292465 (diff)
downloadgcc-f569984bb80c7b7b15baccdc596c71938f49315a.zip
gcc-f569984bb80c7b7b15baccdc596c71938f49315a.tar.gz
gcc-f569984bb80c7b7b15baccdc596c71938f49315a.tar.bz2
No side effects in 'assert' expressions
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?
Diffstat (limited to 'gcc/rust/backend/rust-compile-item.h')
-rw-r--r--gcc/rust/backend/rust-compile-item.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index d79ab55..b64f6f0 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -68,9 +68,10 @@ public:
Bexpression *value = CompileExpr::Compile (var.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
- rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ ok = ctx->get_mappings ()->lookup_canonical_path (
var.get_mappings ().get_crate_num (), var.get_mappings ().get_nodeid (),
- &canonical_path));
+ &canonical_path);
+ rust_assert (ok);
std::string name = canonical_path->get ();
std::string asm_name = ctx->mangle_item (resolved_type, *canonical_path);
@@ -103,9 +104,10 @@ public:
Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
- rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ ok = ctx->get_mappings ()->lookup_canonical_path (
constant.get_mappings ().get_crate_num (),
- constant.get_mappings ().get_nodeid (), &canonical_path));
+ constant.get_mappings ().get_nodeid (), &canonical_path);
+ rust_assert (ok);
std::string ident = canonical_path->get ();
Bexpression *const_expr
@@ -186,9 +188,10 @@ public:
flags |= Backend::function_is_visible;
const Resolver::CanonicalPath *canonical_path = nullptr;
- rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ bool ok = ctx->get_mappings ()->lookup_canonical_path (
function.get_mappings ().get_crate_num (),
- function.get_mappings ().get_nodeid (), &canonical_path));
+ function.get_mappings ().get_nodeid (), &canonical_path);
+ rust_assert (ok);
std::string ir_symbol_name
= canonical_path->get () + fntype->subst_as_string ();
@@ -259,7 +262,7 @@ public:
}
std::vector<Bvariable *> locals;
- bool ok = compile_locals_for_block (*rib, fndecl, locals);
+ ok = compile_locals_for_block (*rib, fndecl, locals);
rust_assert (ok);
Bblock *enclosing_scope = NULL;