Skip to content

Commit 5fa4a1f

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 6b6af6b commit 5fa4a1f

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
@@ -1234,6 +1234,12 @@ impl CompInfo {
12341234
);
12351235

12361236
let mut cursor = ty.declaration();
1237+
1238+
// If there is a definition, that's what we want.
1239+
if let Some(def) = cursor.definition() {
1240+
cursor = def;
1241+
}
1242+
12371243
let mut kind = Self::kind_from_cursor(&cursor);
12381244
if kind.is_err() {
12391245
if let Some(location) = location {

0 commit comments

Comments
 (0)