Skip to content

Commit 9adcb4f

Browse files
[clang] Use llvm::replace (NFC) (#140264)
1 parent 589e7ab commit 9adcb4f

File tree

8 files changed

+18
-19
lines changed

8 files changed

+18
-19
lines changed

clang/include/clang/Basic/JsonSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ inline void printSourceLocationAsJson(raw_ostream &Out, SourceLocation Loc,
106106
return llvm::is_contained(ForbiddenChars, Char);
107107
});
108108
// Handle windows-specific path delimiters.
109-
std::replace(filename.begin(), filename.end(), '\\', '/');
109+
llvm::replace(filename, '\\', '/');
110110
}
111111
Out << "\"line\": " << PLoc.getLine()
112112
<< ", \"column\": " << PLoc.getColumn()

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
310310
// e.g. gfx10-1-generic -> gfx10_1_generic
311311
if (GPUKind >= llvm::AMDGPU::GK_AMDGCN_GENERIC_FIRST &&
312312
GPUKind <= llvm::AMDGPU::GK_AMDGCN_GENERIC_LAST) {
313-
std::replace(CanonName.begin(), CanonName.end(), '-', '_');
313+
llvm::replace(CanonName, '-', '_');
314314
}
315315

316316
Builder.defineMacro(Twine("__") + Twine(CanonName) + Twine("__"));
@@ -329,7 +329,7 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
329329
auto Loc = OffloadArchFeatures.find(F);
330330
if (Loc != OffloadArchFeatures.end()) {
331331
std::string NewF = F.str();
332-
std::replace(NewF.begin(), NewF.end(), '-', '_');
332+
llvm::replace(NewF, '-', '_');
333333
Builder.defineMacro(Twine("__amdgcn_feature_") + Twine(NewF) +
334334
Twine("__"),
335335
Loc->second ? "1" : "0");

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static std::string getBlockDescriptorName(const CGBlockInfo &BlockInfo,
126126
CGM.getContext().getObjCEncodingForBlock(BlockInfo.getBlockExpr());
127127
/// Replace occurrences of '@' with '\1'. '@' is reserved on ELF platforms
128128
/// as a separator between symbol name and symbol version.
129-
std::replace(TypeAtEncoding.begin(), TypeAtEncoding.end(), '@', '\1');
129+
llvm::replace(TypeAtEncoding, '@', '\1');
130130
}
131131
Name += "e" + llvm::to_string(TypeAtEncoding.size()) + "_" + TypeAtEncoding;
132132
Name += "l" + CGM.getObjCRuntime().getRCBlockLayoutStr(CGM, BlockInfo);

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,10 +1454,10 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
14541454
// character that is not a valid type encoding character (and, being
14551455
// non-printable, never will be!)
14561456
if (CGM.getTriple().isOSBinFormatELF())
1457-
std::replace(MangledTypes.begin(), MangledTypes.end(), '@', '\1');
1457+
llvm::replace(MangledTypes, '@', '\1');
14581458
// = in dll exported names causes lld to fail when linking on Windows.
14591459
if (CGM.getTriple().isOSWindows())
1460-
std::replace(MangledTypes.begin(), MangledTypes.end(), '=', '\2');
1460+
llvm::replace(MangledTypes, '=', '\2');
14611461
return MangledTypes;
14621462
}
14631463
llvm::Constant *GetTypeString(llvm::StringRef TypeEncoding) {

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6208,7 +6208,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
62086208
if (is_style_windows(llvm::sys::path::Style::native)) {
62096209
// BoundArch may contains ':', which is invalid in file names on Windows,
62106210
// therefore replace it with '%'.
6211-
std::replace(BoundArch.begin(), BoundArch.end(), ':', '@');
6211+
llvm::replace(BoundArch, ':', '@');
62126212
}
62136213

62146214
llvm::PrettyStackTraceString CrashInfo("Computing output path");

clang/lib/Driver/OffloadBundler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,8 +1906,7 @@ Error OffloadBundler::UnbundleArchive() {
19061906
.str();
19071907
// Replace ':' in optional target feature list with '_' to ensure
19081908
// cross-platform validity.
1909-
std::replace(OutputBundleName.begin(), OutputBundleName.end(), ':',
1910-
'_');
1909+
llvm::replace(OutputBundleName, ':', '_');
19111910

19121911
std::unique_ptr<MemoryBuffer> MemBuf = MemoryBuffer::getMemBufferCopy(
19131912
DataStream.str(), OutputBundleName);

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ RocmInstallationDetector::getInstallationPathCandidates() {
221221
std::string VerStr = DirName.drop_front(strlen("rocm-")).str();
222222
// The ROCm directory name follows the format of
223223
// rocm-{major}.{minor}.{subMinor}[-{build}]
224-
std::replace(VerStr.begin(), VerStr.end(), '-', '.');
224+
llvm::replace(VerStr, '-', '.');
225225
V.tryParse(VerStr);
226226
return V;
227227
};

clang/unittests/Driver/ToolChainTest.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ TEST(ToolChainTest, VFSGCCInstallation) {
9696
C->getDefaultToolChain().printVerboseInfo(OS);
9797
}
9898
if (is_style_windows(llvm::sys::path::Style::native))
99-
std::replace(S.begin(), S.end(), '\\', '/');
99+
llvm::replace(S, '\\', '/');
100100
EXPECT_EQ(
101101
"Found candidate GCC installation: "
102102
"/usr/lib/gcc/arm-linux-gnueabihf/4.6.3\n"
@@ -120,7 +120,7 @@ TEST(ToolChainTest, VFSGCCInstallation) {
120120
C->getDefaultToolChain().printVerboseInfo(OS);
121121
}
122122
if (is_style_windows(llvm::sys::path::Style::native))
123-
std::replace(S.begin(), S.end(), '\\', '/');
123+
llvm::replace(S, '\\', '/');
124124
// Test that 4.5.3 from --sysroot is not overridden by 4.6.3 (larger
125125
// version) from /usr.
126126
EXPECT_EQ("Found candidate GCC installation: "
@@ -162,7 +162,7 @@ TEST(ToolChainTest, VFSGCCInstallationRelativeDir) {
162162
C->getDefaultToolChain().printVerboseInfo(OS);
163163
}
164164
if (is_style_windows(llvm::sys::path::Style::native))
165-
std::replace(S.begin(), S.end(), '\\', '/');
165+
llvm::replace(S, '\\', '/');
166166
EXPECT_EQ("Found candidate GCC installation: "
167167
"/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n"
168168
"Selected GCC installation: "
@@ -213,7 +213,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
213213
C->getDefaultToolChain().printVerboseInfo(OS);
214214
}
215215
if (is_style_windows(llvm::sys::path::Style::native))
216-
std::replace(S.begin(), S.end(), '\\', '/');
216+
llvm::replace(S, '\\', '/');
217217
EXPECT_EQ("Found candidate GCC installation: "
218218
"/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
219219
"Selected GCC installation: "
@@ -237,7 +237,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
237237
C->getDefaultToolChain().printVerboseInfo(OS);
238238
}
239239
if (is_style_windows(llvm::sys::path::Style::native))
240-
std::replace(S.begin(), S.end(), '\\', '/');
240+
llvm::replace(S, '\\', '/');
241241
EXPECT_EQ("Found candidate GCC installation: "
242242
"/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
243243
"Selected GCC installation: "
@@ -261,7 +261,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
261261
C->getDefaultToolChain().printVerboseInfo(OS);
262262
}
263263
if (is_style_windows(llvm::sys::path::Style::native))
264-
std::replace(S.begin(), S.end(), '\\', '/');
264+
llvm::replace(S, '\\', '/');
265265
EXPECT_EQ("Found candidate GCC installation: "
266266
"/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
267267
"Selected GCC installation: "
@@ -285,7 +285,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
285285
C->getDefaultToolChain().printVerboseInfo(OS);
286286
}
287287
if (is_style_windows(llvm::sys::path::Style::native))
288-
std::replace(S.begin(), S.end(), '\\', '/');
288+
llvm::replace(S, '\\', '/');
289289
EXPECT_EQ("Found candidate GCC installation: "
290290
"/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0\n"
291291
"Selected GCC installation: "
@@ -308,7 +308,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
308308
C->getDefaultToolChain().printVerboseInfo(OS);
309309
}
310310
if (is_style_windows(llvm::sys::path::Style::native))
311-
std::replace(S.begin(), S.end(), '\\', '/');
311+
llvm::replace(S, '\\', '/');
312312
EXPECT_EQ("Found candidate GCC installation: "
313313
"/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0\n"
314314
"Selected GCC installation: "
@@ -329,7 +329,7 @@ MATCHER_P(jobHasArgs, Substr, "") {
329329
Args += Arg;
330330
}
331331
if (is_style_windows(llvm::sys::path::Style::native))
332-
std::replace(Args.begin(), Args.end(), '\\', '/');
332+
llvm::replace(Args, '\\', '/');
333333
if (llvm::StringRef(Args).contains(Substr))
334334
return true;
335335
*result_listener << "whose args are '" << Args << "'";

0 commit comments

Comments
 (0)