[clang] [clang][NFC] Compute current instantiation rarer in lookupInBases (PR #208139)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 7 21:19:52 PDT 2026
https://github.com/AnonMiraj created https://github.com/llvm/llvm-project/pull/208139
While benchmarking I noticed that #118003 causes a small compile-time regression. Right now, it computes `isCurrentInstantiation` for every base during name lookup.
We can easily avoid this overhead by only computing it when a dependent base could actually be skipped.
>From 33122f8144b622798975203f828baedcf8cf9c88 Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Wed, 8 Jul 2026 07:00:46 +0300
Subject: [PATCH] [clang][NFC] Compute current instantiation lazily in
lookupInBases
---
clang/lib/AST/CXXInheritance.cpp | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 29f5916284ebb..a8905f0e48ef5 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -162,22 +162,23 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
QualType BaseType =
Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
- bool isCurrentInstantiation = isa<InjectedClassNameType>(BaseType);
- if (!isCurrentInstantiation) {
- if (auto *BaseRecord = cast_if_present<CXXRecordDecl>(
- BaseSpec.getType()->getAsRecordDecl()))
- isCurrentInstantiation = BaseRecord->isDependentContext() &&
- BaseRecord->isCurrentInstantiation(Record);
- }
// C++ [temp.dep]p3:
// In the definition of a class template or a member of a class template,
// if a base class of the class template depends on a template-parameter,
// the base class scope is not examined during unqualified name lookup
// either at the point of definition of the class template or member or
// during an instantiation of the class tem- plate or member.
- if (!LookupInDependent &&
- (BaseType->isDependentType() && !isCurrentInstantiation))
- continue;
+ if (!LookupInDependent && BaseType->isDependentType()) {
+ bool isCurrentInstantiation = isa<InjectedClassNameType>(BaseType);
+ if (!isCurrentInstantiation) {
+ if (auto *BaseRecord = cast_if_present<CXXRecordDecl>(
+ BaseSpec.getType()->getAsRecordDecl()))
+ isCurrentInstantiation = BaseRecord->isDependentContext() &&
+ BaseRecord->isCurrentInstantiation(Record);
+ }
+ if (!isCurrentInstantiation)
+ continue;
+ }
// Determine whether we need to visit this base class at all,
// updating the count of subobjects appropriately.
More information about the cfe-commits
mailing list