<div dir="ltr">You can't get a different result because it's not really important what type you're getting. The type isn't exposed in the interface of this method. It's just checking that pointer is null. The type doesn't matter which is why the comment also says "one of the pointer types".</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 2, 2015 at 1:57 AM, Feng Lu via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</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"><div>Hi, All,</div><div> I am very interested in LLVM, and starting to learn from LLVM source code.</div><div> I encountered one problem that I cannot understand.</div><div><br></div><div> The part of the code is from  llvm/include/llvm/ADT/PointerUnion.h</div><div><br></div><div> class PointerUnion {PointerUnion.h<br>  public:<br>    typedef PointerIntPair<void*, 1, bool,<br>                           PointerUnionUIntTraits<PT1,PT2> > ValTy;<br>  private:<br>    ValTy Val;</div><div><br></div><div>    struct IsPT1 {<br>      static const int Num = 0;<br>    };<br>    struct IsPT2 {<br>      static const int Num = 1;<br>    };<br>    template <typename T><br>    struct UNION_DOESNT_CONTAIN_TYPE { };</div><div><br></div><div>  public:<br>    PointerUnion() {}</div><div><br></div><div>    PointerUnion(PT1 V) : Val(<br>      const_cast<void *>(PointerLikeTypeTraits<PT1>::getAsVoidPointer(V))) {<br>    }<br>    PointerUnion(PT2 V) : Val(<br>      const_cast<void *>(PointerLikeTypeTraits<PT2>::getAsVoidPointer(V)), 1) {<br>    }</div><div><br></div><div>    /// isNull - Return true if the pointer held in the union is null,<br>    /// regardless of which type it is.<br>    <font color="#ff0000">bool isNull() const {</font><br>      // Convert from the void* to one of the pointer types, to make sure that<br>      // we recursively strip off low bits if we have a nested PointerUnion.<br>      <font color="#ff0000">return !PointerLikeTypeTraits<PT1>::getFromVoidPointer(Val.getPointer());</font><br>    }<br></div><div> </div><div>What confusing me is the <font color="#ff0000"> isNull() </font><font color="#000000">function.</font></div><div><font color="#000000">Would it be possible to get different result if I use </font></div><div><font color="#000000">  </font><font color="#000000" style="background-color:rgb(255,255,255)">return !PointerLikeTypeTraits<<font color="#ff0000">PT2</font>>::getFromVoidPointer(Val.getPointer());</font></div><div><font color="#000000">instead of </font></div><font color="#000000"><div><font color="#000000">  </font><font color="#000000" style="background-color:rgb(255,255,255)">return !PointerLikeTypeTraits<<font color="#ff0000">PT1</font>>::getFromVoidPointer(Val.getPointer());</font></div></font><div><font color="#000000">  </font></div><div><font color="#000000">Thanks for your help.</font></div><span class="HOEnZb"><font color="#888888"><div><font color="#000000">Feng Lu</font></div><div><font color="#000000"></font><br></div></font></span></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>