Skip to content

Commit 3dc22fd

Browse files
authored
Merge pull request #1591 from emilio/value-dependent
Improve workaround for LLVM bug when evaluating value-dependent expressions.
2 parents d789817 + 6f92b1c commit 3dc22fd

3 files changed

Lines changed: 38 additions & 19 deletions

File tree

src/clang.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,27 +1875,25 @@ impl EvalResult {
18751875
return None;
18761876
}
18771877

1878-
// Clang has an internal assertion we can trigger if we try to evaluate
1879-
// a cursor containing a variadic template type reference. Triggering
1880-
// the assertion aborts the process, and we don't want that. Clang
1881-
// *also* doesn't expose any API for finding variadic vs non-variadic
1882-
// template type references, let alone whether a type referenced is a
1883-
// template type, instead they seem to show up as type references to an
1884-
// unexposed type. Our solution is to just flat out ban all
1885-
// `CXType_Unexposed` from evaluation.
1886-
let mut found_cant_eval = false;
1887-
cursor.visit(|c| if c.kind() == CXCursor_TypeRef &&
1888-
c.cur_type().kind() == CXType_Unexposed
1878+
// Work around https://bugs.llvm.org/show_bug.cgi?id=42532, see:
1879+
// * https://github.com/rust-lang/rust-bindgen/issues/283
1880+
// * https://github.com/rust-lang/rust-bindgen/issues/1590
18891881
{
1890-
found_cant_eval = true;
1891-
CXChildVisit_Break
1892-
} else {
1893-
CXChildVisit_Recurse
1894-
});
1895-
if found_cant_eval {
1896-
return None;
1897-
}
1882+
let mut found_cant_eval = false;
1883+
cursor.visit(|c| {
1884+
if c.kind() == CXCursor_TypeRef &&
1885+
c.cur_type().canonical_type().kind() == CXType_Unexposed {
1886+
found_cant_eval = true;
1887+
return CXChildVisit_Break;
1888+
}
1889+
1890+
CXChildVisit_Recurse
1891+
});
18981892

1893+
if found_cant_eval {
1894+
return None;
1895+
}
1896+
}
18991897
Some(EvalResult {
19001898
x: unsafe { clang_Cursor_Evaluate(cursor.x) },
19011899
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
#![allow(
4+
dead_code,
5+
non_snake_case,
6+
non_camel_case_types,
7+
non_upper_case_globals
8+
)]
9+
10+
#[repr(C)]
11+
#[derive(Debug, Default, Copy, Clone)]
12+
pub struct e {
13+
pub _address: u8,
14+
}
15+
pub type e_f<d> = d;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// bindgen-flags: -- -std=c++11
2+
3+
template <typename d> class e {
4+
using f = d;
5+
static const auto g = alignof(f);
6+
};

0 commit comments

Comments
 (0)