Skip to content

Commit 58a8710

Browse files
zmodememilio
authored andcommitted
Get the type's definition in CompInfo::from_ty
In llvm/llvm-project#147835, Clang's AST changed so that a TagType's decl will not necessarily refer to the type's definition, but to the exact declaration which produced the type. For example, in typedef struct S T; struct S { int x; }; the 'struct S' type would refer to the incomplete type decl in the typedef, causing CompInfo to fail to see the type's definition. This patch inserts a call to use the definition when available. It fixes the original test case in #3275 and most of the test failures caused by the Clang change but not all.
1 parent d0e7d6b commit 58a8710

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

bindgen/ir/comp.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,12 @@ impl CompInfo {
12691269
);
12701270

12711271
let mut cursor = ty.declaration();
1272+
1273+
// If there is a definition, that's what we want.
1274+
if let Some(def) = cursor.definition() {
1275+
cursor = def;
1276+
}
1277+
12721278
let mut kind = Self::kind_from_cursor(&cursor);
12731279
if kind.is_err() {
12741280
if let Some(location) = location {

0 commit comments

Comments
 (0)