troyj created this revision.
troyj added a reviewer: bruno.
Herald added a project: All.
troyj requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

getFunctionTypeInternal forms a FoldingSetNodeID and then calls 
FunctionProtoTypes.FindNodeOrInsertPos(). Later, upon returning from recursion, 
it calls FunctionProtoTypes.FindNodeOrInsertPos() again with the same ID. This 
second call will yield the same InsertPos unless the recursion caused 
FunctionProtoTypes to rebucket. The rebucketing can be detected by comparing 
the capacity of the set before and after the recursion, which allows us to skip 
the redundant call.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136633

Files:
  clang/lib/AST/ASTContext.cpp


Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4514,13 +4514,17 @@
 
     // Adjust the canonical function result type.
     CanQualType CanResultTy = getCanonicalFunctionResultType(ResultTy);
+    const auto OrigCapacity = FunctionProtoTypes.capacity();
     Canonical =
         getFunctionTypeInternal(CanResultTy, CanonicalArgs, CanonicalEPI, 
true);
 
-    // Get the new insert position for the node we care about.
-    FunctionProtoType *NewIP =
-      FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
-    assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
+    // Get the new insert position for the node we care about, if the recursive
+    // call invalidated InsertPos.
+    if (FunctionProtoTypes.capacity() != OrigCapacity) {
+      FunctionProtoType *NewIP =
+        FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
+      assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
+    }
   }
 
   // Compute the needed size to hold this FunctionProtoType and the


Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4514,13 +4514,17 @@
 
     // Adjust the canonical function result type.
     CanQualType CanResultTy = getCanonicalFunctionResultType(ResultTy);
+    const auto OrigCapacity = FunctionProtoTypes.capacity();
     Canonical =
         getFunctionTypeInternal(CanResultTy, CanonicalArgs, CanonicalEPI, true);
 
-    // Get the new insert position for the node we care about.
-    FunctionProtoType *NewIP =
-      FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
-    assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
+    // Get the new insert position for the node we care about, if the recursive
+    // call invalidated InsertPos.
+    if (FunctionProtoTypes.capacity() != OrigCapacity) {
+      FunctionProtoType *NewIP =
+        FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
+      assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
+    }
   }
 
   // Compute the needed size to hold this FunctionProtoType and the
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D136633: [clan... Troy Johnson via Phabricator via cfe-commits

Reply via email to