Index: include/llvm/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -84,11 +84,10 @@ CodeGenOpt::Level OptLevel = CodeGenOpt::Default; /// Contains target specific asm information. - const MCAsmInfo *AsmInfo; - - const MCRegisterInfo *MRI; - const MCInstrInfo *MII; - const MCSubtargetInfo *STI; + std::unique_ptr AsmInfo; + std::unique_ptr MRI; + std::unique_ptr MII; + std::unique_ptr STI; unsigned RequireStructuredCFG : 1; unsigned O0WantsFastISel : 1; @@ -160,11 +159,11 @@ void resetTargetOptions(const Function &F) const; /// Return target specific asm information. - const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; } + const MCAsmInfo *getMCAsmInfo() const { return AsmInfo.get(); } - const MCRegisterInfo *getMCRegisterInfo() const { return MRI; } - const MCInstrInfo *getMCInstrInfo() const { return MII; } - const MCSubtargetInfo *getMCSubtargetInfo() const { return STI; } + const MCRegisterInfo *getMCRegisterInfo() const { return MRI.get(); } + const MCInstrInfo *getMCInstrInfo() const { return MII.get(); } + const MCSubtargetInfo *getMCSubtargetInfo() const { return STI.get(); } /// If intrinsic information is available, return it. If not, return null. virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { Index: lib/CodeGen/LLVMTargetMachine.cpp =================================================================== --- lib/CodeGen/LLVMTargetMachine.cpp +++ lib/CodeGen/LLVMTargetMachine.cpp @@ -40,14 +40,14 @@ cl::desc("Enable generating trap for unreachable")); void LLVMTargetMachine::initAsmInfo() { - MRI = TheTarget.createMCRegInfo(getTargetTriple().str()); - MII = TheTarget.createMCInstrInfo(); + MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str())); + MII.reset(TheTarget.createMCInstrInfo()); // FIXME: Having an MCSubtargetInfo on the target machine is a hack due // to some backends having subtarget feature dependent module level // code generation. This is similar to the hack in the AsmPrinter for // module level assembly etc. - STI = TheTarget.createMCSubtargetInfo(getTargetTriple().str(), getTargetCPU(), - getTargetFeatureString()); + STI.reset(TheTarget.createMCSubtargetInfo( + getTargetTriple().str(), getTargetCPU(), getTargetFeatureString())); MCAsmInfo *TmpAsmInfo = TheTarget.createMCAsmInfo(*MRI, getTargetTriple().str()); @@ -71,7 +71,7 @@ if (Options.ExceptionModel != ExceptionHandling::None) TmpAsmInfo->setExceptionsType(Options.ExceptionModel); - AsmInfo = TmpAsmInfo; + AsmInfo.reset(TmpAsmInfo); } LLVMTargetMachine::LLVMTargetMachine(const Target &T, Index: lib/Target/BPF/BPFTargetMachine.cpp =================================================================== --- lib/Target/BPF/BPFTargetMachine.cpp +++ lib/Target/BPF/BPFTargetMachine.cpp @@ -70,7 +70,8 @@ Subtarget(TT, CPU, FS, *this) { initAsmInfo(); - BPFMCAsmInfo *MAI = static_cast(const_cast(AsmInfo)); + BPFMCAsmInfo *MAI = + static_cast(const_cast(AsmInfo.get())); MAI->setDwarfUsesRelocationsAcrossSections(!Subtarget.getUseDwarfRIS()); } namespace { Index: lib/Target/TargetMachine.cpp =================================================================== --- lib/Target/TargetMachine.cpp +++ lib/Target/TargetMachine.cpp @@ -40,12 +40,7 @@ RequireStructuredCFG(false), DefaultOptions(Options), Options(Options) { } -TargetMachine::~TargetMachine() { - delete AsmInfo; - delete MRI; - delete MII; - delete STI; -} +TargetMachine::~TargetMachine() = default; bool TargetMachine::isPositionIndependent() const { return getRelocationModel() == Reloc::PIC_;