]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't unconditionally add/return internal "result" variable aaa657e45450e31103b1bc6fa2f2c668f23f99b6 77/head
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 24 Aug 2019 16:46:42 +0000 (18:46 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 2 Sep 2019 10:22:56 +0000 (12:22 +0200)
Found by -Werror=unreachable-code

See https://gitlab.gnome.org/GNOME/vala/issues/838

codegen/valaccodemethodmodule.vala

index 864d6a93e8c5e8d111fe6db413822648c30aab71..105f643328749179bc43731b5462429689273f54 100644 (file)
@@ -601,12 +601,6 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                        }
                                }
 
-                               if (!(m.return_type is VoidType) && !m.return_type.is_real_non_null_struct_type () && !m.coroutine) {
-                                       var vardecl = new CCodeVariableDeclarator ("result", default_value_for_type (m.return_type, true));
-                                       vardecl.init0 = true;
-                                       ccode.add_declaration (get_ccode_name (m.return_type), vardecl);
-                               }
-
                                if (m is CreationMethod) {
                                        if (in_gobject_creation_method) {
                                                if (!m.coroutine) {
@@ -767,13 +761,6 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                        complete_async ();
                                }
 
-                               if (!(m.return_type is VoidType) && !m.return_type.is_real_non_null_struct_type () && !m.coroutine) {
-                                       // add dummy return if exit block is known to be unreachable to silence C compiler
-                                       if (m.return_block != null && m.return_block.get_predecessors ().size == 0) {
-                                               ccode.add_return (new CCodeIdentifier ("result"));
-                                       }
-                               }
-
                                if (m is CreationMethod) {
                                        if (current_type_symbol is Class) {
                                                creturn_type = new ObjectType (current_class);
@@ -840,6 +827,12 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                        cfile.add_function (ccode);
                }
 
+               if (current_method_return && !(m.return_type is VoidType) && !m.return_type.is_real_non_null_struct_type () && !m.coroutine) {
+                       var vardecl = new CCodeVariableDeclarator ("result", default_value_for_type (m.return_type, true));
+                       vardecl.init0 = true;
+                       ccode.add_declaration (get_ccode_name (m.return_type), vardecl);
+               }
+
                pop_context ();
 
                if ((m.is_abstract || m.is_virtual) && !m.coroutine &&
@@ -1199,6 +1192,8 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                }
 
                ccode.add_expression (ccheck);
+
+               current_method_return = true;
        }
 
        public override void visit_creation_method (CreationMethod m) {