Skip to content

Commit

Permalink
Fixes for MInts (#1107)
Browse files Browse the repository at this point in the history
There existed several bugs leading to crashes when the LLVM backend
compiles certain definitions containing the MInt sort. This PR contains
a regression test and the fixes needed to make that test pass, namely:

* Don't emit a case for `evaluate_function_symbol` if the function has a
variable return sort (only happens with functions that have a sort
variable in the return sort that does not appear in the argument list)
* Fix a case where a string literal did not get its initializer set in
all cases.
  • Loading branch information
Dwight Guth authored Jul 12, 2024
1 parent 7fe9b48 commit 71a5f9e
Show file tree
Hide file tree
Showing 4 changed files with 2,592 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/codegen/EmitConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ static void emit_data_for_symbol(
if (is_eval && !is_func) {
continue;
}
if (is_eval && !symbol->get_sort()->is_concrete()) {
continue;
}
auto *case_block
= llvm::BasicBlock::Create(ctx, "tag" + std::to_string(tag), func);
auto *branch = llvm::BranchInst::Create(merge_block, case_block);
Expand Down Expand Up @@ -1310,8 +1313,13 @@ static void emit_return_sort_table(kore_definition *def, llvm::Module *mod) {
auto *char_type = llvm::Type::getInt8Ty(ctx);
auto *str_type = llvm::ArrayType::get(char_type, sort_str.size() + 1);

auto *str = llvm::ConstantDataArray::getString(ctx, sort_str, true);
auto *sort_name
= module->getOrInsertGlobal("sort_name_" + sort_str, str_type);
auto *global_var = llvm::cast<llvm::GlobalVariable>(sort_name);
if (!global_var->hasInitializer()) {
global_var->setInitializer(str);
}

auto *i64_type = llvm::Type::getInt64Ty(ctx);
auto *zero = llvm::ConstantInt::get(i64_type, 0);
Expand Down
Loading

0 comments on commit 71a5f9e

Please sign in to comment.