aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/HLSLExternalSemaSource.cpp
diff options
context:
space:
mode:
authorHelena Kotas <hekotas@microsoft.com>2024-09-29 20:41:54 -0700
committerGitHub <noreply@github.com>2024-09-29 20:41:54 -0700
commite20bf28987b74ed4f4b48f49f4506d0659c09bed (patch)
treeaf579158f8cbb06881fed650a2e496e22dd0256a /clang/lib/Sema/HLSLExternalSemaSource.cpp
parent6292f117c39b9fc72da4e40328eeeda2aa94a5f2 (diff)
downloadllvm-e20bf28987b74ed4f4b48f49f4506d0659c09bed.zip
llvm-e20bf28987b74ed4f4b48f49f4506d0659c09bed.tar.gz
llvm-e20bf28987b74ed4f4b48f49f4506d0659c09bed.tar.bz2
[HLSL] Replace `element_type*` handles in HLSLExternalSemaSource with `__hlsl_resource_t` builtin type (#110079)
Replace `element_type*` handles in HLSLExternalSemaSource with `__hlsl_resource_t` builtin type. The handle used to be defined as `element_type*` which was used by the provisional subscript operator implementation. Now that the handle is `__hlsl_resource_t` the subscript placeholder implementation was updated to add `element_type* e;` field to the resource struct. and return a reference to that. This field is just a temporary workaround until the indexing is implemented properly in llvm/llvm-project#95956, at which point the field will be removed. This seemed like a better solution than disabling many of the existing tests that already use the `[]` operator. One test has to be disabled nevertheless because an error based on interactions of const and template instantiation (potential bug that can be investigated once indexing is implemented the right way). Fixes #84824
Diffstat (limited to 'clang/lib/Sema/HLSLExternalSemaSource.cpp')
-rw-r--r--clang/lib/Sema/HLSLExternalSemaSource.cpp70
1 files changed, 34 insertions, 36 deletions
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index ca521dc0..2913d16f 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -117,33 +117,30 @@ struct BuiltinTypeDeclBuilder {
if (Record->isCompleteDefinition())
return *this;
+ ASTContext &Ctx = S.getASTContext();
TypeSourceInfo *ElementTypeInfo = nullptr;
- QualType Ty = Record->getASTContext().VoidPtrTy;
+ QualType ElemTy = Ctx.Char8Ty;
if (Template) {
if (const auto *TTD = dyn_cast<TemplateTypeParmDecl>(
Template->getTemplateParameters()->getParam(0))) {
- Ty = Record->getASTContext().getPointerType(
- QualType(TTD->getTypeForDecl(), 0));
- QualType ElemType = QualType(TTD->getTypeForDecl(), 0);
- ElementTypeInfo = S.getASTContext().getTrivialTypeSourceInfo(
- ElemType, SourceLocation());
+ ElemTy = QualType(TTD->getTypeForDecl(), 0);
}
}
+ ElementTypeInfo = Ctx.getTrivialTypeSourceInfo(ElemTy, SourceLocation());
// add handle member with resource type attributes
QualType AttributedResTy = QualType();
SmallVector<const Attr *> Attrs = {
- HLSLResourceClassAttr::CreateImplicit(Record->getASTContext(), RC),
- IsROV ? HLSLROVAttr::CreateImplicit(Record->getASTContext()) : nullptr,
- RawBuffer ? HLSLRawBufferAttr::CreateImplicit(Record->getASTContext())
- : nullptr,
- ElementTypeInfo ? HLSLContainedTypeAttr::CreateImplicit(
- Record->getASTContext(), ElementTypeInfo)
- : nullptr};
- Attr *ResourceAttr =
- HLSLResourceAttr::CreateImplicit(Record->getASTContext(), RK);
- if (CreateHLSLAttributedResourceType(S, Ty, Attrs, AttributedResTy))
+ HLSLResourceClassAttr::CreateImplicit(Ctx, RC),
+ IsROV ? HLSLROVAttr::CreateImplicit(Ctx) : nullptr,
+ RawBuffer ? HLSLRawBufferAttr::CreateImplicit(Ctx) : nullptr,
+ ElementTypeInfo
+ ? HLSLContainedTypeAttr::CreateImplicit(Ctx, ElementTypeInfo)
+ : nullptr};
+ Attr *ResourceAttr = HLSLResourceAttr::CreateImplicit(Ctx, RK);
+ if (CreateHLSLAttributedResourceType(S, Ctx.HLSLResourceTy, Attrs,
+ AttributedResTy))
addMemberVariable("h", AttributedResTy, {ResourceAttr}, Access);
return *this;
}
@@ -214,14 +211,14 @@ struct BuiltinTypeDeclBuilder {
assert(Fields.count("h") > 0 &&
"Subscript operator must be added after the handle.");
- FieldDecl *Handle = Fields["h"];
ASTContext &AST = Record->getASTContext();
-
- assert(Handle->getType().getCanonicalType() != AST.VoidPtrTy &&
- "Not yet supported for void pointer handles.");
-
- QualType ElemTy =
- QualType(Handle->getType()->getPointeeOrArrayElementType(), 0);
+ QualType ElemTy = AST.Char8Ty;
+ if (Template) {
+ if (const auto *TTD = dyn_cast<TemplateTypeParmDecl>(
+ Template->getTemplateParameters()->getParam(0))) {
+ ElemTy = QualType(TTD->getTypeForDecl(), 0);
+ }
+ }
QualType ReturnTy = ElemTy;
FunctionProtoType::ExtProtoInfo ExtInfo;
@@ -257,22 +254,23 @@ struct BuiltinTypeDeclBuilder {
auto FnProtoLoc = TSInfo->getTypeLoc().getAs<FunctionProtoTypeLoc>();
FnProtoLoc.setParam(0, IdxParam);
+ // FIXME: Placeholder to make sure we return the correct type - create
+ // field of element_type and return reference to it. This field will go
+ // away once indexing into resources is properly implemented in
+ // llvm/llvm-project#95956.
+ if (Fields.count("e") == 0) {
+ addMemberVariable("e", ElemTy, {});
+ }
+ FieldDecl *ElemFieldDecl = Fields["e"];
+
auto *This =
CXXThisExpr::Create(AST, SourceLocation(),
MethodDecl->getFunctionObjectParameterType(), true);
- auto *HandleAccess = MemberExpr::CreateImplicit(
- AST, This, false, Handle, Handle->getType(), VK_LValue, OK_Ordinary);
-
- auto *IndexExpr = DeclRefExpr::Create(
- AST, NestedNameSpecifierLoc(), SourceLocation(), IdxParam, false,
- DeclarationNameInfo(IdxParam->getDeclName(), SourceLocation()),
- AST.UnsignedIntTy, VK_PRValue);
-
- auto *Array =
- new (AST) ArraySubscriptExpr(HandleAccess, IndexExpr, ElemTy, VK_LValue,
- OK_Ordinary, SourceLocation());
-
- auto *Return = ReturnStmt::Create(AST, SourceLocation(), Array, nullptr);
+ Expr *ElemField = MemberExpr::CreateImplicit(
+ AST, This, false, ElemFieldDecl, ElemFieldDecl->getType(), VK_LValue,
+ OK_Ordinary);
+ auto *Return =
+ ReturnStmt::Create(AST, SourceLocation(), ElemField, nullptr);
MethodDecl->setBody(CompoundStmt::Create(AST, {Return}, FPOptionsOverride(),
SourceLocation(),