Skip to content

Commit

Permalink
[mips] Save a copy of MipsABIInfo in the MipsTargetStreamer to escape…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
atanasyan committed Sep 14, 2015
1 parent fadc359 commit 8620c3b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/Target/Mips/MipsTargetStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -97,18 +98,18 @@ class MipsTargetStreamer : public MCTargetStreamer {
// 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;
Expand Down

0 comments on commit 8620c3b

Please sign in to comment.