summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/PointerUnion.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-08-12 04:31:38 +0000
committerChris Lattner <sabre@nondot.org>2011-08-12 04:31:38 +0000
commit823eb1ca11d684530048f1fe85a727aa1ef622d1 (patch)
tree398a5ff71bd0f1d14900b08fc23e3eaf4fcb2389 /include/llvm/ADT/PointerUnion.h
parent79d7de7650f20bb95aa5a4799e89e06fde57f005 (diff)
downloadllvm-823eb1ca11d684530048f1fe85a727aa1ef622d1.tar.gz
llvm-823eb1ca11d684530048f1fe85a727aa1ef622d1.tar.bz2
llvm-823eb1ca11d684530048f1fe85a727aa1ef622d1.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137428 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/PointerUnion.h')
-rw-r--r--include/llvm/ADT/PointerUnion.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/include/llvm/ADT/PointerUnion.h b/include/llvm/ADT/PointerUnion.h
index 13b98cef07..487096a171 100644
--- a/include/llvm/ADT/PointerUnion.h
+++ b/include/llvm/ADT/PointerUnion.h
@@ -108,7 +108,11 @@ namespace llvm {
/// 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.