summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2022-07-25 11:17:11 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2022-07-25 12:06:38 +0200
commitef2ee38f3a1a2e0d169a610b9bd7bf52ea966059 (patch)
tree864636deeaa0f7b2c706e98bcb6144bb6ffe7646
parent105b9422cd5f8cd7aca9def458c157be219a03ff (diff)
ty: Use canonical type to access pointee.
Using the canonical type fixes this but changes the output of some tests (in particular, pointer to typedefs now point to the underlying type). So do this only in known-bad cases. Fixes #2244
-rw-r--r--src/ir/ty.rs11
-rw-r--r--tests/expectations/tests/pointer-attr.rs10
-rw-r--r--tests/headers/pointer-attr.h1
3 files changed, 21 insertions, 1 deletions
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index d573408c..38ab4564 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -1031,7 +1031,16 @@ impl Type {
CXType_ObjCObjectPointer |
CXType_MemberPointer |
CXType_Pointer => {
- let pointee = ty.pointee_type().unwrap();
+ let mut pointee = ty.pointee_type().unwrap();
+ if *ty != canonical_ty {
+ let canonical_pointee =
+ canonical_ty.pointee_type().unwrap();
+ // clang sometimes loses pointee constness here, see
+ // #2244.
+ if canonical_pointee.is_const() != pointee.is_const() {
+ pointee = canonical_pointee;
+ }
+ }
let inner =
Item::from_ty_or_ref(pointee, location, None, ctx);
TypeKind::Pointer(inner)
diff --git a/tests/expectations/tests/pointer-attr.rs b/tests/expectations/tests/pointer-attr.rs
new file mode 100644
index 00000000..95fe9c5f
--- /dev/null
+++ b/tests/expectations/tests/pointer-attr.rs
@@ -0,0 +1,10 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+extern "C" {
+ pub fn a(arg1: *const ::std::os::raw::c_char);
+}
diff --git a/tests/headers/pointer-attr.h b/tests/headers/pointer-attr.h
new file mode 100644
index 00000000..fe0004b8
--- /dev/null
+++ b/tests/headers/pointer-attr.h
@@ -0,0 +1 @@
+void a(const char __attribute__((btf_type_tag("a"))) *);