OSDN Git Service

Stop lying about pointers' required alignments.
authorTim Northover <tnorthover@apple.com>
Mon, 12 Dec 2016 23:29:07 +0000 (23:29 +0000)
committerTim Northover <tnorthover@apple.com>
Mon, 12 Dec 2016 23:29:07 +0000 (23:29 +0000)
These extra specializations were added in the depths of history (r67984 from
2009) and are clearly problematic now. The pointers actually are aligned to the
default (8 bytes), since otherwise UBsan would be complaining loudly.

I *think* it originally made sense because there was no "alignof" to infer the
correct value so the generic case went with what malloc returned (8-byte
aliged objects), and on 32-bit machines this specialization was correct. It
became wrong when we started compiling for 64-bit, and caused a UBSan failure
when we tried to put a ValueHandle into a DenseMap.

Should fix the Green Dragon UBSan bot.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289496 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Instruction.h
include/llvm/IR/Use.h
include/llvm/IR/Value.h
include/llvm/IR/ValueHandle.h

index e408bcb..fd7c54d 100644 (file)
@@ -599,21 +599,6 @@ private:
   Instruction *cloneImpl() const;
 };
 
-// Instruction* is only 4-byte aligned.
-template<>
-class PointerLikeTypeTraits<Instruction*> {
-  typedef Instruction* PT;
-
-public:
-  static inline void *getAsVoidPointer(PT P) { return P; }
-
-  static inline PT getFromVoidPointer(void *P) {
-    return static_cast<PT>(P);
-  }
-
-  enum { NumLowBitsAvailable = 2 };
-};
-
 } // end namespace llvm
 
 #endif // LLVM_IR_INSTRUCTION_H
index f1c3cbb..ff6b2e1 100644 (file)
@@ -36,18 +36,6 @@ class User;
 class Use;
 template <typename> struct simplify_type;
 
-// Use** is only 4-byte aligned.
-template <> class PointerLikeTypeTraits<Use **> {
-public:
-  static inline void *getAsVoidPointer(Use **P) { return P; }
-
-  static inline Use **getFromVoidPointer(void *P) {
-    return static_cast<Use **>(P);
-  }
-
-  enum { NumLowBitsAvailable = 2 };
-};
-
 /// \brief A Use represents the edge between a Value definition and its users.
 ///
 /// This is notionally a two-dimensional linked list. It supports traversing
index 94dd6a4..ac37a45 100644 (file)
@@ -793,21 +793,6 @@ template <> struct isa_impl<GlobalObject, Value> {
   }
 };
 
-// Value* is only 4-byte aligned.
-template<>
-class PointerLikeTypeTraits<Value*> {
-  typedef Value* PT;
-
-public:
-  static inline void *getAsVoidPointer(PT P) { return P; }
-
-  static inline PT getFromVoidPointer(void *P) {
-    return static_cast<PT>(P);
-  }
-
-  enum { NumLowBitsAvailable = 2 };
-};
-
 // Create wrappers for C Binding types (see CBindingWrapping.h).
 DEFINE_ISA_CONVERSION_FUNCTIONS(Value, LLVMValueRef)
 
index 3c28059..a4d4893 100644 (file)
@@ -22,17 +22,6 @@ namespace llvm {
 class ValueHandleBase;
 template<typename From> struct simplify_type;
 
-// ValueHandleBase** is only 4-byte aligned.
-template<>
-class PointerLikeTypeTraits<ValueHandleBase**> {
-public:
-  static inline void *getAsVoidPointer(ValueHandleBase** P) { return P; }
-  static inline ValueHandleBase **getFromVoidPointer(void *P) {
-    return static_cast<ValueHandleBase**>(P);
-  }
-  enum { NumLowBitsAvailable = 2 };
-};
-
 /// \brief This is the common base class of value handles.
 ///
 /// ValueHandle's are smart pointers to Value's that have special behavior when