Skip to content

[HLSL] make semantic matching case insensitive #129773

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 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -4724,21 +4724,21 @@ def HLSLNumThreads: InheritableAttr {
}

def HLSLSV_GroupThreadID: HLSLAnnotationAttr {
let Spellings = [HLSLAnnotation<"SV_GroupThreadID">];
let Spellings = [HLSLAnnotation<"sv_groupthreadid">];
let Subjects = SubjectList<[ParmVar, Field]>;
let LangOpts = [HLSL];
let Documentation = [HLSLSV_GroupThreadIDDocs];
}

def HLSLSV_GroupID: HLSLAnnotationAttr {
let Spellings = [HLSLAnnotation<"SV_GroupID">];
let Spellings = [HLSLAnnotation<"sv_groupid">];
let Subjects = SubjectList<[ParmVar, Field]>;
let LangOpts = [HLSL];
let Documentation = [HLSLSV_GroupIDDocs];
}

def HLSLSV_GroupIndex: HLSLAnnotationAttr {
let Spellings = [HLSLAnnotation<"SV_GroupIndex">];
let Spellings = [HLSLAnnotation<"sv_groupindex">];
let Subjects = SubjectList<[ParmVar, GlobalVar]>;
let LangOpts = [HLSL];
let Documentation = [HLSLSV_GroupIndexDocs];
Expand Down Expand Up @@ -4790,7 +4790,7 @@ def HLSLPackOffset: HLSLAnnotationAttr {
}

def HLSLSV_DispatchThreadID: HLSLAnnotationAttr {
let Spellings = [HLSLAnnotation<"SV_DispatchThreadID">];
let Spellings = [HLSLAnnotation<"sv_dispatchthreadid">];
let Subjects = SubjectList<[ParmVar, Field]>;
let LangOpts = [HLSL];
let Documentation = [HLSLSV_DispatchThreadIDDocs];
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Basic/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,17 @@ static SmallString<64> normalizeName(const IdentifierInfo *Name,
StringRef ScopeName = normalizeAttrScopeName(Scope, SyntaxUsed);
StringRef AttrName = normalizeAttrName(Name, ScopeName, SyntaxUsed);

std::string StrAttrName = AttrName.str();
if (SyntaxUsed == AttributeCommonInfo::AS_HLSLAnnotation)
StrAttrName = AttrName.lower();

SmallString<64> FullName = ScopeName;
if (!ScopeName.empty()) {
assert(SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
SyntaxUsed == AttributeCommonInfo::AS_C23);
FullName += "::";
}
FullName += AttrName;
FullName += StrAttrName;

return FullName;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ void SemaHLSL::DiagnoseAttrStageMismatch(
HLSLShaderAttr::ConvertEnvironmentTypeToStr(ST));
});
Diag(A->getLoc(), diag::err_hlsl_attr_unsupported_in_stage)
<< A << llvm::Triple::getEnvironmentTypeName(Stage)
<< A->getAttrName() << llvm::Triple::getEnvironmentTypeName(Stage)
<< (AllowedStages.size() != 1) << join(StageStrings, ", ");
}

Expand Down
18 changes: 18 additions & 0 deletions clang/test/SemaHLSL/Semantics/valid_entry_parameter.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ void CSMain3(uint3 : SV_DispatchThreadID) {
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:20 'uint3'
// CHECK-NEXT: HLSLSV_DispatchThreadIDAttr
}
[numthreads(8,8,1)]
void CSMain4(uint3 : SV_DispatchThreadId) {
// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain4 'void (uint3)'
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:20 'uint3'
// CHECK-NEXT: HLSLSV_DispatchThreadIDAttr
}

[numthreads(8,8,1)]
void CSMain_GID(uint ID : SV_GroupID) {
Expand All @@ -49,6 +55,12 @@ void CSMain3_GID(uint3 : SV_GroupID) {
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:24 'uint3'
// CHECK-NEXT: HLSLSV_GroupIDAttr
}
[numthreads(8,8,1)]
void CSMain4_GID(uint3 : Sv_GroupId) {
// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain4_GID 'void (uint3)'
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:24 'uint3'
// CHECK-NEXT: HLSLSV_GroupIDAttr
}

[numthreads(8,8,1)]
void CSMain_GThreadID(uint ID : SV_GroupThreadID) {
Expand All @@ -74,3 +86,9 @@ void CSMain3_GThreadID(uint3 : SV_GroupThreadID) {
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:30 'uint3'
// CHECK-NEXT: HLSLSV_GroupThreadIDAttr
}
[numthreads(8,8,1)]
void CSMain4_GThreadID(uint3 : sv_GroupThreadid) {
// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain4_GThreadID 'void (uint3)'
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:30 'uint3'
// CHECK-NEXT: HLSLSV_GroupThreadIDAttr
}
11 changes: 11 additions & 0 deletions clang/test/TableGen/HLSLAttribute-errors.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: not clang-tblgen -gen-clang-attr-parsed-attr-kinds -I%p/../../include %s -o - 2>&1 | FileCheck %s

include "clang/Basic/Attr.td"

// CHECK: error: HLSLAnnotation Attribute must be lower case.
def HLSLSV_FAKE: HLSLAnnotationAttr {
let Spellings = [HLSLAnnotation<"SV_Fake">];
let Subjects = SubjectList<[ParmVar, Field]>;
let LangOpts = [HLSL];
let Documentation = [HLSLSV_GroupThreadIDDocs];
}
3 changes: 3 additions & 0 deletions clang/utils/TableGen/ClangAttrEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4932,6 +4932,9 @@ void EmitClangAttrParsedAttrKinds(const RecordKeeper &Records,
Matches = &Pragma;
} else if (Variety == "HLSLAnnotation") {
Matches = &HLSLAnnotation;
if (RawSpelling.compare(RawSpelling.lower()) != 0)
PrintError(S.getSpellingRecord().getLoc(),
"HLSLAnnotation Attribute must be lower case.");
}

assert(Matches && "Unsupported spelling variety found");
Expand Down