Skip to content

Commit

Permalink
fix new issue for global variables
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
zengdage committed Jan 3, 2024
1 parent d676e84 commit 57c9915
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion osprey/ir_tools/whirl2llvm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 57c9915

Please sign in to comment.