From: yu.dongliang <18588496441@163.com> Date: Thu, 28 Aug 2025 12:33:09 +0000 (+0800) Subject: fix: scf_dag_node_same() for create() X-Git-Url: http://baseworks.info/?a=commitdiff_plain;ds=inline;p=scf.git fix: scf_dag_node_same() for create() --- diff --git a/core/scf_core_types.h b/core/scf_core_types.h index f27bdb0..0f66624 100644 --- a/core/scf_core_types.h +++ b/core/scf_core_types.h @@ -42,6 +42,7 @@ enum scf_core_types SCF_OP_INC, // ++ SCF_OP_DEC, // -- + // 7 SCF_OP_INC_POST, // ++ SCF_OP_DEC_POST, // -- @@ -61,7 +62,7 @@ enum scf_core_types SCF_OP_LOGIC_OR, // || SCF_OP_LOGIC_NOT, // ! - // 19 + // 20 SCF_OP_ASSIGN, // = assign SCF_OP_ADD_ASSIGN, // += SCF_OP_SUB_ASSIGN, // -= @@ -73,7 +74,7 @@ enum scf_core_types SCF_OP_AND_ASSIGN, // &= SCF_OP_OR_ASSIGN, // |= - // 29 + // 30 SCF_OP_EQ, // == equal SCF_OP_NE, // != not equal SCF_OP_LT, // < less than @@ -81,7 +82,7 @@ enum scf_core_types SCF_OP_LE, // <= less equal SCF_OP_GE, // >= greater equal - // 35 + // 36 SCF_OP_EXPR, // () expr SCF_OP_CALL, // () function call SCF_OP_TYPE_CAST, // (char*) type cast diff --git a/core/scf_dag.c b/core/scf_dag.c index 6290c18..eb0438a 100644 --- a/core/scf_dag.c +++ b/core/scf_dag.c @@ -548,6 +548,9 @@ int scf_dag_node_same(scf_dag_node_t* dn, const scf_node_t* node) scf_logd("dag type: %d, node: %#lx, var: %#lx\n", dn->type, 0xffff & (uintptr_t)dn, 0xffff & (uintptr_t)dn->var); } + if (SCF_OP_CREATE == node->type) + node = node->result_nodes->data[0]; + if (dn->type != node->type) return 0; diff --git a/core/scf_optimizer_auto_gc_find.c b/core/scf_optimizer_auto_gc_find.c index ae9b6f3..f1c9ef8 100644 --- a/core/scf_optimizer_auto_gc_find.c +++ b/core/scf_optimizer_auto_gc_find.c @@ -501,17 +501,16 @@ static int _auto_gc_find_ref(scf_dn_status_t* ds_obj, scf_dag_node_t* dn, scf_3a } if (fret->auto_gc_flag) { - _bb_add_ds (cur_bb, ds_obj); - _bb_add_ds_for_ret(cur_bb, ds_obj, f2); - ds = scf_dn_status_alloc(dn); if (!ds) return -ENOMEM; - _bb_del_ds(cur_bb, ds); scf_dn_status_free(ds); ds = NULL; + + _bb_add_ds (cur_bb, ds_obj); + _bb_add_ds_for_ret(cur_bb, ds_obj, f2); return 2; } } else { @@ -849,7 +848,6 @@ static int _auto_gc_function_find(scf_ast_t* ast, scf_function_t* f, scf_list_t* 0xffff & (uintptr_t)ds, ds->ret_flag, ds->ret_index, ds->dag_node->var->arg_flag); scf_dn_status_print(ds); #endif - if (ds->dag_node->var->arg_flag) ds->dag_node->var->auto_gc_flag = 1; else { diff --git a/examples/auto_gc_1.c b/examples/auto_gc_1.c new file mode 100644 index 0000000..9edd1a4 --- /dev/null +++ b/examples/auto_gc_1.c @@ -0,0 +1,34 @@ +#include"../lib/scf_capi.c" + +struct Object +{ + double d; + + int __init(Object* this, double d) + { + this->d = d; + return 0; + } + + Object* operator+(Object* this, Object* that) + { + Object* res = create Object(this->d + that->d); + return res; + } +}; + +Object* add(Object* x, Object* y) +{ + return x + y; +} + +int main() +{ + Object* a = create Object(1.1); + Object* b = create Object(2.2); + + Object* c = add(a, b); + + printf("c: %lg\n", c->d); + return 0; +}