summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCollin Baker <collinbaker@chromium.org>2022-07-20 11:57:16 -0400
committerEmilio Cobos Álvarez <emilio@crisal.io>2022-08-25 22:19:06 +0200
commita5848cf44e02645cddf020609ea67340cf6e3d24 (patch)
tree30941f48bd08576c1c011537f0b7c2152db96cd7 /tests
parent6dfc3e70df1676a3321cb83624f7c83db6fb92df (diff)
Generate opaque type for template param dependent bit field width
libclang's API does not provide a straightforward way to check for this, and calling clang_getFieldDeclBitWidth is actively unsafe in this case. See https://github.com/llvm/llvm-project/issues/56644 We probably can't generate reasonable bindings for such a type, so make the binding opaque. Ideally libclang would report if the bit width could not be evaluated. Unfortunately making such a change would mean bumping the minimum libclang version from 6.0 to 15.0. Instead, add logic to traverse the AST subtree starting from the field's bit width specifier looking for template parameters. If we find one, we make the resulting type opaque.
Diffstat (limited to 'tests')
-rw-r--r--tests/expectations/tests/issue-2239-template-dependent-bit-width.rs19
-rw-r--r--tests/headers/issue-2239-template-dependent-bit-width.hpp10
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs b/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs
new file mode 100644
index 00000000..75ec9e43
--- /dev/null
+++ b/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs
@@ -0,0 +1,19 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct b {
+ pub _address: u8,
+}
+pub type b_td<a> = a;
+pub type b_ta<a> = a;
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct b_foo {
+ pub _address: u8,
+}
diff --git a/tests/headers/issue-2239-template-dependent-bit-width.hpp b/tests/headers/issue-2239-template-dependent-bit-width.hpp
new file mode 100644
index 00000000..4e6feb3f
--- /dev/null
+++ b/tests/headers/issue-2239-template-dependent-bit-width.hpp
@@ -0,0 +1,10 @@
+template <class a> class b {
+ typedef a td;
+ using ta = a;
+ struct foo {
+ a foo : sizeof(a);
+ a : sizeof(a);
+ td : sizeof(td);
+ ta : sizeof(ta);
+ };
+};