[PATCH] D12805: [mips] Save a copy of MipsABIInfo in the MipsTargetStreamer to escape a dangling pointer
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 08:43:56 PDT 2015
atanasyan created this revision.
atanasyan added a reviewer: dsanders.
atanasyan added a subscriber: llvm-commits.
atanasyan set the repository for this revision to rL LLVM.
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.
Repository:
rL LLVM
http://reviews.llvm.org/D12805
Files:
lib/Target/Mips/MipsTargetStreamer.h
Index: lib/Target/Mips/MipsTargetStreamer.h
===================================================================
--- lib/Target/Mips/MipsTargetStreamer.h
+++ 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 @@
// structure values.
template <class PredicateLibrary>
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<MipsABIInfo> ABI;
MipsABIFlagsSection ABIFlagsSection;
bool GPRInfoSet;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12805.34551.patch
Type: text/x-patch
Size: 1043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150911/c677235e/attachment.bin>
More information about the llvm-commits
mailing list