File 0635-erts-Fix-PAM-bug-where-hashmap-exprs-pushed-to-much.patch of Package erlang
From 413e50a2b1450df4ecdd1e8fa7790ec4dc1668c2 Mon Sep 17 00:00:00 2001
From: Lukas Larsson <lukas@erlang.org>
Date: Thu, 12 Aug 2021 16:37:00 +0200
Subject: [PATCH 5/6] erts: Fix PAM bug where hashmap exprs pushed to much
When a hashmap was used in guard or body it pushed values
to the program when trying to figure out if a hashmap
was constant or if it contained expressions. These values
were not removed if any expression was found and thus the
program broke.
---
erts/emulator/beam/erl_db_util.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/erts/emulator/beam/erl_db_util.c b/erts/emulator/beam/erl_db_util.c
index 7744c98612..83ebdeda68 100644
--- a/erts/emulator/beam/erl_db_util.c
+++ b/erts/emulator/beam/erl_db_util.c
@@ -3963,6 +3963,7 @@ dmc_map(DMCContext *context, DMCHeap *heap, DMC_STACK_TYPE(UWord) *text,
DECLARE_WSTACK(wstack);
Eterm *kv;
int c;
+ int textpos = DMC_STACK_NUM(*text);
ASSERT(is_hashmap(t));
@@ -3980,11 +3981,15 @@ dmc_map(DMCContext *context, DMCHeap *heap, DMC_STACK_TYPE(UWord) *text,
}
if (constant_values) {
+ ASSERT(DMC_STACK_NUM(*text) == textpos);
*constant = 1;
DESTROY_WSTACK(wstack);
return retOk;
}
+ /* reset the program to the original position and re-emit everything */
+ DMC_STACK_NUM(*text) = textpos;
+
*constant = 0;
hashmap_iterator_init(&wstack, t, 1);
--
2.31.1