Skip to content

Implement resource binding type prefix mismatch diagnostic infrastructure #97103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3af2a39
update tests, update code
bob80905 Jun 28, 2024
9119de0
remove mismatch test, will be applied in step 2 PR. update packoffset
bob80905 Jun 28, 2024
77090ad
clang-format
bob80905 Jun 28, 2024
32e2ea6
remove unnecessary header
bob80905 Jul 1, 2024
ee92ca6
full implementation
bob80905 Jul 2, 2024
6fa8415
clang format
bob80905 Jul 2, 2024
6cdb101
fix mismatching register type diagnostic logic
bob80905 Jul 2, 2024
be6ab25
add udt tests
bob80905 Jul 3, 2024
5280128
add warnings to warning-flags.c file, do a nullptr check
bob80905 Jul 3, 2024
c160e6d
clang format
bob80905 Jul 3, 2024
856a1fb
allow multiple reg annotations, complete udt tests
bob80905 Jul 5, 2024
13bad9a
add other test, xfail it
bob80905 Jul 6, 2024
a43e2f3
fix warning flag errs
bob80905 Jul 7, 2024
3ccd165
clean up unused diags, remove comment
bob80905 Jul 8, 2024
05b289b
address Damyan
bob80905 Jul 9, 2024
22cb1e2
fix some asserts
bob80905 Jul 9, 2024
843a2ed
add test for infeasible reg type
bob80905 Jul 9, 2024
3625331
update tests, change multiple annotation diagnostic behavior, rename …
bob80905 Jul 9, 2024
e9121f9
make register types case insensitive, improve array initializatoin
bob80905 Jul 10, 2024
6914992
variable name changes, add diag group silence test, centralize slot i…
bob80905 Jul 10, 2024
36362ba
merge in spelled attribute change / rebase
bob80905 Jul 12, 2024
e7999d2
add test case for static global var
bob80905 Jul 12, 2024
2f0dc87
add groupshared test
bob80905 Jul 13, 2024
3d93ee1
add groupshared attr handling, and improve tests for groupshared basi…
bob80905 Jul 15, 2024
5468006
get resource class attr from non template specialization decls, use s…
bob80905 Jul 15, 2024
34a5a14
remove unneeded type
bob80905 Jul 15, 2024
32f4226
clean up tests, order diagnostics according to spec
bob80905 Jul 16, 2024
efd6202
use enum instead of ints
bob80905 Jul 17, 2024
f7495a5
update implementation to match the spec
bob80905 Aug 6, 2024
927c67d
emit warning for i rather than error to conform to spec
bob80905 Aug 6, 2024
7466f73
remove space variant test
bob80905 Aug 6, 2024
504356b
check for resource attr in fields
bob80905 Aug 7, 2024
10dc55b
address Damyan, clean up, and also retain info about conflicts to not…
bob80905 Aug 15, 2024
e8aca07
address damyan except for common code
bob80905 Aug 19, 2024
ff58d07
refactor complete, but we can do better
bob80905 Aug 19, 2024
3f168e5
make a lambda fxn to reduce repetition
bob80905 Aug 19, 2024
acd7707
address Damyan
bob80905 Aug 21, 2024
662fed9
adjust getRegisterTypeIndex
bob80905 Aug 21, 2024
9b72907
fix failing tests, adjust for attr on handle member now
bob80905 Aug 21, 2024
9110569
remove rov arg
bob80905 Aug 21, 2024
62954bf
address Damyan
bob80905 Aug 22, 2024
1c3fe3f
change group name, capitalize acronyms
bob80905 Aug 22, 2024
f3581c3
address Helena
bob80905 Aug 22, 2024
7329350
remove rwbuffer / template specializations, rename set to update
bob80905 Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -4529,7 +4529,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {

def HLSLResourceBinding: InheritableAttr {
let Spellings = [HLSLAnnotation<"register">];
let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
let LangOpts = [HLSL];
let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
let Documentation = [HLSLResourceBindingDocs];
Expand Down Expand Up @@ -4613,7 +4613,7 @@ def HLSLROV : InheritableAttr {

def HLSLResourceClass : InheritableAttr {
let Spellings = [CXX11<"hlsl", "resource_class">];
let Subjects = SubjectList<[Struct]>;
let Subjects = SubjectList<[Field]>;
let LangOpts = [HLSL];
let Args = [
EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,9 @@ def DXILValidation : DiagGroup<"dxil-validation">;
// Warning for HLSL API availability
def HLSLAvailability : DiagGroup<"hlsl-availability">;

// Warnings for legacy binding behavior
def LegacyConstantRegisterBinding : DiagGroup<"legacy-constant-register-binding">;

// Warnings and notes related to const_var_decl_type attribute checks
def ReadOnlyPlacementChecks : DiagGroup<"read-only-types">;

Expand Down
8 changes: 7 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -12342,7 +12342,13 @@ def err_hlsl_missing_semantic_annotation : Error<
def err_hlsl_init_priority_unsupported : Error<
"initializer priorities are not supported in HLSL">;

def err_hlsl_unsupported_register_type : Error<"invalid resource class specifier '%0' used; expected 'b', 's', 't', or 'u'">;
def warn_hlsl_user_defined_type_missing_member: Warning<"binding type '%select{t|u|b|s|c}0' only applies to types containing %select{SRV resources|UAV resources|constant buffer resources|sampler state|numeric types}0">, InGroup<LegacyConstantRegisterBinding>;
def err_hlsl_binding_type_mismatch: Error<"binding type '%select{t|u|b|s|c}0' only applies to %select{SRV resources|UAV resources|constant buffer resources|sampler state|numeric variables in the global scope}0">;
def err_hlsl_binding_type_invalid: Error<"binding type '%0' is invalid">;
def err_hlsl_duplicate_register_annotation: Error<"binding type '%select{t|u|b|s|c|i}0' cannot be applied more than once">;
def warn_hlsl_register_type_c_packoffset: Warning<"binding type 'c' ignored in buffer declaration. Did you mean 'packoffset'?">, InGroup<LegacyConstantRegisterBinding>, DefaultError;
def warn_hlsl_deprecated_register_type_b: Warning<"binding type 'b' only applies to constant buffers. The 'bool constant' binding type is no longer supported">, InGroup<LegacyConstantRegisterBinding>, DefaultError;
def warn_hlsl_deprecated_register_type_i: Warning<"binding type 'i' ignored. The 'integer constant' binding type is no longer supported">, InGroup<LegacyConstantRegisterBinding>, DefaultError;
def err_hlsl_unsupported_register_number : Error<"register number should be an integer">;
def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; expected 'space' followed by an integer, like space1">;
def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with nonpackoffset elements in a cbuffer">,
Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3021,15 +3021,17 @@ class Parser : public CodeCompletionHandler {
SemaCodeCompletion::AttributeCompletion::None,
const IdentifierInfo *EnclosingScope = nullptr);

void MaybeParseHLSLAnnotations(Declarator &D,
bool MaybeParseHLSLAnnotations(Declarator &D,
SourceLocation *EndLoc = nullptr,
bool CouldBeBitField = false) {
assert(getLangOpts().HLSL && "MaybeParseHLSLAnnotations is for HLSL only");
if (Tok.is(tok::colon)) {
ParsedAttributes Attrs(AttrFactory);
ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
D.takeAttributes(Attrs);
return true;
}
return false;
}

void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,8 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
}

if (getLangOpts().HLSL)
MaybeParseHLSLAnnotations(D);
while (MaybeParseHLSLAnnotations(D))
;

if (Tok.is(tok::kw_requires))
ParseTrailingRequiresClause(D);
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/Sema/HLSLExternalSemaSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,11 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
.addSimpleTemplateParams(*SemaPtr, {"element_type"})
.Record;

onCompletion(Decl, [this](CXXRecordDecl *Decl) {
setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
ResourceKind::TypedBuffer, /*IsROV=*/false)
ResourceKind::TypedBuffer,
/*IsROV=*/false)
.addArraySubscriptOperators()
.completeDefinition();
});
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6889,6 +6889,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
case ParsedAttr::AT_HLSLSV_GroupIndex:
handleSimpleAttribute<HLSLSV_GroupIndexAttr>(S, D, AL);
break;
case ParsedAttr::AT_HLSLGroupSharedAddressSpace:
handleSimpleAttribute<HLSLGroupSharedAddressSpaceAttr>(S, D, AL);
break;
case ParsedAttr::AT_HLSLSV_DispatchThreadID:
S.HLSL().handleSV_DispatchThreadIDAttr(D, AL);
break;
Expand Down
Loading