aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorChris B <chris.bieneman@me.com>2025-09-07 16:05:37 -0500
committerGitHub <noreply@github.com>2025-09-07 16:05:37 -0500
commit799d3466fa97e24082cb036e71a7a92f72597b4e (patch)
tree510834c86a7ad95ce0dffa1984531743d332a63d /clang/lib/CodeGen/CodeGenModule.cpp
parentc4d927ce09780ffed87c2f34c48d71c1abe42bac (diff)
downloadllvm-799d3466fa97e24082cb036e71a7a92f72597b4e.zip
llvm-799d3466fa97e24082cb036e71a7a92f72597b4e.tar.gz
llvm-799d3466fa97e24082cb036e71a7a92f72597b4e.tar.bz2
[NFC] Change const char* to StringRef (#154179)
This API takes a const char* with a default nullptr value and immdiately passes it down to an API taking a StringRef. All of the places this is called from are either using compile time string literals, the default argument, or string objects that have known length. Discarding the length known from a calling API to just have to strlen it to call the next layer down that requires a StringRef is a bit silly, so this change updates CodeGenModule::GetAddrOfConstantCString to use StringRef instead of const char* for the GlobalName parameter. It might be worth also replacing the first parameter with an llvm ADT type that avoids allocation, but that change would have wider impact so we should consider it separately.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp7
1 files changed, 2 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index f1ddaa8..c0cfc24 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6926,8 +6926,8 @@ CodeGenModule::GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *E) {
/// GetAddrOfConstantCString - Returns a pointer to a character array containing
/// the literal and a terminating '\0' character.
/// The result has pointer to array type.
-ConstantAddress CodeGenModule::GetAddrOfConstantCString(
- const std::string &Str, const char *GlobalName) {
+ConstantAddress CodeGenModule::GetAddrOfConstantCString(const std::string &Str,
+ StringRef GlobalName) {
StringRef StrWithNull(Str.c_str(), Str.size() + 1);
CharUnits Alignment = getContext().getAlignOfGlobalVarInChars(
getContext().CharTy, /*VD=*/nullptr);
@@ -6947,9 +6947,6 @@ ConstantAddress CodeGenModule::GetAddrOfConstantCString(
}
}
- // Get the default prefix if a name wasn't specified.
- if (!GlobalName)
- GlobalName = ".str";
// Create a global variable for this.
auto GV = GenerateStringLiteral(C, llvm::GlobalValue::PrivateLinkage, *this,
GlobalName, Alignment);