|
25 | 25 |
|
26 | 26 | namespace clang::CIRGen {
|
27 | 27 |
|
| 28 | +// Forward declaration to avoid a circular dependency |
| 29 | +class CIRGenBuilderTy; |
| 30 | + |
28 | 31 | // Indicates whether a pointer is known not to be null.
|
29 | 32 | enum KnownNonNull_t { NotKnownNonNull, KnownNonNull };
|
30 | 33 |
|
@@ -64,6 +67,9 @@ class Address {
|
64 | 67 | assert(pointer && "Pointer cannot be null");
|
65 | 68 | assert(elementType && "Element type cannot be null");
|
66 | 69 | assert(!alignment.isZero() && "Alignment cannot be zero");
|
| 70 | + |
| 71 | + assert(mlir::cast<cir::PointerType>(pointer.getType()).getPointee() == |
| 72 | + ElementType); |
67 | 73 | }
|
68 | 74 |
|
69 | 75 | Address(mlir::Value basePtr, mlir::Type elementType,
|
@@ -104,15 +110,9 @@ class Address {
|
104 | 110 |
|
105 | 111 | bool hasOffset() const { return bool(offset); }
|
106 | 112 |
|
107 |
| - /// Return address with different element type, but same pointer and |
108 |
| - /// alignment. |
109 |
| - Address withElementType(mlir::Type ElemTy) const { |
110 |
| - if (!hasOffset()) |
111 |
| - return Address(getBasePointer(), ElemTy, getAlignment(), |
112 |
| - getPointerAuthInfo(), /*Offset=*/nullptr, |
113 |
| - isKnownNonNull()); |
114 |
| - return Address(getPointer(), ElemTy, getAlignment(), isKnownNonNull()); |
115 |
| - } |
| 113 | + /// Return address with different element type, a bitcast pointer, and |
| 114 | + /// the same alignment. |
| 115 | + Address withElementType(CIRGenBuilderTy &builder, mlir::Type ElemTy) const; |
116 | 116 |
|
117 | 117 | mlir::Value getPointer() const {
|
118 | 118 | assert(isValid());
|
@@ -142,11 +142,17 @@ class Address {
|
142 | 142 |
|
143 | 143 | /// Return the type of the pointer value.
|
144 | 144 | cir::PointerType getType() const {
|
| 145 | + assert(mlir::cast<cir::PointerType>( |
| 146 | + PointerAndKnownNonNull.getPointer().getType()) |
| 147 | + .getPointee() == ElementType); |
145 | 148 | return mlir::cast<cir::PointerType>(getPointer().getType());
|
146 | 149 | }
|
147 | 150 |
|
148 | 151 | mlir::Type getElementType() const {
|
149 | 152 | assert(isValid());
|
| 153 | + assert(mlir::cast<cir::PointerType>( |
| 154 | + PointerAndKnownNonNull.getPointer().getType()) |
| 155 | + .getPointee() == ElementType); |
150 | 156 | return ElementType;
|
151 | 157 | }
|
152 | 158 |
|
|
0 commit comments