diff options
-rw-r--r-- | src/clang.rs | 15 | ||||
-rw-r--r-- | src/ir/function.rs | 7 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/clang.rs b/src/clang.rs index defdf547..ec6dbbe5 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -56,7 +56,7 @@ impl Cursor { } pub fn mangling(&self) -> String { - unsafe { + unsafe { String_ { x: clang_Cursor_getMangling(self.x) }.to_string() } } @@ -136,6 +136,19 @@ impl Cursor { self.specialized().is_valid() } + pub fn is_fully_specialized_template(&self) -> bool { + self.is_template() && self.num_template_args() > 0 + } + + pub fn is_in_non_fully_specialized_template(&self) -> bool { + if self.is_toplevel() { + return false; + } + let parent = self.semantic_parent(); + (parent.is_template() && !parent.is_fully_specialized_template()) || + parent.is_in_non_fully_specialized_template() + } + pub fn is_valid(&self) -> bool { unsafe { clang_isInvalid(self.kind()) == 0 diff --git a/src/ir/function.rs b/src/ir/function.rs index b95ac57b..af170935 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -75,6 +75,13 @@ fn get_abi(cc: Enum_CXCallingConv) -> abi::Abi { } pub fn cursor_mangling(cursor: &clang::Cursor) -> Option<String> { + // We early return here because libclang may crash in some case + // if we pass in a variable inside a partial specialized template. + // See servo/rust-bindgen#67. + if cursor.is_in_non_fully_specialized_template() { + return None; + } + let mut mangling = cursor.mangling(); // Try to undo backend linkage munging (prepended _, generally) |