Skip to content

[PATCH 5/6] [clang] NNS improvement: getOriginalDecl changes #149747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: users/mizvekov/name-qualification-refactor-4
Choose a base branch
from

Conversation

mizvekov
Copy link
Contributor

No description provided.

@llvmbot llvmbot added backend:CSKY HLSL HLSL Language Support coroutines C++20 coroutines backend:ARC backend:loongarch clang:analysis clang:openmp OpenMP related changes to Clang clang:bytecode Issues for the clang bytecode constexpr interpreter backend:Lanai labels Jul 20, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 20, 2025

@llvm/pr-subscribers-clang-analysis
@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-backend-risc-v
@llvm/pr-subscribers-clang-static-analyzer-1
@llvm/pr-subscribers-backend-x86
@llvm/pr-subscribers-backend-sparc

@llvm/pr-subscribers-backend-hexagon

Author: Matheus Izvekov (mizvekov)

Changes

Patch is 330.74 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149747.diff

167 Files Affected:

  • (modified) clang-tools-extra/clang-doc/Serialize.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp (+5-3)
  • (modified) clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp (+2-1)
  • (modified) clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp (+3-2)
  • (modified) clang-tools-extra/clang-tidy/utils/TypeTraits.cpp (+2-1)
  • (modified) clang-tools-extra/clangd/DumpAST.cpp (+1-1)
  • (modified) clang-tools-extra/clangd/FindTarget.cpp (+1-1)
  • (modified) clang-tools-extra/clangd/Hover.cpp (+1-1)
  • (modified) clang-tools-extra/clangd/IncludeFixer.cpp (+1-1)
  • (modified) clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp (+1-1)
  • (modified) clang-tools-extra/include-cleaner/lib/WalkAST.cpp (+3-3)
  • (modified) clang/include/clang/AST/Type.h (+4-4)
  • (modified) clang/lib/AST/APValue.cpp (+2-1)
  • (modified) clang/lib/AST/ASTContext.cpp (+54-37)
  • (modified) clang/lib/AST/ASTDiagnostic.cpp (+3-2)
  • (modified) clang/lib/AST/ASTImporter.cpp (+8-7)
  • (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+3-3)
  • (modified) clang/lib/AST/ByteCode/Compiler.cpp (+5-4)
  • (modified) clang/lib/AST/ByteCode/Context.cpp (+1-1)
  • (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+4-3)
  • (modified) clang/lib/AST/ByteCode/Pointer.cpp (+1-1)
  • (modified) clang/lib/AST/ByteCode/Program.cpp (+4-3)
  • (modified) clang/lib/AST/ByteCode/Record.cpp (+1-1)
  • (modified) clang/lib/AST/CXXInheritance.cpp (+10-6)
  • (modified) clang/lib/AST/Decl.cpp (+20-12)
  • (modified) clang/lib/AST/DeclCXX.cpp (+14-9)
  • (modified) clang/lib/AST/DeclarationName.cpp (+3-3)
  • (modified) clang/lib/AST/Expr.cpp (+14-7)
  • (modified) clang/lib/AST/ExprConstant.cpp (+32-16)
  • (modified) clang/lib/AST/FormatString.cpp (+6-4)
  • (modified) clang/lib/AST/InheritViz.cpp (+2-2)
  • (modified) clang/lib/AST/ItaniumCXXABI.cpp (+4-4)
  • (modified) clang/lib/AST/ItaniumMangle.cpp (+14-9)
  • (modified) clang/lib/AST/JSONNodeDumper.cpp (+3-3)
  • (modified) clang/lib/AST/MicrosoftMangle.cpp (+2-2)
  • (modified) clang/lib/AST/ODRHash.cpp (+1-1)
  • (modified) clang/lib/AST/PrintfFormatString.cpp (+1-1)
  • (modified) clang/lib/AST/RecordLayoutBuilder.cpp (+4-5)
  • (modified) clang/lib/AST/ScanfFormatString.cpp (+3-2)
  • (modified) clang/lib/AST/TemplateBase.cpp (+1-1)
  • (modified) clang/lib/AST/TextNodeDumper.cpp (+3-3)
  • (modified) clang/lib/AST/Type.cpp (+123-71)
  • (modified) clang/lib/AST/TypeLoc.cpp (+2-3)
  • (modified) clang/lib/AST/TypePrinter.cpp (+4-2)
  • (modified) clang/lib/AST/VTTBuilder.cpp (+9-3)
  • (modified) clang/lib/AST/VTableBuilder.cpp (+5-3)
  • (modified) clang/lib/Analysis/ThreadSafety.cpp (+3-1)
  • (modified) clang/lib/Analysis/ThreadSafetyCommon.cpp (+2-2)
  • (modified) clang/lib/CodeGen/ABIInfo.cpp (+1-1)
  • (modified) clang/lib/CodeGen/ABIInfoImpl.cpp (+18-18)
  • (modified) clang/lib/CodeGen/CGBlocks.cpp (+2-1)
  • (modified) clang/lib/CodeGen/CGCUDANV.cpp (+2-1)
  • (modified) clang/lib/CodeGen/CGCXX.cpp (+5-3)
  • (modified) clang/lib/CodeGen/CGCall.cpp (+13-7)
  • (modified) clang/lib/CodeGen/CGClass.cpp (+29-14)
  • (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+18-14)
  • (modified) clang/lib/CodeGen/CGDecl.cpp (+5-2)
  • (modified) clang/lib/CodeGen/CGExpr.cpp (+20-9)
  • (modified) clang/lib/CodeGen/CGExprAgg.cpp (+17-8)
  • (modified) clang/lib/CodeGen/CGExprCXX.cpp (+12-8)
  • (modified) clang/lib/CodeGen/CGExprConstant.cpp (+21-8)
  • (modified) clang/lib/CodeGen/CGExprScalar.cpp (+7-4)
  • (modified) clang/lib/CodeGen/CGNonTrivialStruct.cpp (+4-2)
  • (modified) clang/lib/CodeGen/CGObjC.cpp (+3-1)
  • (modified) clang/lib/CodeGen/CGObjCMac.cpp (+4-3)
  • (modified) clang/lib/CodeGen/CGObjCRuntime.cpp (+3-1)
  • (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+9-3)
  • (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+3-1)
  • (modified) clang/lib/CodeGen/CodeGenFunction.h (+1-1)
  • (modified) clang/lib/CodeGen/CodeGenModule.cpp (+4-2)
  • (modified) clang/lib/CodeGen/CodeGenTBAA.cpp (+7-6)
  • (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+10-6)
  • (modified) clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp (+2-1)
  • (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+31-16)
  • (modified) clang/lib/CodeGen/SwiftCallingConv.cpp (+5-4)
  • (modified) clang/lib/CodeGen/Targets/AArch64.cpp (+5-4)
  • (modified) clang/lib/CodeGen/Targets/AMDGPU.cpp (+3-3)
  • (modified) clang/lib/CodeGen/Targets/ARC.cpp (+3-2)
  • (modified) clang/lib/CodeGen/Targets/ARM.cpp (+5-4)
  • (modified) clang/lib/CodeGen/Targets/BPF.cpp (+3-2)
  • (modified) clang/lib/CodeGen/Targets/CSKY.cpp (+1-1)
  • (modified) clang/lib/CodeGen/Targets/Hexagon.cpp (+3-2)
  • (modified) clang/lib/CodeGen/Targets/Lanai.cpp (+3-2)
  • (modified) clang/lib/CodeGen/Targets/LoongArch.cpp (+6-4)
  • (modified) clang/lib/CodeGen/Targets/Mips.cpp (+4-4)
  • (modified) clang/lib/CodeGen/Targets/NVPTX.cpp (+3-3)
  • (modified) clang/lib/CodeGen/Targets/PPC.cpp (+5-3)
  • (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+6-4)
  • (modified) clang/lib/CodeGen/Targets/SPIR.cpp (+3-3)
  • (modified) clang/lib/CodeGen/Targets/Sparc.cpp (+1-1)
  • (modified) clang/lib/CodeGen/Targets/SystemZ.cpp (+4-4)
  • (modified) clang/lib/CodeGen/Targets/WebAssembly.cpp (+2-1)
  • (modified) clang/lib/CodeGen/Targets/X86.cpp (+34-23)
  • (modified) clang/lib/CodeGen/Targets/XCore.cpp (+2-2)
  • (modified) clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp (+1-1)
  • (modified) clang/lib/Index/IndexTypeSourceInfo.cpp (+1-1)
  • (modified) clang/lib/Index/USRGeneration.cpp (+7-3)
  • (modified) clang/lib/InstallAPI/Visitor.cpp (+2-2)
  • (modified) clang/lib/Interpreter/InterpreterValuePrinter.cpp (+4-4)
  • (modified) clang/lib/Interpreter/Value.cpp (+3-3)
  • (modified) clang/lib/Sema/Sema.cpp (+12-9)
  • (modified) clang/lib/Sema/SemaAccess.cpp (+5-2)
  • (modified) clang/lib/Sema/SemaAvailability.cpp (+2-2)
  • (modified) clang/lib/Sema/SemaBPF.cpp (+3-3)
  • (modified) clang/lib/Sema/SemaCUDA.cpp (+5-2)
  • (modified) clang/lib/Sema/SemaCXXScopeSpec.cpp (+1-1)
  • (modified) clang/lib/Sema/SemaCast.cpp (+22-23)
  • (modified) clang/lib/Sema/SemaChecking.cpp (+47-22)
  • (modified) clang/lib/Sema/SemaCodeComplete.cpp (+6-7)
  • (modified) clang/lib/Sema/SemaCoroutine.cpp (+3-1)
  • (modified) clang/lib/Sema/SemaDecl.cpp (+33-17)
  • (modified) clang/lib/Sema/SemaDeclAttr.cpp (+11-6)
  • (modified) clang/lib/Sema/SemaDeclCXX.cpp (+36-19)
  • (modified) clang/lib/Sema/SemaDeclObjC.cpp (+12-5)
  • (modified) clang/lib/Sema/SemaExpr.cpp (+25-14)
  • (modified) clang/lib/Sema/SemaExprCXX.cpp (+15-8)
  • (modified) clang/lib/Sema/SemaExprObjC.cpp (+5-4)
  • (modified) clang/lib/Sema/SemaHLSL.cpp (+7-5)
  • (modified) clang/lib/Sema/SemaInit.cpp (+45-27)
  • (modified) clang/lib/Sema/SemaLambda.cpp (+1-1)
  • (modified) clang/lib/Sema/SemaLookup.cpp (+9-4)
  • (modified) clang/lib/Sema/SemaObjC.cpp (+3-2)
  • (modified) clang/lib/Sema/SemaObjCProperty.cpp (+3-1)
  • (modified) clang/lib/Sema/SemaOpenMP.cpp (+4-3)
  • (modified) clang/lib/Sema/SemaOverload.cpp (+44-26)
  • (modified) clang/lib/Sema/SemaPPC.cpp (+4-2)
  • (modified) clang/lib/Sema/SemaSYCL.cpp (+1-1)
  • (modified) clang/lib/Sema/SemaStmt.cpp (+12-10)
  • (modified) clang/lib/Sema/SemaStmtAsm.cpp (+4-2)
  • (modified) clang/lib/Sema/SemaSwift.cpp (+3-2)
  • (modified) clang/lib/Sema/SemaTemplate.cpp (+17-13)
  • (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+1-1)
  • (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+7-5)
  • (modified) clang/lib/Sema/SemaType.cpp (+10-7)
  • (modified) clang/lib/Sema/SemaTypeTraits.cpp (+9-7)
  • (modified) clang/lib/Sema/TreeTransform.h (+6-3)
  • (modified) clang/lib/Sema/UsedDeclVisitor.h (+4-3)
  • (modified) clang/lib/Serialization/ASTReader.cpp (+4-4)
  • (modified) clang/lib/Serialization/TemplateArgumentHasher.cpp (+1-1)
  • (modified) clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp (+1-1)
  • (modified) clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp (+1-1)
  • (modified) clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp (+2-1)
  • (modified) clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp (+2-2)
  • (modified) clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp (+3-1)
  • (modified) clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp (+1-1)
  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp (+2-2)
  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp (+2-2)
  • (modified) clang/lib/StaticAnalyzer/Core/CallEvent.cpp (+4-2)
  • (modified) clang/lib/StaticAnalyzer/Core/RegionStore.cpp (+3-2)
  • (modified) clang/tools/libclang/CIndex.cpp (+3-3)
  • (modified) clang/tools/libclang/CIndexCodeCompletion.cpp (+2-2)
  • (modified) clang/tools/libclang/CXCursor.cpp (+1-1)
  • (modified) clang/tools/libclang/CXIndexDataConsumer.cpp (+1-1)
  • (modified) clang/tools/libclang/CXType.cpp (+4-4)
  • (modified) clang/unittests/AST/ASTImporterTest.cpp (+2-2)
  • (modified) clang/unittests/AST/RandstructTest.cpp (+1-1)
  • (modified) clang/unittests/AST/StructuralEquivalenceTest.cpp (+8-4)
  • (modified) clang/unittests/StaticAnalyzer/SValTest.cpp (+5-8)
  • (modified) clang/unittests/Tooling/LookupTest.cpp (+6-6)
  • (modified) clang/unittests/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp (+1-1)
  • (modified) clang/unittests/Tooling/RecursiveASTVisitorTests/NestedNameSpecifiers.cpp (+1-1)
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 7a0e00c6d9c2d..2b1f0f3c90c0c 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -895,8 +895,8 @@ parseBases(RecordInfo &I, const CXXRecordDecl *D, bool IsFileInRootDir,
     return;
   for (const CXXBaseSpecifier &B : D->bases()) {
     if (const RecordType *Ty = B.getType()->getAs<RecordType>()) {
-      if (const CXXRecordDecl *Base =
-              cast_or_null<CXXRecordDecl>(Ty->getDecl()->getDefinition())) {
+      if (const CXXRecordDecl *Base = cast_or_null<CXXRecordDecl>(
+              Ty->getOriginalDecl()->getDefinition())) {
         // Initialized without USR and name, this will be set in the following
         // if-else stmt.
         BaseRecordInfo BI(
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index b413b12cd37ab..40607597297b5 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -190,7 +190,7 @@ struct InitializerInsertion {
 // Convenience utility to get a RecordDecl from a QualType.
 const RecordDecl *getCanonicalRecordDecl(const QualType &Type) {
   if (const auto *RT = Type.getCanonicalType()->getAs<RecordType>())
-    return RT->getDecl();
+    return RT->getOriginalDecl();
   return nullptr;
 }
 
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
index 76754394de760..40fd15c08f0a1 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
@@ -92,7 +92,7 @@ void SlicingCheck::diagnoseSlicedOverriddenMethods(
   for (const auto &Base : DerivedDecl.bases()) {
     if (const auto *BaseRecordType = Base.getType()->getAs<RecordType>()) {
       if (const auto *BaseRecord = cast_or_null<CXXRecordDecl>(
-              BaseRecordType->getDecl()->getDefinition()))
+              BaseRecordType->getOriginalDecl()->getDefinition()))
         diagnoseSlicedOverriddenMethods(Call, *BaseRecord, BaseDecl);
     }
   }
diff --git a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
index 80ff97a762134..0302a5ad4957c 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -74,7 +74,7 @@ bool MultipleInheritanceCheck::isInterface(const CXXRecordDecl *Node) {
     const auto *Ty = I.getType()->getAs<RecordType>();
     if (!Ty)
       continue;
-    const RecordDecl *D = Ty->getDecl()->getDefinition();
+    const RecordDecl *D = Ty->getOriginalDecl()->getDefinition();
     if (!D)
       continue;
     const auto *Base = cast<CXXRecordDecl>(D);
@@ -106,7 +106,8 @@ void MultipleInheritanceCheck::check(const MatchFinder::MatchResult &Result) {
       const auto *Ty = I.getType()->getAs<RecordType>();
       if (!Ty)
         continue;
-      const auto *Base = cast<CXXRecordDecl>(Ty->getDecl()->getDefinition());
+      const auto *Base =
+          cast<CXXRecordDecl>(Ty->getOriginalDecl()->getDefinition());
       if (!isInterface(Base))
         NumConcrete++;
     }
@@ -117,7 +118,8 @@ void MultipleInheritanceCheck::check(const MatchFinder::MatchResult &Result) {
       const auto *Ty = V.getType()->getAs<RecordType>();
       if (!Ty)
         continue;
-      const auto *Base = cast<CXXRecordDecl>(Ty->getDecl()->getDefinition());
+      const auto *Base =
+          cast<CXXRecordDecl>(Ty->getOriginalDecl()->getDefinition());
       if (!isInterface(Base))
         NumConcrete++;
     }
diff --git a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
index 3deea0620514b..68233ec6bd441 100644
--- a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
@@ -72,7 +72,7 @@ static bool isStdInitializerList(QualType Type) {
   }
   if (const auto *RT = Type->getAs<RecordType>()) {
     if (const auto *Specialization =
-            dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl()))
+            dyn_cast<ClassTemplateSpecializationDecl>(RT->getOriginalDecl()))
       return declIsStdInitializerList(Specialization->getSpecializedTemplate());
   }
   return false;
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index e5e8c91a9da30..8211a0ec6a5e1 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -132,7 +132,7 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
     }
     if (const auto *ECD = dyn_cast<EnumConstantDecl>(Used)) {
       if (const auto *ET = ECD->getType()->getAs<EnumType>())
-        removeFromFoundDecls(ET->getDecl());
+        removeFromFoundDecls(ET->getOriginalDecl());
     }
   };
   // We rely on the fact that the clang AST is walked in order, usages are only
diff --git a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
index 7329b99e4b915..5310f2fd25381 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
@@ -29,7 +29,7 @@ static bool isLockGuardDecl(const NamedDecl *Decl) {
 
 static bool isLockGuard(const QualType &Type) {
   if (const auto *Record = Type->getAs<RecordType>())
-    if (const RecordDecl *Decl = Record->getDecl())
+    if (const RecordDecl *Decl = Record->getOriginalDecl())
       return isLockGuardDecl(Decl);
 
   if (const auto *TemplateSpecType = Type->getAs<TemplateSpecializationType>())
diff --git a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
index 5a04029e4a6fa..447c2437666cf 100644
--- a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
@@ -414,9 +414,9 @@ static bool areTypesCompatible(QualType ArgType, QualType ParamType,
   // Arithmetic types are interconvertible, except scoped enums.
   if (ParamType->isArithmeticType() && ArgType->isArithmeticType()) {
     if ((ParamType->isEnumeralType() &&
-         ParamType->castAs<EnumType>()->getDecl()->isScoped()) ||
+         ParamType->castAs<EnumType>()->getOriginalDecl()->isScoped()) ||
         (ArgType->isEnumeralType() &&
-         ArgType->castAs<EnumType>()->getDecl()->isScoped()))
+         ArgType->castAs<EnumType>()->getOriginalDecl()->isScoped()))
       return false;
 
     return true;
diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
index 0637d0eff688c..aa6aefcf0c493 100644
--- a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
@@ -66,7 +66,8 @@ ExceptionSpecAnalyzer::analyzeBase(const CXXBaseSpecifier &Base,
   if (!RecType)
     return State::Unknown;
 
-  const auto *BaseClass = cast<CXXRecordDecl>(RecType->getDecl());
+  const auto *BaseClass =
+      cast<CXXRecordDecl>(RecType->getOriginalDecl())->getDefinitionOrSelf();
 
   return analyzeRecord(BaseClass, Kind);
 }
diff --git a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
index 7f4ccca84faa5..3229efb957067 100644
--- a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
@@ -465,8 +465,9 @@ bool FormatStringConverter::emitIntegerArgument(
     // the signedness based on the format string, so we need to do the
     // same.
     if (const auto *ET = ArgType->getAs<EnumType>()) {
-      if (const std::optional<std::string> MaybeCastType =
-              castTypeForArgument(ArgKind, ET->getDecl()->getIntegerType()))
+      if (const std::optional<std::string> MaybeCastType = castTypeForArgument(
+              ArgKind,
+              ET->getOriginalDecl()->getDefinitionOrSelf()->getIntegerType()))
         ArgFixes.emplace_back(
             ArgIndex, (Twine("static_cast<") + *MaybeCastType + ">(").str());
       else
diff --git a/clang-tools-extra/clang-tidy/utils/TypeTraits.cpp b/clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
index 44db0c2aed607..96d3a5bbd86a2 100644
--- a/clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
+++ b/clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
@@ -124,7 +124,8 @@ bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context) {
     return true;
 
   if (const auto *RT = CanonicalType->getAs<RecordType>()) {
-    return recordIsTriviallyDefaultConstructible(*RT->getDecl(), Context);
+    return recordIsTriviallyDefaultConstructible(
+        *RT->getOriginalDecl()->getDefinitionOrSelf(), Context);
   }
 
   // No other types can match.
diff --git a/clang-tools-extra/clangd/DumpAST.cpp b/clang-tools-extra/clangd/DumpAST.cpp
index 54e15b2f553c6..14e14a5e9f544 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -261,7 +261,7 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
       return TL.getType().getLocalQualifiers().getAsString(
           Ctx.getPrintingPolicy());
     if (const auto *TT = dyn_cast<TagType>(TL.getTypePtr()))
-      return getDetail(TT->getDecl());
+      return getDetail(TT->getOriginalDecl());
     if (const auto *DT = dyn_cast<DeducedType>(TL.getTypePtr()))
       if (DT->isDeduced())
         return DT->getDeducedType().getAsString(Ctx.getPrintingPolicy());
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index d9b684b3952aa..a5ab40e4221f1 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -878,7 +878,7 @@ refInTypeLoc(TypeLoc L, const HeuristicResolver *Resolver) {
       Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
                                   L.getNameLoc(),
                                   /*IsDecl=*/false,
-                                  {L.getDecl()}});
+                                  {L.getOriginalDecl()}});
     }
 
     void VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc L) {
diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp
index 3aac570f33478..f4b312cde6349 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -452,7 +452,7 @@ std::optional<std::string> printExprValue(const Expr *E,
     // Compare to int64_t to avoid bit-width match requirements.
     int64_t Val = Constant.Val.getInt().getExtValue();
     for (const EnumConstantDecl *ECD :
-         T->castAs<EnumType>()->getDecl()->enumerators())
+         T->castAs<EnumType>()->getOriginalDecl()->enumerators())
       if (ECD->getInitVal() == Val)
         return llvm::formatv("{0} ({1})", ECD->getNameAsString(),
                              printHex(Constant.Val.getInt()))
diff --git a/clang-tools-extra/clangd/IncludeFixer.cpp b/clang-tools-extra/clangd/IncludeFixer.cpp
index 50bc2bd7ccb94..cc1125e705674 100644
--- a/clang-tools-extra/clangd/IncludeFixer.cpp
+++ b/clang-tools-extra/clangd/IncludeFixer.cpp
@@ -173,7 +173,7 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
           // `enum x : int;' is not formally an incomplete type.
           // We may need a full definition anyway.
           if (auto * ET = llvm::dyn_cast<EnumType>(T))
-            if (!ET->getDecl()->getDefinition())
+            if (!ET->getOriginalDecl()->getDefinition())
               return fixIncompleteType(*T);
         }
       }
diff --git a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
index 43cfc769f7f71..7e616968c6046 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -116,7 +116,7 @@ bool PopulateSwitch::prepare(const Selection &Sel) {
   EnumT = Cond->getType().getCanonicalType()->getAsAdjusted<EnumType>();
   if (!EnumT)
     return false;
-  EnumD = EnumT->getDecl();
+  EnumD = EnumT->getOriginalDecl();
   if (!EnumD || EnumD->isDependentType())
     return false;
 
diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index 6f51fa68f45b8..ff64b0b257572 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -337,17 +337,17 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
   }
 
   bool VisitUsingTypeLoc(UsingTypeLoc TL) {
-    reportType(TL.getNameLoc(), TL.getFoundDecl());
+    reportType(TL.getNameLoc(), TL.getDecl());
     return true;
   }
 
   bool VisitTagTypeLoc(TagTypeLoc TTL) {
-    reportType(TTL.getNameLoc(), TTL.getDecl());
+    reportType(TTL.getNameLoc(), TTL.getOriginalDecl());
     return true;
   }
 
   bool VisitTypedefTypeLoc(TypedefTypeLoc TTL) {
-    reportType(TTL.getNameLoc(), TTL.getTypedefNameDecl());
+    reportType(TTL.getNameLoc(), TTL.getDecl());
     return true;
   }
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ca50227b2426a..23a683ededa87 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8867,8 +8867,8 @@ inline bool Type::isIntegerType() const {
   if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
     // Incomplete enum types are not treated as integer types.
     // FIXME: In C++, enum types are never integer types.
-    return IsEnumDeclComplete(ET->getDecl()) &&
-      !IsEnumDeclScoped(ET->getDecl());
+    return IsEnumDeclComplete(ET->getOriginalDecl()) &&
+           !IsEnumDeclScoped(ET->getOriginalDecl());
   }
   return isBitIntType();
 }
@@ -8926,7 +8926,7 @@ inline bool Type::isScalarType() const {
   if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
     // Enums are scalar types, but only if they are defined.  Incomplete enums
     // are not treated as scalar types.
-    return IsEnumDeclComplete(ET->getDecl());
+    return IsEnumDeclComplete(ET->getOriginalDecl());
   return isa<PointerType>(CanonicalType) ||
          isa<BlockPointerType>(CanonicalType) ||
          isa<MemberPointerType>(CanonicalType) ||
@@ -8942,7 +8942,7 @@ inline bool Type::isIntegralOrEnumerationType() const {
   // Check for a complete enum type; incomplete enum types are not properly an
   // enumeration type in the sense required here.
   if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
-    return IsEnumDeclComplete(ET->getDecl());
+    return IsEnumDeclComplete(ET->getOriginalDecl());
 
   return isBitIntType();
 }
diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index ee3dc84479fd9..2d62209bbc28c 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -902,8 +902,9 @@ void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
   }
   case APValue::Struct: {
     Out << '{';
-    const RecordDecl *RD = Ty->castAs<RecordType>()->getDecl();
     bool First = true;
+    const RecordDecl *RD =
+        Ty->castAs<RecordType>()->getOriginalDecl()->getDefinitionOrSelf();
     if (unsigned N = getStructNumBases()) {
       const CXXRecordDecl *CD = cast<CXXRecordDecl>(RD);
       CXXRecordDecl::base_class_const_iterator BI = CD->bases_begin();
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 814e7cf87fec8..2c98bccef5dbb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -653,7 +653,7 @@ comments::FullComment *ASTContext::getCommentForDecl(
       // does not have one of its own.
       QualType QT = TD->getUnderlyingType();
       if (const auto *TT = QT->getAs<TagType>())
-        if (const Decl *TD = TT->getDecl())
+        if (const Decl *TD = TT->getOriginalDecl())
           if (comments::FullComment *FC = getCommentForDecl(TD, PP))
             return cloneFullComment(FC, D);
     }
@@ -1931,10 +1931,12 @@ TypeInfoChars ASTContext::getTypeInfoDataSizeInChars(QualType T) const {
   // of a base-class subobject.  We decide whether that's possible
   // during class layout, so here we can just trust the layout results.
   if (getLangOpts().CPlusPlus) {
-    if (const auto *RT = T->getAs<RecordType>();
-        RT && !RT->getDecl()->isInvalidDecl()) {
-      const ASTRecordLayout &layout = getASTRecordLayout(RT->getDecl());
-      Info.Width = layout.getDataSize();
+    if (const auto *RT = T->getAs<RecordType>()) {
+      const auto *RD = RT->getOriginalDecl()->getDefinitionOrSelf();
+      if (!RD->isInvalidDecl()) {
+        const ASTRecordLayout &layout = getASTRecordLayout(RD);
+        Info.Width = layout.getDataSize();
+      }
     }
   }
 
@@ -2001,8 +2003,9 @@ bool ASTContext::isPromotableIntegerType(QualType T) const {
   // Enumerated types are promotable to their compatible integer types
   // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2).
   if (const auto *ET = T->getAs<EnumType>()) {
-    if (T->isDependentType() || ET->getDecl()->getPromotionType().isNull() ||
-        ET->getDecl()->isScoped())
+    const EnumDecl *ED = ET->getOriginalDecl()->getDefinitionOrSelf();
+    if (T->isDependentType() || ED->getPromotionType().isNull() ||
+        ED->isScoped())
       return false;
 
     return true;
@@ -2470,15 +2473,16 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
   case Type::Record:
   case Type::Enum: {
     const auto *TT = cast<TagType>(T);
+    const TagDecl *TD = TT->getOriginalDecl()->getDefinitionOrSelf();
 
-    if (TT->getDecl()->isInvalidDecl()) {
+    if (TD->isInvalidDecl()) {
       Width = 8;
       Align = 8;
       break;
     }
 
-    if (const auto *ET = dyn_cast<EnumType>(TT)) {
-      const EnumDecl *ED = ET->getDecl();
+    if (isa<EnumType>(TT)) {
+      const EnumDecl *ED = cast<EnumDecl>(TD);
       TypeInfo Info =
           getTypeInfo(ED->getIntegerType()->getUnqualifiedDesugaredType());
       if (unsigned AttrAlign = ED->getMaxAlignment()) {
@@ -2613,8 +2617,7 @@ unsigned ASTContext::getTypeUnadjustedAlign(const Type *T) const {
 
   unsigned UnadjustedAlign;
   if (const auto *RT = T->getAs<RecordType>()) {
-    const RecordDecl *RD = RT->getDecl();
-    const ASTRecordLayout &Layout = getASTRecordLayout(RD);
+    const ASTRecordLayout &Layout = getASTRecordLayout(RT->getOriginalDecl());
     UnadjustedAlign = toBits(Layout.getUnadjustedAlignment());
   } else if (const auto *ObjCI = T->getAs<ObjCInterfaceType>()) {
     const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl());
@@ -2690,7 +2693,7 @@ unsigned ASTContext::getPreferredTypeAlign(const Type *T) const {
     return ABIAlign;
 
   if (const auto *RT = T->getAs<RecordType>()) {
-    const RecordDecl *RD = RT->getDecl();
+    const RecordDecl *RD = RT->getOriginalDecl()->getDefinitionOrSelf();
 
     // When used as part of a typedef, or together with a 'packed' attribute,
     // the 'aligned' attribute can be used to decrease alignment. Note that the
@@ -2713,7 +2716,10 @@ unsigned ASTContext::getPreferredTypeAlign(const Type *T) const {
   if (const auto *CT = T->getAs<ComplexType>())
     T = CT->getElementType().getTypePtr();
   if (const auto *ET = T->getAs<EnumType>())
-    T = ET->getDecl()->getIntegerType().getTypePtr();
+    T = ET->getOriginalDecl()
+            ->getDefinitionOrSelf()
+            ->getIntegerType()
+            .getTypePtr();
   if (T->isSpecificBuiltinType(BuiltinType::Double) ||
       T->isSpecificBuiltinType(BuiltinType::LongLong) ||
       T->isSpecificBuiltinType(BuiltinType::ULongLong) ||
@@ -3040,7 +3046,8 @@ bool ASTContext::hasUniqueObjectRepresentations(
     return !ABI->getMemberPointerInfo(MPT).HasPadding;
 
   if (Ty->isRecordType()) {
-    const RecordDecl *Record = Ty->castAs<RecordType>()->...
[truncated]

@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-4 branch from 5840822 to 6f7eb76 Compare July 21, 2025 00:07
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-5 branch from 3c4412b to 021d58c Compare July 21, 2025 00:07
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-4 branch from 6f7eb76 to 07134c3 Compare July 21, 2025 03:27
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-5 branch from 021d58c to ee9bcb9 Compare July 21, 2025 03:27
Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate you extracting this. these are pretty trivial too.

@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-5 branch from ee9bcb9 to f695908 Compare July 21, 2025 23:55
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-4 branch from 07134c3 to 07588c1 Compare July 21, 2025 23:55
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-5 branch from f695908 to ce5f365 Compare July 22, 2025 00:01
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-4 branch from 07588c1 to 172e50c Compare July 22, 2025 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 backend:AMDGPU backend:ARC backend:ARM backend:CSKY backend:Hexagon backend:Lanai backend:loongarch backend:MIPS backend:PowerPC backend:RISC-V backend:Sparc backend:SystemZ backend:WebAssembly backend:X86 clang:analysis clang:as-a-library libclang and C++ API clang:bytecode Issues for the clang bytecode constexpr interpreter clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang:openmp OpenMP related changes to Clang clang:static analyzer clang Clang issues not falling into any other category clang-tidy clang-tools-extra clangd coroutines C++20 coroutines debuginfo HLSL HLSL Language Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants