]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
ast_ifthen will not create dead blocks anymore
authorWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 30 Nov 2012 11:21:10 +0000 (12:21 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 30 Nov 2012 11:21:10 +0000 (12:21 +0100)
ast.c

diff --git a/ast.c b/ast.c
index 604e6a0c12534ca6db484206d97126ea36b1bd07..7afe3fb0ccdd19b38d592e4b4b40806722b6c0a5 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -2143,26 +2143,29 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
         onfalse = NULL;
 
     /* Merge block were they all merge in to */
-    merge = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "endif"));
-    if (!merge)
-        return false;
-    /* add jumps ot the merge block */
-    if (ontrue && !ontrue_endblock->final && !ir_block_create_jump(ontrue_endblock, merge))
-        return false;
-    if (onfalse && !onfalse_endblock->final && !ir_block_create_jump(onfalse_endblock, merge))
-        return false;
-
-    /* we create the if here, that way all blocks are ordered :)
-     */
-    if (!ir_block_create_if(cond, condval,
-                            (ontrue  ? ontrue  : merge),
-                            (onfalse ? onfalse : merge)))
+    if (!ontrue || !onfalse || !ontrue_endblock->final || !onfalse_endblock->final)
     {
-        return false;
-    }
+        merge = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "endif"));
+        if (!merge)
+            return false;
+        /* add jumps ot the merge block */
+        if (ontrue && !ontrue_endblock->final && !ir_block_create_jump(ontrue_endblock, merge))
+            return false;
+        if (onfalse && !onfalse_endblock->final && !ir_block_create_jump(onfalse_endblock, merge))
+            return false;
 
-    /* Now enter the merge block */
-    func->curblock = merge;
+        /* we create the if here, that way all blocks are ordered :)
+         */
+        if (!ir_block_create_if(cond, condval,
+                                (ontrue  ? ontrue  : merge),
+                                (onfalse ? onfalse : merge)))
+        {
+            return false;
+        }
+
+        /* Now enter the merge block */
+        func->curblock = merge;
+    }
 
     return true;
 }