[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 10:06:27 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Wei Wang (apolloww)

<details>
<summary>Changes</summary>

When creating a new UsingType, the underlying type may change if it is a declaration. This creates an inconsistency between the type searched and type created. Move the update before search so that we always use the same type for search and creation. 

---
Full diff: https://github.com/llvm/llvm-project/pull/79182.diff


1 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+7-6) 


``````````diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..d312ef61fb15d4a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,12 +4672,6 @@ QualType ASTContext::getTypedefType(const TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
                                   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
-    return QualType(T, 0);
-
   const Type *TypeForDecl =
       cast<TypeDecl>(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4687,6 +4681,13 @@ QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
     Underlying = QualType();
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
+    return QualType(T, 0);
+  }
+
   void *Mem =
       Allocate(UsingType::totalSizeToAlloc<QualType>(!Underlying.isNull()),
                alignof(UsingType));

``````````

</details>


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


More information about the cfe-commits mailing list