瀏覽代碼

Fix tailrec opt. error reoprted in #41412

Disable tailrec optimizationi for functions,
if callnode reuult is not used, because otherwise
the value of second call ends up as the return value.

Fixes bug reoprt #41412
Pierre Muller 1 天之前
父節點
當前提交
989b173b0b
共有 1 個文件被更改,包括 3 次插入2 次删除
  1. 3 2
      compiler/opttail.pas

+ 3 - 2
compiler/opttail.pas

@@ -72,8 +72,9 @@ unit opttail;
             result:=
               (n.nodetype=calln) and
               (tcallnode(n).procdefinition=p) and
-              not(assigned(tcallnode(n).methodpointer)) and
-              not has_copyback_paras(tcallnode(n));
+              (not assigned(tcallnode(n).methodpointer)) and
+              (not has_copyback_paras(tcallnode(n))) and
+              (cnf_return_value_used in tcallnode(n).callnodeflags);
             if result then
               usedcallnode:=tcallnode(n)
             else