From 799d3466fa97e24082cb036e71a7a92f72597b4e Mon Sep 17 00:00:00 2001 From: Chris B Date: Sun, 7 Sep 2025 16:05:37 -0500 Subject: [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. --- clang/lib/CodeGen/CodeGenModule.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') 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); -- cgit v1.1