From 911fccfde97f9e46b8281132ec2b022f11321405 Mon Sep 17 00:00:00 2001 From: Philipp Rados Date: Mon, 3 Jun 2024 20:04:49 +0200 Subject: [PATCH] fixed ptr-scale codegen bug --- wrecc_compiler/src/compiler/typechecker/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wrecc_compiler/src/compiler/typechecker/mod.rs b/wrecc_compiler/src/compiler/typechecker/mod.rs index c0fd2e9..49a1c0f 100644 --- a/wrecc_compiler/src/compiler/typechecker/mod.rs +++ b/wrecc_compiler/src/compiler/typechecker/mod.rs @@ -2195,12 +2195,15 @@ impl TypeChecker { let mut right = right.maybe_int_promote(); if let Some((expr, by_amount)) = Self::maybe_scale_index(&mut left, &mut right) { + // have to make sure that result fits into type + let expr_type = QualType::new(Type::Primitive(Primitive::Long(false))); expr.kind = mir::expr::ExprKind::Scale { by_amount, token: token.clone(), direction: mir::expr::ScaleDirection::Up, - expr: Box::new(expr.clone()), + expr: Box::new(Self::maybe_cast(expr_type.clone(), expr.clone())), }; + expr.qtype = expr_type; } Ok(Self::binary_type_promotion(token, left, right)) @@ -2218,7 +2221,7 @@ impl TypeChecker { } } - // scale index when pointer arithmetic + // scale index when doing pointer arithmetic fn maybe_scale_index<'a>( left: &'a mut mir::expr::Expr, right: &'a mut mir::expr::Expr,