Skip to content

Commit dbf60d7

Browse files
authored
[Sema] Only emit warnings on entry point attrs with missing shader attr for libraries (microsoft#6284)
In implementing this PR: microsoft#6243 somehow, the condition to only emit the warning for library shaders was left out. This PR is a follow up on microsoft#6243 to properly restrict the emission of this warning for non-library shaders. This should properly fix microsoft#6100
1 parent b3be6f2 commit dbf60d7

File tree

6 files changed

+21
-39
lines changed

6 files changed

+21
-39
lines changed

tools/clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ def HLSLEffectsSyntax : DiagGroup<"effects-syntax">;
783783
def HLSLForRedefinition : DiagGroup<"for-redefinition">;
784784
def HLSLAttributeStatement : DiagGroup<"attribute-statement">;
785785
def HLSLAttributeType : DiagGroup<"attribute-type">;
786+
def HLSLEntryAttributeWithoutShaderAttrType : DiagGroup<"misplaced-attributes">;
786787
def HLSLSpecifierOverride : DiagGroup<"specifier-override">;
787788
def HLSLPackOffsetOverride : DiagGroup<"packoffset-override">;
788789
def HLSLCommaInInit : DiagGroup<"comma-in-init">;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7702,7 +7702,7 @@ def warn_hlsl_attribute_expects_uint_literal : Warning<
77027702
InGroup<HLSLAttributeType>;
77037703
def warn_hlsl_entry_attribute_without_shader_attribute : Warning<
77047704
"attribute '%0' ignored without accompanying shader attribute">,
7705-
InGroup<HLSLAttributeType>;
7705+
InGroup<HLSLEntryAttributeWithoutShaderAttrType>;
77067706
def err_hlsl_attribute_expects_float_literal : Error<
77077707
"attribute %0 must have a float literal argument">;
77087708
def warn_hlsl_comma_in_init : Warning<

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15795,7 +15795,9 @@ void DiagnoseEntry(Sema &S, FunctionDecl *FD) {
1579515795

1579615796
HLSLShaderAttr *shaderAttr = FD->getAttr<HLSLShaderAttr>();
1579715797
if (!shaderAttr) {
15798-
WarnOnEntryAttrWithoutShaderAttr(S, FD);
15798+
if (S.getLangOpts().IsHLSLLibrary)
15799+
WarnOnEntryAttrWithoutShaderAttr(S, FD);
15800+
1579915801
return;
1580015802
}
1580115803

tools/clang/test/SemaHLSL/attributes.hlsl

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %dxc -Tlib_6_3 -HV 2018 -verify %s
2-
// RUN: %dxc -Tps_6_0 -HV 2018 -verify %s
1+
// RUN: %dxc -Tlib_6_3 -Wno-misplaced-attributes -HV 2018 -verify %s
2+
// RUN: %dxc -Tps_6_0 -HV 2018 -verify %s
33

44
// To test with the classic compiler, run
55
// %sdxroot%\tools\x86\fxc.exe /T ps_5_1 attributes.hlsl
@@ -352,11 +352,8 @@ int uav() {
352352

353353
[domain] int domain_fn_missing() { return 1; } // expected-error {{'domain' attribute takes one argument}} fxc-pass {{}}
354354
[domain()] int domain_fn_empty() { return 1; } // expected-error {{'domain' attribute takes one argument}} fxc-error {{X3000: syntax error: unexpected token ')'}}
355-
/* expected-warning@+1{{attribute 'domain' ignored without accompanying shader attribute}} */
356355
[domain("blerch")] int domain_fn_bad() { return 1; } // expected-error {{attribute 'domain' must have one of these values: tri,quad,isoline}} fxc-pass {{}}
357-
/* expected-warning@+1{{attribute 'domain' ignored without accompanying shader attribute}} */
358356
[domain("quad")] int domain_fn() { return 1; } /* fxc-warning {{X3554: unknown attribute domain, or attribute invalid for this statement}} */
359-
/* expected-warning@+1{{attribute 'domain' ignored without accompanying shader attribute}} */
360357
[domain(1)] int domain_fn_int() { return 1; } // expected-error {{attribute 'domain' must have a string literal argument}} fxc-pass {{}}
361358
[domain("quad","quad")] int domain_fn_mul() { return 1; } // expected-error {{'domain' attribute takes one argument}} fxc-pass {{}}
362359
[instance] int instance_fn() { return 1; } // expected-error {{'instance' attribute takes one argument}} fxc-warning {{X3554: unknown attribute instance, or attribute invalid for this statement}}
@@ -367,7 +364,6 @@ int uav() {
367364
[partitioning] int partitioning_fn() { return 1; } // expected-error {{'partitioning' attribute takes one argument}} fxc-warning {{X3554: unknown attribute partitioning, or attribute invalid for this statement}}
368365
[patchconstantfunc] int patchconstantfunc_fn() { return 1; } // expected-error {{'patchconstantfunc' attribute takes one argument}} fxc-warning {{X3554: unknown attribute patchconstantfunc, or attribute invalid for this statement}}
369366

370-
/* expected-warning@+1{{attribute 'partitioning' ignored without accompanying shader attribute}} */
371367
[partitioning("fractional_even")] int partitioning_fn_ok() { return 1; }
372368

373369
struct HSFoo
@@ -381,30 +377,22 @@ Texture2D<float4> tex1[10] : register( t20, space10 );
381377
`-RegisterAssignment <col:30> register(t20, space10)
382378
*/
383379

384-
/* expected-warning@+1{{attribute 'domain' ignored without accompanying shader attribute}} */
385380
[domain(123)] // expected-error {{attribute 'domain' must have a string literal argument}} fxc-pass {{}}
386381
[partitioning()] // expected-error {{'partitioning' attribute takes one argument}} fxc-error {{X3000: syntax error: unexpected token ')'}}
387-
/* expected-warning@+1{{attribute 'outputtopology' ignored without accompanying shader attribute}} */
388382
[outputtopology("not_triangle_cw")] // expected-error {{attribute 'outputtopology' must have one of these values: point,line,triangle,triangle_cw,triangle_ccw}} fxc-pass {{}}
389-
/* expected-warning@+1{{attribute 'outputcontrolpoints' ignored without accompanying shader attribute}} */
390383
[outputcontrolpoints(-1)] // expected-warning {{attribute 'outputcontrolpoints' must have a uint literal argument}} fxc-pass {{}}
391384
[patchconstantfunc("PatchFoo", "ExtraArgument")] // expected-error {{'patchconstantfunc' attribute takes one argument}} fxc-pass {{}}
392385

393386
void all_wrong() { }
394387

395-
/* expected-warning@+1{{attribute 'domain' ignored without accompanying shader attribute}} */
396388
[domain("quad")]
397389
/*verify-ast
398390
HLSLDomainAttr <col:2, col:15> "quad"
399391
*/
400392

401-
/* expected-warning@+1{{attribute 'partitioning' ignored without accompanying shader attribute}} */
402393
[partitioning("integer")]
403-
/* expected-warning@+1{{attribute 'outputtopology' ignored without accompanying shader attribute}} */
404394
[outputtopology("triangle_cw")]
405-
/* expected-warning@+1{{attribute 'outputcontrolpoints' ignored without accompanying shader attribute}} */
406395
[outputcontrolpoints(16)]
407-
/* expected-warning@+1{{attribute 'patchconstantfunc' ignored without accompanying shader attribute}} */
408396
[patchconstantfunc("PatchFoo")]
409397

410398
HSFoo HSMain( InputPatch<HSFoo, 16> p,
@@ -638,7 +626,6 @@ float4 clipplanes_good_parens();
638626
// place the errors in comments before the function, but not with the standard
639627
// fxc error comments on the line.
640628
struct GSVertex { float4 pos : SV_Position; };
641-
/* expected-warning@+1{{attribute 'maxvertexcount' ignored without accompanying shader attribute}} */
642629
[maxvertexcount (12)]
643630

644631
/*verify-ast
@@ -648,15 +635,13 @@ void maxvertexcount_valid1(triangle GSVertex v[3], inout TriangleStream<GSVertex
648635
{ stream.Append(v[0]); }
649636

650637
static const int sc_count = 12;
651-
/* expected-warning@+1{{attribute 'maxvertexcount' ignored without accompanying shader attribute}} */
652638
[maxvertexcount (sc_count)]
653639

654640
/*verify-ast
655641
HLSLMaxVertexCountAttr <col:2, col:26> 12
656642
*/
657643
void maxvertexcount_valid2(triangle GSVertex v[3], inout TriangleStream<GSVertex> stream)
658644
{ stream.Append(v[0]); }
659-
/* expected-warning@+1{{attribute 'maxvertexcount' ignored without accompanying shader attribute}} */
660645
[maxvertexcount (sc_count + 3)]
661646

662647
/*verify-ast
@@ -668,7 +653,6 @@ void maxvertexcount_valid3(triangle GSVertex v[3], inout TriangleStream<GSVertex
668653
static const int4 sc_count4 = int4(3,6,9,12);
669654

670655
// The following passes fxc, but fails clang.
671-
/* expected-warning@+1{{attribute 'maxvertexcount' ignored without accompanying shader attribute}} */
672656
[maxvertexcount (sc_count4.w)] /* expected-error {{'maxvertexcount' attribute requires an integer constant}} fxc-pass {{}} */
673657

674658
/*verify-ast
@@ -679,7 +663,6 @@ void maxvertexcount_valid4(triangle GSVertex v[3], inout TriangleStream<GSVertex
679663

680664
// fxc:
681665
// error X3084: cannot match attribute maxvertexcount, non-uint parameters found
682-
/* expected-warning@+1{{attribute 'maxvertexcount' ignored without accompanying shader attribute}} */
683666
[maxvertexcount (-12)] /* expected-warning {{attribute 'maxvertexcount' must have a uint literal argument}} fxc-pass {{}} */
684667

685668
void negative_maxvertexcount(triangle GSVertex v[3], inout TriangleStream<GSVertex> stream)
@@ -689,7 +672,6 @@ void negative_maxvertexcount(triangle GSVertex v[3], inout TriangleStream<GSVert
689672
// warning X3554: cannot match attribute maxvertexcount, parameter 1 is expected to be of type int
690673
// warning X3554: unknown attribute maxvertexcount, or attribute invalid for this statement, valid attributes are: maxvertexcount, MaxVertexCount, instance, RootSignature
691674
// error X3514: 'float_maxvertexcount1' must have a max vertex count
692-
/* expected-warning@+1{{attribute 'maxvertexcount' ignored without accompanying shader attribute}} */
693675
[maxvertexcount (1.5)] /* expected-warning {{attribute 'maxvertexcount' must have a uint literal argument}} fxc-pass {{}} */
694676

695677
void float_maxvertexcount1(triangle GSVertex v[3], inout TriangleStream<GSVertex> stream)
@@ -700,7 +682,6 @@ void float_maxvertexcount1(triangle GSVertex v[3], inout TriangleStream<GSVertex
700682
// warning X3554: unknown attribute maxvertexcount, or attribute invalid for this statement, valid attributes are: maxvertexcount, MaxVertexCount, instance, RootSignature
701683
// error X3514: 'float_maxvertexcount2' must have a max vertex count
702684
static const float sc_float = 1.5;
703-
/* expected-warning@+1{{attribute 'maxvertexcount' ignored without accompanying shader attribute}} */
704685
[maxvertexcount (sc_float)] /* expected-error {{'maxvertexcount' attribute requires an integer constant}} fxc-pass {{}} */
705686

706687
void float_maxvertexcount2(triangle GSVertex v[3], inout TriangleStream<GSVertex> stream)
@@ -712,7 +693,6 @@ float f_count;
712693
// fxc:
713694
// error X3084: non-literal parameter(s) found for attribute maxvertexcount
714695
// error X3514: 'uniform_maxvertexcount1' must have a max vertex count
715-
/* expected-warning@+1{{attribute 'maxvertexcount' ignored without accompanying shader attribute}} */
716696
[maxvertexcount (i_count)] /* expected-error {{'maxvertexcount' attribute requires an integer constant}} fxc-pass {{}} */
717697

718698
void uniform_maxvertexcount1(triangle GSVertex v[3], inout TriangleStream<GSVertex> stream)
@@ -722,7 +702,6 @@ void uniform_maxvertexcount1(triangle GSVertex v[3], inout TriangleStream<GSVert
722702
// warning X3554: cannot match attribute maxvertexcount, parameter 1 is expected to be of type int
723703
// warning X3554: unknown attribute maxvertexcount, or attribute invalid for this statement, valid attributes are: maxvertexcount, MaxVertexCount, instance, RootSignature
724704
// error X3514: 'uniform_maxvertexcount2' must have a max vertex count
725-
/* expected-warning@+1{{attribute 'maxvertexcount' ignored without accompanying shader attribute}} */
726705
[maxvertexcount (f_count)] /* expected-error {{'maxvertexcount' attribute requires an integer constant}} fxc-pass {{}} */
727706

728707
void uniform_maxvertexcount2(triangle GSVertex v[3], inout TriangleStream<GSVertex> stream)
@@ -855,7 +834,6 @@ bool Test_Call() {
855834
}
856835

857836
// Test EarlyDepthStencil
858-
/* expected-warning@+1{{attribute 'earlydepthstencil' ignored without accompanying shader attribute}} */
859837
[EarlyDepthStencil]
860838

861839
bool Test_EarlyDepthStencil() {
@@ -888,79 +866,69 @@ bool Test_Loop() {
888866

889867
// Test ClipPlanes
890868
float4 ClipPlanesVal;
891-
/* expected-warning@+1{{attribute 'clipplanes' ignored without accompanying shader attribute}} */
892869
[ClipPlanes(ClipPlanesVal)]
893870

894871
bool Test_ClipPlanes() {
895872
return true;
896873
}
897874

898875
// Test Domain
899-
/* expected-warning@+1{{attribute 'domain' ignored without accompanying shader attribute}} */
900876
[Domain("tri")]
901877

902878
bool Test_Domain() {
903879
return true;
904880
}
905881

906882
// Test Instance
907-
/* expected-warning@+1{{attribute 'instance' ignored without accompanying shader attribute}} */
908883
[Instance(1)]
909884

910885
bool Test_Instance() {
911886
return true;
912887
}
913888

914889
// Test MaxTessFactor
915-
/* expected-warning@+1{{attribute 'maxtessfactor' ignored without accompanying shader attribute}} */
916890
[MaxTessFactor(1)]
917891

918892
bool Test_MaxTessFactor() {
919893
return true;
920894
}
921895

922896
// Test MaxVertexCount
923-
/* expected-warning@+1{{attribute 'maxvertexcount' ignored without accompanying shader attribute}} */
924897
[MaxVertexCount(1)]
925898

926899
bool Test_MaxVertexCount() {
927900
return true;
928901
}
929902

930903
// Test NumThreads
931-
/* expected-warning@+1{{attribute 'numthreads' ignored without accompanying shader attribute}} */
932904
[NumThreads(1,2,3)]
933905

934906
bool Test_NumThreads() {
935907
return true;
936908
}
937909

938910
// Test OutputControlPoints
939-
/* expected-warning@+1{{attribute 'outputcontrolpoints' ignored without accompanying shader attribute}} */
940911
[OutputControlPoints(2)]
941912

942913
bool Test_OutputControlPoints() {
943914
return true;
944915
}
945916

946917
// Test OutputTopology
947-
/* expected-warning@+1{{attribute 'outputtopology' ignored without accompanying shader attribute}} */
948918
[OutputTopology("line")]
949919

950920
bool Test_OutputTopology() {
951921
return true;
952922
}
953923

954924
// Test Partitioning
955-
/* expected-warning@+1{{attribute 'partitioning' ignored without accompanying shader attribute}} */
956925
[Partitioning("integer")]
957926

958927
bool Test_Partitioning() {
959928
return true;
960929
}
961930

962931
// Test PatchConstantFunc
963-
/* expected-warning@+1{{attribute 'patchconstantfunc' ignored without accompanying shader attribute}} */
964932
[PatchConstantFunc("Test_Partitioning")]
965933

966934
bool Test_PatchConstantFunc() {
@@ -969,7 +937,6 @@ bool Test_PatchConstantFunc() {
969937

970938
// Test RootSignature
971939
// strange how RootSignature is the only attribute that is spelled with capitals.
972-
/* expected-warning@+1{{attribute 'RootSignature' ignored without accompanying shader attribute}} */
973940
[RootSignature("")]
974941

975942
bool Test_RootSignature() {

tools/clang/test/SemaHLSL/attributes/wavesize_66.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void main() {
77
}
88

99

10-
[wavesize(4, 8)] /* expected-warning{{attribute 'wavesize' ignored without accompanying shader attribute}} */
11-
[numthreads(1,1,8)] /* expected-warning{{attribute 'numthreads' ignored without accompanying shader attribute}} */
10+
[wavesize(4, 8)]
11+
[numthreads(1,1,8)]
1212
void inactive() {
1313
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %dxc /T cs_6_0 /E cs_1 -Vd %s -verify
2+
// This test verifies that no warnings are emitted
3+
// when an entry point attribute exists on a function
4+
// without a shader attribute
5+
6+
// expected-no-diagnostics
7+
8+
[numthreads(64,1,1)]
9+
void cs_1() {}
10+
11+
[numthreads(64,1,1)]
12+
void cs_2() {}

0 commit comments

Comments
 (0)