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 Types, ArrayRef 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 Types, ArrayRef 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.