@@ -1235,7 +1235,9 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
12351235 bool IsChkVariant = false;
12361236
12371237 auto GetFunctionName = [&]() {
1238- StringRef FunctionName = getASTContext().BuiltinInfo.getName(BuiltinID);
1238+ std::string FunctionNameStr =
1239+ getASTContext().BuiltinInfo.getName(BuiltinID);
1240+ llvm::StringRef FunctionName = FunctionNameStr;
12391241 // Skim off the details of whichever builtin was called to produce a better
12401242 // diagnostic, as it's unlikely that the user wrote the __builtin
12411243 // explicitly.
@@ -1245,7 +1247,7 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
12451247 } else {
12461248 FunctionName.consume_front("__builtin_");
12471249 }
1248- return FunctionName;
1250+ return FunctionName.str() ;
12491251 };
12501252
12511253 switch (BuiltinID) {
@@ -1289,7 +1291,7 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
12891291 unsigned SourceSize) {
12901292 DiagID = diag::warn_fortify_scanf_overflow;
12911293 unsigned Index = ArgIndex + DataIndex;
1292- StringRef FunctionName = GetFunctionName();
1294+ std::string FunctionName = GetFunctionName();
12931295 DiagRuntimeBehavior(TheCall->getArg(Index)->getBeginLoc(), TheCall,
12941296 PDiag(DiagID) << FunctionName << (Index + 1)
12951297 << DestSize << SourceSize);
@@ -1438,7 +1440,7 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
14381440 llvm::APSInt::compareValues(*SourceSize, *DestinationSize) <= 0)
14391441 return;
14401442
1441- StringRef FunctionName = GetFunctionName();
1443+ std::string FunctionName = GetFunctionName();
14421444
14431445 SmallString<16> DestinationStr;
14441446 SmallString<16> SourceStr;
@@ -4546,7 +4548,7 @@ ExprResult Sema::BuiltinAtomicOverloaded(ExprResult TheCallResult) {
45464548 // Get the decl for the concrete builtin from this, we can tell what the
45474549 // concrete integer type we should convert to is.
45484550 unsigned NewBuiltinID = BuiltinIndices[BuiltinIndex][SizeIndex];
4549- StringRef NewBuiltinName = Context.BuiltinInfo.getName(NewBuiltinID);
4551+ std::string NewBuiltinName = Context.BuiltinInfo.getName(NewBuiltinID);
45504552 FunctionDecl *NewBuiltinDecl;
45514553 if (NewBuiltinID == BuiltinID)
45524554 NewBuiltinDecl = FDecl;
@@ -8332,7 +8334,7 @@ static void emitReplacement(Sema &S, SourceLocation Loc, SourceRange Range,
83328334 unsigned AbsKind, QualType ArgType) {
83338335 bool EmitHeaderHint = true;
83348336 const char *HeaderName = nullptr;
8335- StringRef FunctionName;
8337+ std::string FunctionName;
83368338 if (S.getLangOpts().CPlusPlus && !ArgType->isAnyComplexType()) {
83378339 FunctionName = "std::abs";
83388340 if (ArgType->isIntegralOrEnumerationType()) {
@@ -8481,7 +8483,7 @@ void Sema::CheckAbsoluteValueFunction(const CallExpr *Call,
84818483 // Unsigned types cannot be negative. Suggest removing the absolute value
84828484 // function call.
84838485 if (ArgType->isUnsignedIntegerType()) {
8484- StringRef FunctionName =
8486+ std::string FunctionName =
84858487 IsStdAbs ? "std::abs" : Context.BuiltinInfo.getName(AbsKind);
84868488 Diag(Call->getExprLoc(), diag::warn_unsigned_abs) << ArgType << ParamType;
84878489 Diag(Call->getExprLoc(), diag::note_remove_abs)
0 commit comments