From 1bc4400246781fdadfe3f722b87fac4a7edfc039 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 17 Mar 2021 19:39:55 +0100 Subject: [PATCH] Incorrectly removed %=. Now restored with tests. --- src/compiler/ast.c | 2 + test/test_suite/assignment/int_assign.c3t | 67 +++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 test/test_suite/assignment/int_assign.c3t diff --git a/src/compiler/ast.c b/src/compiler/ast.c index 4227c58dc..1391d9122 100644 --- a/src/compiler/ast.c +++ b/src/compiler/ast.c @@ -192,6 +192,7 @@ BinaryOp binary_op[TOKEN_LAST + 1] = { [TOKEN_PLUS_ASSIGN] = BINARYOP_ADD_ASSIGN, [TOKEN_MINUS_ASSIGN] = BINARYOP_SUB_ASSIGN, [TOKEN_DIV_ASSIGN] = BINARYOP_DIV_ASSIGN, + [TOKEN_MOD_ASSIGN] = BINARYOP_MOD_ASSIGN, [TOKEN_BIT_AND_ASSIGN] = BINARYOP_BIT_AND_ASSIGN, [TOKEN_BIT_OR_ASSIGN] = BINARYOP_BIT_OR_ASSIGN, [TOKEN_BIT_XOR_ASSIGN] = BINARYOP_BIT_XOR_ASSIGN, @@ -205,6 +206,7 @@ static BinaryOp assign_binop[BINARYOP_LAST + 1] = { [BINARYOP_ADD_ASSIGN] = BINARYOP_ADD, [BINARYOP_SUB_ASSIGN] = BINARYOP_SUB, [BINARYOP_DIV_ASSIGN] = BINARYOP_DIV, + [BINARYOP_MOD_ASSIGN] = BINARYOP_MOD, [BINARYOP_BIT_AND_ASSIGN] = BINARYOP_BIT_AND, [BINARYOP_BIT_OR_ASSIGN] = BINARYOP_BIT_OR, [BINARYOP_BIT_XOR_ASSIGN] = BINARYOP_BIT_XOR, diff --git a/test/test_suite/assignment/int_assign.c3t b/test/test_suite/assignment/int_assign.c3t new file mode 100644 index 000000000..6942c95bf --- /dev/null +++ b/test/test_suite/assignment/int_assign.c3t @@ -0,0 +1,67 @@ +module test; + +func int foo() +{ + int x = 0; + int y; + x += y; + x -= y; + x %= y; + x /= y; + x *= y; + x <<= y; + x >>= y; + x ^= y; + x |= y; + x &= y; + return x; +} + + +// #expect: int_assign.ll + + %x = alloca i32, align 4 + %y = alloca i32, align 4 + store i32 0, i32* %x, align 4 + store i32 0, i32* %y, align 4 + %0 = load i32, i32* %x, align 4 + %1 = load i32, i32* %y, align 4 + %add = add i32 %0, %1 + store i32 %add, i32* %x, align 4 + %2 = load i32, i32* %x, align 4 + %3 = load i32, i32* %y, align 4 + %sub = sub i32 %2, %3 + store i32 %sub, i32* %x, align 4 + %4 = load i32, i32* %x, align 4 + %5 = load i32, i32* %y, align 4 + %smod = srem i32 %4, %5 + store i32 %smod, i32* %x, align 4 + %6 = load i32, i32* %x, align 4 + %7 = load i32, i32* %y, align 4 + %sdiv = sdiv i32 %6, %7 + store i32 %sdiv, i32* %x, align 4 + %8 = load i32, i32* %x, align 4 + %9 = load i32, i32* %y, align 4 + %mul = mul i32 %8, %9 + store i32 %mul, i32* %x, align 4 + %10 = load i32, i32* %x, align 4 + %11 = load i32, i32* %y, align 4 + %shl = shl i32 %10, %11 + store i32 %shl, i32* %x, align 4 + %12 = load i32, i32* %x, align 4 + %13 = load i32, i32* %y, align 4 + %ashr = ashr i32 %12, %13 + store i32 %ashr, i32* %x, align 4 + %14 = load i32, i32* %x, align 4 + %15 = load i32, i32* %y, align 4 + %xor = xor i32 %14, %15 + store i32 %xor, i32* %x, align 4 + %16 = load i32, i32* %x, align 4 + %17 = load i32, i32* %y, align 4 + %or = or i32 %16, %17 + store i32 %or, i32* %x, align 4 + %18 = load i32, i32* %x, align 4 + %19 = load i32, i32* %y, align 4 + %and = and i32 %18, %19 + store i32 %and, i32* %x, align 4 + %20 = load i32, i32* %x, align 4