1
Fork 0

Rollup merge of #122062 - workingjubilee:initialize-my-fist, r=cuviper

Explicitly assign constructed C++ classes

C++ style guides I am aware of recommend specifically preferring = syntax for any classes with fairly obvious constructors[^0] that do not perform any complicated logic in their constructor. I contend that all constructors that the `rustc_llvm` code uses qualify. This has only become more common since C++ 17 guaranteed many cases of copy initialization elision.

The other detail is that I tried to ask another contributor with infinitely more C++ experience than me (i.e. any) what this constructor syntax was, and they thought it was a macro. I know of no other language that has adopted this same syntax. As the rustc codebase features many contributors experienced in many other languages, using a less... unique... style has many other benefits in making this code more lucid and maintainable, which is something it direly needs.

[^0]: e.g. https://abseil.io/tips/88
This commit is contained in:
Matthias Krüger 2024-03-07 00:57:40 +01:00 committed by GitHub
commit 869529a130
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 53 additions and 52 deletions

View file

@ -120,7 +120,7 @@ extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer(
} }
auto FilenamesWriter = auto FilenamesWriter =
coverage::CoverageFilenamesSectionWriter(ArrayRef<std::string>(FilenameRefs)); coverage::CoverageFilenamesSectionWriter(ArrayRef<std::string>(FilenameRefs));
RawRustStringOstream OS(BufferOut); auto OS = RawRustStringOstream(BufferOut);
FilenamesWriter.write(OS); FilenamesWriter.write(OS);
} }
@ -160,7 +160,7 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer(
ArrayRef<unsigned>(VirtualFileMappingIDs, NumVirtualFileMappingIDs), ArrayRef<unsigned>(VirtualFileMappingIDs, NumVirtualFileMappingIDs),
Expressions, Expressions,
MappingRegions); MappingRegions);
RawRustStringOstream OS(BufferOut); auto OS = RawRustStringOstream(BufferOut);
CoverageMappingWriter.write(OS); CoverageMappingWriter.write(OS);
} }
@ -168,23 +168,23 @@ extern "C" LLVMValueRef LLVMRustCoverageCreatePGOFuncNameVar(
LLVMValueRef F, LLVMValueRef F,
const char *FuncName, const char *FuncName,
size_t FuncNameLen) { size_t FuncNameLen) {
StringRef FuncNameRef(FuncName, FuncNameLen); auto FuncNameRef = StringRef(FuncName, FuncNameLen);
return wrap(createPGOFuncNameVar(*cast<Function>(unwrap(F)), FuncNameRef)); return wrap(createPGOFuncNameVar(*cast<Function>(unwrap(F)), FuncNameRef));
} }
extern "C" uint64_t LLVMRustCoverageHashByteArray( extern "C" uint64_t LLVMRustCoverageHashByteArray(
const char *Bytes, const char *Bytes,
size_t NumBytes) { size_t NumBytes) {
StringRef StrRef(Bytes, NumBytes); auto StrRef = StringRef(Bytes, NumBytes);
return IndexedInstrProf::ComputeHash(StrRef); return IndexedInstrProf::ComputeHash(StrRef);
} }
static void WriteSectionNameToString(LLVMModuleRef M, static void WriteSectionNameToString(LLVMModuleRef M,
InstrProfSectKind SK, InstrProfSectKind SK,
RustStringRef Str) { RustStringRef Str) {
Triple TargetTriple(unwrap(M)->getTargetTriple()); auto TargetTriple = Triple(unwrap(M)->getTargetTriple());
auto name = getInstrProfSectionName(SK, TargetTriple.getObjectFormat()); auto name = getInstrProfSectionName(SK, TargetTriple.getObjectFormat());
RawRustStringOstream OS(Str); auto OS = RawRustStringOstream(Str);
OS << name; OS << name;
} }
@ -200,7 +200,7 @@ extern "C" void LLVMRustCoverageWriteFuncSectionNameToString(LLVMModuleRef M,
extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) { extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) {
auto name = getCoverageMappingVarName(); auto name = getCoverageMappingVarName();
RawRustStringOstream OS(Str); auto OS = RawRustStringOstream(Str);
OS << name; OS << name;
} }

View file

@ -77,9 +77,9 @@ extern "C" void LLVMRustTimeTraceProfilerFinishThread() {
} }
extern "C" void LLVMRustTimeTraceProfilerFinish(const char* FileName) { extern "C" void LLVMRustTimeTraceProfilerFinish(const char* FileName) {
StringRef FN(FileName); auto FN = StringRef(FileName);
std::error_code EC; std::error_code EC;
raw_fd_ostream OS(FN, EC, sys::fs::CD_CreateAlways); auto OS = raw_fd_ostream(FN, EC, sys::fs::CD_CreateAlways);
timeTraceProfilerWrite(OS); timeTraceProfilerWrite(OS);
timeTraceProfilerCleanup(); timeTraceProfilerCleanup();
@ -424,7 +424,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
auto CM = fromRust(RustCM); auto CM = fromRust(RustCM);
std::string Error; std::string Error;
Triple Trip(Triple::normalize(TripleStr)); auto Trip = Triple(Triple::normalize(TripleStr));
const llvm::Target *TheTarget = const llvm::Target *TheTarget =
TargetRegistry::lookupTarget(Trip.getTriple(), Error); TargetRegistry::lookupTarget(Trip.getTriple(), Error);
if (TheTarget == nullptr) { if (TheTarget == nullptr) {
@ -537,8 +537,8 @@ extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
// TargetLibraryInfo pass, so we use this method to do so. // TargetLibraryInfo pass, so we use this method to do so.
extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMR, LLVMModuleRef M, extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMR, LLVMModuleRef M,
bool DisableSimplifyLibCalls) { bool DisableSimplifyLibCalls) {
Triple TargetTriple(unwrap(M)->getTargetTriple()); auto TargetTriple = Triple(unwrap(M)->getTargetTriple());
TargetLibraryInfoImpl TLII(TargetTriple); auto TLII = TargetLibraryInfoImpl(TargetTriple);
if (DisableSimplifyLibCalls) if (DisableSimplifyLibCalls)
TLII.disableAllFunctions(); TLII.disableAllFunctions();
unwrap(PMR)->add(new TargetLibraryInfoWrapperPass(TLII)); unwrap(PMR)->add(new TargetLibraryInfoWrapperPass(TLII));
@ -589,7 +589,7 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMPassManagerRef PMR,
std::string ErrorInfo; std::string ErrorInfo;
std::error_code EC; std::error_code EC;
raw_fd_ostream OS(Path, EC, sys::fs::OF_None); auto OS = raw_fd_ostream(Path, EC, sys::fs::OF_None);
if (EC) if (EC)
ErrorInfo = EC.message(); ErrorInfo = EC.message();
if (ErrorInfo != "") { if (ErrorInfo != "") {
@ -597,9 +597,9 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMPassManagerRef PMR,
return LLVMRustResult::Failure; return LLVMRustResult::Failure;
} }
buffer_ostream BOS(OS); auto BOS = buffer_ostream(OS);
if (DwoPath) { if (DwoPath) {
raw_fd_ostream DOS(DwoPath, EC, sys::fs::OF_None); auto DOS = raw_fd_ostream(DwoPath, EC, sys::fs::OF_None);
EC.clear(); EC.clear();
if (EC) if (EC)
ErrorInfo = EC.message(); ErrorInfo = EC.message();
@ -607,7 +607,7 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMPassManagerRef PMR,
LLVMRustSetLastError(ErrorInfo.c_str()); LLVMRustSetLastError(ErrorInfo.c_str());
return LLVMRustResult::Failure; return LLVMRustResult::Failure;
} }
buffer_ostream DBOS(DOS); auto DBOS = buffer_ostream(DOS);
unwrap(Target)->addPassesToEmitFile(*PM, BOS, &DBOS, FileType, false); unwrap(Target)->addPassesToEmitFile(*PM, BOS, &DBOS, FileType, false);
PM->run(*unwrap(M)); PM->run(*unwrap(M));
} else { } else {
@ -796,7 +796,7 @@ LLVMRustOptimize(
DebugInfoForProfiling); DebugInfoForProfiling);
} }
PassBuilder PB(TM, PTO, PGOOpt, &PIC); auto PB = PassBuilder(TM, PTO, PGOOpt, &PIC);
LoopAnalysisManager LAM; LoopAnalysisManager LAM;
FunctionAnalysisManager FAM; FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM; CGSCCAnalysisManager CGAM;
@ -1112,7 +1112,7 @@ extern "C" LLVMRustResult
LLVMRustPrintModule(LLVMModuleRef M, const char *Path, DemangleFn Demangle) { LLVMRustPrintModule(LLVMModuleRef M, const char *Path, DemangleFn Demangle) {
std::string ErrorInfo; std::string ErrorInfo;
std::error_code EC; std::error_code EC;
raw_fd_ostream OS(Path, EC, sys::fs::OF_None); auto OS = raw_fd_ostream(Path, EC, sys::fs::OF_None);
if (EC) if (EC)
ErrorInfo = EC.message(); ErrorInfo = EC.message();
if (ErrorInfo != "") { if (ErrorInfo != "") {
@ -1120,8 +1120,8 @@ LLVMRustPrintModule(LLVMModuleRef M, const char *Path, DemangleFn Demangle) {
return LLVMRustResult::Failure; return LLVMRustResult::Failure;
} }
RustAssemblyAnnotationWriter AAW(Demangle); auto AAW = RustAssemblyAnnotationWriter(Demangle);
formatted_raw_ostream FOS(OS); auto FOS = formatted_raw_ostream(OS);
unwrap(M)->print(FOS, &AAW); unwrap(M)->print(FOS, &AAW);
return LLVMRustResult::Success; return LLVMRustResult::Success;
@ -1281,8 +1281,8 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
// Load each module's summary and merge it into one combined index // Load each module's summary and merge it into one combined index
for (int i = 0; i < num_modules; i++) { for (int i = 0; i < num_modules; i++) {
auto module = &modules[i]; auto module = &modules[i];
StringRef buffer(module->data, module->len); auto buffer = StringRef(module->data, module->len);
MemoryBufferRef mem_buffer(buffer, module->identifier); auto mem_buffer = MemoryBufferRef(buffer, module->identifier);
Ret->ModuleMap[module->identifier] = mem_buffer; Ret->ModuleMap[module->identifier] = mem_buffer;
@ -1485,7 +1485,7 @@ LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M,
return MOrErr; return MOrErr;
}; };
bool ClearDSOLocal = clearDSOLocalOnDeclarations(Mod, Target); bool ClearDSOLocal = clearDSOLocalOnDeclarations(Mod, Target);
FunctionImporter Importer(Data->Index, Loader, ClearDSOLocal); auto Importer = FunctionImporter(Data->Index, Loader, ClearDSOLocal);
Expected<bool> Result = Importer.importFunctions(Mod, ImportList); Expected<bool> Result = Importer.importFunctions(Mod, ImportList);
if (!Result) { if (!Result) {
LLVMRustSetLastError(toString(Result.takeError()).c_str()); LLVMRustSetLastError(toString(Result.takeError()).c_str());
@ -1510,7 +1510,7 @@ extern "C" LLVMRustThinLTOBuffer*
LLVMRustThinLTOBufferCreate(LLVMModuleRef M, bool is_thin) { LLVMRustThinLTOBufferCreate(LLVMModuleRef M, bool is_thin) {
auto Ret = std::make_unique<LLVMRustThinLTOBuffer>(); auto Ret = std::make_unique<LLVMRustThinLTOBuffer>();
{ {
raw_string_ostream OS(Ret->data); auto OS = raw_string_ostream(Ret->data);
{ {
if (is_thin) { if (is_thin) {
PassBuilder PB; PassBuilder PB;
@ -1557,8 +1557,8 @@ LLVMRustParseBitcodeForLTO(LLVMContextRef Context,
const char *data, const char *data,
size_t len, size_t len,
const char *identifier) { const char *identifier) {
StringRef Data(data, len); auto Data = StringRef(data, len);
MemoryBufferRef Buffer(Data, identifier); auto Buffer = MemoryBufferRef(Data, identifier);
unwrap(Context)->enableDebugTypeODRUniquing(); unwrap(Context)->enableDebugTypeODRUniquing();
Expected<std::unique_ptr<Module>> SrcOrError = Expected<std::unique_ptr<Module>> SrcOrError =
parseBitcodeFile(Buffer, *unwrap(Context)); parseBitcodeFile(Buffer, *unwrap(Context));
@ -1576,8 +1576,8 @@ extern "C" const char *LLVMRustGetSliceFromObjectDataByName(const char *data,
const char *name, const char *name,
size_t *out_len) { size_t *out_len) {
*out_len = 0; *out_len = 0;
StringRef Data(data, len); auto Data = StringRef(data, len);
MemoryBufferRef Buffer(Data, ""); // The id is unused. auto Buffer = MemoryBufferRef(Data, ""); // The id is unused.
file_magic Type = identify_magic(Buffer.getBuffer()); file_magic Type = identify_magic(Buffer.getBuffer());
Expected<std::unique_ptr<object::ObjectFile>> ObjFileOrError = Expected<std::unique_ptr<object::ObjectFile>> ObjFileOrError =
object::ObjectFile::createObjectFile(Buffer, Type); object::ObjectFile::createObjectFile(Buffer, Type);

View file

@ -119,7 +119,7 @@ extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
extern "C" const char *LLVMRustPrintPassTimings(size_t *Len) { extern "C" const char *LLVMRustPrintPassTimings(size_t *Len) {
std::string buf; std::string buf;
raw_string_ostream SS(buf); auto SS = raw_string_ostream(buf);
TimerGroup::printAll(SS); TimerGroup::printAll(SS);
SS.flush(); SS.flush();
*Len = buf.length(); *Len = buf.length();
@ -130,7 +130,7 @@ extern "C" const char *LLVMRustPrintPassTimings(size_t *Len) {
extern "C" const char *LLVMRustPrintStatistics(size_t *Len) { extern "C" const char *LLVMRustPrintStatistics(size_t *Len) {
std::string buf; std::string buf;
raw_string_ostream SS(buf); auto SS = raw_string_ostream(buf);
llvm::PrintStatistics(SS); llvm::PrintStatistics(SS);
SS.flush(); SS.flush();
*Len = buf.length(); *Len = buf.length();
@ -184,7 +184,7 @@ extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
extern "C" LLVMValueRef extern "C" LLVMValueRef
LLVMRustGetOrInsertGlobal(LLVMModuleRef M, const char *Name, size_t NameLen, LLVMTypeRef Ty) { LLVMRustGetOrInsertGlobal(LLVMModuleRef M, const char *Name, size_t NameLen, LLVMTypeRef Ty) {
Module *Mod = unwrap(M); Module *Mod = unwrap(M);
StringRef NameRef(Name, NameLen); auto NameRef = StringRef(Name, NameLen);
// We don't use Module::getOrInsertGlobal because that returns a Constant*, // We don't use Module::getOrInsertGlobal because that returns a Constant*,
// which may either be the real GlobalVariable*, or a constant bitcast of it // which may either be the real GlobalVariable*, or a constant bitcast of it
@ -295,7 +295,7 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
template<typename T> static inline void AddAttributes(T *t, unsigned Index, template<typename T> static inline void AddAttributes(T *t, unsigned Index,
LLVMAttributeRef *Attrs, size_t AttrsLen) { LLVMAttributeRef *Attrs, size_t AttrsLen) {
AttributeList PAL = t->getAttributes(); AttributeList PAL = t->getAttributes();
AttrBuilder B(t->getContext()); auto B = AttrBuilder(t->getContext());
for (LLVMAttributeRef Attr : ArrayRef<LLVMAttributeRef>(Attrs, AttrsLen)) for (LLVMAttributeRef Attr : ArrayRef<LLVMAttributeRef>(Attrs, AttrsLen))
B.addAttribute(unwrap(Attr)); B.addAttribute(unwrap(Attr));
AttributeList PALNew = PAL.addAttributesAtIndex(t->getContext(), Index, B); AttributeList PALNew = PAL.addAttributesAtIndex(t->getContext(), Index, B);
@ -1205,13 +1205,13 @@ extern "C" int64_t LLVMRustDIBuilderCreateOpLLVMFragment() {
} }
extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Ty, RustStringRef Str) { extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Ty, RustStringRef Str) {
RawRustStringOstream OS(Str); auto OS = RawRustStringOstream(Str);
unwrap<llvm::Type>(Ty)->print(OS); unwrap<llvm::Type>(Ty)->print(OS);
} }
extern "C" void LLVMRustWriteValueToString(LLVMValueRef V, extern "C" void LLVMRustWriteValueToString(LLVMValueRef V,
RustStringRef Str) { RustStringRef Str) {
RawRustStringOstream OS(Str); auto OS = RawRustStringOstream(Str);
if (!V) { if (!V) {
OS << "(null)"; OS << "(null)";
} else { } else {
@ -1234,7 +1234,7 @@ extern "C" LLVMTypeRef LLVMRustArrayType(LLVMTypeRef ElementTy,
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Twine, LLVMTwineRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Twine, LLVMTwineRef)
extern "C" void LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef Str) { extern "C" void LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef Str) {
RawRustStringOstream OS(Str); auto OS = RawRustStringOstream(Str);
unwrap(T)->print(OS); unwrap(T)->print(OS);
} }
@ -1246,11 +1246,11 @@ extern "C" void LLVMRustUnpackOptimizationDiagnostic(
llvm::DiagnosticInfoOptimizationBase *Opt = llvm::DiagnosticInfoOptimizationBase *Opt =
static_cast<llvm::DiagnosticInfoOptimizationBase *>(unwrap(DI)); static_cast<llvm::DiagnosticInfoOptimizationBase *>(unwrap(DI));
RawRustStringOstream PassNameOS(PassNameOut); auto PassNameOS = RawRustStringOstream(PassNameOut);
PassNameOS << Opt->getPassName(); PassNameOS << Opt->getPassName();
*FunctionOut = wrap(&Opt->getFunction()); *FunctionOut = wrap(&Opt->getFunction());
RawRustStringOstream FilenameOS(FilenameOut); auto FilenameOS = RawRustStringOstream(FilenameOut);
DiagnosticLocation loc = Opt->getLocation(); DiagnosticLocation loc = Opt->getLocation();
if (loc.isValid()) { if (loc.isValid()) {
*Line = loc.getLine(); *Line = loc.getLine();
@ -1258,7 +1258,7 @@ extern "C" void LLVMRustUnpackOptimizationDiagnostic(
FilenameOS << loc.getAbsolutePath(); FilenameOS << loc.getAbsolutePath();
} }
RawRustStringOstream MessageOS(MessageOut); auto MessageOS = RawRustStringOstream(MessageOut);
MessageOS << Opt->getMsg(); MessageOS << Opt->getMsg();
} }
@ -1301,8 +1301,8 @@ LLVMRustUnpackInlineAsmDiagnostic(LLVMDiagnosticInfoRef DI,
extern "C" void LLVMRustWriteDiagnosticInfoToString(LLVMDiagnosticInfoRef DI, extern "C" void LLVMRustWriteDiagnosticInfoToString(LLVMDiagnosticInfoRef DI,
RustStringRef Str) { RustStringRef Str) {
RawRustStringOstream OS(Str); auto OS = RawRustStringOstream(Str);
DiagnosticPrinterRawOStream DP(OS); auto DP = DiagnosticPrinterRawOStream(OS);
unwrap(DI)->print(DP); unwrap(DI)->print(DP);
} }
@ -1416,7 +1416,7 @@ extern "C" LLVMTypeKind LLVMRustGetTypeKind(LLVMTypeRef Ty) {
default: default:
{ {
std::string error; std::string error;
llvm::raw_string_ostream stream(error); auto stream = llvm::raw_string_ostream(error);
stream << "Rust does not support the TypeID: " << unwrap(Ty)->getTypeID() stream << "Rust does not support the TypeID: " << unwrap(Ty)->getTypeID()
<< " for the type: " << *unwrap(Ty); << " for the type: " << *unwrap(Ty);
stream.flush(); stream.flush();
@ -1442,7 +1442,7 @@ extern "C" bool LLVMRustUnpackSMDiagnostic(LLVMSMDiagnosticRef DRef,
unsigned* RangesOut, unsigned* RangesOut,
size_t* NumRanges) { size_t* NumRanges) {
SMDiagnostic& D = *unwrap(DRef); SMDiagnostic& D = *unwrap(DRef);
RawRustStringOstream MessageOS(MessageOut); auto MessageOS = RawRustStringOstream(MessageOut);
MessageOS << D.getMessage(); MessageOS << D.getMessage();
switch (D.getKind()) { switch (D.getKind()) {
@ -1557,7 +1557,7 @@ extern "C" void LLVMRustPositionBuilderAtStart(LLVMBuilderRef B,
extern "C" void LLVMRustSetComdat(LLVMModuleRef M, LLVMValueRef V, extern "C" void LLVMRustSetComdat(LLVMModuleRef M, LLVMValueRef V,
const char *Name, size_t NameLen) { const char *Name, size_t NameLen) {
Triple TargetTriple(unwrap(M)->getTargetTriple()); Triple TargetTriple = Triple(unwrap(M)->getTargetTriple());
GlobalObject *GV = unwrap<GlobalObject>(V); GlobalObject *GV = unwrap<GlobalObject>(V);
if (TargetTriple.supportsCOMDAT()) { if (TargetTriple.supportsCOMDAT()) {
StringRef NameRef(Name, NameLen); StringRef NameRef(Name, NameLen);
@ -1721,7 +1721,7 @@ extern "C" LLVMRustModuleBuffer*
LLVMRustModuleBufferCreate(LLVMModuleRef M) { LLVMRustModuleBufferCreate(LLVMModuleRef M) {
auto Ret = std::make_unique<LLVMRustModuleBuffer>(); auto Ret = std::make_unique<LLVMRustModuleBuffer>();
{ {
raw_string_ostream OS(Ret->data); auto OS = raw_string_ostream(Ret->data);
WriteBitcodeToFile(*unwrap(M), OS); WriteBitcodeToFile(*unwrap(M), OS);
} }
return Ret.release(); return Ret.release();
@ -1751,8 +1751,8 @@ LLVMRustModuleCost(LLVMModuleRef M) {
extern "C" void extern "C" void
LLVMRustModuleInstructionStats(LLVMModuleRef M, RustStringRef Str) LLVMRustModuleInstructionStats(LLVMModuleRef M, RustStringRef Str)
{ {
RawRustStringOstream OS(Str); auto OS = RawRustStringOstream(Str);
llvm::json::OStream JOS(OS); auto JOS = llvm::json::OStream(OS);
auto Module = unwrap(M); auto Module = unwrap(M);
JOS.object([&] { JOS.object([&] {
@ -1867,7 +1867,7 @@ extern "C" LLVMRustResult LLVMRustWriteImportLibrary(
MinGW); MinGW);
if (Error) { if (Error) {
std::string errorString; std::string errorString;
llvm::raw_string_ostream stream(errorString); auto stream = llvm::raw_string_ostream(errorString);
stream << Error; stream << Error;
stream.flush(); stream.flush();
LLVMRustSetLastError(errorString.c_str()); LLVMRustSetLastError(errorString.c_str());
@ -2051,7 +2051,7 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler(
} }
extern "C" void LLVMRustGetMangledName(LLVMValueRef V, RustStringRef Str) { extern "C" void LLVMRustGetMangledName(LLVMValueRef V, RustStringRef Str) {
RawRustStringOstream OS(Str); auto OS = RawRustStringOstream(Str);
GlobalValue *GV = unwrap<GlobalValue>(V); GlobalValue *GV = unwrap<GlobalValue>(V);
Mangler().getNameWithPrefix(OS, GV, true); Mangler().getNameWithPrefix(OS, GV, true);
} }

View file

@ -11,6 +11,7 @@
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMContext.h"
#include "llvm/Object/ObjectFile.h" #include "llvm/Object/ObjectFile.h"
#include <llvm/Support/raw_ostream.h>
using namespace llvm; using namespace llvm;
using namespace llvm::sys; using namespace llvm::sys;
@ -42,7 +43,7 @@ extern "C" void *LLVMRustGetSymbols(
MemoryBuffer::getMemBuffer(StringRef(BufPtr, BufLen), StringRef("LLVMRustGetSymbolsObject"), MemoryBuffer::getMemBuffer(StringRef(BufPtr, BufLen), StringRef("LLVMRustGetSymbolsObject"),
false); false);
SmallString<0> SymNameBuf; SmallString<0> SymNameBuf;
raw_svector_ostream SymName(SymNameBuf); auto SymName = raw_svector_ostream(SymNameBuf);
// In the scenario when LLVMContext is populated SymbolicFile will contain a // In the scenario when LLVMContext is populated SymbolicFile will contain a
// reference to it, thus SymbolicFile should be destroyed first. // reference to it, thus SymbolicFile should be destroyed first.
@ -60,7 +61,7 @@ extern "C" void *LLVMRustGetSymbols(
if (!ObjOrErr) { if (!ObjOrErr) {
Error E = ObjOrErr.takeError(); Error E = ObjOrErr.takeError();
SmallString<0> ErrorBuf; SmallString<0> ErrorBuf;
raw_svector_ostream Error(ErrorBuf); auto Error = raw_svector_ostream(ErrorBuf);
Error << E << '\0'; Error << E << '\0';
return ErrorCallback(Error.str().data()); return ErrorCallback(Error.str().data());
} }
@ -70,7 +71,7 @@ extern "C" void *LLVMRustGetSymbols(
if (!ObjOrErr) { if (!ObjOrErr) {
Error E = ObjOrErr.takeError(); Error E = ObjOrErr.takeError();
SmallString<0> ErrorBuf; SmallString<0> ErrorBuf;
raw_svector_ostream Error(ErrorBuf); auto Error = raw_svector_ostream(ErrorBuf);
Error << E << '\0'; Error << E << '\0';
return ErrorCallback(Error.str().data()); return ErrorCallback(Error.str().data());
} }
@ -83,7 +84,7 @@ extern "C" void *LLVMRustGetSymbols(
continue; continue;
if (Error E = S.printName(SymName)) { if (Error E = S.printName(SymName)) {
SmallString<0> ErrorBuf; SmallString<0> ErrorBuf;
raw_svector_ostream Error(ErrorBuf); auto Error = raw_svector_ostream(ErrorBuf);
Error << E << '\0'; Error << E << '\0';
return ErrorCallback(Error.str().data()); return ErrorCallback(Error.str().data());
} }