Skip to content

Commit 0eb516c

Browse files
committed
[CSGen] Sanitizer should preserve type of re-introduced member references (if any)
(cherry picked from commit 56089d8)
1 parent 311a78d commit 0eb516c

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

lib/Sema/CSGen.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,6 +3368,20 @@ namespace {
33683368
assert(!isa<ImplicitConversionExpr>(expr) &&
33693369
"ImplicitConversionExpr should be eliminated in walkToExprPre");
33703370

3371+
auto buildMemberRef = [&](Type memberType, Expr *base, SourceLoc dotLoc,
3372+
ConcreteDeclRef member, DeclNameLoc memberLoc,
3373+
bool implicit) -> Expr * {
3374+
auto *memberRef = new (TC.Context)
3375+
MemberRefExpr(base, dotLoc, member, memberLoc, implicit);
3376+
3377+
if (memberType) {
3378+
memberRef->setType(memberType);
3379+
return CS.cacheType(memberRef);
3380+
}
3381+
3382+
return memberRef;
3383+
};
3384+
33713385
// A DotSyntaxCallExpr is a member reference that has already been
33723386
// type-checked down to a call; turn it back into an overloaded
33733387
// member reference expression.
@@ -3377,21 +3391,23 @@ namespace {
33773391
memberLoc);
33783392
if (memberAndFunctionRef.first) {
33793393
assert(!isa<ImplicitConversionExpr>(dotCall->getBase()));
3380-
return new (TC.Context) MemberRefExpr(dotCall->getBase(),
3381-
dotCall->getDotLoc(),
3382-
memberAndFunctionRef.first,
3383-
memberLoc, expr->isImplicit());
3394+
return buildMemberRef(dotCall->getType(),
3395+
dotCall->getBase(),
3396+
dotCall->getDotLoc(),
3397+
memberAndFunctionRef.first,
3398+
memberLoc, expr->isImplicit());
33843399
}
33853400
}
33863401

33873402
if (auto *dynamicMember = dyn_cast<DynamicMemberRefExpr>(expr)) {
33883403
if (auto memberRef = dynamicMember->getMember()) {
33893404
assert(!isa<ImplicitConversionExpr>(dynamicMember->getBase()));
3390-
return new (TC.Context) MemberRefExpr(dynamicMember->getBase(),
3391-
dynamicMember->getDotLoc(),
3392-
memberRef,
3393-
dynamicMember->getNameLoc(),
3394-
expr->isImplicit());
3405+
return buildMemberRef(dynamicMember->getType(),
3406+
dynamicMember->getBase(),
3407+
dynamicMember->getDotLoc(),
3408+
memberRef,
3409+
dynamicMember->getNameLoc(),
3410+
expr->isImplicit());
33953411
}
33963412
}
33973413

@@ -3405,10 +3421,11 @@ namespace {
34053421
memberLoc);
34063422
if (memberAndFunctionRef.first) {
34073423
assert(!isa<ImplicitConversionExpr>(dotIgnored->getLHS()));
3408-
return new (TC.Context) MemberRefExpr(dotIgnored->getLHS(),
3409-
dotIgnored->getDotLoc(),
3410-
memberAndFunctionRef.first,
3411-
memberLoc, expr->isImplicit());
3424+
return buildMemberRef(dotIgnored->getType(),
3425+
dotIgnored->getLHS(),
3426+
dotIgnored->getDotLoc(),
3427+
memberAndFunctionRef.first,
3428+
memberLoc, expr->isImplicit());
34123429
}
34133430
}
34143431
return expr;

0 commit comments

Comments
 (0)