Fix static globals in JIT

pull/78/head
Ibrahim Numanagić 2022-09-29 17:51:50 -07:00
parent 543324d347
commit 010fa3b347
3 changed files with 6 additions and 3 deletions

View File

@ -33,6 +33,7 @@ std::string Cache::rev(const std::string &s) {
void Cache::addGlobal(const std::string &name, ir::Var *var) {
if (!in(globals, name)) {
// LOG("[global] {}", name);
globals[name] = var;
}
}

View File

@ -163,7 +163,7 @@ bool SimplifyVisitor::checkCapture(const SimplifyContext::Item &val) {
// Case: a global variable that has not been marked with `global` statement
if (val->isVar() && val->getBaseName().empty()) {
val->noShadow = true;
if (val->scope.size() == 1)
if (val->scope.size() == 1 && !val->isStatic())
ctx->cache->addGlobal(val->canonicalName);
return false;
}

View File

@ -153,8 +153,10 @@ StmtPtr SimplifyVisitor::transformAssignment(ExprPtr lhs, ExprPtr rhs, ExprPtr t
}
// Register all toplevel variables as global in JIT mode
bool isGlobal = (ctx->cache->isJit && ctx->isGlobal()) || (canonical == VAR_ARGV);
if (isGlobal)
bool isGlobal =
(ctx->cache->isJit && ctx->isGlobal() && getStaticGeneric(type.get()) != 0) ||
(canonical == VAR_ARGV);
if (isGlobal && !getStaticGeneric(type.get()))
ctx->cache->addGlobal(canonical);
return assign;