Skip to content

Commit

Permalink
If a HyperobjectType has an incomplete element type it must
Browse files Browse the repository at this point in the history
be marked as containing an error.
  • Loading branch information
VoxSciurorum authored and neboat committed Dec 15, 2023
1 parent 60c7e90 commit 3d3c7bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 9 additions & 7 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned> Code = ContainsHyperobject(Result))
Diag(Loc, *Code) << Result;
if (std::optional<unsigned> 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.
Expand Down

0 comments on commit 3d3c7bb

Please sign in to comment.