[PATCH] D141083: [NFC][IR] Avoid string leak with target extension types.

Joshua Cranmer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 5 12:55:06 PST 2023


jcranmer-intel created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
jcranmer-intel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141083

Files:
  llvm/include/llvm/IR/DerivedTypes.h
  llvm/lib/IR/Type.cpp


Index: llvm/lib/IR/Type.cpp
===================================================================
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -793,7 +793,7 @@
 
 TargetExtType::TargetExtType(LLVMContext &C, StringRef Name,
                              ArrayRef<Type *> Types, ArrayRef<unsigned> Ints)
-    : Type(C, TargetExtTyID), Name(Name) {
+    : Type(C, TargetExtTyID), Name(C.pImpl->Saver.save(Name)) {
   NumContainedTys = Types.size();
 
   // Parameter storage immediately follows the class in allocation.
Index: llvm/include/llvm/IR/DerivedTypes.h
===================================================================
--- llvm/include/llvm/IR/DerivedTypes.h
+++ llvm/include/llvm/IR/DerivedTypes.h
@@ -740,7 +740,8 @@
   TargetExtType(LLVMContext &C, StringRef Name, ArrayRef<Type *> Types,
                 ArrayRef<unsigned> Ints);
 
-  std::string Name;
+  // These strings are ultimately owned by the context.
+  StringRef Name;
   unsigned *IntParams;
 
 public:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141083.486653.patch
Type: text/x-patch
Size: 985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230105/f445ec39/attachment.bin>


More information about the llvm-commits mailing list