Skip to content

Commit 845b03c

Browse files
committed
[WebAssembly] Use MapVector to stabilize iteration order after D150803
StringMap iteration order is not guaranteed to be deterministic (https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).
1 parent 94830bf commit 845b03c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
#include "WebAssemblyRegisterInfo.h"
2626
#include "WebAssemblyRuntimeLibcallSignatures.h"
2727
#include "WebAssemblyTargetMachine.h"
28+
#include "llvm/ADT/MapVector.h"
2829
#include "llvm/ADT/SmallSet.h"
2930
#include "llvm/ADT/StringExtras.h"
30-
#include "llvm/ADT/StringMap.h"
3131
#include "llvm/Analysis/ValueTracking.h"
3232
#include "llvm/BinaryFormat/Wasm.h"
3333
#include "llvm/CodeGen/Analysis.h"
@@ -565,7 +565,7 @@ void WebAssemblyAsmPrinter::EmitFunctionAttributes(Module &M) {
565565
return;
566566

567567
// Group all the custom attributes by name.
568-
StringMap<SmallVector<MCSymbol *, 4>> CustomSections;
568+
MapVector<StringRef, SmallVector<MCSymbol *, 4>> CustomSections;
569569
const ConstantArray *CA = cast<ConstantArray>(V->getOperand(0));
570570
for (Value *Op : CA->operands()) {
571571
auto *CS = cast<ConstantStruct>(Op);
@@ -580,15 +580,14 @@ void WebAssemblyAsmPrinter::EmitFunctionAttributes(Module &M) {
580580
auto *GV = cast<GlobalVariable>(CS->getOperand(1)->stripPointerCasts());
581581
StringRef AnnotationString;
582582
getConstantStringInfo(GV, AnnotationString);
583-
std::string Name = "annotate." + AnnotationString.str();
584583
auto *Sym = cast<MCSymbolWasm>(getSymbol(F));
585-
CustomSections[Name].push_back(Sym);
584+
CustomSections[AnnotationString].push_back(Sym);
586585
}
587586

588587
// Emit a custom section for each unique attribute.
589588
for (const auto &[Name, Symbols] : CustomSections) {
590589
MCSectionWasm *CustomSection = OutContext.getWasmSection(
591-
".custom_section.llvm.func_attr." + Name, SectionKind::getMetadata());
590+
".custom_section.llvm.func_attr.annotate." + Name, SectionKind::getMetadata());
592591
OutStreamer->pushSection();
593592
OutStreamer->switchSection(CustomSection);
594593

0 commit comments

Comments
 (0)