@@ -1486,7 +1486,7 @@ LLVMValueRef
1486
1486
check_bulk_memory_overflow (AOTCompContext * comp_ctx , AOTFuncContext * func_ctx ,
1487
1487
LLVMValueRef offset , LLVMValueRef bytes )
1488
1488
{
1489
- LLVMValueRef maddr , max_addr , cmp , cmp1 ;
1489
+ LLVMValueRef maddr , max_addr , cmp , cmp1 , offset1 ;
1490
1490
LLVMValueRef mem_base_addr ;
1491
1491
LLVMBasicBlockRef block_curr = LLVMGetInsertBlock (comp_ctx -> builder );
1492
1492
LLVMBasicBlockRef check_succ ;
@@ -1539,8 +1539,18 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
1539
1539
if (mem_data_size > 0 && mem_offset + mem_len <= mem_data_size ) {
1540
1540
/* inside memory space */
1541
1541
/* maddr = mem_base_addr + moffset */
1542
+ /* Perform zero extension in advance to avoid LLVMBuildInBoundsGEP2
1543
+ * interpreting a negative address due to sign extension when
1544
+ * mem_offset >= 2GiB */
1545
+ if (comp_ctx -> pointer_size == sizeof (uint64 )) {
1546
+ offset1 = I64_CONST (mem_offset );
1547
+ }
1548
+ else {
1549
+ offset1 = I32_CONST ((uint32 )mem_offset );
1550
+ }
1551
+ CHECK_LLVM_CONST (offset1 );
1542
1552
if (!(maddr = LLVMBuildInBoundsGEP2 (comp_ctx -> builder , INT8_TYPE ,
1543
- mem_base_addr , & offset , 1 ,
1553
+ mem_base_addr , & offset1 , 1 ,
1544
1554
"maddr" ))) {
1545
1555
aot_set_last_error ("llvm build add failed." );
1546
1556
goto fail ;
0 commit comments