[llvm] 45d9079 - [NFC][IR] Avoid string leak with target extension types.
Joshua Cranmer via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 5 13:55:21 PST 2023
Author: Joshua Cranmer
Date: 2023-01-05T16:53:55-05:00
New Revision: 45d9079f7c3248b3ffb2a73a78028900737c66d3
URL: https://github.com/llvm/llvm-project/commit/45d9079f7c3248b3ffb2a73a78028900737c66d3
DIFF: https://github.com/llvm/llvm-project/commit/45d9079f7c3248b3ffb2a73a78028900737c66d3.diff
LOG: [NFC][IR] Avoid string leak with target extension types.
Reviewed By: nikic, hctim
Differential Revision: https://reviews.llvm.org/D141083
Added:
Modified:
llvm/include/llvm/IR/DerivedTypes.h
llvm/lib/IR/Type.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h
index 3ebe51e5d19d9..85a41c8dcc850 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -740,7 +740,8 @@ class TargetExtType : public Type {
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:
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 291f4f968a257..8d28522c22c40 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -793,7 +793,7 @@ bool PointerType::isLoadableOrStorableType(Type *ElemTy) {
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.
More information about the llvm-commits
mailing list