Skip to content

Commit

Permalink
asm mode: increase global vars size to a multiple of alignment
Browse files Browse the repository at this point in the history
reported by @regehr
  • Loading branch information
nunoplopes committed Dec 18, 2023
1 parent d7766a9 commit 1c70b43
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ir/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ StateValue NullPointerValue::toSMT(State &s) const {
}


void GlobalVariable::increaseSize(uint64_t newsize) {
assert(!arbitrary_size);
assert(newsize >= allocsize);
allocsize = newsize;
}

void GlobalVariable::print(ostream &os) const {
os << getName() << " = " << (isconst ? "constant " : "global ");
if (arbitrary_size)
Expand Down
1 change: 1 addition & 0 deletions ir/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class GlobalVariable final : public Value {
bool isArbitrarySize() const { return arbitrary_size; }
unsigned getAlignment() const { return align; }
bool isConst() const { return isconst; }
void increaseSize(uint64_t newsize);
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
};
Expand Down
13 changes: 13 additions & 0 deletions tools/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,19 @@ void Transform::preprocess() {
to_add.clear();
to_remove.clear();
}

// increase size of global variables to be a multiple of alignment
for (auto p : { &src, &tgt }) {
for (auto gv : p->getGlobalVars()) {
if (gv->isArbitrarySize())
continue;
auto align = gv->getAlignment();
auto sz = gv->size();
auto newsize = round_up(sz, align);
if (newsize != sz)
gv->increaseSize(newsize);
}
}
}

remove_unreachable_bbs(src);
Expand Down

0 comments on commit 1c70b43

Please sign in to comment.