From fd6fe22020df1384b04a6f5489d59b69faf4cab5 Mon Sep 17 00:00:00 2001 From: Lixuanwang Date: Tue, 22 Jul 2025 00:11:42 +0800 Subject: [PATCH] =?UTF-8?q?[backend]=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=AF=B9?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E6=95=B0=E7=BB=84=E7=9A=84=E8=AE=BF=E5=AD=98?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E5=B1=95=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AddressCalculationExpansion.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/AddressCalculationExpansion.cpp b/src/AddressCalculationExpansion.cpp index d157528..12712ae 100644 --- a/src/AddressCalculationExpansion.cpp +++ b/src/AddressCalculationExpansion.cpp @@ -57,11 +57,22 @@ bool AddressCalculationExpansion::run() { } } } else if (GlobalValue* globalValue = dynamic_cast(basePointer)) { - std::cerr << "Warning: GlobalValue dimension handling needs explicit implementation for GEP expansion. Skipping GEP for: "; - SysYPrinter::printValue(globalValue); - std::cerr << "\n"; - ++it; - continue; + // 遍历 GlobalValue 的所有维度操作数 + for (const auto& use_ptr : globalValue->getDims()) { + Value* dimValue = use_ptr->getValue(); + // 将维度值转换为常量整数 + if (ConstantInteger* constVal = dynamic_cast(dimValue)) { + dims.push_back(constVal->getInt()); + } else { + // 如果维度不是常量整数,则无法处理。 + // 根据 IR.h 中 GlobalValue 的构造函数,这种情况不应发生,但作为安全检查是好的。 + std::cerr << "Warning: GlobalValue dimension is not a constant integer. Skipping GEP expansion for: "; + SysYPrinter::printValue(globalValue); + std::cerr << "\n"; + dims.clear(); // 清空已收集的部分维度信息 + break; + } + } } else { std::cerr << "Warning: Base pointer is not AllocaInst/GlobalValue or its array dimensions cannot be determined for GEP expansion. Skipping GEP for: "; SysYPrinter::printValue(basePointer);