diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-08-23 22:08:27 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-08-23 22:08:27 +0000 |
commit | 8c3fbdc6c4649f8c3c018cf32be4407c672e574c (patch) | |
tree | 4b1501127fddc6956350b27ea9cba6d871ef28ed /llvm/lib/CodeGen/MachineModuleInfo.cpp | |
parent | d0cfb7344e101f656be024d29d9cd0aaefea4288 (diff) | |
download | llvm-8c3fbdc6c4649f8c3c018cf32be4407c672e574c.zip llvm-8c3fbdc6c4649f8c3c018cf32be4407c672e574c.tar.gz llvm-8c3fbdc6c4649f8c3c018cf32be4407c672e574c.tar.bz2 |
Revert r279564. It introduces undefined behavior (binding a reference to a
dereferenced null pointer) in MachineModuleInfo::MachineModuleInfo that causes
-Werror builds (including several buildbots) to fail.
llvm-svn: 279580
Diffstat (limited to 'llvm/lib/CodeGen/MachineModuleInfo.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineModuleInfo.cpp | 75 |
1 files changed, 5 insertions, 70 deletions
diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp index e5fc5cd..244e3fb 100644 --- a/llvm/lib/CodeGen/MachineModuleInfo.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -13,7 +13,6 @@ #include "llvm/Analysis/EHPersonalities.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/CodeGen/MachineFunction.h" -#include "llvm/CodeGen/MachineFunctionInitializer.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/Passes.h" #include "llvm/IR/Constants.h" @@ -187,19 +186,15 @@ void MMIAddrLabelMapCallbackPtr::allUsesReplacedWith(Value *V2) { //===----------------------------------------------------------------------===// -MachineModuleInfo::MachineModuleInfo(const TargetMachine &TM, - const MCAsmInfo &MAI, +MachineModuleInfo::MachineModuleInfo(const MCAsmInfo &MAI, const MCRegisterInfo &MRI, - const MCObjectFileInfo *MOFI, - MachineFunctionInitializer *MFI) - : ImmutablePass(ID), TM(TM), Context(&MAI, &MRI, MOFI, nullptr, false), - MFInitializer(MFI) { + const MCObjectFileInfo *MOFI) + : ImmutablePass(ID), Context(&MAI, &MRI, MOFI, nullptr, false) { initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry()); } MachineModuleInfo::MachineModuleInfo() - : ImmutablePass(ID), TM(*((TargetMachine*)nullptr)), - Context(nullptr, nullptr, nullptr) { + : ImmutablePass(ID), Context(nullptr, nullptr, nullptr) { llvm_unreachable("This MachineModuleInfo constructor should never be called, " "MMI should always be explicitly constructed by " "LLVMTargetMachine"); @@ -218,7 +213,7 @@ bool MachineModuleInfo::doInitialization(Module &M) { DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false; PersonalityTypeCache = EHPersonality::Unknown; AddrLabelSymbols = nullptr; - TheModule = &M; + TheModule = nullptr; return false; } @@ -466,63 +461,3 @@ try_next:; FilterIds.push_back(0); // terminator return FilterID; } - -MachineFunction &MachineModuleInfo::getMachineFunction(const Function &F) { - // Shortcut for the common case where a sequence of MachineFunctionPasses - // all query for the same Function. - if (LastRequest == &F) - return *LastResult; - - auto I = MachineFunctions.insert( - std::make_pair(&F, std::unique_ptr<MachineFunction>())); - MachineFunction *MF; - if (I.second) { - // No pre-existing machine function, create a new one. - MF = new MachineFunction(&F, TM, NextFnNum++, *this); - // Update the set entry. - I.first->second.reset(MF); - - if (MFInitializer) - if (MFInitializer->initializeMachineFunction(*MF)) - report_fatal_error("Unable to initialize machine function"); - } else { - MF = I.first->second.get(); - } - - LastRequest = &F; - LastResult = MF; - return *MF; -} - -void MachineModuleInfo::deleteMachineFunctionFor(Function &F) { - MachineFunctions.erase(&F); - LastRequest = nullptr; - LastResult = nullptr; -} - -namespace { -/// This pass frees the MachineFunction object associated with a Function. -class FreeMachineFunction : public FunctionPass { -public: - static char ID; - FreeMachineFunction() : FunctionPass(ID) {} - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequired<MachineModuleInfo>(); - AU.addPreserved<MachineModuleInfo>(); - } - - bool runOnFunction(Function &F) override { - MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>(); - MMI.deleteMachineFunctionFor(F); - return true; - } -}; -char FreeMachineFunction::ID; -} // end anonymous namespace - -namespace llvm { -FunctionPass *createFreeMachineFunctionPass() { - return new FreeMachineFunction(); -} -} // end namespace llvm |