diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h index c8464c1509fb..bd210e1abf31 100644 --- a/llvm/include/llvm/IR/BasicBlock.h +++ b/llvm/include/llvm/IR/BasicBlock.h @@ -337,8 +337,11 @@ public: bool isLandingPad() const; /// \brief Return the landingpad instruction associated with the landing pad. - LandingPadInst *getLandingPadInst(); const LandingPadInst *getLandingPadInst() const; + LandingPadInst *getLandingPadInst() { + return const_cast( + static_cast(this)->getLandingPadInst()); + } private: /// \brief Increment the internal refcount of the number of BlockAddresses diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h index b0bb81e9de15..c256b53e00a2 100644 --- a/llvm/include/llvm/IR/Instruction.h +++ b/llvm/include/llvm/IR/Instruction.h @@ -68,14 +68,20 @@ public: /// Note: this is undefined behavior if the instruction does not have a /// parent, or the parent basic block does not have a parent function. const Module *getModule() const; - Module *getModule(); + Module *getModule() { + return const_cast( + static_cast(this)->getModule()); + } /// Return the function this instruction belongs to. /// /// Note: it is undefined behavior to call this on an instruction not /// currently inserted into a function. const Function *getFunction() const; - Function *getFunction(); + Function *getFunction() { + return const_cast( + static_cast(this)->getFunction()); + } /// This method unlinks 'this' from the containing basic block, but does not /// delete it. diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp index 9047fb0cb7a0..90ca21ab91f8 100644 --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -429,9 +429,6 @@ bool BasicBlock::isLandingPad() const { } /// Return the landingpad instruction associated with the landing pad. -LandingPadInst *BasicBlock::getLandingPadInst() { - return dyn_cast(getFirstNonPHI()); -} const LandingPadInst *BasicBlock::getLandingPadInst() const { return dyn_cast(getFirstNonPHI()); } diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp index 8674342a88ae..d2114dc24af7 100644 --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -60,12 +60,6 @@ const Module *Instruction::getModule() const { return getParent()->getModule(); } -Module *Instruction::getModule() { - return getParent()->getModule(); -} - -Function *Instruction::getFunction() { return getParent()->getParent(); } - const Function *Instruction::getFunction() const { return getParent()->getParent(); }