From 94580db32b5c117756527941f4cfdfe03fa079a1 Mon Sep 17 00:00:00 2001 From: Nuri Amari Date: Fri, 6 Jun 2025 14:44:02 -0700 Subject: [PATCH] [llvm-cgdata] Fix Dangling StringRefs `OutputFilename` and `Filename` are assigned to StringRefs in `parseArgs`, but after `parseArgs` returns the `InputArgsList` that once owned the underlying strings is popped off the stack, and the StringRefs can be left pointing at garbage. Switch to std::string to own the strings. --- llvm/tools/llvm-cgdata/llvm-cgdata.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/tools/llvm-cgdata/llvm-cgdata.cpp b/llvm/tools/llvm-cgdata/llvm-cgdata.cpp index 5c028311b06b5..98fa5c5657353 100644 --- a/llvm/tools/llvm-cgdata/llvm-cgdata.cpp +++ b/llvm/tools/llvm-cgdata/llvm-cgdata.cpp @@ -75,8 +75,8 @@ class CGDataOptTable : public opt::GenericOptTable { // Options static StringRef ToolName; -static StringRef OutputFilename = "-"; -static StringRef Filename; +static std::string OutputFilename = "-"; +static std::string Filename; static bool ShowCGDataVersion; static bool SkipTrim; static CGDataAction Action;