fix: avoid Windows crash while preserving entry metadata#38
fix: avoid Windows crash while preserving entry metadata#38
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the entry-metadata handling path to avoid generic LLVM function attribute iteration, addressing a Windows CI crash (STATUS_ACCESS_VIOLATION) likely originating from LLVM/inkwell FFI behavior.
Changes:
- Switch entry-function detection to a direct lookup for the
entry_pointstring attribute (no attribute iteration). - Update
get_entry_attributesto fetch a fixed set of known QIR entry attributes via direct lookups. - Remove entry-related attributes during translation by explicitly removing known keys rather than iterating attributes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/lib.rs |
Replaces attribute iteration with fixed-key lookups for entry metadata extraction and fixed-key removal during translation. |
src/convert.rs |
Updates find_entry_function to use direct attribute lookup and removes the generic string-attribute iterator helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let count = usize::try_from(unsafe { | ||
| LLVMGetAttributeCountAtIndex(function.as_value_ref(), LLVMAttributeFunctionIndex) | ||
| }) | ||
| .unwrap_or(0); | ||
| let mut attrs: Vec<LLVMAttributeRef> = vec![std::ptr::null_mut(); count]; | ||
|
|
||
| unsafe { | ||
| LLVMGetAttributesAtIndex( | ||
| function.as_value_ref(), | ||
| LLVMAttributeFunctionIndex, | ||
| attrs.as_mut_ptr(), | ||
| ); | ||
| } |
There was a problem hiding this comment.
get_string_attrs always calls LLVMGetAttributesAtIndex even when the attribute count is 0. When count == 0, attrs.as_mut_ptr() comes from an empty Vec and is a dangling non-null pointer; passing it across FFI is risky if LLVM ever dereferences the pointer even when the count is zero. Guard the call (only invoke LLVMGetAttributesAtIndex when count > 0) or pass a null pointer in the zero-count case.
Summary
This PR fixes the Windows CI crash in the isolated
test_get_entry_attributespath, scoped separately from the broader QIR 2.0 work in #34.What Changed
inkwellfunction-attribute iteration when finding the entry function.create_module_from_ir.get_string_attrssafely returns all string function attributes again.get_entry_attributeson input QIR.Notes
#34 overlaps with adjacent code, but it does not fully replace this fix on its own. This branch also updates the bitcode parsing path used by
get_entry_attributes,validate_qir, andqir_to_qis, and preserves spec-compatible metadata extraction for output schemas without leaking source entry metadata into translated output.