From: Rico Tzschichholz Date: Thu, 4 Feb 2021 14:53:55 +0000 (+0100) Subject: vala: Add Block.unreachable_exit and have it set accordingly by FlowAnalyzer X-Git-Tag: 0.51.1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1bf1e999fcfd32dacbc7396dbeda64882272b8a;p=thirdparty%2Fvala.git vala: Add Block.unreachable_exit and have it set accordingly by FlowAnalyzer Use this control flow information in codegen rather than doing an educated guess based on occurring ReturnStatement nodes. See https://gitlab.gnome.org/GNOME/vala/issues/838 --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 9e46dd2f6..a5c42b01c 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -2404,17 +2404,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { cfile.add_function (unref_fun); } - bool reachable_exit_block = true; foreach (Statement stmt in b.get_statements ()) { - if (stmt is ReturnStatement) { - reachable_exit_block = false; - } push_line (stmt.source_reference); stmt.emit (this); pop_line (); } - if (reachable_exit_block) { + if (!b.unreachable_exit) { if (b.parent_symbol is Method) { unowned Method m = (Method) b.parent_symbol; // check postconditions diff --git a/vala/valablock.vala b/vala/valablock.vala index e13f2b2be..e002909bf 100644 --- a/vala/valablock.vala +++ b/vala/valablock.vala @@ -32,6 +32,11 @@ public class Vala.Block : Symbol, Statement { */ public bool contains_jump_statement { get; set; } + /** + * Specifies whether the end of this block is unreachable. + */ + public bool unreachable_exit { get; set; } + public bool captured { get; set; } private List statement_list = new ArrayList (); diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala index a86bda42a..a5a8be993 100644 --- a/vala/valaflowanalyzer.vala +++ b/vala/valaflowanalyzer.vala @@ -235,6 +235,8 @@ public class Vala.FlowAnalyzer : CodeVisitor { } current_block.connect (m.return_block); + } else { + m.body.unreachable_exit = true; } analyze_body (m.entry_block);