symexec: handle case when __globalvars_init BB doesnt exist
MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -20,6 +20,7 @@ using llvm::LLVMContext;
namespace {
ostream *out;
+unsigned constexpr_idx;
#if 0
string_view s(llvm::StringRef str) {
@@ -80,7 +81,6 @@ class llvm2alive_ : public llvm::InstVisitor<llvm2alive_, unique_ptr<Instr>> {
Value* convert_constexpr(llvm::ConstantExpr *cexpr) {
llvm::Instruction *newI = cexpr->getAsInstruction();
- static unsigned constexpr_idx = 0;
newI->setName("__constexpr_" + to_string(constexpr_idx++));
i_constexprs.push_back(newI);
@@ -648,6 +648,8 @@ public:
}
optional<Function> run() {
+ constexpr_idx = 0;
+
auto type = llvm_type2alive(f.getReturnType());
if (!type)
return {};
@@ -713,7 +715,6 @@ public:
continue;
auto gv = M->getGlobalVariable(GV->getName().substr(1), true);
- assert(gv);
if (!gv->hasInitializer())
continue;
else if (auto CE = dyn_cast<llvm::ConstantExpr>(gv->getInitializer())) {

MODIFY
llvm_util/utils.cpp
llvm_util/utils.cpp
@@ -216,7 +216,7 @@ Value* get_operand(llvm::Value *v,
if (gv->hasInitializer() && gv->isConstant()) {
auto initializer = gv->getInitializer();
if (!isa<llvm::ConstantExpr>(initializer))
- if (!(initval = get_operand(gv->getInitializer(), constexpr_conv)))
+ if (!(initval = get_operand(initializer, constexpr_conv)))
return nullptr;
}
int size = DL->getTypeAllocSize(gv->getValueType());

MODIFY
tv/tv.cpp
tv/tv.cpp
@@ -106,7 +106,8 @@ struct TVPass : public llvm::FunctionPass {
itr->second.first.getGlobalVarNames());
if (!init_fn) {
- fns.erase(F.getName());
+ if (!first)
+ fns.erase(itr);
return false;
}

MODIFY
util/symexec.cpp
util/symexec.cpp
@@ -25,6 +25,11 @@ void sym_exec(State &s) {
s.exec(Value::voidVal);
bool first = true;
+ if (f.getFirstBB().getName() != "__globalvars_init") {
+ s.finishInitializer();
+ first = false;
+ }
+
for (auto &bb : f.getBBs()) {
if (!s.startBB(*bb))
continue;
@@ -36,15 +41,15 @@ void sym_exec(State &s) {
if (config::symexec_print_each_value && name[0] == '%')
cout << name << " = " << val << '\n';
}
- if (first) {
+
+ if (first)
s.finishInitializer();
first = false;
}
- }
if (config::symexec_print_each_value) {
- cout << "domain = " << s.returnDomain() << '\n';
- cout << "return = " << s.returnVal().first << "\n\n";
+ cout << "domain = " << s.returnDomain()
+ << "\nreturn = " << s.returnVal().first << "\n\n";
}
}

symexec: handle case when __globalvars_init BB doesnt exist