]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix ICE on empty constexpr loops
authorTom Schollenberger <tss2344@g.rit.edu>
Thu, 8 May 2025 11:26:07 +0000 (07:26 -0400)
committerPhilip Herron <philip.herron@embecosm.com>
Thu, 8 May 2025 15:37:43 +0000 (15:37 +0000)
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 <tss2344@g.rit.edu>
gcc/rust/backend/rust-constexpr.cc
gcc/testsuite/rust/compile/issue-3618.rs [new file with mode: 0644]

index dc2d6b1066becb6a62b55466e6878b52769c0673..0ed56c71ad305d7e6c39df911484826de0dc2367 100644 (file)
@@ -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 (file)
index 0000000..9728613
--- /dev/null
@@ -0,0 +1 @@
+static _X: () = loop {}; // { dg-error "loop iteration count exceeds limit" }