diff --git a/src/docode.c b/src/docode.c
index 2bea1888a4ff44143d798d90c4efa390685efb2e..d656af91e6c1d399f90fa3aebf9ab3c6e091cc31 100644
--- a/src/docode.c
+++ b/src/docode.c
@@ -620,9 +620,11 @@ static int do_encode_automap_arg_list(node *n,
 	depth++;
       }
       emit0(F_MARK);
+      PUSH_CLEANUP_FRAME(do_pop_mark, 0);
       code_expression(n, 0, "[*]");
       emit1(F_NUMBER, depth);
       emit_apply_builtin("__builtin.automap_marker");
+      POP_AND_DONT_CLEANUP;
       return 1;
     }
   }
@@ -899,9 +901,11 @@ static void emit_multi_assign(node *vals, node *vars, int no)
 	} else if (!level) {
 	  f += inh->identifier_level;
 	  emit0(F_MARK);
+	  PUSH_CLEANUP_FRAME(do_pop_mark, 0);
 	  code_expression(val, 0, "RHS");
 	  emit_multi_assign(vals, vars, no+1);
 	  emit1(F_CALL_LFUN, f);
+	  POP_AND_DONT_CLEANUP;
 	  emit0(F_POP_VALUE);
 	}
       }
@@ -1430,6 +1434,7 @@ static int do_docode2(node *n, int flags)
             yywarning("Variable %S lacks a setter.", id->name);
           } else if (!level) {
             f += inh->identifier_level;
+	    PUSH_CLEANUP_FRAME(do_pop_mark, 0);
             if (flags & DO_POP) {
 #ifndef USE_APPLY_N
               emit0(F_MARK);
@@ -1447,6 +1452,7 @@ static int do_docode2(node *n, int flags)
 #else
             emit1(F_CALL_LFUN, f);
 #endif
+	    POP_AND_DONT_CLEANUP;
             emit0(F_POP_VALUE);
             return !(flags & DO_POP);
           }
@@ -1541,15 +1547,19 @@ static int do_docode2(node *n, int flags)
 	Pike_fatal("HELP! FATAL INTERNAL COMPILER ERROR (1)\n");
 #endif
 
+      PUSH_CLEANUP_FRAME(do_pop_mark, 0);
       emit0(F_MARK);
+      PUSH_CLEANUP_FRAME(do_pop_mark, 0);
       emit0(F_MARK);
       emit0(F_LTOSVAL);
       emit1(F_NUMBER, depth);
       emit_apply_builtin("__builtin.automap_marker");
+      POP_AND_DONT_CLEANUP;
       emit_builtin_svalue("`+");
       emit2(F_REARRANGE,1,1);
       emit1(F_NUMBER, 1);
       emit_apply_builtin("__automap__");
+      POP_AND_DONT_CLEANUP;
 
       if(flags & DO_POP)
       {
@@ -1603,15 +1613,19 @@ static int do_docode2(node *n, int flags)
 	Pike_fatal("HELP! FATAL INTERNAL COMPILER ERROR (1)\n");
 #endif
 
+      PUSH_CLEANUP_FRAME(do_pop_mark, 0);
       emit0(F_MARK);
+      PUSH_CLEANUP_FRAME(do_pop_mark, 0);
       emit0(F_MARK);
       emit0(F_LTOSVAL);
       emit1(F_NUMBER, depth);
       emit_apply_builtin("__builtin.automap_marker");
+      POP_AND_DONT_CLEANUP;
       emit_builtin_svalue("`-");
       emit2(F_REARRANGE,1,1);
       emit1(F_NUMBER, 1);
       emit_apply_builtin("__automap__");
+      POP_AND_DONT_CLEANUP;
 
       if(flags & DO_POP)
       {
@@ -2761,9 +2775,11 @@ static int do_docode2(node *n, int flags)
 
   case F_AUTO_MAP:
     emit0(F_MARK);
+    PUSH_CLEANUP_FRAME(do_pop_mark, 0);
     code_expression(CAR(n), 0, "automap function");
     do_encode_automap_arg_list(CDR(n),0);
     emit_apply_builtin("__automap__");
+    POP_AND_DONT_CLEANUP;
     return 1;
 
   case F_AUTO_MAP_MARKER:
diff --git a/src/testsuite.in b/src/testsuite.in
index 53beaa3b1cff5cae2f96528a045136c68d586092..d63a5ed7ae0c5e80e07bfda029945018e70eb234 100644
--- a/src/testsuite.in
+++ b/src/testsuite.in
@@ -3085,6 +3085,16 @@ test_any([[
   return 0;
 ]], 0)
 
+test_any_equal([[
+  // Test automap combined with splice. [LysLysKOM 23258037]
+  array ret = ({});
+  for (int x = 0; x < 10; x++) {
+    array a = ({ x, });
+    ret += `+(a[*], @a);
+  }
+  return ret;
+]], ({ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 }))
+
 test_any([[
   // Test eval_low() on seemingly constant expressions, that
   // attempt to access variables in the fake object. [Bug 5273]