Skip to content

Commit

Permalink
Handle references to hyperobjects
Browse files Browse the repository at this point in the history
  • Loading branch information
VoxSciurorum committed Dec 4, 2021
1 parent 5f3d028 commit d448b6d
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2020,42 +2020,36 @@ Expr *Sema::BuildHyperobjectLookup(Expr *E) {
if (!isa<VarDecl>(D))
return E;

QualType OuterType = D->getType();

/* The hyperobject attribute may be on the declaration or a
typedef name providing its type, but not on any other
type declaration. */
type declaration.
TODO: A loop is probably required. */
HyperobjectAttr *H = cast<VarDecl>(D)->getAttr<HyperobjectAttr>();

if (!H) {
const TypedefType *T = D->getType()->getAs<TypedefType>();
const TypedefType *T = OuterType->getAs<TypedefType>();
if (!T)
return E;
H = T->getDecl()->getAttr<HyperobjectAttr>();
if (!H)
return E;
}

QualType Ty = E->getType();

if (false) {
llvm::errs() << "reducer reference ";
Ty.dump();
llvm::errs() << " | ";
D->dump();
llvm::errs() << '\n';
}

Expr *Lookup = H->getLookup();
if (!Lookup || !isa<DeclRefExpr>(Lookup))
return E;

QualType Ptr = Context.getPointerType(D->getType());

Expr *A = UnaryOperator::Create(Context, E, UO_AddrOf, Ptr,
VK_RValue, OK_Ordinary,
SourceLocation(), false,
CurFPFeatureOverrides());
QualType ResultType = OuterType.getNonReferenceType();
QualType Ptr = Context.getPointerType(ResultType);

Expr *VarAddr = UnaryOperator::Create(Context, E, UO_AddrOf, Ptr,
VK_RValue, OK_Ordinary,
SourceLocation(), false,
CurFPFeatureOverrides());

ExprResult Call = BuildCallExpr(nullptr, Lookup, E->getExprLoc(),
{ A }, E->getExprLoc(), nullptr);
{ VarAddr }, E->getExprLoc(), nullptr);

if (!Call.isUsable())
return E; /* error should have been printed */
Expand All @@ -2065,11 +2059,9 @@ Expr *Sema::BuildHyperobjectLookup(Expr *E) {
CK_BitCast /*???*/,
Call.get(), nullptr, VK_RValue,
CurFPFeatureOverrides());
auto *UO =
UnaryOperator::Create(Context, Casted, UO_Deref, Ty,
VK_LValue, OK_Ordinary, SourceLocation(),
false, CurFPFeatureOverrides());
return UO;
return UnaryOperator::Create(Context, Casted, UO_Deref, ResultType,
VK_LValue, OK_Ordinary, SourceLocation(),
false, CurFPFeatureOverrides());
}

/// BuildDeclRefExpr - Build an expression that references a
Expand Down

0 comments on commit d448b6d

Please sign in to comment.