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 committed Dec 9, 2023
1 parent b167f6b commit b7d1860
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
7 changes: 4 additions & 3 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
return CanQualType::CreateUnsafe(getComplexType((QualType) T));
}

QualType getHyperobjectType(QualType T, Expr *R, Expr *I) const;
CanQualType getHyperobjectType(CanQualType T, Expr *R, Expr *I) const {
return CanQualType::CreateUnsafe(getHyperobjectType((QualType) T, R, I));
QualType getHyperobjectType(QualType T, Expr *R, Expr *I, bool Error) const;
CanQualType getHyperobjectType(CanQualType T, Expr *R, Expr *I,
bool E) const {
return CanQualType::CreateUnsafe(getHyperobjectType((QualType) T, R, I, E));
}

/// Return the uniqued reference to the type for a pointer to
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -6583,7 +6583,8 @@ class HyperobjectType final : public Type, public llvm::FoldingSetNode {

HyperobjectType(QualType Element, QualType CanonicalPtr,
Expr *i, const FunctionDecl *ifn,
Expr *r, const FunctionDecl *rfn);
Expr *r, const FunctionDecl *rfn,
bool Error);

public:
QualType getElementType() const { return ElementType; }
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/TypeProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let Class = HyperobjectType in {
}

def : Creator<[{
return ctx.getHyperobjectType(elementType, reduce, identity);
return ctx.getHyperobjectType(elementType, reduce, identity, false);
}]>;
}

Expand Down
12 changes: 7 additions & 5 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3323,7 +3323,8 @@ static const FunctionDecl *getFunction(Expr *E) {
return F->getFirstDecl();
}

QualType ASTContext::getHyperobjectType(QualType T, Expr *I, Expr *R) const {
QualType ASTContext::getHyperobjectType(QualType T, Expr *I, Expr *R,
bool Error) const {
assert(I && R);
bool IN = HyperobjectType::isNullish(I);
bool RN = HyperobjectType::isNullish(R);
Expand All @@ -3334,13 +3335,13 @@ QualType ASTContext::getHyperobjectType(QualType T, Expr *I, Expr *R) const {

QualType Canonical;
if (!T.isCanonical())
Canonical = getHyperobjectType(getCanonicalType(T), I, R);
Canonical = getHyperobjectType(getCanonicalType(T), I, R, Error);

// Do not unique hyperobject types with variable expressions.
if (Varies) {
auto *New =
new (*this, TypeAlignment)
HyperobjectType(T, Canonical, I, IF, R, RF);
HyperobjectType(T, Canonical, I, IF, R, RF, Error);
Types.push_back(New);
return QualType(New, 0);
}
Expand All @@ -3357,7 +3358,7 @@ QualType ASTContext::getHyperobjectType(QualType T, Expr *I, Expr *R) const {

auto *New =
new (*this, TypeAlignment)
HyperobjectType(T, Canonical, I, IF, R, RF);
HyperobjectType(T, Canonical, I, IF, R, RF, Error);
Types.push_back(New);
HyperobjectTypes.InsertNode(New, InsertPos);
return QualType(New, 0);
Expand Down Expand Up @@ -12912,9 +12913,10 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
const auto *HX = cast<HyperobjectType>(X), *HY = cast<HyperobjectType>(Y);
assert(Ctx.hasSameExpr(HX->getIdentity(), HY->getIdentity()));
assert(Ctx.hasSameExpr(HX->getReduce(), HY->getReduce()));
// TODO: Does error need to be handled better?
return Ctx.getHyperobjectType(
Ctx.getCommonSugaredType(HX->getElementType(), HY->getElementType()),
HX->getIdentity(), HX->getReduce());
HX->getIdentity(), HX->getReduce(), false);
}
}
llvm_unreachable("Unknown Type Class");
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3202,10 +3202,13 @@ bool HyperobjectType::isNullish(Expr *E) {

HyperobjectType::HyperobjectType(QualType Element, QualType CanonicalPtr,
Expr *i, const FunctionDecl *ifn,
Expr *r, const FunctionDecl *rfn)
Expr *r, const FunctionDecl *rfn,
bool Error)
: Type(Hyperobject, CanonicalPtr, Element->getDependence()),
ElementType(Element), Identity(i), Reduce(r),
IdentityID(ifn), ReduceID(rfn) {
if (Error)
addDependence(TypeDependence::Error);
}

bool HyperobjectType::hasCallbacks() const {
Expand Down
20 changes: 11 additions & 9 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;
if (!RequireCompleteType(Loc, Element, CompleteTypeKind::Normal,
diag::incomplete_hyperobject)) {
if (std::optional<unsigned> Code = ContainsHyperobject(Result))
Diag(Loc, *Code) << Result;
// 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.
bool Error = RequireCompleteType(Loc, Element, CompleteTypeKind::Normal,
diag::incomplete_hyperobject);
if (!Error) {
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);
return Context.getHyperobjectType(Element, Identity, Reduce, Error);
}

/// Build a Read-only Pipe type.
Expand Down

0 comments on commit b7d1860

Please sign in to comment.