@@ -275,6 +275,8 @@ func (b *builder) zeroUndefBytes(llvmType llvm.Type, ptr llvm.Value) error {
275
275
// we handle nested types. Next, we determine if there are any padding bytes before the next
276
276
// element and zero those as well.
277
277
278
+ zero := llvm .ConstInt (b .ctx .Int32Type (), 0 , false )
279
+
278
280
switch llvmType .TypeKind () {
279
281
case llvm .IntegerTypeKind :
280
282
// no padding bytes
@@ -286,9 +288,11 @@ func (b *builder) zeroUndefBytes(llvmType llvm.Type, ptr llvm.Value) error {
286
288
llvmArrayType := llvmType
287
289
llvmElemType := llvmType .ElementType ()
288
290
291
+ zero := llvm .ConstInt (b .ctx .Int32Type (), 0 , false )
292
+
289
293
for i := 0 ; i < llvmArrayType .ArrayLength (); i ++ {
290
294
idx := llvm .ConstInt (b .uintptrType , uint64 (i ), false )
291
- elemPtr := b .CreateGEP (llvmArrayType , ptr , []llvm.Value {idx }, "" )
295
+ elemPtr := b .CreateInBoundsGEP (llvmArrayType , ptr , []llvm.Value {zero , idx }, "" )
292
296
293
297
// zero any padding bytes in this element
294
298
b .zeroUndefBytes (llvmElemType , elemPtr )
@@ -300,21 +304,22 @@ func (b *builder) zeroUndefBytes(llvmType llvm.Type, ptr llvm.Value) error {
300
304
llvmElementTypes := llvmStructType .StructElementTypes ()
301
305
302
306
for i := 0 ; i < llvmStructType .StructElementTypesCount (); i ++ {
303
- offset := b .targetData .ElementOffset (llvmStructType , i )
304
- llvmOffset := llvm .ConstInt (b .uintptrType , offset , false )
305
- elemPtr := b .CreateGEP (b .ctx .Int8Type (), ptr , []llvm.Value {llvmOffset }, "" )
307
+ idx := llvm .ConstInt (b .ctx .Int32Type (), uint64 (i ), false )
308
+ elemPtr := b .CreateInBoundsGEP (llvmType , ptr , []llvm.Value {zero , idx }, "" )
306
309
307
310
// zero any padding bytes in this field
308
311
llvmElemType := llvmElementTypes [i ]
309
312
b .zeroUndefBytes (llvmElemType , elemPtr )
310
313
311
314
// zero any padding bytes before the next field, if any
312
315
if i < numFields - 1 {
316
+ offset := b .targetData .ElementOffset (llvmStructType , i )
313
317
nextOffset := b .targetData .ElementOffset (llvmStructType , i + 1 )
314
318
if storeSize := b .targetData .TypeStoreSize (llvmElemType ); offset + storeSize != nextOffset {
315
319
n := llvm .ConstInt (b .uintptrType , nextOffset - (offset + storeSize ), false )
316
- llvmSize := llvm .ConstInt (b .uintptrType , storeSize , false )
317
- paddingStart := b .CreateGEP (b .ctx .Int8Type (), elemPtr , []llvm.Value {llvmSize }, "" )
320
+ llvmStoreSize := llvm .ConstInt (b .uintptrType , storeSize , false )
321
+ elemPtr = b .CreateBitCast (elemPtr , b .i8ptrType , "" )
322
+ paddingStart := b .CreateInBoundsGEP (b .i8ptrType , elemPtr , []llvm.Value {llvmStoreSize }, "" )
318
323
b .createRuntimeCall ("memzero" , []llvm.Value {paddingStart , n }, "" )
319
324
}
320
325
}
@@ -327,8 +332,8 @@ func (b *builder) zeroUndefBytes(llvmType llvm.Type, ptr llvm.Value) error {
327
332
328
333
if allocSize != lastElemOffset + lastElemStore {
329
334
n := llvm .ConstInt (b .uintptrType , allocSize - (lastElemOffset + lastElemStore ), false )
330
- llvmSize := llvm .ConstInt (b .uintptrType , lastElemOffset + lastElemStore , false )
331
- paddingStart := b .CreateGEP (b .ctx .Int8Type (), ptr , []llvm.Value {llvmSize }, "" )
335
+ llvmStoreSize := llvm .ConstInt (b .uintptrType , lastElemOffset + lastElemStore , false )
336
+ paddingStart := b .CreateInBoundsGEP (b .ctx .Int8Type (), ptr , []llvm.Value {llvmStoreSize }, "" )
332
337
b .createRuntimeCall ("memzero" , []llvm.Value {paddingStart , n }, "" )
333
338
}
334
339
}
0 commit comments