Skip to content

Commit

Permalink
ty: Use canonical type to access pointee.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
emilio committed Jul 25, 2022
1 parent 105b942 commit d3d6a44
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/expectations/tests/pointer-attr.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/headers/pointer-attr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void a(const char __attribute__((btf_type_tag("a"))) *);

0 comments on commit d3d6a44

Please sign in to comment.