summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/memory-utils.cpp16
-rw-r--r--test/lit/ctor-eval/data_drop.wast38
2 files changed, 47 insertions, 7 deletions
diff --git a/src/ir/memory-utils.cpp b/src/ir/memory-utils.cpp
index f1471b7a4..b21d8f0ad 100644
--- a/src/ir/memory-utils.cpp
+++ b/src/ir/memory-utils.cpp
@@ -24,19 +24,21 @@ bool flatten(Module& wasm) {
if (wasm.memories.size() > 1) {
return false;
}
- // The presence of any MemoryInit instructions is a problem because they care
- // about segment identity, which flattening gets rid of ( when it merges them
- // all into one big segment).
+ // The presence of any instruction that cares about segment identity is a
+ // problem because flattening gets rid of that (when it merges them all into
+ // one big segment).
ModuleUtils::ParallelFunctionAnalysis<bool> analysis(
- wasm, [&](Function* func, bool& hasMemoryInit) {
+ wasm, [&](Function* func, bool& noticesSegmentIdentity) {
if (func->imported()) {
return;
}
- hasMemoryInit = FindAll<MemoryInit>(func->body).list.size() > 0;
+ noticesSegmentIdentity =
+ FindAll<MemoryInit>(func->body).list.size() > 0 ||
+ FindAll<DataDrop>(func->body).list.size() > 0;
});
- for (auto& [func, hasMemoryInit] : analysis.map) {
- if (hasMemoryInit) {
+ for (auto& [func, noticesSegmentIdentity] : analysis.map) {
+ if (noticesSegmentIdentity) {
return false;
}
}
diff --git a/test/lit/ctor-eval/data_drop.wast b/test/lit/ctor-eval/data_drop.wast
new file mode 100644
index 000000000..eeec5f165
--- /dev/null
+++ b/test/lit/ctor-eval/data_drop.wast
@@ -0,0 +1,38 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+;; RUN: wasm-ctor-eval %s --ctors=test --kept-exports=test --quiet -all -S -o - | filecheck %s
+
+(module
+ ;; CHECK: (type $none_=>_none (func))
+
+ ;; CHECK: (memory $0 1)
+ (memory $0 1)
+ (data (i32.const 0) "__________")
+ (data (i32.const 20) "__________")
+
+ (func "test"
+ ;; A store that can be evalled, but we do not do so because of the
+ ;; instruction after us.
+ (i32.store8
+ (i32.const 4)
+ (i32.const 100)
+ )
+
+ ;; A memory init cannot be evalled since ctor-eval flattens memory segments
+ ;; atm. In fact the module would not validate as we refer to segment 1 here
+ ;; but after flattening only segment 0 exists.
+ (data.drop 1)
+ )
+)
+;; CHECK: (data (i32.const 0) "__________")
+
+;; CHECK: (data (i32.const 20) "__________")
+
+;; CHECK: (export "test" (func $0))
+
+;; CHECK: (func $0 (type $none_=>_none)
+;; CHECK-NEXT: (i32.store8
+;; CHECK-NEXT: (i32.const 4)
+;; CHECK-NEXT: (i32.const 100)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (data.drop 1)
+;; CHECK-NEXT: )