]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Do not declare result variable if it is unused
authorJürg Billeter <j@bitron.ch>
Wed, 16 Sep 2009 12:15:29 +0000 (14:15 +0200)
committerJürg Billeter <j@bitron.ch>
Wed, 16 Sep 2009 12:15:29 +0000 (14:15 +0200)
codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala

index 9f5611dda3871dc37c700f70e4b2f5a746c769e0..5063d38c1f3f0b20d670283e475772398001b7ee 100644 (file)
@@ -1517,9 +1517,12 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                        }
 
                        if (acc.readable && !returns_real_struct) {
-                               var cdecl = new CCodeDeclaration (acc.value_type.get_cname ());
-                               cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
-                               function.block.prepend_statement (cdecl);
+                               // do not declare result variable if exit block is known to be unreachable
+                               if (acc.exit_block == null || acc.exit_block.get_predecessors ().size > 0) {
+                                       var cdecl = new CCodeDeclaration (acc.value_type.get_cname ());
+                                       cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
+                                       function.block.prepend_statement (cdecl);
+                               }
                        }
 
                        if (current_method_inner_error) {
index 3125e749fd6797b2da56539bd255d288fc7536a4..2eb974b7b3d9f3b914594a0fcbc54ca3a86dfb3f 100644 (file)
@@ -492,9 +492,12 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
                                }
 
                                if (!(m.return_type is VoidType) && !m.return_type.is_real_struct_type () && !m.coroutine) {
-                                       var cdecl = new CCodeDeclaration (m.return_type.get_cname ());
-                                       cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
-                                       cinit.append (cdecl);
+                                       // do not declare result variable if exit block is known to be unreachable
+                                       if (m.exit_block == null || m.exit_block.get_predecessors ().size > 0) {
+                                               var cdecl = new CCodeDeclaration (m.return_type.get_cname ());
+                                               cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
+                                               cinit.append (cdecl);
+                                       }
                                }
 
                                if (inner_error) {