3737#include " llvm/include/llvm/Support/raw_ostream.h"
3838
3939using clang::ast_matchers::allOf;
40- using clang::ast_matchers::elaboratedType;
4140using clang::ast_matchers::hasDeclaration;
4241using clang::ast_matchers::hasName;
4342using clang::ast_matchers::hasType;
4443using clang::ast_matchers::recordDecl;
44+ using clang::ast_matchers::recordType;
4545using clang::ast_matchers::typedefDecl;
46+ using clang::ast_matchers::typedefType;
4647using clang::ast_matchers::varDecl;
4748
4849using clang::ast_matchers::MatchFinder;
@@ -64,14 +65,10 @@ struct DriverStructReporter : public MatchFinder::MatchCallback {
6465 auto get_struct_definition_matcher (std::string struct_name) {
6566 // Nvidia's driver typedefs all their struct. We search for the
6667 // typedef declaration, and go from there to find the struct definition.
67- return typedefDecl (
68- allOf (hasName (struct_name),
69- // Match and bind to the struct declaration.
70- hasType (
71- // Need to specify elaboratedType, otherwise hasType
72- // will complain that the type is ambiguous.
73- elaboratedType (hasDeclaration (
74- recordDecl ().bind (" struct_decl" ))))))
68+ return typedefDecl (allOf (hasName (struct_name),
69+ // Match and bind to the struct declaration.
70+ hasType (recordType (hasDeclaration (
71+ recordDecl ().bind (" struct_decl" ))))))
7572 .bind (" typedef_decl" );
7673 }
7774
@@ -84,10 +81,7 @@ struct DriverStructReporter : public MatchFinder::MatchCallback {
8481 return typedefDecl (
8582 allOf (hasName (struct_name),
8683 // Match and bind to the struct declaration.
87- hasType (
88- // Need to specify elaboratedType, otherwise hasType
89- // will complain that the type is ambiguous.
90- elaboratedType (hasDeclaration (typedefDecl ())))))
84+ hasType (typedefType (hasDeclaration (typedefDecl ())))))
9185 .bind (" typedef_decl" );
9286 }
9387
@@ -142,7 +136,7 @@ struct DriverStructReporter : public MatchFinder::MatchCallback {
142136 return ;
143137 }
144138
145- add_type_definition (ctx->getTypeDeclType (struct_decl), name, ctx);
139+ add_type_definition (ctx->getCanonicalTagType (struct_decl), name, ctx);
146140 }
147141
148142 // Adds the type definition of `type` to either `RecordDefinitions` or
@@ -226,7 +220,10 @@ struct DriverStructReporter : public MatchFinder::MatchCallback {
226220 std::string source =
227221 record_decl->getLocation ().printToString (ctx->getSourceManager ());
228222 // getTypeSize returns the size in bits, so we divide by 8 to get bytes.
229- uint64_t size = ctx->getTypeSize (record_decl->getTypeForDecl ()) / 8 ;
223+ uint64_t size =
224+ ctx->getTypeSize (
225+ record_decl->getASTContext ().getCanonicalTagType (record_decl)) /
226+ 8 ;
230227 bool is_union = record_decl->isUnion ();
231228 RecordDefinitions[name] = json::object ({{" source" , source},
232229 {" fields" , fields},
0 commit comments