Skip to content

Commit f1e1312

Browse files
committed
fixup: resource_getpointer sema checks
1 parent 17b9223 commit f1e1312

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12496,7 +12496,6 @@ def err_hlsl_pointers_unsupported : Error<
1249612496
"%select{pointers|references}0 are unsupported in HLSL">;
1249712497
def err_hlsl_missing_resource_class : Error<"HLSL resource needs to have [[hlsl::resource_class()]] attribute">;
1249812498
def err_hlsl_attribute_needs_intangible_type: Error<"attribute %0 can be used only on HLSL intangible type %1">;
12499-
def err_hlsl_builtin_requires_resource: Error<"operand must be of __hlsl_resource_t type">;
1250012499

1250112500
def err_hlsl_operator_unsupported : Error<
1250212501
"the '%select{&|*|->}0' operator is unsupported in HLSL">;

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ static bool CheckResourceHandle(
19081908
const HLSLAttributedResourceType *ResTy =
19091909
ArgType.getTypePtr()->getAs<HLSLAttributedResourceType>();
19101910
if (!ResTy) {
1911-
S->Diag(TheCall->getArg(0)->getBeginLoc(),
1911+
S->Diag(TheCall->getArg(ArgIndex)->getBeginLoc(),
19121912
diag::err_typecheck_expect_hlsl_resource)
19131913
<< ArgType;
19141914
return true;
@@ -1927,17 +1927,15 @@ static bool CheckResourceHandle(
19271927
bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
19281928
switch (BuiltinID) {
19291929
case Builtin::BI__builtin_hlsl_resource_getpointer: {
1930-
if (SemaRef.checkArgCount(TheCall, 2))
1931-
return true;
1932-
auto *ResourceTy =
1933-
TheCall->getArg(0)->getType()->getAs<HLSLAttributedResourceType>();
1934-
if (!ResourceTy) {
1935-
SemaRef.Diag(TheCall->getBeginLoc(),
1936-
diag::err_hlsl_builtin_requires_resource)
1937-
<< TheCall->getArg(0)->getSourceRange();
1930+
if (SemaRef.checkArgCount(TheCall, 2) ||
1931+
CheckResourceHandle(&SemaRef, TheCall, 0) ||
1932+
CheckArgTypeMatches(&SemaRef, TheCall->getArg(1),
1933+
SemaRef.getASTContext().UnsignedIntTy))
19381934
return true;
1939-
}
19401935

1936+
auto *ResourceTy = TheCall->getArg(0)
1937+
->getType()
1938+
->castAs<HLSLAttributedResourceType>();
19411939
QualType ContainedTy = ResourceTy->getContainedType();
19421940
// TODO: Map to an hlsl_device address space.
19431941
TheCall->setType(getASTContext().getPointerType(ContainedTy));

0 commit comments

Comments
 (0)