================
@@ -3768,17 +3786,46 @@ QualType ASTContext::getCountAttributedType(
     return QualType(CATy, 0);
 
   QualType CanonTy = getCanonicalType(WrappedTy);
-  size_t Size = CountAttributedType::totalSizeToAlloc<TypeCoupledDeclRefInfo>(
-      DependentDecls.size());
-  CATy = (CountAttributedType *)Allocate(Size, TypeAlignment);
-  new (CATy) CountAttributedType(WrappedTy, CanonTy, CountExpr, CountInBytes,
-                                 OrNull, DependentDecls);
+  ArrayRef<TypeCoupledDeclRefInfo> Decls =
+      allocateCoupledDecls(*this, DependentDecls);
+  CATy = new (*this, alignof(CountAttributedType)) CountAttributedType(
+      WrappedTy, CanonTy, CountExpr, CountInBytes, OrNull, Decls);
   Types.push_back(CATy);
   CountAttributedTypes.insert(CATy, Token);
 
   return QualType(CATy, 0);
 }
 
+CountAttributedType *ASTContext::getIncompleteCountAttributedType(
+    QualType WrappedTy, bool CountInBytes, bool OrNull) const {
+  assert(WrappedTy->isPointerType() || WrappedTy->isArrayType());
+
+  // Deliberately not uniqued. `CountAttributedType::Profile` keys on the
+  // `CountExpr` pointer, so every incomplete node would hash identically as
+  // `(WrappedTy, flags, nullptr)` and two fields with different counts would
+  // share a node. This is fine because expressions are not shared anyway.
+  // `getVariableArrayType` declines to unique for the same
+  // underlying reason: expressions themselves are not uniqued.
+  //
+  // Not added to `Types` yet: an incomplete node whose position turns out to 
be
+  // invalid (a nested counted_by, or a rejected argument) is abandoned without
+  // completion, and a node with a null count must never be reachable by
+  // anything that iterates `Types`. It is registered in
+  // `completeCountAttributedType` instead.
+  return new (*this, alignof(CountAttributedType)) CountAttributedType(
+      WrappedTy, getCanonicalType(WrappedTy), /*CountExpr=*/nullptr,
+      CountInBytes, OrNull, /*CoupledDecls=*/{});
+}
+
+void ASTContext::completeCountAttributedType(
+    CountAttributedType *CATy, Expr *CountExpr,
+    ArrayRef<TypeCoupledDeclRefInfo> DependentDecls) const {
+  ArrayRef<TypeCoupledDeclRefInfo> Decls =
----------------
erichkeane wrote:

I'm of the preference that `CountAttributedType` should 'own' its memory, and 
thus be the one in charge of this allocation.  It seems weird that ASTContext 
is the one doing it.

https://github.com/llvm/llvm-project/pull/223267
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to