File tree 3 files changed +22
-1
lines changed
3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ use super::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
12
12
use crate :: clang;
13
13
use crate :: codegen:: struct_layout:: { align_to, bytes_from_bits_pow2} ;
14
14
use crate :: ir:: derive:: CanDeriveCopy ;
15
+ use crate :: ir:: item;
15
16
use crate :: parse:: { ClangItemParser , ParseError } ;
16
17
use crate :: HashMap ;
17
18
use crate :: NonCopyUnionStyle ;
@@ -1422,7 +1423,9 @@ impl CompInfo {
1422
1423
1423
1424
// A declaration of an union or a struct without name
1424
1425
// could also be an unnamed field, unfortunately.
1425
- if cur. spelling ( ) . is_empty ( ) &&
1426
+ let mut spelling = cur. spelling ( ) ;
1427
+ item:: normalize_name_for_clang_16 ( & mut spelling) ;
1428
+ if spelling. is_empty ( ) &&
1426
1429
cur. kind ( ) != CXCursor_EnumDecl
1427
1430
{
1428
1431
let ty = cur. cur_type ( ) ;
Original file line number Diff line number Diff line change @@ -2016,3 +2016,16 @@ impl<'a> NameOptions<'a> {
2016
2016
self . item . real_canonical_name ( self . ctx , self )
2017
2017
}
2018
2018
}
2019
+
2020
+ /// Normalizes names so that we can handle them identically in Clang 16 and earlier versions.
2021
+ ///
2022
+ /// In Clang 16, anonymous names have names like `(anonymous union at foo.c:16)`, whereas in earlier
2023
+ /// versions of Clang they were the empty string. This function normalizes all such names to the
2024
+ /// empty string so that we can handle them identically.
2025
+ pub fn normalize_name_for_clang_16 ( name : & mut String ) {
2026
+ // This may seem fragile, but ")" is not a valid character in C identifiers, so it should
2027
+ // actually be a reasonably robust check.
2028
+ if name. ends_with ( ")" ) {
2029
+ name. truncate ( 0 ) ;
2030
+ }
2031
+ }
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ use super::template::{
14
14
} ;
15
15
use super :: traversal:: { EdgeKind , Trace , Tracer } ;
16
16
use crate :: clang:: { self , Cursor } ;
17
+ use crate :: ir:: item;
17
18
use crate :: parse:: { ClangItemParser , ParseError , ParseResult } ;
18
19
use std:: borrow:: Cow ;
19
20
use std:: io;
@@ -1112,6 +1113,8 @@ impl Type {
1112
1113
}
1113
1114
}
1114
1115
1116
+ item:: normalize_name_for_clang_16 ( & mut name) ;
1117
+
1115
1118
TypeKind :: Enum ( enum_)
1116
1119
}
1117
1120
CXType_Record => {
@@ -1132,6 +1135,8 @@ impl Type {
1132
1135
}
1133
1136
}
1134
1137
1138
+ item:: normalize_name_for_clang_16 ( & mut name) ;
1139
+
1135
1140
TypeKind :: Comp ( complex)
1136
1141
}
1137
1142
CXType_Vector => {
You can’t perform that action at this time.
0 commit comments