string.hlsl 5.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -ffreestanding -verify %s
  2. static const string s_global1 = "my global string 1";
  3. /*verify-ast
  4. VarDecl <col:1, col:33> col:21 used s_global1 'string':'string' static cinit
  5. `-ImplicitCastExpr <col:33> 'const string' <ArrayToPointerDecay>
  6. `-StringLiteral <col:33> 'literal string' lvalue "my global string 1"
  7. */
  8. string s_global2 = "my global string 2";
  9. string s_global3 = s_global1;
  10. /*verify-ast
  11. VarDecl <col:1, col:20> col:8 s_global3 'string':'string' static cinit
  12. `-DeclRefExpr <col:20> 'string':'string' lvalue Var 's_global1' 'string':'string'
  13. */
  14. string s_global_concat = "my string " "with "
  15. /*verify-ast
  16. VarDecl <col:1, line:25:4> line:18:8 s_global_concat 'string':'string' static cinit
  17. `-ImplicitCastExpr <col:26, line:25:4> 'const string' <ArrayToPointerDecay>
  18. `-StringLiteral <col:26, line:25:4> 'literal string' lvalue "my string with broken up parts"
  19. */
  20. "broken up"
  21. " parts";
  22. static const bool b1 = s_global1; /* expected-error {{cannot initialize a variable of type 'const bool' with an lvalue of type 'string'}} fxc-error {{X3017: cannot implicitly convert from 'const string' to 'const bool'}} */
  23. static const bool b2 = false;
  24. static const string s_global4 = true; /* expected-error {{cannot initialize a variable of type 'string' with an rvalue of type 'bool'}} fxc-error {{X3017: cannot implicitly convert from 'bool' to 'const string'}} */
  25. static const string s_global5 = b2; /* expected-error {{cannot initialize a variable of type 'string' with an lvalue of type 'const bool'}} fxc-error {{X3017: cannot implicitly convert from 'const bool' to 'const string'}} */
  26. static const int i1 = s_global1; /* expected-error {{cannot initialize a variable of type 'const int' with an lvalue of type 'string'}} fxc-error {{X3017: cannot implicitly convert from 'const string' to 'const int'}} */
  27. static const int i2 = 10;
  28. static const string s_global6 = 10; /* expected-error {{cannot initialize a variable of type 'string' with an rvalue of type 'literal int'}} fxc-error {{X3017: cannot implicitly convert from 'int' to 'const string'}} */
  29. static const string s_global7 = i2; /* expected-error {{cannot initialize a variable of type 'string' with an lvalue of type 'const int'}} fxc-error {{X3017: cannot implicitly convert from 'const int' to 'const string'}} */
  30. static const float f1 = s_global1; /* expected-error {{cannot initialize a variable of type 'const float' with an lvalue of type 'string'}} fxc-error {{X3017: cannot implicitly convert from 'const string' to 'const float'}} */
  31. static const float f2 = 3.15;
  32. static const string s_global8= 3.14; /* expected-error {{cannot initialize a variable of type 'string' with an rvalue of type 'literal float'}} fxc-error {{X3017: cannot implicitly convert from 'float' to 'const string'}} */
  33. static const string s_global9= f2; /* expected-error {{cannot initialize a variable of type 'string' with an lvalue of type 'const float'}} fxc-error {{X3017: cannot implicitly convert from 'const float' to 'const string'}} */
  34. static const string s_global10 = { 'A', 'B', 'C' }; /* expected-error {{too many elements in vector initialization (expected 1 element, have 3)}} fxc-error {{X3017: 's_global10': initializer does not match type}} */
  35. static const string s_global11 = { 1, 2, 3 }; /* expected-error {{too many elements in vector initialization (expected 1 element, have 3)}} fxc-error {{X3017: 's_global11': initializer does not match type}} */
  36. static const string s_global12 = { "ABC" };
  37. string g_strArray[5]; /* expected-error {{array of type string is not supported}} fxc-pass {{}} */
  38. vector<string, 4> g_strVector1; /* expected-error {{'string' cannot be used as a type parameter where a scalar is required}} fxc-error {{X3122: vector element type must be a scalar type}} */
  39. matrix<string, 4, 4> g_strMatrix1; /* expected-error {{'string' cannot be used as a type parameter where a scalar is required}} fxc-error {{X3123: matrix element type must be a scalar type}} */
  40. void hello_here(string message, string s, float f) { /* expected-error {{parameter of type string is not supported}} expected-error {{parameter of type string is not supported}} fxc-pass {{}} */
  41. printf(s);
  42. printf(message);
  43. printf("%f", f);
  44. }
  45. string get_message() { /* expected-error {{return value of type string is not supported}} fxc-error {{X3038: 'get_message': function return value cannot contain Effects objects}} */
  46. return "foo";
  47. }
  48. struct test {
  49. string field; /* expected-error {{string declaration may only appear in global scope}} fxc-pass {{}} */
  50. };
  51. float4 main() : SV_Target0 { /* */
  52. string str; /* expected-error {{string declaration may only appear in global scope}} fxc-pass {{}} */
  53. str = s_global2; /* expected-error {{use of undeclared identifier 'str'}} fxc-pass {{}} */
  54. string strArray[5]; /* expected-error {{array of type string is not supported}} fxc-pass {{}} */
  55. vector<string, 4> strVector1; /* expected-error {{'string' cannot be used as a type parameter where a scalar is required}} fxc-error {{X3122: vector element type must be a scalar type}} */
  56. matrix<string, 4, 4> strMatrix1; /* expected-error {{'string' cannot be used as a type parameter where a scalar is required}} fxc-error {{X3123: matrix element type must be a scalar type}} */
  57. float4 cp4_local;
  58. printf("hi mom", 1, 2, 3);
  59. hello_here("a", "b", 1);
  60. return cp4_local;
  61. }