Skip to content

Commit cc94ee1

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 cc94ee1

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/ir/ty.rs

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

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)