aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-constexpr.cc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2024-12-02 13:54:29 +0000
committerPhilip Herron <philip.herron@embecosm.com>2024-12-02 17:31:30 +0000
commit0d00f79134c9210e4a0df21a1fc18e52f48bff0d (patch)
treeeb30e08cd472aeb1a83bfd4f3fe8daa1f2cef03b /gcc/rust/backend/rust-constexpr.cc
parentdb3d8fb22c8d10a3687742a85de85242a96ac1ba (diff)
downloadgcc-0d00f79134c9210e4a0df21a1fc18e52f48bff0d.zip
gcc-0d00f79134c9210e4a0df21a1fc18e52f48bff0d.tar.gz
gcc-0d00f79134c9210e4a0df21a1fc18e52f48bff0d.tar.bz2
gccrs: add checks for division by zero and left shift overflow
These are ported from the c-family code c-warn.cc and c/c-typchk.cc Fixes Rust-GCC#2394 gcc/rust/ChangeLog: * backend/rust-constexpr.cc (eval_store_expression): check for null (eval_call_expression): remove bad warning * rust-gcc.cc (arithmetic_or_logical_expression): add warnings gcc/testsuite/ChangeLog: * rust/compile/issue-2394.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend/rust-constexpr.cc')
-rw-r--r--gcc/rust/backend/rust-constexpr.cc8
1 files changed, 5 insertions, 3 deletions
diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc
index bfd7d95..2f2bbbd 100644
--- a/gcc/rust/backend/rust-constexpr.cc
+++ b/gcc/rust/backend/rust-constexpr.cc
@@ -2929,8 +2929,13 @@ eval_store_expression (const constexpr_ctx *ctx, tree t, bool lval,
}
}
+ if (*non_constant_p)
+ return t;
+
/* Don't share a CONSTRUCTOR that might be changed later. */
init = unshare_constructor (init);
+ if (init == NULL_TREE)
+ return t;
if (*valp && TREE_CODE (*valp) == CONSTRUCTOR
&& TREE_CODE (init) == CONSTRUCTOR)
@@ -3585,9 +3590,6 @@ eval_call_expression (const constexpr_ctx *ctx, tree t, bool lval,
result = *ctx->global->values.get (res);
if (result == NULL_TREE && !*non_constant_p)
{
- if (!ctx->quiet)
- error ("%<constexpr%> call flows off the end "
- "of the function");
*non_constant_p = true;
}
}