1 # http://reviews.llvm.org/D10271 |
|
2 # Backported to 3.6.2. |
|
3 --- include/llvm/IR/DerivedTypes.h 2014-11-21 14:03:35.000000000 -0500 |
|
4 +++ include/llvm/IR/DerivedTypes.h 2015-08-23 17:27:29.355504909 -0400 |
|
5 @@ -140,7 +140,8 @@ |
|
6 return T->getTypeID() == FunctionTyID; |
|
7 } |
|
8 }; |
|
9 - |
|
10 +static_assert(AlignOf<FunctionType>::Alignment >= AlignOf<Type *>::Alignment, |
|
11 + "Insufficient alignment for objects appended to FunctionType"); |
|
12 |
|
13 /// CompositeType - Common super class of ArrayType, StructType, PointerType |
|
14 /// and VectorType. |
|
15 --- include/llvm/IR/User.h 2014-10-15 16:39:05.000000000 -0400 |
|
16 +++ include/llvm/IR/User.h 2015-08-23 17:27:29.365505148 -0400 |
|
17 @@ -22,6 +22,7 @@ |
|
18 #include "llvm/ADT/iterator.h" |
|
19 #include "llvm/ADT/iterator_range.h" |
|
20 #include "llvm/IR/Value.h" |
|
21 +#include "llvm/Support/AlignOf.h" |
|
22 #include "llvm/Support/ErrorHandling.h" |
|
23 |
|
24 namespace llvm { |
|
25 @@ -172,6 +173,11 @@ |
|
26 return isa<Instruction>(V) || isa<Constant>(V); |
|
27 } |
|
28 }; |
|
29 +// Either Use objects, or a Use pointer can be prepended to User. |
|
30 +static_assert(AlignOf<Use>::Alignment >= AlignOf<User>::Alignment, |
|
31 + "Insufficient alignment after objects prepended to User"); |
|
32 +static_assert(AlignOf<Use *>::Alignment >= AlignOf<User>::Alignment, |
|
33 + "Insufficient alignment after objects prepended to User"); |
|
34 |
|
35 template<> struct simplify_type<User::op_iterator> { |
|
36 typedef Value* SimpleType; |
|
37 --- include/llvm/Support/AlignOf.h 2014-01-08 22:28:55.000000000 -0500 |
|
38 +++ include/llvm/Support/AlignOf.h 2015-08-23 17:27:29.365505148 -0400 |
|
39 @@ -36,9 +36,18 @@ |
|
40 /// compile-time constant (e.g., for template instantiation). |
|
41 template <typename T> |
|
42 struct AlignOf { |
|
43 +#ifndef _MSC_VER |
|
44 + // Avoid warnings from GCC like: |
|
45 + // comparison between 'enum llvm::AlignOf<X>::<anonymous>' and 'enum |
|
46 + // llvm::AlignOf<Y>::<anonymous>' [-Wenum-compare] |
|
47 + // by using constexpr instead of enum. |
|
48 + // (except on MSVC, since it doesn't support constexpr yet). |
|
49 + static constexpr unsigned Alignment = |
|
50 + static_cast<unsigned int>(sizeof(AlignmentCalcImpl<T>) - sizeof(T)); |
|
51 +#else |
|
52 enum { Alignment = |
|
53 static_cast<unsigned int>(sizeof(AlignmentCalcImpl<T>) - sizeof(T)) }; |
|
54 - |
|
55 +#endif |
|
56 enum { Alignment_GreaterEqual_2Bytes = Alignment >= 2 ? 1 : 0 }; |
|
57 enum { Alignment_GreaterEqual_4Bytes = Alignment >= 4 ? 1 : 0 }; |
|
58 enum { Alignment_GreaterEqual_8Bytes = Alignment >= 8 ? 1 : 0 }; |
|
59 @@ -50,6 +59,10 @@ |
|
60 enum { Alignment_LessEqual_16Bytes = Alignment <= 16 ? 1 : 0 }; |
|
61 }; |
|
62 |
|
63 +#ifndef _MSC_VER |
|
64 +template <typename T> constexpr unsigned AlignOf<T>::Alignment; |
|
65 +#endif |
|
66 + |
|
67 /// alignOf - A templated function that returns the minimum alignment of |
|
68 /// of a type. This provides no extra functionality beyond the AlignOf |
|
69 /// class besides some cosmetic cleanliness. Example usage: |
|
70 --- lib/IR/AttributeImpl.h 2014-08-13 12:26:38.000000000 -0400 |
|
71 +++ lib/IR/AttributeImpl.h 2015-08-23 17:27:29.366505172 -0400 |
|
72 @@ -180,6 +180,9 @@ |
|
73 AttrList[I].Profile(ID); |
|
74 } |
|
75 }; |
|
76 +static_assert(AlignOf<AttributeSetNode>::Alignment >= |
|
77 + AlignOf<Attribute>::Alignment, |
|
78 + "Insufficient alignment for objects appended to AttributeSetNode"); |
|
79 |
|
80 //===----------------------------------------------------------------------===// |
|
81 /// \class |
|
82 @@ -188,9 +191,11 @@ |
|
83 class AttributeSetImpl : public FoldingSetNode { |
|
84 friend class AttributeSet; |
|
85 |
|
86 - LLVMContext &Context; |
|
87 - |
|
88 +public: |
|
89 typedef std::pair<unsigned, AttributeSetNode*> IndexAttrPair; |
|
90 + |
|
91 +private: |
|
92 + LLVMContext &Context; |
|
93 unsigned NumAttrs; ///< Number of entries in this set. |
|
94 |
|
95 /// \brief Return a pointer to the IndexAttrPair for the specified slot. |
|
96 @@ -205,6 +210,7 @@ |
|
97 AttributeSetImpl(LLVMContext &C, |
|
98 ArrayRef<std::pair<unsigned, AttributeSetNode *> > Attrs) |
|
99 : Context(C), NumAttrs(Attrs.size()) { |
|
100 + |
|
101 #ifndef NDEBUG |
|
102 if (Attrs.size() >= 2) { |
|
103 for (const std::pair<unsigned, AttributeSetNode *> *i = Attrs.begin() + 1, |
|
104 @@ -266,6 +272,9 @@ |
|
105 |
|
106 void dump() const; |
|
107 }; |
|
108 +static_assert(AlignOf<AttributeSetImpl>::Alignment >= |
|
109 + AlignOf<AttributeSetImpl::IndexAttrPair>::Alignment, |
|
110 + "Insufficient alignment for objects appended to AttributeSetImpl"); |
|
111 |
|
112 } // end llvm namespace |
|
113 |
|
114 --- lib/IR/User.cpp 2015-08-23 17:27:29.366505172 -0400 |
|
115 +++ lib/IR/User.cpp 2015-08-23 17:34:56.427494589 -0400 |
|
116 @@ -40,6 +40,11 @@ |
|
117 //===----------------------------------------------------------------------===// |
|
118 |
|
119 Use *User::allocHungoffUses(unsigned N) const { |
|
120 + static_assert(AlignOf<Use>::Alignment >= AlignOf<Use::UserRef>::Alignment, |
|
121 + "Insufficient alignment for hung-off-uses objects"); |
|
122 + static_assert(AlignOf<Use::UserRef>::Alignment >= |
|
123 + AlignOf<BasicBlock*>::Alignment, |
|
124 + "Insufficient alignment for hung-off-uses objects"); |
|
125 // Allocate the array of Uses, followed by a pointer (with bottom bit set) to |
|
126 // the User. |
|
127 size_t size = N * sizeof(Use) + sizeof(Use::UserRef); |
|