qir-alliance / pyqir

PyQIR is a set of APIs for generating, parsing, and evaluating Quantum Intermediate Representation (QIR).
https://qir-alliance.github.io/pyqir
MIT License
54 stars 24 forks source link

Passing a null pointer to extract_byte_string causes Python to segfault #237

Closed johngarvin-quantinuum closed 1 year ago

johngarvin-quantinuum commented 1 year ago

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