Fix StringRef conversion for LLVM 11 (777180a32b61070a10dd330b4f038bf24e916af1) (#3305)

This commit is contained in:
Fangrui Song 2020-01-31 17:52:35 -08:00 committed by GitHub
parent 97e0d978ee
commit 0a007a55f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 31 additions and 28 deletions

View file

@ -96,7 +96,7 @@ bool ConfigFile::locate(std::string &pathstr) {
{ \
sys::path::append(p, filename); \
if (sys::fs::exists(p.str())) { \
pathstr = p.str(); \
pathstr = {p.data(), p.size()}; \
return true; \
} \
}

View file

@ -37,29 +37,29 @@ const string &exe_path::getExePath() {
string exe_path::getBinDir() {
assert(!exePath.empty());
return path::parent_path(exePath);
return string(path::parent_path(exePath));
}
string exe_path::getBaseDir() {
string binDir = getBinDir();
assert(!binDir.empty());
return path::parent_path(binDir);
return string(path::parent_path(binDir));
}
string exe_path::getLibDir() {
llvm::SmallString<128> r(getBaseDir());
path::append(r, "lib" LDC_LIBDIR_SUFFIX);
return r.str();
return {r.data(), r.size()};
}
string exe_path::prependBinDir(const llvm::Twine &suffix) {
llvm::SmallString<128> r(getBinDir());
path::append(r, suffix);
return r.str();
return {r.data(), r.size()};
}
string exe_path::prependLibDir(const llvm::Twine &suffix) {
llvm::SmallString<128> r(getLibDir());
path::append(r, suffix);
return r.str();
return {r.data(), r.size()};
}

View file

@ -250,7 +250,7 @@ void appendFullLibPathCandidates(std::vector<std::string> &paths,
for (const char *dir : ConfigFile::instance.libDirs()) {
llvm::SmallString<128> candidate(dir);
llvm::sys::path::append(candidate, filename);
paths.push_back(candidate.str());
paths.emplace_back(candidate.data(), candidate.size());
}
// for backwards compatibility
@ -310,7 +310,7 @@ void ArgsBuilder::addASanLinkFlags(const llvm::Triple &triple) {
// Add the path to the resource dir to rpath to support using the shared
// lib from the default location without copying.
args.push_back("-rpath");
args.push_back(llvm::sys::path::parent_path(filepath));
args.push_back(std::string(llvm::sys::path::parent_path(filepath)));
}
return;
@ -508,7 +508,7 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
}
args.push_back("-o");
args.push_back(outputPath);
args.push_back(std::string(outputPath));
addSanitizers(*global.params.targetTriple);

View file

@ -60,7 +60,7 @@ void addLibIfFound(std::vector<std::string> &args, const llvm::Twine &name) {
llvm::SmallString<128> candidate(dir);
llvm::sys::path::append(candidate, name);
if (llvm::sys::fs::exists(candidate)) {
args.push_back(candidate.str());
args.emplace_back(candidate.data(), candidate.size());
return;
}
}

View file

@ -126,7 +126,7 @@ static std::string getOutputName() {
auto EC = llvm::sys::fs::createTemporaryFile(
result, extension ? extension : "", tempFilename);
if (!EC)
result = tempFilename.str();
result = {tempFilename.data(), tempFilename.size()};
} else if (extension) {
result += '.';
result += extension;

View file

@ -109,7 +109,7 @@ void printVersion(llvm::raw_ostream &OS) {
#endif
#endif
OS << " Default target: " << llvm::sys::getDefaultTargetTriple() << "\n";
std::string CPU = llvm::sys::getHostCPUName();
std::string CPU(llvm::sys::getHostCPUName());
if (CPU == "generic" || env::has("SOURCE_DATE_EPOCH")) {
// Env variable SOURCE_DATE_EPOCH indicates that a reproducible build is
// wanted. Don't print the actual host CPU in such an environment to aid
@ -564,7 +564,7 @@ void fixupUClibcEnv() {
llvm::Triple triple(mTargetTriple);
if (triple.getEnvironmentName().find("uclibc") != 0)
return;
std::string envName = triple.getEnvironmentName();
std::string envName(triple.getEnvironmentName());
envName.replace(0, 6, "gnu");
triple.setEnvironmentName(envName);
mTargetTriple = triple.normalize();

View file

@ -162,7 +162,7 @@ static std::string getX86TargetCPU(const llvm::Triple &triple) {
static std::string getARMTargetCPU(const llvm::Triple &triple) {
auto defaultCPU = llvm::ARM::getDefaultCPU(triple.getArchName());
if (!defaultCPU.empty())
return defaultCPU;
return std::string(defaultCPU);
// Return the most base CPU with thumb interworking supported by LLVM.
return (triple.getEnvironment() == llvm::Triple::GNUEABIHF) ? "arm1176jzf-s"
@ -172,7 +172,7 @@ static std::string getARMTargetCPU(const llvm::Triple &triple) {
static std::string getAArch64TargetCPU(const llvm::Triple &triple) {
auto defaultCPU = llvm::AArch64::getDefaultCPU(triple.getArchName());
if (!defaultCPU.empty())
return defaultCPU;
return std::string(defaultCPU);
return "generic";
}

View file

@ -362,7 +362,7 @@ void writeModule(llvm::Module *m, const char *filename) {
llvm::SmallString<128> buffer(filename);
llvm::sys::path::replace_extension(buffer,
llvm::StringRef(ext.ptr, ext.length));
return buffer.str();
return {buffer.data(), buffer.size()};
};
// write LLVM bitcode
@ -433,7 +433,7 @@ void writeModule(llvm::Module *m, const char *filename) {
if (!global.params.output_s) {
llvm::SmallString<16> buffer;
llvm::sys::fs::createUniqueFile("ldc-%%%%%%%.s", buffer);
spath = buffer.str();
spath = {buffer.data(), buffer.size()};
} else {
spath = replaceExtensionWith(global.s_ext);
}

View file

@ -9,6 +9,7 @@
#include "dmd/root/ctfloat.h"
#include "gen/llvm.h"
#include "llvm/Support/Error.h"
using llvm::APFloat;

View file

@ -204,10 +204,13 @@ void fixRtModule(llvm::Module &newModule,
// function, ignore
continue;
}
assert(!contains(thunkVar2func, it.second.thunkVar->getName()));
thunkVar2func.insert({it.second.thunkVar->getName(), it.first->getName()});
thunkFun2func.insert({it.second.thunkFunc->getName(), it.first->getName()});
externalFuncs.insert(it.first->getName());
assert(
!contains(thunkVar2func, std::string(it.second.thunkVar->getName())));
thunkVar2func.emplace(std::string(it.second.thunkVar->getName()),
it.first->getName());
thunkFun2func.emplace(std::string(it.second.thunkFunc->getName()),
it.first->getName());
externalFuncs.insert(std::string(it.first->getName()));
}
// Replace call to thunks in jitted code with direct calls to functions
@ -216,7 +219,7 @@ void fixRtModule(llvm::Module &newModule,
for (auto &op : instr.operands()) {
auto val = op.get();
if (auto callee = llvm::dyn_cast<llvm::Function>(val)) {
auto it = thunkFun2func.find(callee->getName());
auto it = thunkFun2func.find(std::string(callee->getName()));
if (thunkFun2func.end() != it) {
auto realFunc = newModule.getFunction(it->second);
assert(nullptr != realFunc);
@ -257,14 +260,14 @@ void removeFunctionsTargets(IRState *irs, llvm::Module &module) {
std::unordered_map<std::string, IrFunction *> funcMap;
for (auto &&fun : irs->targetCpuOrFeaturesOverridden) {
assert(nullptr != fun);
funcMap.insert({fun->getLLVMFunc()->getName(), fun});
funcMap.emplace(std::string(fun->getLLVMFunc()->getName()), fun);
}
for (auto &&fun : module.functions()) {
// Remove 'target-cpu' and 'target-features' attributes from all
// functions except when they are set explicitly by user.
// They will be set again by jitting lib to jit host values
auto it = funcMap.find(fun.getName());
auto it = funcMap.find(std::string(fun.getName()));
if (funcMap.end() != it) {
auto irFunc = it->second;
if (!irFunc->targetCpuOverridden) {

View file

@ -196,7 +196,7 @@ DValue *DtoInlineIRExpr(Loc &loc, FuncDeclaration *fdecl,
std::unique_ptr<llvm::Module> m =
llvm::parseAssemblyString(stream.str().c_str(), err, gIR->context());
std::string errstr = err.getMessage();
std::string errstr(err.getMessage());
if (!errstr.empty()) {
error(tinst->loc,
"can't parse inline LLVM IR:\n`%s`\n%s\n%s\nThe input string "

View file

@ -310,7 +310,7 @@ void applyAttrTarget(StructLiteralExp *sle, llvm::Function *func,
if (func->hasFnAttribute("target-features")) {
auto attr = func->getFnAttribute("target-features");
features.push_back(attr.getValueAsString());
features.push_back(std::string(attr.getValueAsString()));
}
llvm::SmallVector<llvm::StringRef, 4> fragments;

View file

@ -92,8 +92,7 @@ void enumModules(const RtCompileModuleList *modlist_head,
}
}
std::string decorate(const std::string &name,
const llvm::DataLayout &datalayout) {
std::string decorate(llvm::StringRef name, const llvm::DataLayout &datalayout) {
assert(!name.empty());
llvm::SmallVector<char, 64> ret;
llvm::Mangler::getNameWithPrefix(ret, name, datalayout);