From 142c131f0661a97a0d6a59576061b0320ac5b068 Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 2 Sep 2005 20:32:09 +0000 Subject: [PATCH] Fixed a problem with evaluation of the address size git-svn-id: svn://svn.cc65.org/cc65/trunk@3621 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/studyexpr.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/ca65/studyexpr.c b/src/ca65/studyexpr.c index 407862a17..f16f3b199 100644 --- a/src/ca65/studyexpr.c +++ b/src/ca65/studyexpr.c @@ -1378,34 +1378,30 @@ void StudyExpr (ExprNode* Expr, ExprDesc* D) */ if (ED_IsValid (D)) { unsigned char AddrSize; - if (D->SymCount == 1 && D->SecCount == 0) { - /* Exactly one symbol. Assume that the expression has the size of - * the symbol, provided that this size is known. - */ - const SymEntry* Sym = D->SymRef[0].Ref; - AddrSize = GetSymAddrSize (Sym); - if (AddrSize != ADDR_SIZE_DEFAULT) { - D->AddrSize = AddrSize; - } else { - AddrSize = GetConstAddrSize (D->Val); + + /* If there are symbols or sections, use the largest one. If the + * expression resolves to a const, use the address size of the value. + */ + if (D->SymCount > 0 || D->SecCount > 0) { + + D->AddrSize = ADDR_SIZE_DEFAULT; + + for (I = 0; I < D->SymCount; ++I) { + const SymEntry* Sym = D->SymRef[I].Ref; + AddrSize = GetSymAddrSize (Sym); if (AddrSize > D->AddrSize) { D->AddrSize = AddrSize; } } - } else if (D->SymCount == 0 && D->SecCount == 1) { - /* Exactly one segment reference (segment+offset). In this case, - * the expression has the address size of the segment. - */ - unsigned SegNum = D->SecRef[0].Ref; - AddrSize = GetSegAddrSize (SegNum); - if (AddrSize != ADDR_SIZE_DEFAULT) { - D->AddrSize = AddrSize; - } else { - AddrSize = GetConstAddrSize (D->Val); + + for (I = 0; I < D->SecCount; ++I) { + unsigned SegNum = D->SecRef[0].Ref; + AddrSize = GetSegAddrSize (SegNum); if (AddrSize > D->AddrSize) { D->AddrSize = AddrSize; } } + } else { AddrSize = GetConstAddrSize (D->Val); if (AddrSize > D->AddrSize) { -- 2.39.5