From a02e859a7cdacbb647c7e02f6729ce31584c74eb Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Fri, 5 Apr 2024 21:26:14 -0700 Subject: [PATCH] Parser: boolcast lhs of logical `or` expression even if not evaluating it Ensure that the value, if present, is zero or one. Closes #668 --- src/aro/Parser.zig | 2 ++ test/cases/float values.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/aro/Parser.zig b/src/aro/Parser.zig index ac3ceef5..7ac783c6 100644 --- a/src/aro/Parser.zig +++ b/src/aro/Parser.zig @@ -6415,6 +6415,8 @@ fn lorExpr(p: *Parser) Error!Result { if (try lhs.adjustTypes(tok, &rhs, p, .boolean_logic)) { const res = lhs.val.toBool(p.comp) or rhs.val.toBool(p.comp); lhs.val = Value.fromBool(res); + } else { + lhs.val.boolCast(p.comp); } try lhs.boolRes(p, .bool_or_expr, rhs); } diff --git a/test/cases/float values.c b/test/cases/float values.c index 3d16702c..d349c79d 100644 --- a/test/cases/float values.c +++ b/test/cases/float values.c @@ -1,2 +1,6 @@ _Static_assert(-1.0 - 1.0 == -2.0, ""); _Static_assert(-2.0f == -2.0, ""); +_Static_assert(1.0 == (2.0||0), ""); +void foo(void) { + float f = 2.0 || 0; +}