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)});