Add support for void pointers in Opir JSON output#155
Add support for void pointers in Opir JSON output#155tokyovigilante wants to merge 1 commit intoPMunch:masterfrom
Conversation
Fixes KeyError crash when Opir outputs pointer types without "base" key.
Problem:
Futhark unconditionally accessed json["base"] without checking existence, causing crashes on bare pointer types from certain C headers.
Fix:
Add hasKey("base") guards where required before accessing json["base"].
Generate opaque `pointer` type when base is missing.
|
Hmm, this is very strange. Futhark definitely should support void pointers. Not quite sure what the caret notation in your snippet is though, is that even valid C? |
Strictly speaking no, it's an LLVM C extension for blocks, which underpins Objective-C blocks as used in libdispatch. Sorry I've realised the description above isn't clear. https://clang.llvm.org/docs/BlockLanguageSpec.html Acknowledge this is not Futhark's issue, but hopefully the patch is additive only and doesn't break any other codegen. Haven't seen any issues with any of the other C libraries I'm using. |
|
Just as an update, I'm no longer using libdispatch as the interoperability with non-Swift languages on Linux isn't great (can't guarantee main queue executes on main thread primarily) which is disappointing given that the performance was very good in non-UI tasks. So I'm happy if you want to close this. |
Futhark crashes when parsing C headers containing LLVM block pointer types, identified when attempting to wrap Apple's libdispatch library.
https://github.com/swiftlang/swift-corelibs-libdispatch/blob/main/src/BlocksRuntime/Block.h
Attempting to parse with Futhark:
gives the error:
Error: unhandled exception: Field 'base' not found in JsonNode [KeyError]Opir output for the above:
{ "kind": "pointer", "depth": 1 }Absent
basekey (appropriately) but then later unconditionally accessesjson["base"]cause crashes.findAlias()(Line 265): Crashes extracting type aliasesaddUsings()(Line 311): Crashes tracking dependenciestoNimType()(Lines 346, 370, 382, 408): Crashes generating type definitionsPatch adds
hasKey("base")guards before accessingjson["base"]in all relevant locations:findAlias(): Return empty string (no alias to track)addUsings(): Skip dependency tracking (bare pointers have no dependencies)toNimType(): Generate opaquepointertypeDisclosure: patch partially generated by Claude Code, but thoroughly manually tested and reviewed.