r285799 - Fix Clang-tidy readability-redundant-string-cstr warnings
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 2 03:39:28 PDT 2016
Author: malcolm.parsons
Date: Wed Nov 2 05:39:27 2016
New Revision: 285799
URL: http://llvm.org/viewvc/llvm-project?rev=285799&view=rev
Log:
Fix Clang-tidy readability-redundant-string-cstr warnings
Reviewers: aaron.ballman, mehdi_amini, dblaikie
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D26206
Modified:
cfe/trunk/lib/ARCMigrate/FileRemapper.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/Job.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp
Modified: cfe/trunk/lib/ARCMigrate/FileRemapper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/FileRemapper.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/FileRemapper.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/FileRemapper.cpp Wed Nov 2 05:39:27 2016
@@ -64,7 +64,7 @@ bool FileRemapper::initFromFile(StringRe
std::vector<std::pair<const FileEntry *, const FileEntry *> > pairs;
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileBuf =
- llvm::MemoryBuffer::getFile(infoFile.c_str());
+ llvm::MemoryBuffer::getFile(infoFile);
if (!fileBuf)
return report("Error opening file: " + infoFile, Diag);
Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Nov 2 05:39:27 2016
@@ -2647,8 +2647,7 @@ llvm::Function *CGObjCGNU::ModuleInitFun
for (std::vector<ClassAliasPair>::iterator iter = ClassAliases.begin();
iter != ClassAliases.end(); ++iter) {
llvm::Constant *TheClass =
- TheModule.getGlobalVariable(("_OBJC_CLASS_" + iter->first).c_str(),
- true);
+ TheModule.getGlobalVariable("_OBJC_CLASS_" + iter->first, true);
if (TheClass) {
TheClass = llvm::ConstantExpr::getBitCast(TheClass, PtrTy);
Builder.CreateCall(RegisterAlias,
Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Nov 2 05:39:27 2016
@@ -7457,7 +7457,7 @@ class FieldEncoding {
std::string Enc;
public:
FieldEncoding(bool b, SmallStringEnc &e) : HasName(b), Enc(e.c_str()) {}
- StringRef str() {return Enc.c_str();}
+ StringRef str() { return Enc; }
bool operator<(const FieldEncoding &rhs) const {
if (HasName != rhs.HasName) return HasName;
return Enc < rhs.Enc;
@@ -7623,7 +7623,7 @@ StringRef TypeStringCache::lookupStr(con
E.State = IncompleteUsed;
++IncompleteUsedCount;
}
- return E.Str.c_str();
+ return E.Str;
}
/// The XCore ABI includes a type information section that communicates symbol
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Nov 2 05:39:27 2016
@@ -874,8 +874,7 @@ void Driver::setUpResponseFiles(Compilat
return;
std::string TmpName = GetTemporaryPath("response", "txt");
- Cmd.setResponseFile(
- C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str())));
+ Cmd.setResponseFile(C.addTempFile(C.getArgs().MakeArgString(TmpName)));
}
int Driver::ExecuteCompilation(
@@ -3295,7 +3294,7 @@ const char *Driver::GetNamedOutputPath(C
std::pair<StringRef, StringRef> Split = Name.split('.');
std::string TmpName = GetTemporaryPath(
Split.first, types::getTypeTempSuffix(JA.getType(), IsCLMode()));
- return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
+ return C.addTempFile(C.getArgs().MakeArgString(TmpName));
}
SmallString<128> BasePath(BaseInput);
@@ -3344,7 +3343,7 @@ const char *Driver::GetNamedOutputPath(C
NamedOutput = C.getArgs().MakeArgString(Output.c_str());
}
} else if (JA.getType() == types::TY_PCH && IsCLMode()) {
- NamedOutput = C.getArgs().MakeArgString(GetClPchPath(C, BaseName).c_str());
+ NamedOutput = C.getArgs().MakeArgString(GetClPchPath(C, BaseName));
} else {
const char *Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode());
assert(Suffix && "All types used for output should have a suffix.");
@@ -3394,7 +3393,7 @@ const char *Driver::GetNamedOutputPath(C
std::pair<StringRef, StringRef> Split = Name.split('.');
std::string TmpName = GetTemporaryPath(
Split.first, types::getTypeTempSuffix(JA.getType(), IsCLMode()));
- return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
+ return C.addTempFile(C.getArgs().MakeArgString(TmpName));
}
}
Modified: cfe/trunk/lib/Driver/Job.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Job.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Job.cpp (original)
+++ cfe/trunk/lib/Driver/Job.cpp Wed Nov 2 05:39:27 2016
@@ -182,7 +182,7 @@ void Command::Print(raw_ostream &OS, con
// Replace the input file name with the crashinfo's file name.
OS << ' ';
StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename);
- printArg(OS, ShortName.str().c_str(), Quote);
+ printArg(OS, ShortName.str(), Quote);
continue;
}
}
@@ -195,7 +195,7 @@ void Command::Print(raw_ostream &OS, con
OS << ' ';
printArg(OS, "-ivfsoverlay", Quote);
OS << ' ';
- printArg(OS, CrashInfo->VFSPath.str().c_str(), Quote);
+ printArg(OS, CrashInfo->VFSPath.str(), Quote);
// Insert -fmodules-cache-path and use the relative module directory
// <name>.cache/vfs/modules where we already dumped the modules.
@@ -207,7 +207,7 @@ void Command::Print(raw_ostream &OS, con
ModCachePath.append(RelModCacheDir.c_str());
OS << ' ';
- printArg(OS, ModCachePath.c_str(), Quote);
+ printArg(OS, ModCachePath, Quote);
}
if (ResponseFile != nullptr) {
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Nov 2 05:39:27 2016
@@ -10753,14 +10753,14 @@ void visualstudio::Linker::ConstructJob(
std::string UniversalCRTLibPath;
if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath))
CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
- UniversalCRTLibPath.c_str()));
+ UniversalCRTLibPath));
}
}
std::string WindowsSdkLibPath;
if (MSVC.getWindowsSDKLibraryPath(WindowsSdkLibPath))
- CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
- WindowsSdkLibPath.c_str()));
+ CmdArgs.push_back(
+ Args.MakeArgString(std::string("-libpath:") + WindowsSdkLibPath));
}
if (!C.getDriver().IsCLMode() && Args.hasArg(options::OPT_L))
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Nov 2 05:39:27 2016
@@ -1469,7 +1469,7 @@ static void ParseHeaderSearchArgs(Header
Path = Buffer.str();
}
- Opts.AddPath(Path.c_str(), Group, IsFramework,
+ Opts.AddPath(Path, Group, IsFramework,
/*IgnoreSysroot*/ true);
IsIndexHeaderMap = false;
}
Modified: cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp Wed Nov 2 05:39:27 2016
@@ -863,9 +863,9 @@ RewriteModernObjC::getIvarAccessString(O
CDecl = CatDecl->getClassInterface();
std::string RecName = CDecl->getName();
RecName += "_IMPL";
- RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl,
- SourceLocation(), SourceLocation(),
- &Context->Idents.get(RecName.c_str()));
+ RecordDecl *RD =
+ RecordDecl::Create(*Context, TTK_Struct, TUDecl, SourceLocation(),
+ SourceLocation(), &Context->Idents.get(RecName));
QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD));
unsigned UnsignedIntSize =
static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy));
@@ -5301,11 +5301,9 @@ Stmt *RewriteModernObjC::SynthBlockInitE
// Initialize the block descriptor.
std::string DescData = "__" + FuncName + "_block_desc_" + BlockNumber + "_DATA";
- VarDecl *NewVD = VarDecl::Create(*Context, TUDecl,
- SourceLocation(), SourceLocation(),
- &Context->Idents.get(DescData.c_str()),
- Context->VoidPtrTy, nullptr,
- SC_Static);
+ VarDecl *NewVD = VarDecl::Create(
+ *Context, TUDecl, SourceLocation(), SourceLocation(),
+ &Context->Idents.get(DescData), Context->VoidPtrTy, nullptr, SC_Static);
UnaryOperator *DescRefExpr =
new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, false,
Context->VoidPtrTy,
@@ -7522,9 +7520,9 @@ Stmt *RewriteModernObjC::RewriteObjCIvar
CDecl = CatDecl->getClassInterface();
std::string RecName = CDecl->getName();
RecName += "_IMPL";
- RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl,
- SourceLocation(), SourceLocation(),
- &Context->Idents.get(RecName.c_str()));
+ RecordDecl *RD = RecordDecl::Create(
+ *Context, TTK_Struct, TUDecl, SourceLocation(), SourceLocation(),
+ &Context->Idents.get(RecName));
QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD));
unsigned UnsignedIntSize =
static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy));
Modified: cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp Wed Nov 2 05:39:27 2016
@@ -4426,11 +4426,9 @@ Stmt *RewriteObjC::SynthBlockInitExpr(Bl
// Initialize the block descriptor.
std::string DescData = "__" + FuncName + "_block_desc_" + BlockNumber + "_DATA";
- VarDecl *NewVD = VarDecl::Create(*Context, TUDecl,
- SourceLocation(), SourceLocation(),
- &Context->Idents.get(DescData.c_str()),
- Context->VoidPtrTy, nullptr,
- SC_Static);
+ VarDecl *NewVD = VarDecl::Create(
+ *Context, TUDecl, SourceLocation(), SourceLocation(),
+ &Context->Idents.get(DescData), Context->VoidPtrTy, nullptr, SC_Static);
UnaryOperator *DescRefExpr =
new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, false,
Context->VoidPtrTy,
@@ -5650,14 +5648,12 @@ void RewriteObjCFragileABI::RewriteObjCC
InstanceMethods.push_back(Setter);
}
RewriteObjCMethodsMetaData(InstanceMethods.begin(), InstanceMethods.end(),
- true, "CATEGORY_", FullCategoryName.c_str(),
- Result);
-
+ true, "CATEGORY_", FullCategoryName, Result);
+
// Build _objc_method_list for class's class methods if needed
RewriteObjCMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(),
- false, "CATEGORY_", FullCategoryName.c_str(),
- Result);
-
+ false, "CATEGORY_", FullCategoryName, Result);
+
// Protocols referenced in class declaration?
// Null CDecl is case of a category implementation with no category interface
if (CDecl)
@@ -5776,7 +5772,7 @@ void RewriteObjCFragileABI::RewriteObjCM
Result += "{\n\t0, " + utostr(NumMethods) + "\n";
Result += "\t,{{(SEL)\"";
- Result += (*MethodBegin)->getSelector().getAsString().c_str();
+ Result += (*MethodBegin)->getSelector().getAsString();
std::string MethodTypeString;
Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString);
Result += "\", \"";
@@ -5786,7 +5782,7 @@ void RewriteObjCFragileABI::RewriteObjCM
Result += "}\n";
for (++MethodBegin; MethodBegin != MethodEnd; ++MethodBegin) {
Result += "\t ,{(SEL)\"";
- Result += (*MethodBegin)->getSelector().getAsString().c_str();
+ Result += (*MethodBegin)->getSelector().getAsString();
std::string MethodTypeString;
Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString);
Result += "\", \"";
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Nov 2 05:39:27 2016
@@ -2234,7 +2234,7 @@ void Parser::MaybeParseAndDiagnoseDeclSp
if (!(Function.TypeQuals & TypeQual)) {
std::string Name(FixItName);
Name += " ";
- Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name.c_str());
+ Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name);
Function.TypeQuals |= TypeQual;
*QualifierLoc = SpecLoc.getRawEncoding();
}
Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp Wed Nov 2 05:39:27 2016
@@ -106,7 +106,7 @@ getCheckerOptList(const AnalyzerOptions
SmallVector<CheckerOptInfo, 8> checkerOpts;
for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {
const std::pair<std::string, bool> &opt = opts.CheckersControlList[i];
- checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second));
+ checkerOpts.push_back(CheckerOptInfo(opt.first, opt.second));
}
return checkerOpts;
}
Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=285799&r1=285798&r2=285799&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Wed Nov 2 05:39:27 2016
@@ -71,8 +71,7 @@ testImport(const std::string &FromCode,
ToCtx.getSourceManager().getFileManager().getVirtualFileSystem().get());
vfs::InMemoryFileSystem *MFS = static_cast<vfs::InMemoryFileSystem *>(
OFS->overlays_begin()->get());
- MFS->addFile(InputFileName, 0,
- llvm::MemoryBuffer::getMemBuffer(FromCode.c_str()));
+ MFS->addFile(InputFileName, 0, llvm::MemoryBuffer::getMemBuffer(FromCode));
ASTImporter Importer(ToCtx, ToAST->getFileManager(),
FromCtx, FromAST->getFileManager(), false);
More information about the cfe-commits
mailing list