Skip to content

Crash with LLVMBuildStore when trying to store a boolean (LLVMInt1Type) #164135

@wedesoft

Description

@wedesoft

Hi, I am using the LLVM C library to do JIT compilation for a Guile extension.
Here is some C code calling LLVMBuildStore (see here for complete file).

SCM llvm_build_store(SCM scm_function, SCM scm_type, SCM scm_value, SCM scm_address)
{
  struct llvm_function_t *function = get_llvm_function(scm_function);
  struct llvm_value_t *value = get_llvm_value(scm_value);
  struct llvm_value_t *address = get_llvm_value(scm_address);
  int type = scm_to_int(scm_type);
  LLVMValueRef pointer = LLVMBuildIntToPtr(function->builder, address->value, LLVMPointerType(llvm_type(type), 0), "x");
  LLVMBuildStore(function->builder, value->value, pointer);
  return SCM_UNSPECIFIED;
}

Basically this code works for most datatypes but when llvm_type returns LLVMInt1Type() (used for boolean values), it crashes in llvm::DataLayout::getAlignment(llvm::Type*, bool) const ().
The code used to work with LLVM 14. Now I tried to upgrade to LLVM 17, 18, and now 19. With 17 I got infinite recursion (and crash) and with 19 I just get a crash.

Thread 1 "guile" received signal SIGSEGV, Segmentation fault.
0x00007fffe596256a in llvm::DataLayout::getAlignment(llvm::Type*, bool) const () from /lib/x86_64-linux-gnu/libLLVM.so.19.1
(gdb) p function->builder
No symbol "function" in current context.
(gdb) up
#1  0x00007fffe596299c in llvm::DataLayout::getPrefTypeAlignment(llvm::Type*) const () from /lib/x86_64-linux-gnu/libLLVM.so.19.1
(gdb)
#2  0x0000000000000000 in ?? ()

Let me know if you have any suggestions.
Kind regards
Jan

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions