const-expr.hlsl 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -ffreestanding -verify %s
  2. float overload1(float f) { return 1; } /* expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} fxc-pass {{}} */
  3. double overload1(double f) { return 2; } /* expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} fxc-pass {{}} */
  4. int overload1(int i) { return 3; } /* expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} fxc-pass {{}} */
  5. uint overload1(uint i) { return 4; } /* expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} fxc-pass {{}} */
  6. min12int overload1(min12int i) { return 5; } /* expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-note {{candidate function}} expected-warning {{min12int is promoted to min16int}} expected-warning {{min12int is promoted to min16int}} fxc-pass {{}} */
  7. static const float2 g_f2_arr[8] =
  8. {
  9. float2 (-0.1234, 0.4321) / 0.8750,
  10. float2 ( 0.0000, -0.0012) / 0.8750,
  11. float2 ( 0.5555, 0.5555) / 0.8750,
  12. float2 (-0.6666, 0.0000) / 0.8750,
  13. float2 ( 0.3333, -0.0000) / 0.8750,
  14. float2 ( 0.0000, 0.3213) / 0.8750,
  15. float2 (-0.1234, -0.4567) / 0.8750,
  16. float2 ( 0.1255, 0.0000) / 0.8750,
  17. };
  18. float2 g_f2;
  19. float2 rotation;
  20. float fn_f_f(float r)
  21. {
  22. float ambiguous1 = overload1(1.5); /* expected-error {{call to 'overload1' is ambiguous}} fxc-error {{X3067: 'overload1': ambiguous function call}} */
  23. float ambiguous2 = overload1(2); /* expected-error {{call to 'overload1' is ambiguous}} fxc-error {{X3067: 'overload1': ambiguous function call}} */
  24. // 1-digit integers go through separate code path, so also check multi-digit:
  25. float ambiguous3 = overload1(123); /* expected-error {{call to 'overload1' is ambiguous}} fxc-error {{X3067: 'overload1': ambiguous function call}} */
  26. float ambiguous4 = overload1(1.5 * 2); /* expected-error {{call to 'overload1' is ambiguous}} fxc-error {{X3067: 'overload1': ambiguous function call}} */
  27. float ambiguous5 = overload1(1.5 * 10); /* expected-error {{call to 'overload1' is ambiguous}} fxc-error {{X3067: 'overload1': ambiguous function call}} */
  28. int tap = 0;
  29. float2x2 rotationMatrix = { rotation.x, rotation.y, -rotation.y, rotation.x };
  30. /*verify-ast
  31. DeclStmt <col:3, col:80>
  32. `-VarDecl <col:3, col:79> col:12 used rotationMatrix 'float2x2':'matrix<float, 2, 2>' cinit
  33. `-InitListExpr <col:29, col:79> 'float2x2':'matrix<float, 2, 2>'
  34. |-ImplicitCastExpr <col:31, col:40> 'float' <LValueToRValue>
  35. | `-HLSLVectorElementExpr <col:31, col:40> 'const float' lvalue vectorcomponent x
  36. | `-DeclRefExpr <col:31> 'const float2':'const vector<float, 2>' lvalue Var 'rotation' 'const float2':'const vector<float, 2>'
  37. |-ImplicitCastExpr <col:43, col:52> 'float' <LValueToRValue>
  38. | `-HLSLVectorElementExpr <col:43, col:52> 'const float' lvalue vectorcomponent y
  39. | `-DeclRefExpr <col:43> 'const float2':'const vector<float, 2>' lvalue Var 'rotation' 'const float2':'const vector<float, 2>'
  40. |-UnaryOperator <col:55, col:65> 'float' prefix '-'
  41. | `-ImplicitCastExpr <col:56, col:65> 'float' <LValueToRValue>
  42. | `-HLSLVectorElementExpr <col:56, col:65> 'const float' lvalue vectorcomponent y
  43. | `-DeclRefExpr <col:56> 'const float2':'const vector<float, 2>' lvalue Var 'rotation' 'const float2':'const vector<float, 2>'
  44. `-ImplicitCastExpr <col:68, col:77> 'float' <LValueToRValue>
  45. `-HLSLVectorElementExpr <col:68, col:77> 'const float' lvalue vectorcomponent x
  46. `-DeclRefExpr <col:68> 'const float2':'const vector<float, 2>' lvalue Var 'rotation' 'const float2':'const vector<float, 2>'
  47. */
  48. float2 offs = mul(g_f2_arr[tap], rotationMatrix) * r;
  49. /*verify-ast
  50. DeclStmt <col:3, col:55>
  51. `-VarDecl <col:3, col:54> col:10 used offs 'float2':'vector<float, 2>' cinit
  52. `-BinaryOperator <col:17, col:54> 'vector<float, 2>':'vector<float, 2>' '*'
  53. |-CallExpr <col:17, col:50> 'vector<float, 2>':'vector<float, 2>'
  54. | |-ImplicitCastExpr <col:17> 'vector<float, 2> (*)(vector<float, 2>, matrix<float, 2, 2>)' <FunctionToPointerDecay>
  55. | | `-DeclRefExpr <col:17> 'vector<float, 2> (vector<float, 2>, matrix<float, 2, 2>)' lvalue Function 'mul' 'vector<float, 2> (vector<float, 2>, matrix<float, 2, 2>)'
  56. | |-ImplicitCastExpr <col:21, col:33> 'float2':'vector<float, 2>' <LValueToRValue>
  57. | | `-ArraySubscriptExpr <col:21, col:33> 'const float2':'const vector<float, 2>' lvalue
  58. | | |-ImplicitCastExpr <col:21> 'const float2 [8]' <LValueToRValue>
  59. | | | `-DeclRefExpr <col:21> 'const float2 [8]' lvalue Var 'g_f2_arr' 'const float2 [8]'
  60. | | `-ImplicitCastExpr <col:30> 'int' <LValueToRValue>
  61. | | `-DeclRefExpr <col:30> 'int' lvalue Var 'tap' 'int'
  62. | `-ImplicitCastExpr <col:36> 'float2x2':'matrix<float, 2, 2>' <LValueToRValue>
  63. | `-DeclRefExpr <col:36> 'float2x2':'matrix<float, 2, 2>' lvalue Var 'rotationMatrix' 'float2x2':'matrix<float, 2, 2>'
  64. `-ImplicitCastExpr <col:54> 'vector<float, 2>':'vector<float, 2>' <HLSLVectorSplat>
  65. `-ImplicitCastExpr <col:54> 'float' <LValueToRValue>
  66. `-DeclRefExpr <col:54> 'float' lvalue ParmVar 'r' 'float'
  67. */
  68. return offs.x;
  69. }
  70. uint fn_f3_f3io_u(float3 wn, inout float3 tsn)
  71. {
  72. uint e3 = 0;
  73. float d1 = (wn.x + wn.y + wn.z) * 0.5;
  74. /*verify-ast
  75. DeclStmt <col:3, col:40>
  76. `-VarDecl <col:3, col:37> col:9 used d1 'float' cinit
  77. `-BinaryOperator <col:14, col:37> 'float' '*'
  78. |-ParenExpr <col:14, col:33> 'float'
  79. | `-BinaryOperator <col:15, col:32> 'float' '+'
  80. | |-BinaryOperator <col:15, col:25> 'float' '+'
  81. | | |-ImplicitCastExpr <col:15, col:18> 'float' <LValueToRValue>
  82. | | | `-HLSLVectorElementExpr <col:15, col:18> 'float' lvalue vectorcomponent x
  83. | | | `-DeclRefExpr <col:15> 'float3':'vector<float, 3>' lvalue ParmVar 'wn' 'float3':'vector<float, 3>'
  84. | | `-ImplicitCastExpr <col:22, col:25> 'float' <LValueToRValue>
  85. | | `-HLSLVectorElementExpr <col:22, col:25> 'float' lvalue vectorcomponent y
  86. | | `-DeclRefExpr <col:22> 'float3':'vector<float, 3>' lvalue ParmVar 'wn' 'float3':'vector<float, 3>'
  87. | `-ImplicitCastExpr <col:29, col:32> 'float' <LValueToRValue>
  88. | `-HLSLVectorElementExpr <col:29, col:32> 'float' lvalue vectorcomponent z
  89. | `-DeclRefExpr <col:29> 'float3':'vector<float, 3>' lvalue ParmVar 'wn' 'float3':'vector<float, 3>'
  90. `-ImplicitCastExpr <col:37> 'float' <FloatingCast>
  91. `-FloatingLiteral <col:37> 'literal float' 5.000000e-01
  92. */
  93. float d2 = wn.x - d1;
  94. float d3 = wn.y - d1;
  95. float d4 = wn.z - d1;
  96. float dm = max(max(d1, d2), max(d3, d4));
  97. float3 nn = tsn;
  98. if (d2 == dm) { e3 = 1; nn *= float3 (1, -1, -1); dm += 2; }
  99. if (d3 == dm) { e3 = 2; nn *= float3 (-1, 1, -1); dm += 2; }
  100. if (d4 == dm) { e3 = 3; nn *= float3 (-1, -1, 1); }
  101. tsn.z = nn.x + nn.y + nn.z;
  102. tsn.y = nn.z - nn.x;
  103. tsn.x = tsn.z - 3 * nn.y;
  104. const float sqrt_2 = 1.414213562373f;
  105. const float sqrt_3 = 1.732050807569f;
  106. const float sqrt_6 = 2.449489742783f;
  107. tsn *= float3 (1.0 / sqrt_6, 1.0 / sqrt_2, 1.0 / sqrt_3);
  108. /*verify-ast
  109. CompoundAssignOperator <col:3, col:58> 'float3':'vector<float, 3>' lvalue '*=' ComputeLHSTy='float3':'vector<float, 3>' ComputeResultTy='float3':'vector<float, 3>'
  110. |-DeclRefExpr <col:3> 'float3':'vector<float, 3>' lvalue ParmVar 'tsn' 'float3 &__restrict'
  111. `-CXXFunctionalCastExpr <col:10, col:58> 'float3':'vector<float, 3>' functional cast to float3 <NoOp>
  112. `-InitListExpr <col:18, col:52> 'float3':'vector<float, 3>'
  113. |-BinaryOperator <col:18, col:24> 'float' '/'
  114. | |-ImplicitCastExpr <col:18> 'float' <FloatingCast>
  115. | | `-FloatingLiteral <col:18> 'literal float' 1.000000e+00
  116. | `-ImplicitCastExpr <col:24> 'float' <LValueToRValue>
  117. | `-DeclRefExpr <col:24> 'const float' lvalue Var 'sqrt_6' 'const float'
  118. |-BinaryOperator <col:32, col:38> 'float' '/'
  119. | |-ImplicitCastExpr <col:32> 'float' <FloatingCast>
  120. | | `-FloatingLiteral <col:32> 'literal float' 1.000000e+00
  121. | `-ImplicitCastExpr <col:38> 'float' <LValueToRValue>
  122. | `-DeclRefExpr <col:38> 'const float' lvalue Var 'sqrt_2' 'const float'
  123. `-BinaryOperator <col:46, col:52> 'float' '/'
  124. |-ImplicitCastExpr <col:46> 'float' <FloatingCast>
  125. | `-FloatingLiteral <col:46> 'literal float' 1.000000e+00
  126. `-ImplicitCastExpr <col:52> 'float' <LValueToRValue>
  127. `-DeclRefExpr <col:52> 'const float' lvalue Var 'sqrt_3' 'const float'
  128. */
  129. return e3;
  130. }
  131. //////////////////////////////////////////////////////////////////////////////
  132. // Constant evaluation.
  133. void fn_const_eval() {
  134. const float f_one = 1;
  135. const double d_zero = 0;
  136. const uint u = 3;
  137. const int i = 4;
  138. const int i_neg_4 = -4;
  139. uint u_var = 10;
  140. // Operators:
  141. float f_ice_plus[+u];
  142. float f_ice_minus[-i_neg_4];
  143. float f_ice_add[u + 2];
  144. float f_ice_sub[u - 2];
  145. float f_ice_mul[u * 2];
  146. float f_ice_div[u / 2];
  147. float f_ice_rem[u % 2];
  148. float f_ice_shl[u << 1];
  149. float f_ice_shr[u >> 1];
  150. float f_ice_ternary[u > 1 ? 3 : 4]; /* fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  151. float f_ice_lt[u < 1 ? 3 : 4]; /* fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  152. float f_ice_le[u <= 1 ? 3 : 4]; /* fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  153. float f_ice_gt[u > 1 ? 3 : 4]; /* fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  154. float f_ice_ge[u >= 1 ? 3 : 4]; /* fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  155. float f_ice_eq[u == 1 ? 3 : 4]; /* fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  156. float f_ice_ne[u != 1 ? 3 : 4]; /* fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  157. float f_ice_bin_and[u & 0x1];
  158. float f_ice_bin_or[u | 0x1];
  159. float f_ice_bin_xor[u ^ 0x1];
  160. float f_ice_log_and[u && true ? 3 : 4]; /* fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  161. float f_ice_log_or[u || false ? 3 : 4]; /* fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  162. // This fails, as it should, but the error recovery isn't very good
  163. // and the error messages could be improved.
  164. float f_ice_assign[u_var = 3]; // expected-error {{expected ']'}} expected-error {{variable length arrays are not supported in HLSL}} expected-note {{to match this '['}} fxc-error {{X3058: array dimensions must be literal scalar expressions}}
  165. // Data types:
  166. // Check with all primitive types.
  167. // Check with vectors and matrices.
  168. // Precision modes:
  169. // Check with IEEE strict or relaxed.
  170. // Intrinsics:
  171. // Based on the intrinsic table. Intrinsics on objects aren't supported for constant folding.
  172. // (UINT)hlsl::IntrinsicOp::IOP_AddUint64, 3, g_Intrinsics_Args0,
  173. //NO (UINT)hlsl::IntrinsicOp::IOP_AllMemoryBarrier, 1, g_Intrinsics_Args1,
  174. //NO (UINT)hlsl::IntrinsicOp::IOP_AllMemoryBarrierWithGroupSync, 1, g_Intrinsics_Args2,
  175. //NO (UINT)hlsl::IntrinsicOp::IOP_CheckAccessFullyMapped, 2, g_Intrinsics_Args3,
  176. // (UINT)hlsl::IntrinsicOp::IOP_D3DCOLORtoUBYTE4, 2, g_Intrinsics_Args4,
  177. //NO (UINT)hlsl::IntrinsicOp::IOP_DeviceMemoryBarrier, 1, g_Intrinsics_Args5,
  178. //NO (UINT)hlsl::IntrinsicOp::IOP_DeviceMemoryBarrierWithGroupSync, 1, g_Intrinsics_Args6,
  179. //NO (UINT)hlsl::IntrinsicOp::IOP_EvaluateAttributeAtSample, 3, g_Intrinsics_Args7,
  180. //NO (UINT)hlsl::IntrinsicOp::IOP_EvaluateAttributeCentroid, 2, g_Intrinsics_Args8,
  181. //NO (UINT)hlsl::IntrinsicOp::IOP_EvaluateAttributeSnapped, 3, g_Intrinsics_Args9,
  182. //NO (UINT)hlsl::IntrinsicOp::IOP_GetRenderTargetSampleCount, 1, g_Intrinsics_Args10,
  183. //NO (UINT)hlsl::IntrinsicOp::IOP_GetRenderTargetSamplePosition, 2, g_Intrinsics_Args11,
  184. //NO (UINT)hlsl::IntrinsicOp::IOP_GroupMemoryBarrier, 1, g_Intrinsics_Args12,
  185. //NO (UINT)hlsl::IntrinsicOp::IOP_GroupMemoryBarrierWithGroupSync, 1, g_Intrinsics_Args13,
  186. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedAdd, 3, g_Intrinsics_Args14,
  187. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedAdd, 4, g_Intrinsics_Args15,
  188. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedAnd, 3, g_Intrinsics_Args16,
  189. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedAnd, 4, g_Intrinsics_Args17,
  190. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedCompareExchange, 5, g_Intrinsics_Args18,
  191. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedCompareStore, 4, g_Intrinsics_Args19,
  192. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedExchange, 4, g_Intrinsics_Args20,
  193. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedMax, 3, g_Intrinsics_Args21,
  194. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedMax, 4, g_Intrinsics_Args22,
  195. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedMin, 3, g_Intrinsics_Args23,
  196. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedMin, 4, g_Intrinsics_Args24,
  197. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedOr, 3, g_Intrinsics_Args25,
  198. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedOr, 4, g_Intrinsics_Args26,
  199. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedXor, 3, g_Intrinsics_Args27,
  200. //NO (UINT)hlsl::IntrinsicOp::IOP_InterlockedXor, 4, g_Intrinsics_Args28,
  201. //NO (UINT)hlsl::IntrinsicOp::IOP_NonUniformResourceIndex, 2, g_Intrinsics_Args29,
  202. //NO (UINT)hlsl::IntrinsicOp::IOP_Process2DQuadTessFactorsAvg, 6, g_Intrinsics_Args30,
  203. //NO (UINT)hlsl::IntrinsicOp::IOP_Process2DQuadTessFactorsMax, 6, g_Intrinsics_Args31,
  204. //NO (UINT)hlsl::IntrinsicOp::IOP_Process2DQuadTessFactorsMin, 6, g_Intrinsics_Args32,
  205. //NO (UINT)hlsl::IntrinsicOp::IOP_ProcessIsolineTessFactors, 5, g_Intrinsics_Args33,
  206. //NO (UINT)hlsl::IntrinsicOp::IOP_ProcessQuadTessFactorsAvg, 6, g_Intrinsics_Args34,
  207. //NO (UINT)hlsl::IntrinsicOp::IOP_ProcessQuadTessFactorsMax, 6, g_Intrinsics_Args35,
  208. //NO (UINT)hlsl::IntrinsicOp::IOP_ProcessQuadTessFactorsMin, 6, g_Intrinsics_Args36,
  209. //NO (UINT)hlsl::IntrinsicOp::IOP_ProcessTriTessFactorsAvg, 6, g_Intrinsics_Args37,
  210. //NO (UINT)hlsl::IntrinsicOp::IOP_ProcessTriTessFactorsMax, 6, g_Intrinsics_Args38,
  211. //NO (UINT)hlsl::IntrinsicOp::IOP_ProcessTriTessFactorsMin, 6, g_Intrinsics_Args39,
  212. //NO (UINT)hlsl::IntrinsicOp::IOP_abort, 1, g_Intrinsics_Args40,
  213. // (UINT)hlsl::IntrinsicOp::IOP_abs, 2, g_Intrinsics_Args41,
  214. // (UINT)hlsl::IntrinsicOp::IOP_acos, 2, g_Intrinsics_Args42,
  215. // (UINT)hlsl::IntrinsicOp::IOP_all, 2, g_Intrinsics_Args43,
  216. // (UINT)hlsl::IntrinsicOp::IOP_any, 2, g_Intrinsics_Args44,
  217. // (UINT)hlsl::IntrinsicOp::IOP_asdouble, 3, g_Intrinsics_Args45,
  218. // (UINT)hlsl::IntrinsicOp::IOP_asfloat, 2, g_Intrinsics_Args46,
  219. // (UINT)hlsl::IntrinsicOp::IOP_asin, 2, g_Intrinsics_Args47,
  220. // (UINT)hlsl::IntrinsicOp::IOP_asint, 2, g_Intrinsics_Args48,
  221. // (UINT)hlsl::IntrinsicOp::IOP_asuint, 4, g_Intrinsics_Args49,
  222. // (UINT)hlsl::IntrinsicOp::IOP_asuint, 2, g_Intrinsics_Args50,
  223. // (UINT)hlsl::IntrinsicOp::IOP_atan, 2, g_Intrinsics_Args51,
  224. // (UINT)hlsl::IntrinsicOp::IOP_atan2, 3, g_Intrinsics_Args52,
  225. // (UINT)hlsl::IntrinsicOp::IOP_ceil, 2, g_Intrinsics_Args53,
  226. // (UINT)hlsl::IntrinsicOp::IOP_clamp, 4, g_Intrinsics_Args54,
  227. //NO (UINT)hlsl::IntrinsicOp::IOP_clip, 2, g_Intrinsics_Args55,
  228. // (UINT)hlsl::IntrinsicOp::IOP_cos, 2, g_Intrinsics_Args56,
  229. // (UINT)hlsl::IntrinsicOp::IOP_cosh, 2, g_Intrinsics_Args57,
  230. // (UINT)hlsl::IntrinsicOp::IOP_countbits, 2, g_Intrinsics_Args58,
  231. // (UINT)hlsl::IntrinsicOp::IOP_cross, 3, g_Intrinsics_Args59,
  232. //NO (UINT)hlsl::IntrinsicOp::IOP_ddx, 2, g_Intrinsics_Args60,
  233. //NO (UINT)hlsl::IntrinsicOp::IOP_ddx_coarse, 2, g_Intrinsics_Args61,
  234. //NO (UINT)hlsl::IntrinsicOp::IOP_ddx_fine, 2, g_Intrinsics_Args62,
  235. //NO (UINT)hlsl::IntrinsicOp::IOP_ddy, 2, g_Intrinsics_Args63,
  236. //NO (UINT)hlsl::IntrinsicOp::IOP_ddy_coarse, 2, g_Intrinsics_Args64,
  237. //NO (UINT)hlsl::IntrinsicOp::IOP_ddy_fine, 2, g_Intrinsics_Args65,
  238. // (UINT)hlsl::IntrinsicOp::IOP_degrees, 2, g_Intrinsics_Args66,
  239. // (UINT)hlsl::IntrinsicOp::IOP_determinant, 2, g_Intrinsics_Args67,
  240. // (UINT)hlsl::IntrinsicOp::IOP_distance, 3, g_Intrinsics_Args68,
  241. // (UINT)hlsl::IntrinsicOp::IOP_dot, 3, g_Intrinsics_Args69,
  242. // (UINT)hlsl::IntrinsicOp::IOP_dst, 3, g_Intrinsics_Args70,
  243. // (UINT)hlsl::IntrinsicOp::IOP_exp, 2, g_Intrinsics_Args71,
  244. // (UINT)hlsl::IntrinsicOp::IOP_exp2, 2, g_Intrinsics_Args72,
  245. // (UINT)hlsl::IntrinsicOp::IOP_f16tof32, 2, g_Intrinsics_Args73,
  246. // (UINT)hlsl::IntrinsicOp::IOP_f32tof16, 2, g_Intrinsics_Args74,
  247. //NO (UINT)hlsl::IntrinsicOp::IOP_faceforward, 4, g_Intrinsics_Args75,
  248. // (UINT)hlsl::IntrinsicOp::IOP_firstbithigh, 2, g_Intrinsics_Args76,
  249. // (UINT)hlsl::IntrinsicOp::IOP_firstbitlow, 2, g_Intrinsics_Args77,
  250. // (UINT)hlsl::IntrinsicOp::IOP_floor, 2, g_Intrinsics_Args78,
  251. // (UINT)hlsl::IntrinsicOp::IOP_fma, 4, g_Intrinsics_Args79,
  252. // (UINT)hlsl::IntrinsicOp::IOP_fmod, 3, g_Intrinsics_Args80,
  253. // (UINT)hlsl::IntrinsicOp::IOP_frac, 2, g_Intrinsics_Args81,
  254. // (UINT)hlsl::IntrinsicOp::IOP_frexp, 3, g_Intrinsics_Args82,
  255. // (UINT)hlsl::IntrinsicOp::IOP_fwidth, 2, g_Intrinsics_Args83,
  256. // (UINT)hlsl::IntrinsicOp::IOP_isfinite, 2, g_Intrinsics_Args84,
  257. // (UINT)hlsl::IntrinsicOp::IOP_isinf, 2, g_Intrinsics_Args85,
  258. // (UINT)hlsl::IntrinsicOp::IOP_isnan, 2, g_Intrinsics_Args86,
  259. // (UINT)hlsl::IntrinsicOp::IOP_ldexp, 3, g_Intrinsics_Args87,
  260. // (UINT)hlsl::IntrinsicOp::IOP_length, 2, g_Intrinsics_Args88,
  261. // (UINT)hlsl::IntrinsicOp::IOP_lerp, 4, g_Intrinsics_Args89,
  262. // (UINT)hlsl::IntrinsicOp::IOP_lit, 4, g_Intrinsics_Args90,
  263. // (UINT)hlsl::IntrinsicOp::IOP_log, 2, g_Intrinsics_Args91,
  264. // (UINT)hlsl::IntrinsicOp::IOP_log10, 2, g_Intrinsics_Args92,
  265. // (UINT)hlsl::IntrinsicOp::IOP_log2, 2, g_Intrinsics_Args93,
  266. // (UINT)hlsl::IntrinsicOp::IOP_mad, 4, g_Intrinsics_Args94,
  267. // (UINT)hlsl::IntrinsicOp::IOP_max, 3, g_Intrinsics_Args95,
  268. double intrin_max = max(f_one, d_zero);
  269. // The following assertion will fail because static assert expects an ICE,
  270. // but the intrin_max subexpression isn't one (even if the binary comparsion
  271. // expression is).
  272. // _Static_assert(intrin_max == 2, "expected 2");
  273. _Static_assert(max(1, 2) == 2, "expected 2"); /* fxc-error {{X3004: undeclared identifier '_Static_assert'}} */
  274. _Static_assert(max(1, -2) == 1, "expected 1"); /* fxc-error {{X3004: undeclared identifier '_Static_assert'}} */
  275. // (UINT)hlsl::IntrinsicOp::IOP_min, 3, g_Intrinsics_Args96,
  276. // (UINT)hlsl::IntrinsicOp::IOP_modf, 3, g_Intrinsics_Args97,
  277. // (UINT)hlsl::IntrinsicOp::IOP_msad4, 4, g_Intrinsics_Args98,
  278. // (UINT)hlsl::IntrinsicOp::IOP_mul, 3, g_Intrinsics_Args99,
  279. // (UINT)hlsl::IntrinsicOp::IOP_mul, 3, g_Intrinsics_Args100,
  280. // (UINT)hlsl::IntrinsicOp::IOP_mul, 3, g_Intrinsics_Args101,
  281. // (UINT)hlsl::IntrinsicOp::IOP_mul, 3, g_Intrinsics_Args102,
  282. // (UINT)hlsl::IntrinsicOp::IOP_mul, 3, g_Intrinsics_Args103,
  283. // (UINT)hlsl::IntrinsicOp::IOP_mul, 3, g_Intrinsics_Args104,
  284. // (UINT)hlsl::IntrinsicOp::IOP_mul, 3, g_Intrinsics_Args105,
  285. // (UINT)hlsl::IntrinsicOp::IOP_mul, 3, g_Intrinsics_Args106,
  286. // (UINT)hlsl::IntrinsicOp::IOP_mul, 3, g_Intrinsics_Args107,
  287. //NO (UINT)hlsl::IntrinsicOp::IOP_noise, 2, g_Intrinsics_Args108,
  288. // (UINT)hlsl::IntrinsicOp::IOP_normalize, 2, g_Intrinsics_Args109,
  289. // (UINT)hlsl::IntrinsicOp::IOP_pow, 3, g_Intrinsics_Args110,
  290. // (UINT)hlsl::IntrinsicOp::IOP_radians, 2, g_Intrinsics_Args111,
  291. // (UINT)hlsl::IntrinsicOp::IOP_rcp, 2, g_Intrinsics_Args112,
  292. // (UINT)hlsl::IntrinsicOp::IOP_reflect, 3, g_Intrinsics_Args113,
  293. // (UINT)hlsl::IntrinsicOp::IOP_refract, 4, g_Intrinsics_Args114,
  294. // (UINT)hlsl::IntrinsicOp::IOP_reversebits, 2, g_Intrinsics_Args115,
  295. // (UINT)hlsl::IntrinsicOp::IOP_round, 2, g_Intrinsics_Args116,
  296. // (UINT)hlsl::IntrinsicOp::IOP_rsqrt, 2, g_Intrinsics_Args117,
  297. // (UINT)hlsl::IntrinsicOp::IOP_saturate, 2, g_Intrinsics_Args118,
  298. // (UINT)hlsl::IntrinsicOp::IOP_sign, 2, g_Intrinsics_Args119,
  299. // (UINT)hlsl::IntrinsicOp::IOP_sin, 2, g_Intrinsics_Args120,
  300. // (UINT)hlsl::IntrinsicOp::IOP_sincos, 4, g_Intrinsics_Args121,
  301. // (UINT)hlsl::IntrinsicOp::IOP_sinh, 2, g_Intrinsics_Args122,
  302. // (UINT)hlsl::IntrinsicOp::IOP_smoothstep, 4, g_Intrinsics_Args123,
  303. //?? (UINT)hlsl::IntrinsicOp::IOP_source_mark, 1, g_Intrinsics_Args124,
  304. // (UINT)hlsl::IntrinsicOp::IOP_sqrt, 2, g_Intrinsics_Args125,
  305. // (UINT)hlsl::IntrinsicOp::IOP_step, 3, g_Intrinsics_Args126,
  306. // (UINT)hlsl::IntrinsicOp::IOP_tan, 2, g_Intrinsics_Args127,
  307. // (UINT)hlsl::IntrinsicOp::IOP_tanh, 2, g_Intrinsics_Args128,
  308. //NO (UINT)hlsl::IntrinsicOp::IOP_tex1D, 3, g_Intrinsics_Args129,
  309. //NO (UINT)hlsl::IntrinsicOp::IOP_tex1D, 5, g_Intrinsics_Args130,
  310. //NO (UINT)hlsl::IntrinsicOp::IOP_tex1Dbias, 3, g_Intrinsics_Args131,
  311. //NO (UINT)hlsl::IntrinsicOp::IOP_tex1Dgrad, 5, g_Intrinsics_Args132,
  312. //NO (UINT)hlsl::IntrinsicOp::IOP_tex1Dlod, 3, g_Intrinsics_Args133,
  313. //NO (UINT)hlsl::IntrinsicOp::IOP_tex1Dproj, 3, g_Intrinsics_Args134,
  314. //NO (UINT)hlsl::IntrinsicOp::IOP_tex2D, 3, g_Intrinsics_Args135,
  315. //NO (UINT)hlsl::IntrinsicOp::IOP_tex2D, 5, g_Intrinsics_Args136,
  316. //NO (UINT)hlsl::IntrinsicOp::IOP_tex2Dbias, 3, g_Intrinsics_Args137,
  317. //NO (UINT)hlsl::IntrinsicOp::IOP_tex2Dgrad, 5, g_Intrinsics_Args138,
  318. //NO (UINT)hlsl::IntrinsicOp::IOP_tex2Dlod, 3, g_Intrinsics_Args139,
  319. //NO (UINT)hlsl::IntrinsicOp::IOP_tex2Dproj, 3, g_Intrinsics_Args140,
  320. //NO (UINT)hlsl::IntrinsicOp::IOP_tex3D, 3, g_Intrinsics_Args141,
  321. //NO (UINT)hlsl::IntrinsicOp::IOP_tex3D, 5, g_Intrinsics_Args142,
  322. //NO (UINT)hlsl::IntrinsicOp::IOP_tex3Dbias, 3, g_Intrinsics_Args143,
  323. //NO (UINT)hlsl::IntrinsicOp::IOP_tex3Dgrad, 5, g_Intrinsics_Args144,
  324. //NO (UINT)hlsl::IntrinsicOp::IOP_tex3Dlod, 3, g_Intrinsics_Args145,
  325. //NO (UINT)hlsl::IntrinsicOp::IOP_tex3Dproj, 3, g_Intrinsics_Args146,
  326. //NO (UINT)hlsl::IntrinsicOp::IOP_texCUBE, 3, g_Intrinsics_Args147,
  327. //NO (UINT)hlsl::IntrinsicOp::IOP_texCUBE, 5, g_Intrinsics_Args148,
  328. //NO (UINT)hlsl::IntrinsicOp::IOP_texCUBEbias, 3, g_Intrinsics_Args149,
  329. //NO (UINT)hlsl::IntrinsicOp::IOP_texCUBEgrad, 5, g_Intrinsics_Args150,
  330. //NO (UINT)hlsl::IntrinsicOp::IOP_texCUBElod, 3, g_Intrinsics_Args151,
  331. //NO (UINT)hlsl::IntrinsicOp::IOP_texCUBEproj, 3, g_Intrinsics_Args152,
  332. // (UINT)hlsl::IntrinsicOp::IOP_transpose, 2, g_Intrinsics_Args153,
  333. // (UINT)hlsl::IntrinsicOp::IOP_trunc, 2, g_Intrinsics_Args154,
  334. }
  335. //////////////////////////////////////////////////////////////////////////////
  336. // ICE.
  337. void fn_ice() {
  338. // Scalar ints.
  339. static uint s_One = 1;
  340. static uint s_Two = uint(s_One) + 1;
  341. float arr_s_One[s_One]; /* expected-error {{variable length arrays are not supported in HLSL}} fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  342. float arr_s_Two[s_Two]; /* expected-error {{variable length arrays are not supported in HLSL}} fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  343. static const uint sc_One = 1;
  344. static const uint sc_Two = uint(sc_One) + 1;
  345. float arr_sc_One[sc_One];
  346. float arr_sc_Two[sc_Two];
  347. // Vector ints.
  348. static uint1 v_One = 1;
  349. static uint1 v_Two = uint1(v_One) + 1;
  350. float arr_v_One[v_One]; /* expected-error {{size of array has non-integer type 'uint1'}} fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  351. float arr_v_Two[v_Two]; /* expected-error {{size of array has non-integer type 'uint1'}} fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  352. static const uint1 vc_One = 1;
  353. static const uint1 vc_Two = uint1(vc_One) + 1;
  354. float arr_vc_One[vc_One]; /* expected-error {{size of array has non-integer type 'uint1'}} fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  355. float arr_vc_Two[vc_Two]; /* expected-error {{size of array has non-integer type 'uint1'}} fxc-error {{X3058: array dimensions must be literal scalar expressions}} */
  356. // Note: here dxc is different from fxc, where a const integral vector can be used in ICE.
  357. // It would be desirable to have this supported.
  358. float arr_vc_One[vc_One.x]; /* expected-error {{variable length arrays are not supported in HLSL}} fxc-pass {{}} */
  359. float arr_vc_Two[vc_Two.x]; /* expected-error {{variable length arrays are not supported in HLSL}} fxc-pass {{}} */
  360. }
  361. void cs_main() {
  362. }