From f8835d2867d428484fd7a300fbbc1213a8af1c70 Mon Sep 17 00:00:00 2001 From: acqn Date: Sat, 13 Mar 2021 14:25:51 +0800 Subject: [PATCH] Fixed codegen with addresses as boolean test conditions. Fixed warning on unreachable code of if body. --- src/cc65/testexpr.c | 9 +++++++-- src/cc65/testexpr.h | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cc65/testexpr.c b/src/cc65/testexpr.c index e5db488de..243f3ebf9 100644 --- a/src/cc65/testexpr.c +++ b/src/cc65/testexpr.c @@ -70,7 +70,7 @@ unsigned Test (unsigned Label, int Invert) DoDeferred (SQP_KEEP_NONE, &Expr); /* Result is constant, so we know the outcome */ - Result = (Expr.IVal != 0); + Result = (Expr.IVal != 0) ? TESTEXPR_TRUE : TESTEXPR_FALSE; /* Constant rvalue */ if (!Invert && Expr.IVal == 0) { @@ -86,7 +86,12 @@ unsigned Test (unsigned Label, int Invert) DoDeferred (SQP_KEEP_NONE, &Expr); /* Object addresses are non-NULL */ - Result = 1; + Result = TESTEXPR_TRUE; + + /* Condition is always true */ + if (Invert) { + g_jump (Label); + } } else { diff --git a/src/cc65/testexpr.h b/src/cc65/testexpr.h index 478280a28..84b957af2 100644 --- a/src/cc65/testexpr.h +++ b/src/cc65/testexpr.h @@ -44,9 +44,9 @@ -#define TESTEXPR_UNKNOWN 0 /* Result of expression unknown */ +#define TESTEXPR_UNKNOWN -1 /* Result of expression unknown */ #define TESTEXPR_TRUE 1 /* Expression yields true */ -#define TESTEXPR_FALSE 2 /* Expression yields false */ +#define TESTEXPR_FALSE 0 /* Expression yields false */