Skip to content

Commit 7abd1ca

Browse files
authored
Change llvm void pointer to i8 pointer to avoid assert failed (#250)
1 parent 44ccfd2 commit 7abd1ca

File tree

4 files changed

+2
-50
lines changed

4 files changed

+2
-50
lines changed

core/iwasm/compilation/aot_compiler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ typedef enum FloatArithmetic {
192192
#define INT64_PTR_TYPE comp_ctx->basic_types.int64_ptr_type
193193
#define F32_PTR_TYPE comp_ctx->basic_types.float32_ptr_type
194194
#define F64_PTR_TYPE comp_ctx->basic_types.float64_ptr_type
195-
#define VOID_PTR_TYPE comp_ctx->basic_types.void_ptr_type
196195

197196
#define I32_CONST(v) LLVMConstInt(I32_TYPE, v, true)
198197
#define I64_CONST(v) LLVMConstInt(I64_TYPE, v, true)

core/iwasm/compilation/aot_emit_memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ aot_compile_op_memory_grow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
583583

584584
/* To be simple, call wasm_runtime_set_exception() no matter
585585
enlarge success or not */
586-
param_types[1] = VOID_PTR_TYPE;
586+
param_types[1] = INT8_PTR_TYPE;
587587
ret_type = VOID_TYPE;
588588
if (!(func_type = LLVMFunctionType(ret_type, param_types, 2, false))) {
589589
aot_set_last_error("llvm add function type failed.");
@@ -614,7 +614,7 @@ aot_compile_op_memory_grow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
614614
}
615615

616616
/* Call function wasm_runtime_set_exception(aot_inst, NULL) */
617-
param_values[1] = LLVMConstNull(VOID_PTR_TYPE);
617+
param_values[1] = LLVMConstNull(INT8_PTR_TYPE);
618618
CHECK_LLVM_CONST(param_values[1]);
619619
if (!(LLVMBuildCall(comp_ctx->builder, func, param_values, 2, ""))) {
620620
aot_set_last_error("llvm build call failed.");

core/iwasm/compilation/aot_llvm.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -359,45 +359,6 @@ create_cur_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
359359
return true;
360360
}
361361

362-
static bool
363-
create_func_ptrs(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
364-
{
365-
LLVMValueRef offset, func_ptrs_ptr;
366-
LLVMTypeRef void_ptr_type;
367-
368-
offset = I32_CONST(offsetof(AOTModuleInstance, func_ptrs.ptr));
369-
func_ptrs_ptr = LLVMBuildInBoundsGEP(comp_ctx->builder,
370-
func_ctx->aot_inst,
371-
&offset, 1,
372-
"func_ptrs_ptr");
373-
if (!func_ptrs_ptr) {
374-
aot_set_last_error("llvm build in bounds gep failed.");
375-
return false;
376-
}
377-
378-
if (!(void_ptr_type = LLVMPointerType(VOID_PTR_TYPE, 0))
379-
|| !(void_ptr_type = LLVMPointerType(void_ptr_type, 0))) {
380-
aot_set_last_error("llvm get pointer type failed.");
381-
return false;
382-
}
383-
384-
func_ctx->func_ptrs = LLVMBuildBitCast(comp_ctx->builder, func_ptrs_ptr,
385-
void_ptr_type, "func_ptrs_tmp");
386-
if (!func_ctx->func_ptrs) {
387-
aot_set_last_error("llvm build bit cast failed.");
388-
return false;
389-
}
390-
391-
func_ctx->func_ptrs = LLVMBuildLoad(comp_ctx->builder, func_ctx->func_ptrs,
392-
"func_ptrs");
393-
if (!func_ctx->func_ptrs) {
394-
aot_set_last_error("llvm build load failed.");
395-
return false;
396-
}
397-
398-
return true;
399-
}
400-
401362
static bool
402363
create_func_type_indexes(AOTCompContext *comp_ctx,
403364
AOTFuncContext *func_ctx)
@@ -636,10 +597,6 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
636597
if (!create_cur_exception(comp_ctx, func_ctx))
637598
goto fail;
638599

639-
/* Load function pointers */
640-
if (!create_func_ptrs(comp_ctx, func_ctx))
641-
goto fail;
642-
643600
/* Load function type indexes */
644601
if (!create_func_type_indexes(comp_ctx, func_ctx))
645602
goto fail;
@@ -723,15 +680,13 @@ aot_set_llvm_basic_types(AOTLLVMTypes *basic_types, LLVMContextRef context)
723680
basic_types->int64_ptr_type = LLVMPointerType(basic_types->int64_type, 0);
724681
basic_types->float32_ptr_type = LLVMPointerType(basic_types->float32_type, 0);
725682
basic_types->float64_ptr_type = LLVMPointerType(basic_types->float64_type, 0);
726-
basic_types->void_ptr_type = LLVMPointerType(basic_types->void_type, 0);
727683

728684
return (basic_types->int8_ptr_type
729685
&& basic_types->int16_ptr_type
730686
&& basic_types->int32_ptr_type
731687
&& basic_types->int64_ptr_type
732688
&& basic_types->float32_ptr_type
733689
&& basic_types->float64_ptr_type
734-
&& basic_types->void_ptr_type
735690
&& basic_types->meta_data_type) ? true : false;
736691
}
737692

core/iwasm/compilation/aot_llvm.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ typedef struct AOTFuncContext {
122122
LLVMBasicBlockRef got_exception_block;
123123
LLVMBasicBlockRef func_return_block;
124124
LLVMValueRef exception_id_phi;
125-
LLVMValueRef func_ptrs;
126125
LLVMValueRef func_type_indexes;
127126
LLVMValueRef locals[1];
128127
} AOTFuncContext;
@@ -143,7 +142,6 @@ typedef struct AOTLLVMTypes {
143142
LLVMTypeRef int64_ptr_type;
144143
LLVMTypeRef float32_ptr_type;
145144
LLVMTypeRef float64_ptr_type;
146-
LLVMTypeRef void_ptr_type;
147145

148146
LLVMTypeRef meta_data_type;
149147
} AOTLLVMTypes;

0 commit comments

Comments
 (0)