fix: scf_dag_node_same() for create() master
authoryu.dongliang <18588496441@163.com>
Thu, 28 Aug 2025 12:33:09 +0000 (20:33 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 28 Aug 2025 12:33:09 +0000 (20:33 +0800)
core/scf_core_types.h
core/scf_dag.c
core/scf_optimizer_auto_gc_find.c
examples/auto_gc_1.c [new file with mode: 0644]

index f27bdb08e15964885e4d950e6b32bbc67ad5c095..0f66624527800ff24a39cbf8726ce6253fd52d49 100644 (file)
@@ -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
index 6290c18dfcebee3fc163afc730005c583cb9c45e..eb0438aad2626bb18a2f5c62e952ac0ab85085c0 100644 (file)
@@ -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;
 
index ae9b6f39f4c7c2ae8f0fc7fb7d8f48ea5ab8328e..f1c9ef89a3c6e8ef2d4f74333af691ab5b96b3cd 100644 (file)
@@ -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 (file)
index 0000000..9edd1a4
--- /dev/null
@@ -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;
+}