fix compilation with recent LLVM + misc fixes to last patch
MODIFY
ir/memory.cpp
ir/memory.cpp
@@ -204,6 +204,12 @@ expr Memory::mk_val_array(const char *name) const {
expr::mkUInt(0, 8 + 1)); // val+poison bit
}
+expr Memory::mk_liveness_uf() const {
+ unsigned bits_bids = bits_for_local_bid + bits_for_nonlocal_bid;
+ return expr::mkArray("blks_liveness", expr::mkUInt(0, bits_bids),
+ expr::mkUInt(0, 1));
+}
+
Memory::Memory(State &state) : state(&state) {
blocks_val = mk_val_array("blks_val");
{
@@ -213,11 +219,12 @@ Memory::Memory(State &state) : state(&state) {
expr val = expr::mkIf(idx.is_local(), poison, blocks_val.load(idx()));
blocks_val = expr::mkLambda({ idx() }, move(val));
}
+
+ blocks_liveness = mk_liveness_uf();
+
unsigned bits_bids = bits_for_local_bid + bits_for_nonlocal_bid;
- auto bidDomain = expr::mkUInt(0, bits_bids);
- blocks_liveness = expr::mkArray("blks_liveness", bidDomain,
+ blocks_kind = expr::mkArray("blks_kind", expr::mkUInt(0, bits_bids),
expr::mkUInt(0, 1));
- blocks_kind = expr::mkArray("blks_kind", bidDomain, expr::mkUInt(0, 1));
assert(bits_for_offset <= bits_size_t);
}
@@ -232,17 +239,15 @@ pair<expr, vector<expr>> Memory::mkInput(const char *name) {
}
expr Memory::alloc(const expr &bytes, unsigned align, bool heap) {
- Pointer p(*this, ++last_bid, heap);
+ Pointer p(*this, ++last_bid, !heap);
state->addPre(p.is_aligned(align));
expr size = bytes.zextOrTrunc(bits_size_t);
state->addPre(p.block_size() == size);
- const expr &blocks_liveness_at_start =
- state->getMemoryAtEntry().blocks_liveness;
- state->addPre(blocks_liveness_at_start.load(p.get_bid()) == 0);
+ state->addPre(mk_liveness_uf().load(p.get_bid()) == 0);
blocks_liveness = blocks_liveness.store(p.get_bid(), expr::mkUInt(1, 1));
- blocks_kind = blocks_kind.store(p.get_bid(), expr::mkUInt(heap ? 1 : 0, 1));
+ blocks_kind = blocks_kind.store(p.get_bid(), expr::mkUInt(heap, 1));
return p();
}

MODIFY
ir/memory.h
ir/memory.h
@@ -90,7 +90,6 @@ class Memory {
unsigned bits_for_nonlocal_bid = 8;
unsigned bits_size_t = 64;
-public:
smt::expr blocks_val; // array: (bid, offset) -> StateValue
smt::expr blocks_liveness; // array: bid -> uint(1bit), 1 if alive, 0 if freed
smt::expr blocks_kind; // array: bid -> uint(1bit), 1 if heap, 0 otherwise
@@ -101,7 +100,9 @@ public:
std::string mkName(const char *str) const;
smt::expr mk_val_array(const char *name) const;
+ smt::expr mk_liveness_uf() const;
+public:
Memory(State &state);
std::pair<smt::expr, std::vector<smt::expr>> mkInput(const char *name);

MODIFY
ir/state.cpp
ir/state.cpp
@@ -32,11 +32,6 @@ const StateValue& State::exec(const Value &v) {
return get<1>(values.back()).first;
}
-const Memory &State::getMemoryAtEntry() const {
- return *memoryAtEntry;
-}
-
-
const StateValue& State::operator[](const Value &val) {
auto &[var, val_uvars, used] = values[values_map.at(&val)];
auto &[sval, uvars] = val_uvars;
@@ -85,10 +80,6 @@ bool State::startBB(const BasicBlock &bb) {
ENSURE(seen_bbs.emplace(&bb).second);
current_bb = &bb;
- if (bb.getName() == f.getFirstBB().getName()) {
- memoryAtEntry = memory;
- }
-
auto I = predecessor_data.find(&bb);
if (I == predecessor_data.end())
return false;

MODIFY
ir/state.h
ir/state.h
#include "ir/state_value.h"
#include "smt/expr.h"
#include <array>
-#include <optional>
#include <ostream>
#include <set>
#include <tuple>
@@ -51,10 +50,6 @@ private:
predecessor_data;
std::unordered_set<const BasicBlock*> seen_bbs;
- // The initial memory at the first basic block.
- // startBB() initializes this variable when starting entry.
- std::optional<Memory> memoryAtEntry;
-
// temp state
DomainTy domain;
Memory memory;
@@ -75,9 +70,6 @@ public:
const ValTy& at(const Value &val) const;
const smt::expr* jumpCondFrom(const BasicBlock &bb) const;
- // Returns the initial memory at the first basic block.
- const Memory &getMemoryAtEntry() const;
-
bool startBB(const BasicBlock &bb);
void addJump(const BasicBlock &dst);
// boolean cond

MODIFY
llvm_util/utils.cpp
llvm_util/utils.cpp
@@ -336,20 +336,18 @@ public:
if (!fn) // TODO: support indirect calls
return error(i);
- if (llvm::isMallocLikeFn(&i, &TLI, false) && fn->getName() == "malloc") {
- // This is a call to C/C++'s malloc() function.
+ // TODO: add support for checking mismatch of C vs C++ alloc fns
+ if (llvm::isMallocLikeFn(&i, &TLI, false)) {
auto ptr = get_operand(i.getArgOperand(0));
auto ty = llvm_type2alive(i.getType());
if (!ptr || !ty)
return error(i);
-
RETURN_IDENTIFIER(make_unique<Malloc>(*ty, value_name(i), *ptr));
- } else if (llvm::isFreeCall(&i, &TLI) && fn->getName() == "free") {
- // This is a call to C/C++'s free() function.
+
+ } else if (llvm::isFreeCall(&i, &TLI)) {
auto ptr = get_operand(i.getArgOperand(0));
if (!ptr)
return error(i);
-
RETURN_IDENTIFIER(make_unique<Free>(*ptr));
}

MODIFY
tools/alive-tv.cpp
tools/alive-tv.cpp
@@ -71,17 +71,17 @@ static llvm::cl::opt<bool> opt_smt_verbose(
static llvm::cl::opt<bool> opt_bidirectional("bidirectional",
llvm::cl::init(false), llvm::cl::cat(opt_alive),
- llvm::cl::desc("Alive: Run refinement check in both directions (default=false)"));
+ llvm::cl::desc("Alive: Run refinement check in both directions"));
static llvm::ExitOnError ExitOnErr;
// adapted from llvm-dis.cpp
static std::unique_ptr<llvm::Module> openInputFile(llvm::LLVMContext &Context,
std::string InputFilename) {
- std::unique_ptr<llvm::MemoryBuffer> MB =
+ auto MB =
ExitOnErr(errorOrToExpected(llvm::MemoryBuffer::getFile(InputFilename)));
llvm::SMDiagnostic Diag;
- std::unique_ptr<llvm::Module> M = getLazyIRModule(std::move(MB), Diag, Context,
+ auto M = getLazyIRModule(move(MB), Diag, Context,
/*ShouldLazyLoadMetadata=*/true);
if (!M) {
Diag.print("", llvm::errs(), false);
@@ -229,25 +229,29 @@ int main(int argc, char **argv) {
auto M2 = openInputFile(Context, opt_file2);
if (!M2.get())
- llvm::report_fatal_error("Could not read bitcode from '" + opt_file2 + "'");
+ llvm::report_fatal_error(
+ "Could not read bitcode from '" + opt_file2 + "'");
auto F2 = getSingleFunction(M2.get());
if (cmpTypes(F1->getFunctionType(), F2->getFunctionType(), F1, F2))
- llvm::report_fatal_error("Only functions with identical signatures can be checked");
+ llvm::report_fatal_error(
+ "Only functions with identical signatures can be checked");
if (M1.get()->getTargetTriple() != M2.get()->getTargetTriple())
llvm::report_fatal_error("Modules have different target triple");
auto targetTriple = llvm::Triple(M1.get()->getTargetTriple());
- auto TLI = llvm::TargetLibraryInfoWrapperPass(targetTriple).getTLI();
+ auto TLI = llvm::TargetLibraryInfoWrapperPass(targetTriple).getTLI(*F1);
auto Func1 = llvm2alive(*F1, TLI);
if (!Func1)
- llvm::report_fatal_error("Could not translate '" + opt_file1 + "' to Alive IR");
+ llvm::report_fatal_error(
+ "Could not translate '" + opt_file1 + "' to Alive IR");
auto Func2 = llvm2alive(*F2, TLI);
if (!Func2)
- llvm::report_fatal_error("Could not translate '" + opt_file2 + "' to Alive IR");
+ llvm::report_fatal_error(
+ "Could not translate '" + opt_file2 + "' to Alive IR");
Transform t;
t.src = move(*Func1);

MODIFY
tools/alive_parser.cpp
tools/alive_parser.cpp
@@ -885,8 +885,7 @@ static unique_ptr<Instr> parse_copyop(string_view name, token t) {
}
static unique_ptr<Instr> parse_instr(string_view name) {
- auto t = *tokenizer;
- switch (t) {
+ switch (auto t = *tokenizer) {
case ADD:
case SUB:
case MUL:
@@ -990,7 +989,7 @@ static void parse_fn(Function &f) {
/*if_non_poison=*/false));
break;
default:
- string_view name = "";
+ string_view name;
if (t == REGISTER) {
name = yylval.str;
tokenizer.ensure(EQUALS);
@@ -1002,7 +1001,8 @@ static void parse_fn(Function &f) {
tokenizer.unget(t);
goto exit;
}
- if (name.length() != 0) {
+
+ if (!name.empty()) {
if (!identifiers.emplace(name, i.get()).second)
error("Duplicated assignment to " + string(name));
}

MODIFY
tv/tv.cpp
tv/tv.cpp
@@ -96,8 +96,7 @@ struct TVPass : public llvm::FunctionPass {
TVPass() : FunctionPass(ID) {}
bool runOnFunction(llvm::Function &F) override {
- const llvm::TargetLibraryInfo &TLI =
- getAnalysis<llvm::TargetLibraryInfoWrapperPass>().getTLI();
+ auto &TLI = getAnalysis<llvm::TargetLibraryInfoWrapperPass>().getTLI(F);
auto fn = llvm2alive(F, TLI);
if (!fn) {

fix compilation with recent LLVM + misc fixes to last patch