From c03b37697a1e117995ea76203e5c0ce7d6696c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 9 Nov 2022 13:33:19 +0100 Subject: [PATCH] ir: Don't crash with built-in unexposed types from libclang. This fixes #2325. The issue is that `__bf16` is not exposed at all by libclang, which causes us to crash. It's a bit of a shame libclang doesn't expose it but there's no rust equivalent I think, so this should be ok for now. Unfortunately no test because the header crashes older clang versions. --- bindgen/ir/ty.rs | 3 +-- bindgen/ir/var.rs | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 9edc43d419..c9403f66c9 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -1145,8 +1145,7 @@ impl Type { location, None, ctx, - ) - .expect("Not able to resolve vector element?"); + )?; TypeKind::Vector(inner, ty.num_elements().unwrap()) } CXType_ConstantArray => { diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 198206b9f1..c86742ff69 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -293,11 +293,11 @@ impl ClangSubItemParser for Var { let ty = match Item::from_ty(&ty, cursor, None, ctx) { Ok(ty) => ty, Err(e) => { - assert_eq!( - ty.kind(), - CXType_Auto, + assert!( + matches!(ty.kind(), CXType_Auto | CXType_Unexposed), "Couldn't resolve constant type, and it \ - wasn't an nondeductible auto type!" + wasn't an nondeductible auto type or unexposed \ + type!" ); return Err(e); }