[llvm-commits] [llvm] r137428 - /llvm/trunk/include/llvm/ADT/PointerUnion.h

Chris Lattner sabre at nondot.org
Thu Aug 11 21:31:39 PDT 2011


Author: lattner
Date: Thu Aug 11 23:31:38 2011
New Revision: 137428

URL: http://llvm.org/viewvc/llvm-project?rev=137428&view=rev
Log:
Fix an obscure bug in PointerUnion that would bite PointerUnion3/4.  Basically,
when checking isNull(), we'd pick off the sentinel bit for the outer 
PointerUnion, but would not recursively convert the inner pointerunion to bool,
so if *its* sentinel bit is set, isNull() would incorrectly return false.

No testcase, because someone hit this when they were trying to refactor code
to use PointerUnion3, but they since found a better solution.


Modified:
    llvm/trunk/include/llvm/ADT/PointerUnion.h

Modified: llvm/trunk/include/llvm/ADT/PointerUnion.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/PointerUnion.h?rev=137428&r1=137427&r2=137428&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/PointerUnion.h (original)
+++ llvm/trunk/include/llvm/ADT/PointerUnion.h Thu Aug 11 23:31:38 2011
@@ -108,7 +108,11 @@
     
     /// isNull - Return true if the pointer held in the union is null,
     /// regardless of which type it is.
-    bool isNull() const { return Val.getPointer() == 0; }
+    bool isNull() const {
+      // Convert from the void* to one of the pointer types, to make sure that
+      // we recursively strip off low bits if we have a nested PointerUnion.
+      return !PointerLikeTypeTraits<PT1>::getFromVoidPointer(Val.getPointer());
+    }
     operator bool() const { return !isNull(); }
 
     /// is<T>() return true if the Union currently holds the type matching T.





More information about the llvm-commits mailing list