From 1ccdc14b423da5c59a758989ff1152988a324431 Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Thu, 25 Apr 2024 09:25:31 -0700 Subject: [PATCH] Parser: use correct token for division overflow message --- src/aro/Parser.zig | 2 +- test/cases/arithmetic overflow.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/aro/Parser.zig b/src/aro/Parser.zig index fc2afcc0..f7996b3b 100644 --- a/src/aro/Parser.zig +++ b/src/aro/Parser.zig @@ -6648,7 +6648,7 @@ fn mulExpr(p: *Parser) Error!Result { lhs.ty.signedness(p.comp) != .unsigned) try p.errOverflow(mul.?, lhs); } else if (div != null) { if (try lhs.val.div(lhs.val, rhs.val, lhs.ty, p.comp) and - lhs.ty.signedness(p.comp) != .unsigned) try p.errOverflow(mul.?, lhs); + lhs.ty.signedness(p.comp) != .unsigned) try p.errOverflow(div.?, lhs); } else { var res = try Value.rem(lhs.val, rhs.val, lhs.ty, p.comp); if (res.opt_ref == .none) { diff --git a/test/cases/arithmetic overflow.c b/test/cases/arithmetic overflow.c index bcd4450e..845baf6d 100644 --- a/test/cases/arithmetic overflow.c +++ b/test/cases/arithmetic overflow.c @@ -5,3 +5,7 @@ _Static_assert(0x00000000 - 0x00000001 == 0xFFFFFFFF, ""); _Static_assert(0x80000000 * 2 == 0, ""); _Static_assert(2 * 0x80000000 == 0, ""); _Static_assert(sizeof(int) != 4 || ((unsigned)(-1) << 1) == 0xFFFFFFFFU - 1, ""); +_Static_assert((-9223372036854775807LL - 1LL) / -1 != 0, "failed"); + +#define EXPECTED_ERRORS "arithmetic overflow.c:8:47: warning: overflow in expression; result is '9223372036854775808' [-Winteger-overflow]" \ +