Skip to content

Commit d3d6a44

Browse files
committed
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
1 parent 105b942 commit d3d6a44

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/ir/ty.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,16 @@ impl Type {
10311031
CXType_ObjCObjectPointer |
10321032
CXType_MemberPointer |
10331033
CXType_Pointer => {
1034-
let pointee = ty.pointee_type().unwrap();
1034+
let mut pointee = ty.pointee_type().unwrap();
1035+
if *ty != canonical_ty {
1036+
let canonical_pointee =
1037+
canonical_ty.pointee_type().unwrap();
1038+
// clang sometimes loses pointee constness here, see
1039+
// #2244.
1040+
if canonical_pointee.is_const() != pointee.is_const() {
1041+
pointee = canonical_pointee;
1042+
}
1043+
}
10351044
let inner =
10361045
Item::from_ty_or_ref(pointee, location, None, ctx);
10371046
TypeKind::Pointer(inner)

tests/expectations/tests/pointer-attr.rs

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/headers/pointer-attr.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void a(const char __attribute__((btf_type_tag("a"))) *);

0 commit comments

Comments
 (0)