Skip to content

Commit dc401d9

Browse files
committed
Handle implicit this methods (#4123)
This catches a case I missed in #4112, for handling implicit `this` in member method lookups.
1 parent 1b2c1ae commit dc401d9

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

tools/clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,10 @@ CXXThisExpr *Sema::genereateHLSLThis(SourceLocation Loc, QualType ThisType,
982982
bool isImplicit) {
983983
// Expressions cannot be of reference type - instead, they yield
984984
// an lvalue on the underlying type.
985-
CXXThisExpr *ResultExpr = new (Context)
986-
CXXThisExpr(Loc, ThisType.getTypePtr()->getPointeeType(), isImplicit);
985+
const Type *TypePtr = ThisType.getTypePtr();
986+
CXXThisExpr *ResultExpr = new (Context) CXXThisExpr(
987+
Loc, TypePtr->isPointerType() ? TypePtr->getPointeeType() : ThisType,
988+
isImplicit);
987989
ResultExpr->setValueKind(ExprValueKind::VK_LValue);
988990
return ResultExpr;
989991
}

tools/clang/lib/Sema/SemaOverload.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11835,9 +11835,12 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
1183511835
Qualifier = UnresExpr->getQualifier();
1183611836

1183711837
QualType ObjectType = UnresExpr->getBaseType();
11838-
Expr::Classification ObjectClassification
11839-
= UnresExpr->isArrow()? Expr::Classification::makeSimpleLValue()
11840-
: UnresExpr->getBase()->Classify(Context);
11838+
// HLSL Change Begin - This is a reference
11839+
Expr::Classification ObjectClassification =
11840+
(getLangOpts().HLSL || UnresExpr->isArrow())
11841+
? Expr::Classification::makeSimpleLValue()
11842+
: UnresExpr->getBase()->Classify(Context);
11843+
// HLSL Change End - This is a reference
1184111844

1184211845
// Add overload candidates
1184311846
OverloadCandidateSet CandidateSet(UnresExpr->getMemberLoc(),
@@ -12691,9 +12694,14 @@ Expr *Sema::FixOverloadedFunctionReference(Expr *E, DeclAccessPair Found,
1269112694
if (MemExpr->getQualifier())
1269212695
Loc = MemExpr->getQualifierLoc().getBeginLoc();
1269312696
CheckCXXThisCapture(Loc);
12694-
Base = new (Context) CXXThisExpr(Loc,
12695-
MemExpr->getBaseType(),
12696-
/*isImplicit=*/true);
12697+
// HLSL Change Begin - This is a reference
12698+
if (getLangOpts().HLSL)
12699+
Base = genereateHLSLThis(Loc, MemExpr->getBaseType(),
12700+
/*isImplicit=*/true);
12701+
else
12702+
Base = new (Context) CXXThisExpr(Loc, MemExpr->getBaseType(),
12703+
/*isImplicit=*/true);
12704+
// HLSL Change End - This is a reference
1269712705
}
1269812706
} else
1269912707
Base = MemExpr->getBase();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %dxc -T ps_6_0 -ast-dump %s | FileCheck %s
2+
3+
struct Foo {
4+
float m;
5+
float2 f(float2 v) { return 0; }
6+
float3 f(float3 v) { return 1; }
7+
float2 g(float2 v) { return f(v); }
8+
};
9+
10+
// CHECK: CXXMemberCallExpr 0x{{[0-9a-zA-Z]+}} <col:31, col:34> 'float2':'vector<float, 2>'
11+
// CHECK-NEXT: MemberExpr 0x{{[0-9a-zA-Z]+}} <col:31> '<bound member function type>' .f
12+
// CHECK-NEXT: CXXThisExpr 0x{{[0-9a-zA-Z]+}} <col:31> 'Foo' lvalue this
13+
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-zA-Z]+}} <col:33> 'float2':'vector<float, 2>' <LValueToRValue>
14+
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-zA-Z]+}} <col:33> 'float2':'vector<float, 2>' lvalue ParmVar 0x{{[0-9a-zA-Z]+}} 'v' 'float2':'vector<float, 2>'
15+
16+
float4 main(float2 coord: TEXCOORD) : SV_TARGET {
17+
Foo foo = { coord.x };
18+
return float4(foo.g(coord.y), 0, 1);
19+
}

0 commit comments

Comments
 (0)