summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2022-11-09 13:33:19 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2022-11-09 13:54:34 +0100
commitc03b37697a1e117995ea76203e5c0ce7d6696c4e (patch)
tree0b04b07add048cb3e7fe265174d600e5a39eb826
parent0631a27bee19601e393e31e7dfc2563412b2fe01 (diff)
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.
-rw-r--r--bindgen/ir/ty.rs3
-rw-r--r--bindgen/ir/var.rs8
2 files changed, 5 insertions, 6 deletions
diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs
index 9edc43d4..c9403f66 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 198206b9..c86742ff 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);
}