Skip to content

Commit bf3a90c

Browse files
committed
fix AST dump so semantic params are showing
1 parent cb816bd commit bf3a90c

File tree

7 files changed

+46
-10
lines changed

7 files changed

+46
-10
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,8 @@ class HLSLSemanticAttr<bit Indexable> : HLSLAnnotationAttr {
787787
let Spellings = [];
788788
let Subjects = SubjectList<[ParmVar, Field, Function]>;
789789
let LangOpts = [HLSL];
790+
let Args = [DeclArgument<Named, "Target">, IntArgument<"SemanticIndex">,
791+
BoolArgument<"SemanticExplicitIndex">];
790792
}
791793

792794
/// A target-specific attribute. This class is meant to be used as a mixin

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,17 @@ class SemaHLSL : public SemaBase {
174174
bool handleResourceTypeAttr(QualType T, const ParsedAttr &AL);
175175

176176
template <typename T>
177-
T *createSemanticAttr(const AttributeCommonInfo &ACI, Decl *TargetDecl,
177+
T *createSemanticAttr(const AttributeCommonInfo &ACI, NamedDecl *TargetDecl,
178178
std::optional<unsigned> Location) {
179-
T *Attr = ::new (getASTContext()) T(getASTContext(), ACI);
179+
T *Attr =
180+
::new (getASTContext()) T(getASTContext(), ACI, TargetDecl,
181+
Location.value_or(0), Location.has_value());
180182

181-
if (Attr->isSemanticIndexable())
182-
Attr->setSemanticIndex(Location ? *Location : 0);
183-
else if (Location.has_value()) {
183+
if (!Attr->isSemanticIndexable() && Location.has_value()) {
184184
Diag(Attr->getLocation(), diag::err_hlsl_semantic_indexing_not_supported)
185185
<< Attr->getAttrName()->getName();
186186
return nullptr;
187187
}
188-
189-
Attr->setTargetDecl(TargetDecl);
190188
return Attr;
191189
}
192190

@@ -258,7 +256,7 @@ class SemaHLSL : public SemaBase {
258256
void checkSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param,
259257
const HLSLSemanticAttr *SemanticAttr);
260258
HLSLSemanticAttr *createSemantic(const SemanticInfo &Semantic,
261-
Decl *TargetDecl);
259+
DeclaratorDecl *TargetDecl);
262260
bool determineActiveSemanticOnScalar(FunctionDecl *FD, DeclaratorDecl *D,
263261
SemanticInfo &ActiveSemantic);
264262
bool determineActiveSemantic(FunctionDecl *FD, DeclaratorDecl *D,

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ void SemaHLSL::ActOnTopLevelFunction(FunctionDecl *FD) {
770770
}
771771

772772
HLSLSemanticAttr *SemaHLSL::createSemantic(const SemanticInfo &Info,
773-
Decl *TargetDecl) {
773+
DeclaratorDecl *TargetDecl) {
774774
std::string SemanticName = Info.Semantic->getAttrName()->getName().upper();
775775

776776
if (SemanticName == "SV_DISPATCHTHREADID") {

clang/test/SemaHLSL/Semantics/entry_parameter.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ void CSMain(int GI : SV_GroupIndex, uint ID : SV_DispatchThreadID, uint GID : SV
1111
// CHECK-NEXT: HLSLSV_GroupIDAttr
1212
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:96 GThreadID 'uint'
1313
// CHECK-NEXT: HLSLSV_GroupThreadIDAttr
14+
15+
// CHECK: HLSLSV_GroupIndexAttr 0x{{[0-9a-fA-F]+}} <{{.*}}> ParmVar 0x{{[0-9a-fA-F]+}} 'GI' 'int' 0
16+
// CHECK-NEXT: HLSLSV_DispatchThreadIDAttr 0x{{[0-9a-fA-F]+}} <{{.*}}> ParmVar 0x{{[0-9a-fA-F]+}} 'ID' 'uint':'unsigned int' 0
17+
// CHECK-NEXT: HLSLSV_GroupIDAttr 0x{{[0-9a-fA-F]+}} <{{.*}}> ParmVar 0x{{[0-9a-fA-F]+}} 'GID' 'uint':'unsigned int' 0
18+
// CHECK-NEXT: HLSLSV_GroupThreadIDAttr 0x{{[0-9a-fA-F]+}} <{{.*}}> ParmVar 0x{{[0-9a-fA-F]+}} 'GThreadID' 'uint':'unsigned int' 0
1419
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-pixel -x hlsl -finclude-default-header -o - %s -ast-dump | FileCheck %s
22

3-
float4 main(float4 a : SV_Position) {
3+
float4 main(float4 a : SV_Position2) {
44
// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:8 main 'float4 (float4)'
55
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:20 a 'float4':'vector<float, 4>'
66
// CHECK-NEXT: HLSLSV_PositionAttr 0x{{[0-9a-fA-F]+}} <{{.*}}>
7+
8+
// CHECK: HLSLSV_PositionAttr 0x{{[0-9a-fA-F]+}} <{{.*}}> ParmVar 0x{{[0-9a-fA-F]+}} 'a' 'float4':'vector<float, 4>' 2 SemanticExplicitIndex
79
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-pixel -x hlsl -finclude-default-header -o - %s -ast-dump | FileCheck %s
2+
3+
struct S {
4+
float4 f0 : SV_Position;
5+
// CHECK: FieldDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:10 f0 'float4':'vector<float, 4>'
6+
// CHECK: HLSLSV_PositionAttr 0x{{[0-9a-fA-F]+}} <col:15> <<<NULL>>> 0
7+
float4 f1 : SV_Position3;
8+
// CHECK: FieldDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:10 f1 'float4':'vector<float, 4>'
9+
// CHECK: HLSLSV_PositionAttr 0x{{[0-9a-fA-F]+}} <col:15> <<<NULL>>> 3 SemanticExplicitIndex
10+
};
11+
12+
float4 main(S s) {
13+
// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:8 main 'float4 (S)'
14+
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:15 s 'S'
15+
16+
// CHECK: HLSLSV_PositionAttr 0x{{[0-9a-fA-F]+}} <{{.*}}> Field 0x{{[0-9a-fA-F]+}} 'f0' 'float4':'vector<float, 4>' 0
17+
// CHECK: HLSLSV_PositionAttr 0x{{[0-9a-fA-F]+}} <{{.*}}> Field 0x{{[0-9a-fA-F]+}} 'f1' 'float4':'vector<float, 4>' 3 SemanticExplicitIndex
18+
}

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,17 @@ static void emitAttributes(const RecordKeeper &Records, raw_ostream &OS,
30783078

30793079
OS << " {\n";
30803080

3081+
// The generator puts the arguments for each attribute in the child class,
3082+
// even if those are set in the inherited attribute class (in the TD
3083+
// file). This means I cannot access those from the parent class, and have
3084+
// to do this weirdness. Maybe the generator should be changed to
3085+
// arguments are put in the class they are declared in inside the TD file?
3086+
if (HLSLSemantic) {
3087+
OS << " if (SemanticExplicitIndex)\n";
3088+
OS << " setSemanticIndex(SemanticIndex);\n";
3089+
OS << " setTargetDecl(Target);\n";
3090+
}
3091+
30813092
for (auto const &ai : Args) {
30823093
if (!shouldEmitArg(ai))
30833094
continue;

0 commit comments

Comments
 (0)