Skip to content

Commit 57ff5a3

Browse files
committed
Split-off from LongVector diagnostics / Fold err_hlsl_node_record_object
and err_hlsl_objectintemplateargument
1 parent 18e7c1c commit 57ff5a3

18 files changed

Lines changed: 758 additions & 725 deletions

tools/clang/include/clang/AST/DeclCXX.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,6 @@ class CXXRecordDecl : public RecordDecl {
469469
/// class containing an HLSL vector longer than 4 elements.
470470
bool HasHLSLLongVector : 1;
471471

472-
/// \brief Whether this class contains at least one member or base
473-
/// class containing an HLSL HitObject.
474-
bool HasHLSLHitObject : 1;
475-
476472
/// \brief The number of base class specifiers in Bases.
477473
unsigned NumBases;
478474

@@ -1033,11 +1029,6 @@ class CXXRecordDecl : public RecordDecl {
10331029
/// \brief Set that this class contains an HLSL long vector of over 4 elements
10341030
bool setHasHLSLLongVector() { return data().HasHLSLLongVector = true; }
10351031

1036-
// \brief Determine whether this class contains an HLSL HitObject.
1037-
bool hasHLSLHitObject() { return data().HasHLSLHitObject; }
1038-
/// \brief Set that this class contains an HLSL HitObject.
1039-
bool setHasHLSLHitObject() { return data().HasHLSLHitObject = true; }
1040-
10411032
/// \brief Determine whether this class describes a lambda function object.
10421033
bool isLambda() const {
10431034
// An update record can't turn a non-lambda into a lambda.

tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7558,8 +7558,6 @@ def err_hlsl_missing_type_specifier : Error< // Patterened after err_missing_typ
75587558
"HLSL requires a type specifier for all declarations">;
75597559
def err_hlsl_multiple_concrete_bases : Error<
75607560
"multiple concrete base types specified">;
7561-
def err_hlsl_objectintemplateargument : Error<
7562-
"%0 is an object and cannot be used as a type parameter">;
75637561
def err_hlsl_packoffset_requires_cbuffer : Error<
75647562
"packoffset is only allowed in a constant buffer">;
75657563
def warn_hlsl_packoffset_mix : Warning<
@@ -7878,14 +7876,23 @@ def err_hlsl_load_from_mesh_out_arrays: Error<
78787876
"output arrays of a mesh shader can not be read from">;
78797877
def err_hlsl_out_indices_array_incorrect_access: Error<
78807878
"a vector in out indices array must be accessed as a whole">;
7881-
def err_hlsl_unsupported_type
7882-
: Error<"%select{vectors of over 4 elements|HitObjects}0 in "
7879+
def err_hlsl_unsupported_long_vector
7880+
: Error<"vectors of over 4 elements in "
78837881
"%select{ConstantBuffers or TextureBuffers|"
78847882
"tessellation patches|geometry streams|node records|"
78857883
"cbuffers or tbuffers|user-defined struct parameter|"
78867884
"entry function parameters|entry function return type|"
78877885
"patch constant function parameters|patch constant function return type|"
7888-
"payload parameters|attributes}1 are not supported">;
7886+
"payload parameters|attributes}0 are not supported">;
7887+
// %select options must be compatible with err_hlsl_unsupported_long_vector (same index used)
7888+
def err_hlsl_unsupported_object_context
7889+
: Error<"object '%0' is not allowed in "
7890+
"%select{ConstantBuffers or TextureBuffers|"
7891+
"tessellation patches|geometry streams|node records|"
7892+
"cbuffers or tbuffers|user-defined struct parameter|"
7893+
"entry function parameters|entry function return type|"
7894+
"patch constant function parameters|patch constant function return type|"
7895+
"payload parameters|attributes|type parameters|structured buffers|global variables|groupshared variables}1">;
78897896
def err_hlsl_logical_binop_scalar : Error<
78907897
"operands for short-circuiting logical binary operator must be scalar, for non-scalar types use '%select{and|or}0'">;
78917898
def err_hlsl_ternary_scalar : Error<
@@ -7970,8 +7977,6 @@ def err_hlsl_too_many_node_inputs : Error<
79707977
"Node shader '%0' may not have more than one input record">;
79717978
def err_hlsl_node_record_type : Error<
79727979
"%0 is not valid as a node record type - struct/class required">;
7973-
def err_hlsl_node_record_object : Error<
7974-
"object %0 may not appear in a node record">;
79757980
def err_hlsl_array_disallowed : Error<
79767981
"%select{entry parameter|declaration}1 of type %0 may not be an array">;
79777982
def err_hlsl_inputpatch_size: Error<

tools/clang/include/clang/Sema/SemaHLSL.h

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ bool DiagnoseNodeStructArgument(clang::Sema *self,
5959
clang::QualType ArgTy, bool &Empty,
6060
const clang::FieldDecl *FD = nullptr);
6161

62+
// Keep this in sync with err_hlsl_unsupported_object in DiagnosticSemaKinds.td
63+
enum class TypeDiagContext {
64+
ConstantBuffersOrTextureBuffers = 0,
65+
TessellationPatches = 1,
66+
GeometryStreams = 2,
67+
NodeRecords = 3,
68+
CBuffersOrTBuffers = 4,
69+
UserDefinedStructParameter = 5,
70+
EntryFunctionParameters = 6,
71+
EntryFunctionReturnType = 7,
72+
PatchConstantFunctionParameters = 8,
73+
PatchConstantFunctionReturnType = 9,
74+
PayloadParameters = 10,
75+
Attributes = 11,
76+
TypeParameter = 12,
77+
StructuredBuffers = 13,
78+
GlobalVariables = 14,
79+
GroupShared = 15,
80+
};
81+
bool DiagnoseTypeElements(clang::Sema &S, clang::SourceLocation Loc,
82+
clang::QualType Ty, TypeDiagContext DiagContext,
83+
const clang::FieldDecl *FD = nullptr);
84+
6285
void DiagnoseControlFlowConditionForHLSL(clang::Sema *self,
6386
clang::Expr *condExpr,
6487
llvm::StringRef StmtName);
@@ -129,14 +152,6 @@ unsigned CaculateInitListArraySizeForHLSL(clang::Sema *sema,
129152
const clang::QualType EltTy);
130153

131154
bool ContainsLongVector(clang::QualType);
132-
bool ContainsHitObject(clang::QualType);
133-
134-
/// \brief Determine if the given type contains a long vector or a hit object.
135-
/// \param QT The type to check.
136-
/// \param DiagTypeIdx The index of the type in the diagnostic message.
137-
/// \returns True if the type contains a long vector or a hit object, false
138-
/// otherwise.
139-
bool ContainsLongVecOrHitObject(clang::QualType QT, unsigned &DiagTypeIdx);
140155

141156
bool IsConversionToLessOrEqualElements(clang::Sema *self,
142157
const clang::ExprResult &sourceExpr,

tools/clang/lib/AST/DeclCXX.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D)
7272
ImplicitCopyAssignmentHasConstParam(true),
7373
HasDeclaredCopyConstructorWithConstParam(false),
7474
HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false),
75-
IsParsingBaseSpecifiers(false), HasHLSLLongVector(false),
76-
HasHLSLHitObject(false), NumBases(0), NumVBases(0), Bases(), VBases(),
77-
Definition(D), FirstFriend() {}
75+
IsParsingBaseSpecifiers(false), HasHLSLLongVector(false), NumBases(0),
76+
NumVBases(0), Bases(), VBases(), Definition(D), FirstFriend() {}
7877
// HLSL Change End - Add HasLongVector and clang-format
7978

8079
CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const {
@@ -207,8 +206,6 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
207206
// HLSL Change Begin - Propagate presence of long vector to child classes.
208207
if (BaseClassDecl->hasHLSLLongVector())
209208
data().HasHLSLLongVector = true;
210-
if (BaseClassDecl->hasHLSLHitObject())
211-
data().HasHLSLHitObject = true;
212209
// HLSL Change End
213210

214211
// Record if this base is the first non-literal field or base.
@@ -396,8 +393,6 @@ void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) {
396393
// HLSL Change Begin - Propagate presence of long vector to child classes.
397394
if (Subobj->hasHLSLLongVector())
398395
data().HasHLSLLongVector = true;
399-
if (Subobj->hasHLSLHitObject())
400-
data().HasHLSLHitObject = true;
401396
// HLSL Change End
402397
}
403398

tools/clang/lib/AST/HlslTypes.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ bool IsHLSLNumericUserDefinedType(clang::QualType type) {
113113
for (auto member : RD->fields()) {
114114
if (!IsHLSLNumericOrAggregateOfNumericType(member->getType()))
115115
return false;
116+
if (auto *Child = dyn_cast<CXXRecordDecl>(RD))
117+
// Walk up the inheritance chain and check base class fields
118+
for (auto &Base : Child->bases())
119+
if (!IsHLSLNumericOrAggregateOfNumericType(Base.getType()))
120+
return false;
116121
}
117122
return true;
118123
}
@@ -125,8 +130,6 @@ bool IsHLSLNumericUserDefinedType(clang::QualType type) {
125130
// which can't be annotated. But includes UDTs of trivially copyable data and
126131
// the builtin trivially copyable raytracing structs.
127132
bool IsHLSLCopyableAnnotatableRecord(clang::QualType QT) {
128-
if (ContainsHitObject(QT))
129-
return false;
130133
return IsHLSLNumericUserDefinedType(QT) ||
131134
IsHLSLBuiltinRayAttributeStruct(QT);
132135
}

tools/clang/lib/Sema/SemaDXR.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,9 @@ void DiagnoseBuiltinCallWithPayload(Sema &S, const VarDecl *Payload,
827827
}
828828

829829
// Verify that the payload type is legal
830+
if (DiagnoseTypeElements(S, Payload->getLocation(), Payload->getType(),
831+
TypeDiagContext::PayloadParameters))
832+
return;
830833
if (!hlsl::IsHLSLCopyableAnnotatableRecord(Payload->getType())) {
831834
S.Diag(Payload->getLocation(), diag::err_payload_attrs_must_be_udt)
832835
<< /*payload|attributes|callable*/ 0 << /*parameter %2|type*/ 0
@@ -835,11 +838,9 @@ void DiagnoseBuiltinCallWithPayload(Sema &S, const VarDecl *Payload,
835838
}
836839

837840
if (ContainsLongVector(Payload->getType())) {
838-
// No need to check for HitObject, checked with payload diagnosis.
839-
const unsigned LongVectorIdx = 0;
840841
const unsigned PayloadParametersIdx = 10;
841-
S.Diag(Payload->getLocation(), diag::err_hlsl_unsupported_type)
842-
<< LongVectorIdx << PayloadParametersIdx;
842+
S.Diag(Payload->getLocation(), diag::err_hlsl_unsupported_long_vector)
843+
<< PayloadParametersIdx;
843844
return;
844845
}
845846

tools/clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13247,16 +13247,10 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
1324713247
SmallVector<FieldDecl*, 32> RecFields;
1324813248

1324913249
bool ARCErrReported = false;
13250-
bool HasHitObject = false;
1325113250
for (ArrayRef<Decl *>::iterator i = Fields.begin(), end = Fields.end();
1325213251
i != end; ++i) {
1325313252
FieldDecl *FD = cast<FieldDecl>(*i);
1325413253

13255-
// HLSL Change Begin - set HitObject bit for fields
13256-
if (!HasHitObject && hlsl::ContainsHitObject(FD->getType()))
13257-
HasHitObject = true;
13258-
// HLSL Change End
13259-
1326013254
// Get the type for the field.
1326113255
const Type *FDTy = FD->getType().getTypePtr();
1326213256

@@ -13445,12 +13439,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
1344513439
I = CXXRecord->conversion_begin(),
1344613440
E = CXXRecord->conversion_end(); I != E; ++I)
1344713441
I.setAccess((*I)->getAccess());
13448-
13449-
// HLSL Change Begin - set HitObject bit for fields
13450-
if (HasHitObject)
13451-
CXXRecord->setHasHLSLHitObject();
13452-
// HLSL Change End
13453-
13442+
1345413443
if (!CXXRecord->isDependentType()) {
1345513444
if (CXXRecord->hasUserDeclaredDestructor()) {
1345613445
// Adjust user-defined destructor exception spec.

0 commit comments

Comments
 (0)