diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-04-04 12:14:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-04 12:14:46 -0500 |
commit | ad01eb2ad6e6078358cc233793e4c396977881a9 (patch) | |
tree | 1d9cc5914f7f09536ae848761f680b9dd3678899 | |
parent | 642b69580e6b3f368870c966152924a721590c28 (diff) | |
parent | f2ef3d1e7e4c4f78ea752538290f96670c68a8db (diff) |
Auto merge of #612 - fitzgen:fallback-to-opaque, r=emilio
Fall back to opaque types rather than panicking on parse failure
Getting closer to figuring out some of the other template related issues in clang 4.0, but not quite ready to land them yet. Figure this should probably land in the meantime. This is just a better fallback in the face of the unknown for panics that we've had reports of in the wild, but which I haven't had time to creduce.
r? @emilio
-rw-r--r-- | src/ir/context.rs | 6 | ||||
-rw-r--r-- | src/ir/item.rs | 9 | ||||
-rw-r--r-- | src/ir/ty.rs | 14 |
3 files changed, 21 insertions, 8 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs index fe079ef0..32ee5bd0 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -424,7 +424,11 @@ impl<'ctx> BindgenContext<'ctx> { for (id, ty, loc, parent_id) in typerefs { let _resolved = { let resolved = Item::from_ty(&ty, loc, parent_id, self) - .expect("What happened?"); + .unwrap_or_else(|_| { + warn!("Could not resolve type reference, falling back \ + to opaque blob"); + Item::new_opaque_type(self.next_item_id(), &ty, self) + }); let mut item = self.items.get_mut(&id).unwrap(); *item.kind_mut().as_type_mut().unwrap().kind_mut() = diff --git a/src/ir/item.rs b/src/ir/item.rs index 89422e87..5477dee9 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -433,10 +433,11 @@ impl Item { } } - fn new_opaque_type(with_id: ItemId, - ty: &clang::Type, - ctx: &mut BindgenContext) - -> ItemId { + /// Construct a new opaque item type. + pub fn new_opaque_type(with_id: ItemId, + ty: &clang::Type, + ctx: &mut BindgenContext) + -> ItemId { let ty = Opaque::from_clang_ty(ty); let kind = ItemKind::Type(ty); let parent = ctx.root_module(); diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 60d750ed..594e4c03 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -1096,9 +1096,17 @@ impl Type { let complex = CompInfo::from_ty(potential_id, ty, Some(location), - ctx) - .expect("C'mon"); - TypeKind::Comp(complex) + ctx); + match complex { + Ok(complex) => TypeKind::Comp(complex), + Err(_) => { + warn!("Could not create complex type \ + from class template or base \ + specifier, using opaque blob"); + let opaque = Opaque::from_clang_ty(ty); + return Ok(ParseResult::New(opaque, None)); + } + } } CXCursor_TypeAliasTemplateDecl => { debug!("TypeAliasTemplateDecl"); |