[llvm-branch-commits] [clang] [clang] NFC: Provide inline definitions for {get, cast}TagDecl and friends (PR #155051)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Aug 23 13:26:17 PDT 2025


================
@@ -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;
----------------
Sirraide 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.

I see; I figured it might be something like that.

https://github.com/llvm/llvm-project/pull/155051


More information about the llvm-branch-commits mailing list