================ @@ -23,6 +23,55 @@ namespace clang { +inline CXXRecordDecl *Type::getAsCXXRecordDecl() const { + const auto *TT = dyn_cast<TagType>(CanonicalType); + if (!isa_and_present<RecordType, InjectedClassNameType>(TT)) + return nullptr; + auto *TD = TT->getOriginalDecl(); + if (!isa<InjectedClassNameType>(TT) && !isa<CXXRecordDecl>(TD)) + return nullptr; ---------------- mizvekov wrote:
Yeah, from my experience experimenting for the previous patch, touching the type Kind field is almost free, but doing the indirection to the decl Kind field can be expensive. For example, we could have gotten rid of EnumType, RecordType and InjectedClassNameType as a simplification, as these types are basically the same in all ways except the kinds of declarations they store. So we could have kept just TagType. Except that whenever you need to test you have a record, having a different TypeClass allows you to quickly bail out without having to touch the declaration, otherwise you get a a performance regression. The current variant will also assert in debug builds if for some reason you get an InjectedClassNameType with a straight RecordDecl. I think your last suggestion is also okay, we would be basically replacing a list of all types which are C++ only, with a list of types which can be used in both language modes. https://github.com/llvm/llvm-project/pull/155051 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits