From 3d3c7bbafb2cf2e827dcce3ff4eff02dbb67b582 Mon Sep 17 00:00:00 2001 From: "John F. Carr" Date: Sat, 9 Dec 2023 16:35:02 -0500 Subject: [PATCH] If a HyperobjectType has an incomplete element type it must be marked as containing an error. --- clang/lib/AST/Type.cpp | 2 ++ clang/lib/Sema/SemaType.cpp | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 5b7463d8d403..d32e47372e40 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -3206,6 +3206,8 @@ HyperobjectType::HyperobjectType(QualType Element, QualType CanonicalPtr, : Type(Hyperobject, CanonicalPtr, Element->getDependence()), ElementType(Element), Identity(i), Reduce(r), IdentityID(ifn), ReduceID(rfn) { + if (Element->isIncompleteType()) // diagnosed in caller + addDependence(TypeDependence::Error); } bool HyperobjectType::hasCallbacks() const { diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 0cff893f0c0d..e4b9c77abacf 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2442,20 +2442,22 @@ Expr *Sema::ValidateReducerCallback(Expr *E, unsigned NumArgs, QualType Sema::BuildHyperobjectType(QualType Element, Expr *Identity, Expr *Reduce, SourceLocation Loc) { - QualType Result = Element; + // This function must return a HyperobjectType with the given + // element type, otherwise the rest of the front end will get angry. + // Template instantiation is quite strict about preserving structure. + // The compiler will also get angry if the element type is incomplete + // and the HyperobjectType is not marked as containing an error. if (!RequireCompleteType(Loc, Element, CompleteTypeKind::Normal, diag::incomplete_hyperobject)) { - if (std::optional Code = ContainsHyperobject(Result)) - Diag(Loc, *Code) << Result; + if (std::optional Code = ContainsHyperobject(Element)) + Diag(Loc, *Code) << Element; } Identity = ValidateReducerCallback(Identity, 1, Loc); Reduce = ValidateReducerCallback(Reduce, 2, Loc); - // The result of this function must be HyperobjectType if it is called - // from C++ template instantiation when rebuilding an existing hyperobject - // type. - return Context.getHyperobjectType(Result, Identity, Reduce); + // The result will be marked erroneous if Element is incomplete. + return Context.getHyperobjectType(Element, Identity, Reduce); } /// Build a Read-only Pipe type.