From 91fd30611a3e24a8d0702d5345812cdbf1a79671 Mon Sep 17 00:00:00 2001 From: acqn Date: Mon, 29 Mar 2021 14:30:44 +0800 Subject: [PATCH] Fixed ICE on error cases such as '&func + int a'. --- src/cc65/expr.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/cc65/expr.c b/src/cc65/expr.c index be53b22f9..58de0d891 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -2850,27 +2850,31 @@ static void parseadd (ExprDesc* Expr, int DoArrayRef) } else { /* OOPS */ AddDone = -1; + /* Avoid further errors */ + ED_MakeConstAbsInt (Expr, 0); } - /* Do constant calculation if we can */ - if (ED_IsAbs (&Expr2) && - (ED_IsAbs (Expr) || lscale == 1)) { - if (IsClassInt (lhst) && IsClassInt (rhst)) { - Expr->Type = ArithmeticConvert (Expr->Type, Expr2.Type); + if (!AddDone) { + /* Do constant calculation if we can */ + if (ED_IsAbs (&Expr2) && + (ED_IsAbs (Expr) || lscale == 1)) { + if (IsClassInt (lhst) && IsClassInt (rhst)) { + Expr->Type = ArithmeticConvert (Expr->Type, Expr2.Type); + } + Expr->IVal = Expr->IVal * lscale + Expr2.IVal * rscale; + AddDone = 1; + } else if (ED_IsAbs (Expr) && + (ED_IsAbs (&Expr2) || rscale == 1)) { + if (IsClassInt (lhst) && IsClassInt (rhst)) { + Expr2.Type = ArithmeticConvert (Expr2.Type, Expr->Type); + } + Expr2.IVal = Expr->IVal * lscale + Expr2.IVal * rscale; + /* Adjust the flags */ + Expr2.Flags |= Expr->Flags & ~E_MASK_KEEP_SUBEXPR; + /* Get the symbol and the name */ + *Expr = Expr2; + AddDone = 1; } - Expr->IVal = Expr->IVal * lscale + Expr2.IVal * rscale; - AddDone = 1; - } else if (ED_IsAbs (Expr) && - (ED_IsAbs (&Expr2) || rscale == 1)) { - if (IsClassInt (lhst) && IsClassInt (rhst)) { - Expr2.Type = ArithmeticConvert (Expr2.Type, Expr->Type); - } - Expr2.IVal = Expr->IVal * lscale + Expr2.IVal * rscale; - /* Adjust the flags */ - Expr2.Flags |= Expr->Flags & ~E_MASK_KEEP_SUBEXPR; - /* Get the symbol and the name */ - *Expr = Expr2; - AddDone = 1; } if (AddDone) {