<div dir="ltr">Why would const_casting the Module * result in your formulation not also be a problem?</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br><div class="gmail_quote">On Mon, Jan 23, 2017 at 9:36 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 21, 2017 at 11:04 PM Craig Topper via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ctopper<br class="m_-4422342111502564595gmail_msg">
Date: Sun Jan 22 00:53:04 2017<br class="m_-4422342111502564595gmail_msg">
New Revision: 292753<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=292753&view=rev" rel="noreferrer" class="m_-4422342111502564595gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=292753&view=rev</a><br class="m_-4422342111502564595gmail_msg">
Log:<br class="m_-4422342111502564595gmail_msg">
[IR] Use const_cast to reuse the const version of two BasicBlock methods that are duplicated for both const and non-const. NFC<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
Similar is already done for other methods in BasicBlock.<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
Modified:<br class="m_-4422342111502564595gmail_msg">
    llvm/trunk/include/llvm/IR/<wbr>BasicBlock.h<br class="m_-4422342111502564595gmail_msg">
    llvm/trunk/lib/IR/BasicBlock.<wbr>cpp<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
Modified: llvm/trunk/include/llvm/IR/<wbr>BasicBlock.h<br class="m_-4422342111502564595gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/BasicBlock.h?rev=292753&r1=292752&r2=292753&view=diff" rel="noreferrer" class="m_-4422342111502564595gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/IR/BasicBlock.h?rev=<wbr>292753&r1=292752&r2=292753&<wbr>view=diff</a><br class="m_-4422342111502564595gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_-4422342111502564595gmail_msg">
--- llvm/trunk/include/llvm/IR/<wbr>BasicBlock.h (original)<br class="m_-4422342111502564595gmail_msg">
+++ llvm/trunk/include/llvm/IR/<wbr>BasicBlock.h Sun Jan 22 00:53:04 2017<br class="m_-4422342111502564595gmail_msg">
@@ -104,13 +104,17 @@ public:<br class="m_-4422342111502564595gmail_msg">
   /// or nullptr it the function does not have a module.<br class="m_-4422342111502564595gmail_msg">
   ///<br class="m_-4422342111502564595gmail_msg">
   /// Note: this is undefined behavior if the block does not have a parent.<br class="m_-4422342111502564595gmail_msg">
-  const Module *getModule() const;<br class="m_-4422342111502564595gmail_msg">
   Module *getModule();<br class="m_-4422342111502564595gmail_msg">
+  const Module *getModule() const {<br class="m_-4422342111502564595gmail_msg">
+    return const_cast<BasicBlock *>(this)->getModule();<br class="m_-4422342111502564595gmail_msg"></blockquote><div><br></div><div>I think this is technically UB if the BasicBlock were actually const (though I suppose we don't have any of those)<br><br>But the opposite formulation - implementing the non-const version in terms of the const one, doesn't have that problem:<br><br>  Module *getModule() {</div><div>    return const_cast<Module*>(implicit_<wbr>cast<const BasicBlock*>(this)->getModule(<wbr>));</div><div>  }<br><br>(I don't think we have an implicit_cast template - we could add one, but don't necessarily have to for this example/case)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  }<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
   /// \brief Returns the terminator instruction if the block is well formed or<br class="m_-4422342111502564595gmail_msg">
   /// null if the block is not well formed.<br class="m_-4422342111502564595gmail_msg">
   TerminatorInst *getTerminator();<br class="m_-4422342111502564595gmail_msg">
-  const TerminatorInst *getTerminator() const;<br class="m_-4422342111502564595gmail_msg">
+  const TerminatorInst *getTerminator() const {<br class="m_-4422342111502564595gmail_msg">
+    return const_cast<BasicBlock *>(this)->getTerminator();<br class="m_-4422342111502564595gmail_msg">
+  }<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
   /// \brief Returns the call instruction calling @llvm.experimental.deoptimize<br class="m_-4422342111502564595gmail_msg">
   /// prior to the terminating return instruction of this basic block, if such a<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
Modified: llvm/trunk/lib/IR/BasicBlock.<wbr>cpp<br class="m_-4422342111502564595gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/BasicBlock.cpp?rev=292753&r1=292752&r2=292753&view=diff" rel="noreferrer" class="m_-4422342111502564595gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/IR/<wbr>BasicBlock.cpp?rev=292753&r1=<wbr>292752&r2=292753&view=diff</a><br class="m_-4422342111502564595gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_-4422342111502564595gmail_msg">
--- llvm/trunk/lib/IR/BasicBlock.<wbr>cpp (original)<br class="m_-4422342111502564595gmail_msg">
+++ llvm/trunk/lib/IR/BasicBlock.<wbr>cpp Sun Jan 22 00:53:04 2017<br class="m_-4422342111502564595gmail_msg">
@@ -113,10 +113,6 @@ void BasicBlock::moveAfter(<wbr>BasicBlock *M<br class="m_-4422342111502564595gmail_msg">
       getIterator());<br class="m_-4422342111502564595gmail_msg">
 }<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
-const Module *BasicBlock::getModule() const {<br class="m_-4422342111502564595gmail_msg">
-  return getParent()->getParent();<br class="m_-4422342111502564595gmail_msg">
-}<br class="m_-4422342111502564595gmail_msg">
-<br class="m_-4422342111502564595gmail_msg">
 Module *BasicBlock::getModule() {<br class="m_-4422342111502564595gmail_msg">
   return getParent()->getParent();<br class="m_-4422342111502564595gmail_msg">
 }<br class="m_-4422342111502564595gmail_msg">
@@ -125,11 +121,6 @@ TerminatorInst *BasicBlock::getTerminato<br class="m_-4422342111502564595gmail_msg">
   if (InstList.empty()) return nullptr;<br class="m_-4422342111502564595gmail_msg">
   return dyn_cast<TerminatorInst>(&<wbr>InstList.back());<br class="m_-4422342111502564595gmail_msg">
 }<br class="m_-4422342111502564595gmail_msg">
-<br class="m_-4422342111502564595gmail_msg">
-const TerminatorInst *BasicBlock::getTerminator() const {<br class="m_-4422342111502564595gmail_msg">
-  if (InstList.empty()) return nullptr;<br class="m_-4422342111502564595gmail_msg">
-  return dyn_cast<TerminatorInst>(&<wbr>InstList.back());<br class="m_-4422342111502564595gmail_msg">
-}<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
 CallInst *BasicBlock::<wbr>getTerminatingMustTailCall() {<br class="m_-4422342111502564595gmail_msg">
   if (InstList.empty())<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
<br class="m_-4422342111502564595gmail_msg">
______________________________<wbr>_________________<br class="m_-4422342111502564595gmail_msg">
llvm-commits mailing list<br class="m_-4422342111502564595gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="m_-4422342111502564595gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="m_-4422342111502564595gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="m_-4422342111502564595gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br class="m_-4422342111502564595gmail_msg">
</blockquote></div></div>
</blockquote></div><br></div>