Skip to content

Commit

Permalink
fix #996: asm mode increase gv var size in tgt only
Browse files Browse the repository at this point in the history
  • Loading branch information
nunoplopes committed Dec 26, 2023
1 parent 93b947e commit 262ecaa
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ir/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void Function::addConstant(unique_ptr<Value> &&c) {
constants.emplace_back(std::move(c));
}

Value* Function::getConstant(string_view name) const {
Value* Function::getGlobalVar(string_view name) const {
for (auto &c : constants) {
if (c->getName() == name)
return c.get();
Expand Down Expand Up @@ -300,7 +300,7 @@ void Function::syncDataWithSrc(Function &src) {
auto copy_fns = [](const auto &src, auto &dst) {
for (auto &c : src.getConstants()) {
auto *gv = dynamic_cast<const GlobalVariable*>(&c);
if (gv && gv->isArbitrarySize() && !dst.getConstant(gv->getName()))
if (gv && gv->isArbitrarySize() && !dst.getGlobalVar(gv->getName()))
dst.addConstant(make_unique<GlobalVariable>(*gv));
}
};
Expand Down
2 changes: 1 addition & 1 deletion ir/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Function final {
}
unsigned numConstants() const { return constants.size(); }
Value &getConstant(int idx) const { return *constants[idx]; }
Value* getConstant(std::string_view name) const;
Value* getGlobalVar(std::string_view name) const;

std::vector<GlobalVariable *> getGlobalVars() const;
std::vector<std::string_view> getGlobalVarNames() const;
Expand Down
2 changes: 1 addition & 1 deletion ir/instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ StateValue FnCall::toSMT(State &s) const {
// This is a direct call, but check if there are indirect calls elsewhere
// to this function. If so, call it indirectly to match the other calls.
if (!ptr)
ptr = s.getFn().getConstant(string_view(fnName).substr(1));
ptr = s.getFn().getGlobalVar(string_view(fnName).substr(1));

ostringstream fnName_mangled;
if (ptr) {
Expand Down
4 changes: 2 additions & 2 deletions ir/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ State::addFnCall(const string &name, vector<StateValue> &&inputs,
}

auto isgvar = [&](const auto &decl) {
if (auto gv = getFn().getConstant(string_view(decl.name).substr(1)))
if (auto gv = getFn().getGlobalVar(string_view(decl.name).substr(1)))
return Pointer::mkPointerFromNoAttrs(memory, fn_ptr).getAddress() ==
Pointer(memory, (*this)[*gv].value).getAddress();
return expr();
Expand Down Expand Up @@ -1306,7 +1306,7 @@ void State::mkAxioms(State &tgt) {

if (has_indirect_fncalls) {
for (auto &decl : f.getFnDecls()) {
if (auto gv = f.getConstant(string_view(decl.name).substr(1)))
if (auto gv = f.getGlobalVar(string_view(decl.name).substr(1)))
addAxiom(
expr::mkUF("#fndeclty",
{ Pointer(memory, (*this)[*gv].value).reprWithoutAttrs() },
Expand Down
20 changes: 11 additions & 9 deletions tools/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1659,15 +1659,17 @@ void Transform::preprocess() {
}

// 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);
for (auto gv : tgt.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);
if (auto src_gv = dynamic_cast<GlobalVariable*>(
src.getGlobalVar(gv->getName())))
src_gv->increaseSize(newsize);
}
}
}
Expand Down

0 comments on commit 262ecaa

Please sign in to comment.