From 4b0e2c75b4bf51fed03f9ba3e965f049d0de1f4e Mon Sep 17 00:00:00 2001 From: Lee Date: Sun, 7 Jul 2024 22:47:18 +0800 Subject: [PATCH] Update assignment expression logic for array subscripting --- src/qbe_ir_generator.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/qbe_ir_generator.cpp b/src/qbe_ir_generator.cpp index 9c6770cb..36434878 100644 --- a/src/qbe_ir_generator.cpp +++ b/src/qbe_ir_generator.cpp @@ -1101,12 +1101,16 @@ void QbeIrGenerator::Visit(const SimpleAssignmentExprNode& assign_expr) { FuncScopeTemp{reg_num_to_id_num.at(lhs_num)}); } } else { - // Global array subscripting will return the target address instead of the - // address of `id`. - if (assign_expr.lhs->is_global && - !dynamic_cast(assign_expr.lhs.get())) { - WriteInstr_("storew {}, {}", FuncScopeTemp{rhs_num}, - user_defined::GlobalPointer{reg_num_to_id.at(lhs_num)}); + if (assign_expr.lhs->is_global) { + // Global array subscripting will return the target address instead of the + // address of `id`. + if (dynamic_cast(assign_expr.lhs.get())) { + WriteInstr_("storew {}, {}", FuncScopeTemp{rhs_num}, + FuncScopeTemp{reg_num_to_id_num.at(lhs_num)}); + } else { + WriteInstr_("storew {}, {}", FuncScopeTemp{rhs_num}, + user_defined::GlobalPointer{reg_num_to_id.at(lhs_num)}); + } } else { WriteInstr_("storew {}, {}", FuncScopeTemp{rhs_num}, FuncScopeTemp{reg_num_to_id_num.at(lhs_num)});