diff --git a/llvm/include/llvm/MC/MCSymbolWasm.h b/llvm/include/llvm/MC/MCSymbolWasm.h --- a/llvm/include/llvm/MC/MCSymbolWasm.h +++ b/llvm/include/llvm/MC/MCSymbolWasm.h @@ -19,15 +19,13 @@ bool IsHidden = false; bool IsComdat = false; mutable bool IsUsedInGOT = false; + Optional ImportModule; + Optional ImportName; + Optional ExportName; + wasm::WasmSignature *Signature = nullptr; Optional GlobalType; Optional EventType; - // Non-owning pointers since MCSymbol must be trivially destructible. - std::string *ImportModule = nullptr; - std::string *ImportName = nullptr; - std::string *ExportName = nullptr; - wasm::WasmSignature *Signature = nullptr; - /// An expression describing how to calculate the size of a symbol. If a /// symbol has no size this field will be NULL. const MCExpr *SymbolSize = nullptr; @@ -71,32 +69,31 @@ bool isComdat() const { return IsComdat; } void setComdat(bool isComdat) { IsComdat = isComdat; } - bool hasImportModule() const { return ImportModule != nullptr; } + bool hasImportModule() const { return ImportModule.hasValue(); } const StringRef getImportModule() const { - if (ImportModule) - return StringRef(*ImportModule); + if (ImportModule.hasValue()) { + return ImportModule.getValue(); + } // Use a default module name of "env" for now, for compatibility with // existing tools. // TODO(sbc): Find a way to specify a default value in the object format // without picking a hardcoded value like this. return "env"; } - void setImportModule(std::string *Name) { ImportModule = Name; } + void setImportModule(StringRef Name) { ImportModule = Name; } - bool hasImportName() const { return ImportName != nullptr; } + bool hasImportName() const { return ImportName.hasValue(); } const StringRef getImportName() const { - if (ImportName) - return StringRef(*ImportName); + if (ImportName.hasValue()) { + return ImportName.getValue(); + } return getName(); } - void setImportName(std::string *Name) { ImportName = Name; } + void setImportName(StringRef Name) { ImportName = Name; } - bool hasExportName() const { return ExportName != nullptr; } - const StringRef getExportName() const { - assert(ExportName); - return StringRef(*ExportName); - } - void setExportName(std::string *Name) { ExportName = Name; } + bool hasExportName() const { return ExportName.hasValue(); } + const StringRef getExportName() const { return ExportName.getValue(); } + void setExportName(StringRef Name) { ExportName = Name; } void setUsedInGOT() const { IsUsedInGOT = true; } bool isUsedInGOT() const { return IsUsedInGOT; } diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -233,10 +233,10 @@ Signatures.push_back(std::move(Sig)); } - std::string *storeName(StringRef Name) { + StringRef storeName(StringRef Name) { std::unique_ptr N = std::make_unique(Name); Names.push_back(std::move(N)); - return Names.back().get(); + return *Names.back(); } std::pair nestingString(NestingType NT) { diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h --- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h +++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h @@ -28,10 +28,10 @@ std::vector> Signatures; std::vector> Names; - std::string *storeName(StringRef Name) { + StringRef storeName(StringRef Name) { std::unique_ptr N = std::make_unique(Name); Names.push_back(std::move(N)); - return Names.back().get(); + return *Names.back(); } public: