?: with omitted true-expression needs special handling if the condition ends in a...
authorChristoph Mallon <christoph.mallon@gmx.de>
Sun, 21 Dec 2008 18:25:56 +0000 (18:25 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sun, 21 Dec 2008 18:25:56 +0000 (18:25 +0000)
[r24843]

ast.c
ast2firm.c

diff --git a/ast.c b/ast.c
index ac8caeb..613da53 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -629,12 +629,12 @@ static void print_builtin_types_compatible(
 static void print_conditional(const conditional_expression_t *expression)
 {
        print_expression_prec(expression->condition, PREC_LOGICAL_OR);
-       fputs(" ? ", out);
        if (expression->true_expression != NULL) {
+               fputs(" ? ", out);
                print_expression_prec(expression->true_expression, PREC_EXPRESSION);
                fputs(" : ", out);
        } else {
-               fputs(": ", out);
+               fputs(" ?: ", out);
        }
        precedence_t prec = c_mode & _CXX ? PREC_ASSIGNMENT : PREC_CONDITIONAL;
        print_expression_prec(expression->false_expression, prec);
index 8bc11fb..cd72ad4 100644 (file)
@@ -2853,11 +2853,11 @@ static ir_node *conditional_to_firm(const conditional_expression_t *expression)
        set_cur_block(cur_block);
        ir_node *const cond_expr = create_condition_evaluation(expression->condition, true_block, false_block);
        if (expression->true_expression == NULL) {
-               if (cond_expr != NULL) {
+               if (cond_expr != NULL && get_irn_mode(cond_expr) != mode_b) {
                        true_val = cond_expr;
                } else {
-                       /* Condition ended with a short circuit (&&, ||, !) operation.
-                        * Generate a "1" as value for the true branch. */
+                       /* Condition ended with a short circuit (&&, ||, !) operation or a
+                        * comparison.  Generate a "1" as value for the true branch. */
                        true_val = new_Const(get_mode_one(mode_Is));
                }
        }