Skip to content

Commit 062f092

Browse files
authored
Update source map names indices in prolog/epilog (#8113)
#8068 failed to update `prologLocation` and `epilogLocation`, which caused the CI failure: https://app.circleci.com/pipelines/github/emscripten-core/emscripten/47832/workflows/ea0292aa-124d-4a3f-b988-0a96823e9bcd/jobs/1089017/tests This updates them properly.
1 parent fb4aef6 commit 062f092

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/wasm/wasm-binary.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,14 +1245,20 @@ void WasmBinaryWriter::writeSourceMapProlog() {
12451245
std::map<Index, Index> oldToNewIndex;
12461246

12471247
// Collect all used symbol name indexes.
1248-
for (auto& func : wasm->functions) {
1249-
for (auto& [_, location] : func->debugLocations) {
1248+
auto prepareIndexMap =
1249+
[&](const std::optional<Function::DebugLocation>& location) {
12501250
if (location && location->symbolNameIndex) {
12511251
uint32_t oldIndex = *location->symbolNameIndex;
12521252
assert(oldIndex < wasm->debugInfoSymbolNames.size());
12531253
oldToNewIndex[oldIndex] = 0; // placeholder
12541254
}
1255+
};
1256+
for (auto& func : wasm->functions) {
1257+
for (auto& [_, location] : func->debugLocations) {
1258+
prepareIndexMap(location);
12551259
}
1260+
prepareIndexMap(func->prologLocation);
1261+
prepareIndexMap(func->epilogLocation);
12561262
}
12571263

12581264
// Create the new list of names and the mapping from old to new indices.
@@ -1263,13 +1269,18 @@ void WasmBinaryWriter::writeSourceMapProlog() {
12631269
}
12641270

12651271
// Update all debug locations to point to the new indices.
1272+
auto updateIndex = [&](std::optional<Function::DebugLocation>& location) {
1273+
if (location && location->symbolNameIndex) {
1274+
uint32_t oldIndex = *location->symbolNameIndex;
1275+
location->symbolNameIndex = oldToNewIndex[oldIndex];
1276+
}
1277+
};
12661278
for (auto& func : wasm->functions) {
12671279
for (auto& [_, location] : func->debugLocations) {
1268-
if (location && location->symbolNameIndex) {
1269-
uint32_t oldIndex = *location->symbolNameIndex;
1270-
location->symbolNameIndex = oldToNewIndex[oldIndex];
1271-
}
1280+
updateIndex(location);
12721281
}
1282+
updateIndex(func->prologLocation);
1283+
updateIndex(func->epilogLocation);
12731284
}
12741285

12751286
// Replace the old symbol names with the new, pruned list.

test/lit/source-map-names.wast

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
;; After --remove-unused-module-elements, the output source map's 'names' field
66
;; should NOT contain 'unused'
77

8-
;; OUT-MAP: "names":["used","used2"]
8+
;; OUT-MAP: "names":["used","used2","usedProlog"]
99

1010
(module
1111
(export "used" (func $used))
1212
(export "used2" (func $used2))
13+
(export "usedProlog" (func $usedProlog))
1314

1415
(func $unused
1516
;;@ src.cpp:1:1:unused
@@ -29,4 +30,11 @@
2930
;;@ src.cpp:3:1:used2
3031
(nop)
3132
)
33+
34+
;; OUT-WAST: ;;@ src.cpp:4:1:usedProlog
35+
;; OUT-WAST-NEXT: (func
36+
;;@ src.cpp:4:1:usedProlog
37+
(func $usedProlog
38+
(nop)
39+
)
3240
)

0 commit comments

Comments
 (0)