summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-09-17 11:25:18 -0700
committerGitHub <noreply@github.com>2024-09-17 11:25:18 -0700
commit0da6d3e5b729e1fe7cc608720dc3d428fefcdb03 (patch)
treec73621438a93434f61407c55a2fe573fc28fb6f9 /src
parent34ad6a7598e662e9ff357987f2c81fde1e05c522 (diff)
downloadbinaryen-0da6d3e5b729e1fe7cc608720dc3d428fefcdb03.tar.gz
binaryen-0da6d3e5b729e1fe7cc608720dc3d428fefcdb03.tar.bz2
binaryen-0da6d3e5b729e1fe7cc608720dc3d428fefcdb03.zip
Fix selects of packed fields in GlobalStructOptimization (#6947)
We emit a select between two objects when only two objects exist of a particular type. However, if the field is packed, we did not handle truncating the written values.
Diffstat (limited to 'src')
-rw-r--r--src/passes/GlobalStructInference.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/passes/GlobalStructInference.cpp b/src/passes/GlobalStructInference.cpp
index 7526cdb76..4158db051 100644
--- a/src/passes/GlobalStructInference.cpp
+++ b/src/passes/GlobalStructInference.cpp
@@ -50,6 +50,7 @@
#include <variant>
+#include "ir/bits.h"
#include "ir/debuginfo.h"
#include "ir/find_all.h"
#include "ir/module-utils.h"
@@ -421,8 +422,9 @@ struct GlobalStructInference : public Pass {
Expression* ret;
if (value.isConstant()) {
// This is known to be a constant, so simply emit an expression for
- // that constant.
- ret = value.getConstant().makeExpression(wasm);
+ // that constant, and handle if the field is packed.
+ auto* expr = value.getConstant().makeExpression(wasm);
+ ret = Bits::makePackedFieldGet(expr, field, curr->signed_, wasm);
} else {
// Otherwise, this is non-constant, so we are in the situation where
// we want to un-nest the value out of the struct.new it is in. Note