qir-alliance/pyqir

Passing a null pointer to extract_byte_string causes Python to segfault

johngarvin-quantinuum opened this issue · 0 comments

Describe the bug

extract_byte_string causes Python to segfault if its argument is a Value representing a null pointer.

To Reproduce

from pyqir import Context, Module, extract_byte_string

llvm_ir = """
define void @program_main() {
entry:
  %0 = add i64 1, 2
  call void @__quantum__rt__int_record_output(i64 %0, i8* null)
  ret void
}

declare void @__quantum__rt__int_record_output(i64, i8*)
"""

module = Module.from_ir(Context(), llvm_ir, "module")
null_ptr_value = module.functions[0].basic_blocks[0].instructions[1].operands[1]
x = extract_byte_string(null_ptr_value)

Expected behavior

I would expect extract_byte_string to return None or raise an exception in this case.

System information

  • pyqir version 0.8.1
  • python version 3.9.6