diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp index 5090a0559eab2..cb16fe1b36c68 100644 --- a/clang/lib/CodeGen/CGCUDANV.cpp +++ b/clang/lib/CodeGen/CGCUDANV.cpp @@ -94,7 +94,7 @@ class CGNVCUDARuntime : public CGCUDARuntime { /// where the C code specifies const char*. llvm::Constant *makeConstantString(const std::string &Str, const std::string &Name = "") { - return CGM.GetAddrOfConstantCString(Str, Name.c_str()).getPointer(); + return CGM.GetAddrOfConstantCString(Str, Name).getPointer(); } /// Helper function which generates an initialized constant array from Str, diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 26fba751e6f9d..e8456a44f8367 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3513,11 +3513,10 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) { CGM.getCXXABI().getMangleContext().getBlockId(BD, true); if (Discriminator) Name += "_" + Twine(Discriminator + 1).str(); - auto C = CGM.GetAddrOfConstantCString(Name, GVName.c_str()); + auto C = CGM.GetAddrOfConstantCString(Name, GVName); return MakeAddrLValue(C, E->getType(), AlignmentSource::Decl); } else { - auto C = - CGM.GetAddrOfConstantCString(std::string(FnName), GVName.c_str()); + auto C = CGM.GetAddrOfConstantCString(std::string(FnName), GVName); return MakeAddrLValue(C, E->getType(), AlignmentSource::Decl); } } diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index e4147de8fc639..06643d4bdc211 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -195,7 +195,7 @@ class CGObjCGNU : public CGObjCRuntime { /// Helper function that generates a constant string and returns a pointer to /// the start of the string. The result of this function can be used anywhere /// where the C code specifies const char*. - llvm::Constant *MakeConstantString(StringRef Str, const char *Name = "") { + llvm::Constant *MakeConstantString(StringRef Str, StringRef Name = "") { ConstantAddress Array = CGM.GetAddrOfConstantCString(std::string(Str), Name); return Array.getPointer(); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index f1ddaa875f3e4..c0cfc24f02877 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); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index b4b3a17662045..f62350fd8d378 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1186,9 +1186,8 @@ class CodeGenModule : public CodeGenTypeCache { /// /// \param GlobalName If provided, the name to use for the global (if one is /// created). - ConstantAddress - GetAddrOfConstantCString(const std::string &Str, - const char *GlobalName = nullptr); + ConstantAddress GetAddrOfConstantCString(const std::string &Str, + StringRef GlobalName = ".str"); /// Returns a pointer to a constant global variable for the given file-scope /// compound literal expression.