Skip to content

Commit dd5962b

Browse files
committed
Avoid mangling name for tpl class member. Fix #68
1 parent 2034f77 commit dd5962b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/clang.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Cursor {
5656
}
5757

5858
pub fn mangling(&self) -> String {
59-
unsafe {
59+
unsafe {
6060
String_ { x: clang_Cursor_getMangling(self.x) }.to_string()
6161
}
6262
}
@@ -136,6 +136,19 @@ impl Cursor {
136136
self.specialized().is_valid()
137137
}
138138

139+
pub fn is_fully_specialized_template(&self) -> bool {
140+
self.is_template() && self.num_template_args() > 0
141+
}
142+
143+
pub fn is_in_non_fully_specialized_template(&self) -> bool {
144+
if self.is_toplevel() {
145+
return false;
146+
}
147+
let parent = self.semantic_parent();
148+
(parent.is_template() && !parent.is_fully_specialized_template()) ||
149+
parent.is_in_non_fully_specialized_template()
150+
}
151+
139152
pub fn is_valid(&self) -> bool {
140153
unsafe {
141154
clang_isInvalid(self.kind()) == 0

src/ir/function.rs

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ fn get_abi(cc: Enum_CXCallingConv) -> abi::Abi {
7575
}
7676

7777
pub fn cursor_mangling(cursor: &clang::Cursor) -> Option<String> {
78+
// We early return here because libclang may crash in some case
79+
// if we pass in a variable inside a partial specialized template.
80+
// See servo/rust-bindgen#67.
81+
if cursor.is_in_non_fully_specialized_template() {
82+
return None;
83+
}
84+
7885
let mut mangling = cursor.mangling();
7986

8087
// Try to undo backend linkage munging (prepended _, generally)

0 commit comments

Comments
 (0)