From 8620c3bae57ce32ff664718b854a9d4004d26ca2 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Mon, 14 Sep 2015 11:18:03 +0000 Subject: [PATCH] [mips] Save a copy of MipsABIInfo in the MipsTargetStreamer to escape a dangling pointer The MipsTargetELFStreamer can receive ABI info from many sources. For example, from the MipsAsmParser instance. Lifetime of the MipsAsmParser can be shorter than MipsTargetELFStreamer's lifetime. In that case we get a dangling pointer to MipsABIInfo. Differential Revision: http://reviews.llvm.org/D12805 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247546 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Mips/MipsTargetStreamer.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Target/Mips/MipsTargetStreamer.h b/lib/Target/Mips/MipsTargetStreamer.h index 6ce1be707d0..8e03caf50a0 100644 --- a/lib/Target/Mips/MipsTargetStreamer.h +++ b/lib/Target/Mips/MipsTargetStreamer.h @@ -12,6 +12,7 @@ #include "MCTargetDesc/MipsABIFlagsSection.h" #include "MCTargetDesc/MipsABIInfo.h" +#include "llvm/ADT/Optional.h" #include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCStreamer.h" @@ -97,18 +98,18 @@ public: // structure values. template void updateABIInfo(const PredicateLibrary &P) { - ABI = &P.getABI(); + ABI = P.getABI(); ABIFlagsSection.setAllFromPredicates(P); } MipsABIFlagsSection &getABIFlagsSection() { return ABIFlagsSection; } const MipsABIInfo &getABI() const { - assert(ABI && "ABI hasn't been set!"); + assert(ABI.hasValue() && "ABI hasn't been set!"); return *ABI; } protected: - const MipsABIInfo *ABI; + llvm::Optional ABI; MipsABIFlagsSection ABIFlagsSection; bool GPRInfoSet; -- 2.34.1