semantics.hlsl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // RUN: %clang_cc1 -fsyntax-only -ffreestanding -verify %s
  2. //////////////////////////////////////////////////////////////////////////////
  3. // Global variables.
  4. float g_foo1 : foo;
  5. float g_foo2 : foo : fubar;
  6. float g_foo3 : foo : fubar : register(c3);
  7. float g_foo4 : register(c4) : foo : fubar;
  8. cbuffer CBInit : register(b2)
  9. {
  10. float g2_foo1 : foo; /* fxc-error {{X3530: cannot mix packoffset elements with nonpackoffset elements in a cbuffer}} */
  11. float g2_foo2 : foo : fubar; /* fxc-error {{X3530: cannot mix packoffset elements with nonpackoffset elements in a cbuffer}} */
  12. float g2_foo3 : foo : fubar : register(c3); /* fxc-error {{X3530: cannot mix packoffset elements with nonpackoffset elements in a cbuffer}} */
  13. float g2_foo4 : register(c4) : foo : fubar; /* fxc-error {{X3530: cannot mix packoffset elements with nonpackoffset elements in a cbuffer}} */
  14. float g2_foo5 : foo : fubar : packoffset(c5);
  15. float g2_foo6 : packoffset(c6) : foo : fubar;
  16. /*verify-ast
  17. VarDecl parent cbuffer <col:5, col:11> col:11 g2_foo6 'const float'
  18. |-ConstantPacking <col:21> packoffset(c6.x)
  19. |-SemanticDecl <col:38> "foo"
  20. `-SemanticDecl <col:44> "fubar"
  21. */
  22. }
  23. cbuffer CBInit2 : register(b3) : cbuffer_semantic /* fxc-warning {{X3202: usage semantics do not apply to cbuffers}} */
  24. /*verify-ast
  25. HLSLBufferDecl <col:1, line:36:1> line:26:9 cbuffer CBInit2
  26. |-RegisterAssignment <col:19> register(b3)
  27. |-SemanticDecl <col:34> "cbuffer_semantic"
  28. `-VarDecl parent cbuffer <line:35:5, col:11> col:11 g3_foo1 'const float'
  29. `-SemanticDecl <col:21> "foo"
  30. */
  31. {
  32. float g3_foo1 : foo;
  33. }
  34. //////////////////////////////////////////////////////////////////////////////
  35. // Typedefs.
  36. typedef float t_f : SEMANTIC; /* expected-error {{semantic is not a valid modifier for a typedef}} fxc-error {{X3000: syntax error: unexpected token ':'}} */
  37. struct semantic_on_struct : semantic { /* expected-error {{expected class name}} fxc-error {{X3000: syntax error: unexpected token 'semantic'}} */
  38. float a;
  39. };
  40. struct semantic_on_struct_instance {
  41. /*verify-ast
  42. CXXRecordDecl <col:1, line:57:1> line:46:8 struct semantic_on_struct_instance definition
  43. |-CXXRecordDecl <col:1, col:8> col:8 implicit struct semantic_on_struct_instance
  44. `-FieldDecl <line:56:5, col:11> col:11 a 'float'
  45. VarDecl <col:1, line:57:3> col:3 g_struct 'const struct semantic_on_struct_instance':'const semantic_on_struct_instance'
  46. `-SemanticDecl <col:14> "semantic"
  47. VarDecl <col:1, line:58:3> col:3 g_struct2 'const struct semantic_on_struct_instance':'const semantic_on_struct_instance'
  48. `-SemanticDecl <col:15> "semantic2"
  49. */
  50. float a;
  51. } g_struct : semantic,
  52. g_struct2 : semantic2;
  53. //////////////////////////////////////////////////////////////////////////////
  54. // Fields.
  55. struct s_fields {
  56. float a : semantic_a;
  57. /*verify-ast
  58. FieldDecl <col:5, col:11> col:11 a 'float'
  59. `-SemanticDecl <col:15> "semantic_a"
  60. */
  61. float b : semantic_b : also_b;
  62. /*verify-ast
  63. FieldDecl <col:5, col:11> col:11 b 'float'
  64. |-SemanticDecl <col:15> "semantic_b"
  65. `-SemanticDecl <col:28> "also_b"
  66. */
  67. };
  68. //////////////////////////////////////////////////////////////////////////////
  69. // Functions and Parameters
  70. float fn_foo1(float a : a, float b : b) : sem_ret { return 1.0f; }
  71. float fn_foo2(float a : a, float b : b : also_b) : sem_ret : also_ret { return 1.0f; }
  72. /*verify-ast
  73. FunctionDecl <col:1, col:86> col:7 fn_foo2 'float (float, float)'
  74. |-ParmVarDecl <col:15, col:21> col:21 a 'float'
  75. | `-SemanticDecl <col:25> "a"
  76. |-ParmVarDecl <col:28, col:34> col:34 b 'float'
  77. | |-SemanticDecl <col:38> "b"
  78. | `-SemanticDecl <col:42> "also_b"
  79. |-CompoundStmt <col:71, col:86>
  80. | `-ReturnStmt <col:73, col:80>
  81. | `-FloatingLiteral <col:80> 'float' 1.000000e+00
  82. |-SemanticDecl <col:52> "sem_ret"
  83. `-SemanticDecl <col:62> "also_ret"
  84. */
  85. //////////////////////////////////////////////////////////////////////////////
  86. // Locals.
  87. void vain() {
  88. float a : Sem_a; /* expected-error {{semantic is not a valid modifier for a local variable}} fxc-error {{X3043: 'a': local variables cannot have semantics}} */
  89. float b : Sem_b : also_b; /* expected-error {{semantic is not a valid modifier for a local variable}} expected-error {{semantic is not a valid modifier for a local variable}} fxc-error {{X3043: 'b': local variables cannot have semantics}} */
  90. float a2 : Sem_a2 = 1.0f; /* expected-error {{semantic is not a valid modifier for a local variable}} fxc-error {{X3043: 'a2': local variables cannot have semantics}} */
  91. float b2 : Sem_b2 : also_b2 = 2.0f; /* expected-error {{semantic is not a valid modifier for a local variable}} expected-error {{semantic is not a valid modifier for a local variable}} fxc-error {{X3043: 'b2': local variables cannot have semantics}} */
  92. struct {
  93. float a : sem_a;
  94. float b : sem_b : also_b;
  95. } s;
  96. struct : anon_semantic { /* expected-error {{expected class name}} fxc-error {{X3000: syntax error: unexpected token ':'}} */
  97. float a : sem_a;
  98. } s2 : semantic; /* expected-error {{semantic is not a valid modifier for a local variable}} fxc-pass {{}} */
  99. }