From 57c9915e633655bbd03ffd723986d41e944df3f0 Mon Sep 17 00:00:00 2001 From: Zhijin Zeng Date: Fri, 10 Nov 2023 11:43:30 +0800 Subject: [PATCH] fix new issue for global variables 1. The w2ll will crash if compile the code like that: ``` int sre_random(void) { long rnd1; static long tbl[64]; int i; for (i = 0; i < 64; i++) { tbl[i] = rnd1; if (tbl[i] < 0) tbl[i] += 0; } return 0; } ``` 2. Error Log: ``` w2ll: /workspace/toolchain/llvm/llvm/lib/IR/Globals.cpp:472: void llvm::GlobalVariable::setInitializer(llvm::Constant*): Assertion `InitVal->getType() == getValueType() && "Initializer type must match GlobalVariable type"' failed. (xcalcc:571) ``` Signed-off-by: Zhijin Zeng --- osprey/ir_tools/whirl2llvm.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osprey/ir_tools/whirl2llvm.cxx b/osprey/ir_tools/whirl2llvm.cxx index 75d6abe0..3a44486b 100644 --- a/osprey/ir_tools/whirl2llvm.cxx +++ b/osprey/ir_tools/whirl2llvm.cxx @@ -4543,7 +4543,7 @@ void ST2llvm::operator() (UINT idx, ST *st) const { if (INITV_IDX val = ST_has_initv(st)) { gvar->setInitializer(whirl2llvm->INITV2llvm(Initv_Table[val], ST_type(st))); } else { - SetZeroInitializer(gvar, gvar->getType(), st); + SetZeroInitializer(gvar, gvar->getValueType(), st); } if (ST_is_const_var(st)) {