@@ -18,7 +18,7 @@ type ExprGetElementPtr struct {
18
18
// Source address.
19
19
Src Constant
20
20
// Element indicies.
21
- Indices []* Index
21
+ Indices []Constant // *Int, *Vector or *Index
22
22
23
23
// extra.
24
24
@@ -31,7 +31,7 @@ type ExprGetElementPtr struct {
31
31
32
32
// NewGetElementPtr returns a new getelementptr expression based on the given
33
33
// source address and element indices.
34
- func NewGetElementPtr (src Constant , indices ... * Index ) * ExprGetElementPtr {
34
+ func NewGetElementPtr (src Constant , indices ... Constant ) * ExprGetElementPtr {
35
35
e := & ExprGetElementPtr {Src : src , Indices : indices }
36
36
// Compute type.
37
37
e .Type ()
@@ -96,7 +96,7 @@ func (e *ExprGetElementPtr) Simplify() Constant {
96
96
// Index is an index of a getelementptr constant expression.
97
97
type Index struct {
98
98
// Element index.
99
- Index Constant
99
+ Constant
100
100
101
101
// extra.
102
102
@@ -108,26 +108,30 @@ type Index struct {
108
108
109
109
// NewIndex returns a new gep element index.
110
110
func NewIndex (index Constant ) * Index {
111
- return & Index {Index : index }
111
+ return & Index {Constant : index }
112
112
}
113
113
114
114
// String returns a string representation of the getelementptr index.
115
115
func (index * Index ) String () string {
116
116
// OptInrange Type Constant
117
117
if index .InRange {
118
- return fmt .Sprintf ("inrange %s" , index .Index )
118
+ return fmt .Sprintf ("inrange %s" , index .Constant )
119
119
}
120
- return index .Index .String ()
120
+ return index .Constant .String ()
121
121
}
122
122
123
123
// ### [ Helper functions ] ####################################################
124
124
125
125
// gepType returns the pointer type or vector of pointers type to the element at
126
126
// the position in the type specified by the given indices, as calculated by the
127
127
// getelementptr instruction.
128
- func gepType (elemType types.Type , indices []* Index ) types.Type {
128
+ func gepType (elemType types.Type , indices []Constant ) types.Type {
129
129
e := elemType
130
130
for i , index := range indices {
131
+ // unpack inrange indices.
132
+ if idx , ok := index .(* Index ); ok {
133
+ index = idx .Constant
134
+ }
131
135
if i == 0 {
132
136
// Ignore checking the 0th index as it simply follows the pointer of
133
137
// src.
@@ -144,7 +148,7 @@ func gepType(elemType types.Type, indices []*Index) types.Type {
144
148
case * types.ArrayType :
145
149
e = t .ElemType
146
150
case * types.StructType :
147
- switch index := index .Index . (type ) {
151
+ switch index := index .(type ) {
148
152
case * Int :
149
153
e = t .Fields [index .X .Int64 ()]
150
154
case * Vector :
@@ -183,7 +187,12 @@ func gepType(elemType types.Type, indices []*Index) types.Type {
183
187
// %116 = bitcast i8** %115 to <2 x %struct.fileinfo*>*, !dbg !4738
184
188
// store <2 x %struct.fileinfo*> %113, <2 x %struct.fileinfo*>* %116, align 8, !dbg !4738, !tbaa !1793
185
189
if len (indices ) > 0 {
186
- if t , ok := indices [0 ].Index .Type ().(* types.VectorType ); ok {
190
+ index := indices [0 ]
191
+ // unpack inrange index.
192
+ if idx , ok := index .(* Index ); ok {
193
+ index = idx .Constant
194
+ }
195
+ if t , ok := index .Type ().(* types.VectorType ); ok {
187
196
return types .NewVector (t .Len , types .NewPointer (e ))
188
197
}
189
198
}
0 commit comments