Skip to content

Commit 431eaa8

Browse files
authored
[HLSL] make semantic matching case insensitive (#129773)
Make semantic matching case insensitive update tests to reflect semantic printed as all lower case in error messages add new tests to show case insensitivity Closes #128063
1 parent 934d916 commit 431eaa8

File tree

6 files changed

+42
-6
lines changed

6 files changed

+42
-6
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4717,21 +4717,21 @@ def HLSLNumThreads: InheritableAttr {
47174717
}
47184718

47194719
def HLSLSV_GroupThreadID: HLSLAnnotationAttr {
4720-
let Spellings = [HLSLAnnotation<"SV_GroupThreadID">];
4720+
let Spellings = [HLSLAnnotation<"sv_groupthreadid">];
47214721
let Subjects = SubjectList<[ParmVar, Field]>;
47224722
let LangOpts = [HLSL];
47234723
let Documentation = [HLSLSV_GroupThreadIDDocs];
47244724
}
47254725

47264726
def HLSLSV_GroupID: HLSLAnnotationAttr {
4727-
let Spellings = [HLSLAnnotation<"SV_GroupID">];
4727+
let Spellings = [HLSLAnnotation<"sv_groupid">];
47284728
let Subjects = SubjectList<[ParmVar, Field]>;
47294729
let LangOpts = [HLSL];
47304730
let Documentation = [HLSLSV_GroupIDDocs];
47314731
}
47324732

47334733
def HLSLSV_GroupIndex: HLSLAnnotationAttr {
4734-
let Spellings = [HLSLAnnotation<"SV_GroupIndex">];
4734+
let Spellings = [HLSLAnnotation<"sv_groupindex">];
47354735
let Subjects = SubjectList<[ParmVar, GlobalVar]>;
47364736
let LangOpts = [HLSL];
47374737
let Documentation = [HLSLSV_GroupIndexDocs];
@@ -4783,7 +4783,7 @@ def HLSLPackOffset: HLSLAnnotationAttr {
47834783
}
47844784

47854785
def HLSLSV_DispatchThreadID: HLSLAnnotationAttr {
4786-
let Spellings = [HLSLAnnotation<"SV_DispatchThreadID">];
4786+
let Spellings = [HLSLAnnotation<"sv_dispatchthreadid">];
47874787
let Subjects = SubjectList<[ParmVar, Field]>;
47884788
let LangOpts = [HLSL];
47894789
let Documentation = [HLSLSV_DispatchThreadIDDocs];

clang/lib/Basic/Attributes.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,17 @@ static SmallString<64> normalizeName(const IdentifierInfo *Name,
143143
StringRef ScopeName = normalizeAttrScopeName(Scope, SyntaxUsed);
144144
StringRef AttrName = normalizeAttrName(Name, ScopeName, SyntaxUsed);
145145

146+
std::string StrAttrName = AttrName.str();
147+
if (SyntaxUsed == AttributeCommonInfo::AS_HLSLAnnotation)
148+
StrAttrName = AttrName.lower();
149+
146150
SmallString<64> FullName = ScopeName;
147151
if (!ScopeName.empty()) {
148152
assert(SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
149153
SyntaxUsed == AttributeCommonInfo::AS_C23);
150154
FullName += "::";
151155
}
152-
FullName += AttrName;
156+
FullName += StrAttrName;
153157

154158
return FullName;
155159
}

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ void SemaHLSL::DiagnoseAttrStageMismatch(
752752
HLSLShaderAttr::ConvertEnvironmentTypeToStr(ST));
753753
});
754754
Diag(A->getLoc(), diag::err_hlsl_attr_unsupported_in_stage)
755-
<< A << llvm::Triple::getEnvironmentTypeName(Stage)
755+
<< A->getAttrName() << llvm::Triple::getEnvironmentTypeName(Stage)
756756
<< (AllowedStages.size() != 1) << join(StageStrings, ", ");
757757
}
758758

clang/test/SemaHLSL/Semantics/valid_entry_parameter.hlsl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ void CSMain3(uint3 : SV_DispatchThreadID) {
2424
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:20 'uint3'
2525
// CHECK-NEXT: HLSLSV_DispatchThreadIDAttr
2626
}
27+
[numthreads(8,8,1)]
28+
void CSMain4(uint3 : SV_DispatchThreadId) {
29+
// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain4 'void (uint3)'
30+
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:20 'uint3'
31+
// CHECK-NEXT: HLSLSV_DispatchThreadIDAttr
32+
}
2733

2834
[numthreads(8,8,1)]
2935
void CSMain_GID(uint ID : SV_GroupID) {
@@ -49,6 +55,12 @@ void CSMain3_GID(uint3 : SV_GroupID) {
4955
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:24 'uint3'
5056
// CHECK-NEXT: HLSLSV_GroupIDAttr
5157
}
58+
[numthreads(8,8,1)]
59+
void CSMain4_GID(uint3 : Sv_GroupId) {
60+
// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain4_GID 'void (uint3)'
61+
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:24 'uint3'
62+
// CHECK-NEXT: HLSLSV_GroupIDAttr
63+
}
5264

5365
[numthreads(8,8,1)]
5466
void CSMain_GThreadID(uint ID : SV_GroupThreadID) {
@@ -74,3 +86,9 @@ void CSMain3_GThreadID(uint3 : SV_GroupThreadID) {
7486
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:30 'uint3'
7587
// CHECK-NEXT: HLSLSV_GroupThreadIDAttr
7688
}
89+
[numthreads(8,8,1)]
90+
void CSMain4_GThreadID(uint3 : sv_GroupThreadid) {
91+
// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain4_GThreadID 'void (uint3)'
92+
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:30 'uint3'
93+
// CHECK-NEXT: HLSLSV_GroupThreadIDAttr
94+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: not clang-tblgen -gen-clang-attr-parsed-attr-kinds -I%p/../../include %s -o - 2>&1 | FileCheck %s
2+
3+
include "clang/Basic/Attr.td"
4+
5+
// CHECK: error: HLSLAnnotation Attribute must be lower case.
6+
def HLSLSV_FAKE: HLSLAnnotationAttr {
7+
let Spellings = [HLSLAnnotation<"SV_Fake">];
8+
let Subjects = SubjectList<[ParmVar, Field]>;
9+
let LangOpts = [HLSL];
10+
let Documentation = [HLSLSV_GroupThreadIDDocs];
11+
}

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4932,6 +4932,9 @@ void EmitClangAttrParsedAttrKinds(const RecordKeeper &Records,
49324932
Matches = &Pragma;
49334933
} else if (Variety == "HLSLAnnotation") {
49344934
Matches = &HLSLAnnotation;
4935+
if (RawSpelling.compare(RawSpelling.lower()) != 0)
4936+
PrintError(S.getSpellingRecord().getLoc(),
4937+
"HLSLAnnotation Attribute must be lower case.");
49354938
}
49364939

49374940
assert(Matches && "Unsupported spelling variety found");

0 commit comments

Comments
 (0)