From: Tom Schollenberger <tss2...@g.rit.edu>

Empty loops have no body which means this is a NULL_TREE during const
evaluation which needs a check. Fixes Rust-GCC #3618.

gcc/rust/ChangeLog:

        * backend/rust-constexpr.cc (eval_constant_expression):  Check if t is 
a NULL_TREE

gcc/testsuite/ChangeLog:

        * rust/compile/issue-3618.rs: Test empty loops error properly.

Signed-off-by: Tom Schollenberger <tss2...@g.rit.edu>
---
 gcc/rust/backend/rust-constexpr.cc       | 3 +++
 gcc/testsuite/rust/compile/issue-3618.rs | 1 +
 2 files changed, 4 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issue-3618.rs

diff --git a/gcc/rust/backend/rust-constexpr.cc 
b/gcc/rust/backend/rust-constexpr.cc
index dc2d6b1066b..0ed56c71ad3 100644
--- a/gcc/rust/backend/rust-constexpr.cc
+++ b/gcc/rust/backend/rust-constexpr.cc
@@ -1901,6 +1901,9 @@ eval_constant_expression (const constexpr_ctx *ctx, tree 
t, bool lval,
 
   location_t loc = EXPR_LOCATION (t);
 
+  if (t == NULL_TREE)
+    return NULL_TREE;
+
   if (CONSTANT_CLASS_P (t))
     {
       if (TREE_OVERFLOW (t))
diff --git a/gcc/testsuite/rust/compile/issue-3618.rs 
b/gcc/testsuite/rust/compile/issue-3618.rs
new file mode 100644
index 00000000000..97286135e3a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3618.rs
@@ -0,0 +1 @@
+static _X: () = loop {}; // { dg-error "loop iteration count exceeds limit" }
-- 
2.49.0

Reply via email to