[vala/0.44] codegen: Don't append unreachable clean-up section of	Block
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc: 
- Subject: [vala/0.44] codegen: Don't append unreachable clean-up section of	Block
- Date: Sun,  8 Sep 2019 16:24:02 +0000 (UTC)
commit bac757d37211668dcb17a4d18babfa69b1499e49
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Aug 29 12:26:52 2019 +0200
    codegen: Don't append unreachable clean-up section of Block
    
    Found by -Werror=unreachable-code
    
    See https://gitlab.gnome.org/GNOME/vala/issues/838
 codegen/valaccodebasemodule.vala | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9b64b478e..d2729283c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2321,7 +2321,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        }
                }
 
-               if (b.parent_symbol is Method) {
+               bool unreachable_exit_block = false;
+               if (b.parent_symbol is Subroutine) {
+                       unowned BasicBlock? exit_block = ((Subroutine) b.parent_symbol).exit_block;
+                       unreachable_exit_block = (exit_block == null || exit_block.get_predecessors ().size 
<= 0);
+               }
+
+               if (!unreachable_exit_block && b.parent_symbol is Method) {
                        var m = (Method) b.parent_symbol;
                        foreach (Parameter param in m.get_parameters ()) {
                                if (!param.captured && !param.ellipsis && requires_destroy 
(param.variable_type) && param.direction == ParameterDirection.IN) {
@@ -2334,14 +2340,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        foreach (var postcondition in m.get_postconditions ()) {
                                create_postcondition_statement (postcondition);
                        }
-               } else if (b.parent_symbol is PropertyAccessor) {
+               } else if (!unreachable_exit_block && b.parent_symbol is PropertyAccessor) {
                        var acc = (PropertyAccessor) b.parent_symbol;
                        if (acc.value_parameter != null && !acc.value_parameter.captured && requires_destroy 
(acc.value_parameter.variable_type)) {
                                ccode.add_expression (destroy_parameter (acc.value_parameter));
                        }
                }
 
-               if (b.captured) {
+               if (!unreachable_exit_block && b.captured) {
                        int block_id = get_block_id (b);
 
                        var data_unref = new CCodeFunctionCall (new CCodeIdentifier 
("block%d_data_unref".printf (block_id)));
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]