aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaExprMember.cpp
diff options
context:
space:
mode:
authorChris Bieneman <chris.bieneman@me.com>2023-08-30 15:55:04 -0500
committerChris Bieneman <chris.bieneman@me.com>2023-09-05 19:38:50 -0500
commit400d3261a0da56554aee8e5a2fbc27eade9d05db (patch)
tree0d9b1bbd49c5484bd5f1b46ad7756dbe11e98008 /clang/lib/Sema/SemaExprMember.cpp
parent68e94f1f27b658183c3ebbce4aaadc437d0cee3a (diff)
downloadllvm-400d3261a0da56554aee8e5a2fbc27eade9d05db.zip
llvm-400d3261a0da56554aee8e5a2fbc27eade9d05db.tar.gz
llvm-400d3261a0da56554aee8e5a2fbc27eade9d05db.tar.bz2
[HLSL] Cleanup support for `this` as an l-value
The goal of this change is to clean up some of the code surrounding HLSL using CXXThisExpr as a non-pointer l-value. This change cleans up a bunch of assumptions and inconsistencies around how the type of `this` is handled through the AST and code generation. This change is be mostly NFC for HLSL, and completely NFC for other language modes. This change introduces a new member to query for the this object's type and seeks to clarify the normal usages of the this type. With the introudction of HLSL to clang, CXXThisExpr may now be an l-value and behave like a reference type rather than C++'s normal method of it being an r-value of pointer type. With this change there are now three ways in which a caller might need to query the type of `this`: * The type of the `CXXThisExpr` * The type of the object `this` referrs to * The type of the implicit (or explicit) `this` argument This change codifies those three ways you may need to query respectively as: * CXXMethodDecl::getThisType() * CXXMethodDecl::getThisObjectType() * CXXMethodDecl::getThisArgType() This change then revisits all uses of `getThisType()`, and in cases where the only use was to resolve the pointee type, it replaces the call with `getThisObjectType()`. In other cases it evaluates whether the desired returned type is the type of the `this` expr, or the type of the `this` function argument. The `this` expr type is used for creating additional expr AST nodes and for member lookup, while the argument type is used mostly for code generation. Additionally some cases that used `getThisType` in simple queries could be substituted for `getThisObjectType`. Since `getThisType` is implemented in terms of `getThisObjectType` calling the later should be more efficient if the former isn't needed. Reviewed By: aaron.ballman, bogner Differential Revision: https://reviews.llvm.org/D159247
Diffstat (limited to 'clang/lib/Sema/SemaExprMember.cpp')
-rw-r--r--clang/lib/Sema/SemaExprMember.cpp19
1 files changed, 5 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index 3d14ca3..fe92215 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1897,20 +1897,11 @@ Sema::BuildImplicitMemberExpr(const CXXScopeSpec &SS,
if (SS.getRange().isValid())
Loc = SS.getRange().getBegin();
baseExpr = BuildCXXThisExpr(loc, ThisTy, /*IsImplicit=*/true);
- if (getLangOpts().HLSL && ThisTy.getTypePtr()->isPointerType()) {
- ThisTy = ThisTy.getTypePtr()->getPointeeType();
- return BuildMemberReferenceExpr(baseExpr, ThisTy,
- /*OpLoc*/ SourceLocation(),
- /*IsArrow*/ false, SS, TemplateKWLoc,
- /*FirstQualifierInScope*/ nullptr, R,
- TemplateArgs, S);
- }
}
- return BuildMemberReferenceExpr(baseExpr, ThisTy,
- /*OpLoc*/ SourceLocation(),
- /*IsArrow*/ true,
- SS, TemplateKWLoc,
- /*FirstQualifierInScope*/ nullptr,
- R, TemplateArgs, S);
+ return BuildMemberReferenceExpr(
+ baseExpr, ThisTy,
+ /*OpLoc=*/SourceLocation(),
+ /*IsArrow=*/!getLangOpts().HLSL, SS, TemplateKWLoc,
+ /*FirstQualifierInScope=*/nullptr, R, TemplateArgs, S);
}