]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Add Block.unreachable_exit and have it set accordingly by FlowAnalyzer
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 4 Feb 2021 14:53:55 +0000 (15:53 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 4 Feb 2021 14:53:55 +0000 (15:53 +0100)
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

codegen/valaccodebasemodule.vala
vala/valablock.vala
vala/valaflowanalyzer.vala

index 9e46dd2f60fde26ac5b82341a1a965c28dea5293..a5c42b01c9f19ed3f0f12909eaa45ae8f24e8171 100644 (file)
@@ -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
index e13f2b2be213820a54e5556f5cd4721311684533..e002909bf3c0e46bcc73d26914878e22ad6d4489 100644 (file)
@@ -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> statement_list = new ArrayList<Statement> ();
index a86bda42a61761c0277a13778e58cc3476a0e3e5..a5a8be993f00c3121f922db79d7a511ff6c0d6d3 100644 (file)
@@ -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);