Skip to content

Commit 44119eb

Browse files
author
bors-servo
authored
Auto merge of #466 - emilio:tpl, r=upsuper
ir: Fix is_in_non_fully_specialized_template check. Fixes #462 r? @upsuper
2 parents bdd034b + 993a959 commit 44119eb

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

src/clang.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ impl Cursor {
201201
}
202202

203203
/// Is the referent a template specialization?
204-
pub fn is_template(&self) -> bool {
204+
pub fn is_template_specialization(&self) -> bool {
205205
self.specialized().is_some()
206206
}
207207

208208
/// Is the referent a fully specialized template specialization without any
209209
/// remaining free template arguments?
210210
pub fn is_fully_specialized_template(&self) -> bool {
211-
self.is_template() && self.num_template_args().unwrap_or(0) > 0
211+
self.is_template_specialization() && self.num_template_args().unwrap_or(0) > 0
212212
}
213213

214214
/// Is the referent a template specialization that still has remaining free
@@ -217,9 +217,17 @@ impl Cursor {
217217
if self.is_toplevel() {
218218
return false;
219219
}
220+
220221
let parent = self.semantic_parent();
221-
(parent.is_template() && !parent.is_fully_specialized_template()) ||
222-
parent.is_in_non_fully_specialized_template()
222+
if parent.is_fully_specialized_template() {
223+
return false;
224+
}
225+
226+
if !parent.is_template_like() {
227+
return parent.is_in_non_fully_specialized_template();
228+
}
229+
230+
return true;
223231
}
224232

225233
/// Is this cursor pointing a valid referent?

src/ir/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn get_abi(cc: CXCallingConv) -> abi::Abi {
9393
pub fn cursor_mangling(cursor: &clang::Cursor) -> Option<String> {
9494
// We early return here because libclang may crash in some case
9595
// if we pass in a variable inside a partial specialized template.
96-
// See servo/rust-bindgen#67.
96+
// See servo/rust-bindgen#67, and servo/rust-bindgen#462.
9797
if cursor.is_in_non_fully_specialized_template() {
9898
return None;
9999
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
9+
pub struct Test<Args> {
10+
pub _address: u8,
11+
pub _phantom_0: ::std::marker::PhantomData<Args>,
12+
}
13+
#[repr(C)]
14+
#[derive(Debug, Copy, Clone)]
15+
pub struct Outer<T> {
16+
pub _address: u8,
17+
pub _phantom_0: ::std::marker::PhantomData<T>,
18+
}
19+
#[repr(C)]
20+
#[derive(Debug, Copy, Clone)]
21+
pub struct Outer_Inner<T> {
22+
pub _address: u8,
23+
pub _phantom_0: ::std::marker::PhantomData<T>,
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// bindgen-flags: -- -std=c++11
2+
3+
// This test ensure we protect ourselves from an LLVM crash.
4+
5+
template <class... Args>
6+
struct Test {
7+
static constexpr bool x[] = {Args::x...};
8+
};
9+
10+
template<typename... T>
11+
struct Outer {
12+
struct Inner {
13+
static constexpr int value[] = { T::value... };
14+
};
15+
};

0 commit comments

Comments
 (0)