Fix Clang-tidy readability-redundant-string-cstr warnings

Reviewers: beanz, lattner, jlebar

Subscribers: jholewinski, llvm-commits, mehdi_amini

Differential Revision: https://reviews.llvm.org/D26235

llvm-svn: 285832
This commit is contained in:
Malcolm Parsons 2016-11-02 16:43:50 +00:00
parent b8292c3d65
commit 06ac79c210
13 changed files with 22 additions and 23 deletions

View File

@ -254,7 +254,7 @@ static llvm::AllocaInst *createEntryBlockAlloca(llvm::Function &function,
llvm::Constant *initWith = 0) {
llvm::BasicBlock &block = function.getEntryBlock();
llvm::IRBuilder<> tmp(&block, block.begin());
llvm::AllocaInst *ret = tmp.CreateAlloca(type, 0, varName.c_str());
llvm::AllocaInst *ret = tmp.CreateAlloca(type, 0, varName);
if (initWith)
tmp.CreateStore(initWith, ret);

View File

@ -1047,7 +1047,7 @@ bool MIParser::parseIRConstant(StringRef::iterator Loc, StringRef StringValue,
const Constant *&C) {
auto Source = StringValue.str(); // The source has to be null terminated.
SMDiagnostic Err;
C = parseConstantValue(Source.c_str(), Err, *MF.getFunction()->getParent(),
C = parseConstantValue(Source, Err, *MF.getFunction()->getParent(),
&PFS.IRSlots);
if (!C)
return error(Loc + Err.getColumnNo(), Err.getMessage());

View File

@ -614,7 +614,7 @@ bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
TAA, TAAParsed, StubSize);
if (!ErrorStr.empty())
return Error(Loc, ErrorStr.c_str());
return Error(Loc, ErrorStr);
// Issue a warning if the target is not powerpc and Section is a *coal* section.
Triple TT = getParser().getContext().getObjectFileInfo()->getTargetTriple();

View File

@ -422,7 +422,7 @@ void MachObjectWriter::writeLinkerOptionsLoadCommand(
uint64_t BytesWritten = sizeof(MachO::linker_option_command);
for (const std::string &Option : Options) {
// Write each string, including the null byte.
writeBytes(Option.c_str(), Option.size() + 1);
writeBytes(Option, Option.size() + 1);
BytesWritten += Option.size() + 1;
}

View File

@ -51,7 +51,7 @@ void MappingTraits<YamlObjectFile>::mapping(IO &IO,
else
IO.setError(
llvm::Twine("YAML Object File unsupported document type tag '") +
llvm::Twine(Tag.c_str()) + llvm::Twine("'!"));
llvm::Twine(Tag) + llvm::Twine("'!"));
}
}
}

View File

@ -1504,7 +1504,7 @@ bool HexagonAsmParser::OutOfRange(SMLoc IDLoc, long long Val, long long Max) {
ES << "0-" << Max;
else
ES << Max << "-" << (-Max - 1);
return Parser.printError(IDLoc, ES.str().c_str());
return Parser.printError(IDLoc, ES.str());
}
int HexagonAsmParser::processInstruction(MCInst &Inst,

View File

@ -80,7 +80,7 @@ static void addAsmInstr(MachineBasicBlock *MBB, unsigned Reg,
MachineFunction &Fn) {
std::string VDescStr = ".long 0x1dffe0" + getStringReg(Reg);
const char *cstr = Fn.createExternalSymbolName(VDescStr.c_str());
const char *cstr = Fn.createExternalSymbolName(VDescStr);
unsigned ExtraInfo = InlineAsm::Extra_HasSideEffects;
BuildMI(*MBB, I, DL, QII->get(TargetOpcode::INLINEASM))
.addExternalSymbol(cstr)

View File

@ -224,8 +224,7 @@ void NVPTXAsmPrinter::lowerImageHandleSymbol(unsigned Index, MCOperand &MCOp) {
const char *Sym = MFI->getImageHandleSymbol(Index);
std::string *SymNamePtr =
nvTM.getManagedStrPool()->getManagedString(Sym);
MCOp = GetSymbolRef(OutContext.getOrCreateSymbol(
StringRef(SymNamePtr->c_str())));
MCOp = GetSymbolRef(OutContext.getOrCreateSymbol(StringRef(*SymNamePtr)));
}
void NVPTXAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {

View File

@ -271,7 +271,7 @@ public:
return nullptr;
// Load the object from the cache filename
ErrorOr<std::unique_ptr<MemoryBuffer>> IRObjectBuffer =
MemoryBuffer::getFile(CacheName.c_str(), -1, false);
MemoryBuffer::getFile(CacheName, -1, false);
// If the file isn't there, that's OK.
if (!IRObjectBuffer)
return nullptr;

View File

@ -823,7 +823,7 @@ int main(int argc, char **argv) {
for (unsigned i = BaseArg; i < InputFilenames.size(); ++i) {
CurrentActivity = "loading file '" + InputFilenames[i] + "'";
ErrorOr<std::unique_ptr<LTOModule>> ModuleOrErr =
LTOModule::createFromFile(Context, InputFilenames[i].c_str(), Options);
LTOModule::createFromFile(Context, InputFilenames[i], Options);
std::unique_ptr<LTOModule> &Module = *ModuleOrErr;
CurrentActivity = "";
@ -851,11 +851,11 @@ int main(int argc, char **argv) {
// Add all the exported symbols to the table of symbols to preserve.
for (unsigned i = 0; i < ExportedSymbols.size(); ++i)
CodeGen.addMustPreserveSymbol(ExportedSymbols[i].c_str());
CodeGen.addMustPreserveSymbol(ExportedSymbols[i]);
// Add all the dso symbols to the table of symbols to expose.
for (unsigned i = 0; i < KeptDSOSyms.size(); ++i)
CodeGen.addMustPreserveSymbol(KeptDSOSyms[i].c_str());
CodeGen.addMustPreserveSymbol(KeptDSOSyms[i]);
// Set cpu and attrs strings for the default target/subtarget.
CodeGen.setCpu(MCPU.c_str());
@ -870,7 +870,7 @@ int main(int argc, char **argv) {
}
if (!attrs.empty())
CodeGen.setAttr(attrs.c_str());
CodeGen.setAttr(attrs);
if (FileType.getNumOccurrences())
CodeGen.setFileType(FileType);
@ -887,7 +887,7 @@ int main(int argc, char **argv) {
ModuleFilename += ".merged.bc";
std::string ErrMsg;
if (!CodeGen.writeMergedModules(ModuleFilename.c_str()))
if (!CodeGen.writeMergedModules(ModuleFilename))
error("writing merged module failed.");
}

View File

@ -153,7 +153,7 @@ static void lto_add_attrs(lto_code_gen_t cg) {
attrs.append(MAttrs[i]);
}
CG->setAttr(attrs.c_str());
CG->setAttr(attrs);
}
if (OptLevel < '0' || OptLevel > '3')

View File

@ -46,7 +46,7 @@ struct FunctionPassPrinter : public FunctionPass {
return false;
}
StringRef getPassName() const override { return PassName.c_str(); }
StringRef getPassName() const override { return PassName; }
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequiredID(PassToPrint->getTypeInfo());
@ -83,7 +83,7 @@ struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
return false;
}
StringRef getPassName() const override { return PassName.c_str(); }
StringRef getPassName() const override { return PassName; }
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequiredID(PassToPrint->getTypeInfo());
@ -115,7 +115,7 @@ struct ModulePassPrinter : public ModulePass {
return false;
}
StringRef getPassName() const override { return PassName.c_str(); }
StringRef getPassName() const override { return PassName; }
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequiredID(PassToPrint->getTypeInfo());
@ -148,7 +148,7 @@ struct LoopPassPrinter : public LoopPass {
return false;
}
StringRef getPassName() const override { return PassName.c_str(); }
StringRef getPassName() const override { return PassName; }
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequiredID(PassToPrint->getTypeInfo());
@ -183,7 +183,7 @@ struct RegionPassPrinter : public RegionPass {
return false;
}
StringRef getPassName() const override { return PassName.c_str(); }
StringRef getPassName() const override { return PassName; }
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequiredID(PassToPrint->getTypeInfo());
@ -217,7 +217,7 @@ struct BasicBlockPassPrinter : public BasicBlockPass {
return false;
}
StringRef getPassName() const override { return PassName.c_str(); }
StringRef getPassName() const override { return PassName; }
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequiredID(PassToPrint->getTypeInfo());

View File

@ -67,7 +67,7 @@ protected:
// If ARCH has sub-arch support, find it
SmallVectorImpl<std::string>::const_iterator I = SupportedSubArchs.begin();
for(; I != SupportedSubArchs.end(); ++I)
if (Host.getArchName().startswith(I->c_str()))
if (Host.getArchName().startswith(*I))
return true;
return false;