diff options
author | Gabor Greif <ggreif@gmail.com> | 2008-10-16 15:33:02 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2008-10-16 15:33:02 +0000 |
commit | 023f84ecafa08a67101937ac80f0dfd9f5e69dfb (patch) | |
tree | 8831767019372b83349c401cfe91078e1b4b12d6 | |
parent | cc30d9caa5d4a7b7f08c33915d8c2f438a1d8c2b (diff) | |
download | external_llvm-023f84ecafa08a67101937ac80f0dfd9f5e69dfb.zip external_llvm-023f84ecafa08a67101937ac80f0dfd9f5e69dfb.tar.gz external_llvm-023f84ecafa08a67101937ac80f0dfd9f5e69dfb.tar.bz2 |
Introduce a typing refinenement on tagged data
using the 'volatile' qualifier. This should not have any operational consequences
on code, because tags should always be stripped off (giving a non-volatile pointer)
before dereferencing. The new qualification is there to catch some attempts to use
tagged pointers in a context where an untagged pointer is appropriate.
Notably this approach does not catch dereferencing of tagged pointers, but helps
in separating the two concepts a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57641 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Use.h | 10 | ||||
-rw-r--r-- | lib/VMCore/Use.cpp | 8 |
2 files changed, 8 insertions, 10 deletions
diff --git a/include/llvm/Use.h b/include/llvm/Use.h index d966703..f88d435 100644 --- a/include/llvm/Use.h +++ b/include/llvm/Use.h @@ -34,27 +34,27 @@ enum Tag { noTag, tagOne, tagTwo, tagThree }; /// addTag - insert tag bits into an (untagged) pointer template <typename T, typename TAG> -inline T *addTag(const T *P, TAG Tag) { +inline volatile T *addTag(const T *P, TAG Tag) { return reinterpret_cast<T*>(ptrdiff_t(P) | Tag); } /// stripTag - remove tag bits from a pointer, /// making it dereferencable template <ptrdiff_t MASK, typename T> -inline T *stripTag(const T *P) { +inline T *stripTag(const volatile T *P) { return reinterpret_cast<T*>(ptrdiff_t(P) & ~MASK); } /// extractTag - extract tag bits from a pointer template <typename TAG, TAG MASK, typename T> -inline TAG extractTag(const T *P) { +inline TAG extractTag(const volatile T *P) { return TAG(ptrdiff_t(P) & MASK); } /// transferTag - transfer tag bits from a pointer, /// to an untagged pointer template <ptrdiff_t MASK, typename T> -inline T *transferTag(const T *From, const T *To) { +inline volatile T *transferTag(const volatile T *From, const T *To) { return reinterpret_cast<T*>((ptrdiff_t(From) & MASK) | ptrdiff_t(To)); } @@ -126,7 +126,7 @@ private: static Use *initTags(Use *Start, Use *Stop, ptrdiff_t Done = 0); Value *Val; - Use *Next, **Prev; + Use *Next, *volatile*Prev; void setPrev(Use **NewPrev) { Prev = transferTag<fullStopTag>(Prev, NewPrev); diff --git a/lib/VMCore/Use.cpp b/lib/VMCore/Use.cpp index d96a0e5..5eadaad 100644 --- a/lib/VMCore/Use.cpp +++ b/lib/VMCore/Use.cpp @@ -127,7 +127,7 @@ void Use::zap(Use *Start, const Use *Stop, bool del) { //===----------------------------------------------------------------------===// struct AugmentedUse : Use { - User *ref; + volatile User *ref; AugmentedUse(); // not implemented }; @@ -138,12 +138,10 @@ struct AugmentedUse : Use { User *Use::getUser() const { const Use *End = getImpliedUser(); - User *She = static_cast<const AugmentedUse*>(End - 1)->ref; - She = extractTag<Tag, tagOne>(She) + volatile User *She = static_cast<const AugmentedUse*>(End - 1)->ref; + return extractTag<Tag, tagOne>(She) ? llvm::stripTag<tagOne>(She) : reinterpret_cast<User*>(const_cast<Use*>(End)); - - return She; } //===----------------------------------------------------------------------===// |