fixed_point_errors.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // RUN: %clang_cc1 -verify -ffixed-point %s
  2. /* We do not yet support long long. No recommended bit widths are given for this
  3. * size. */
  4. long long _Accum longlong_accum; // expected-error{{'long long _Accum' is invalid}}
  5. unsigned long long _Accum u_longlong_accum; // expected-error{{'long long _Accum' is invalid}}
  6. long long _Fract longlong_fract; // expected-error{{'long long _Fract' is invalid}}
  7. unsigned long long _Fract u_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
  8. _Sat long long _Accum sat_longlong_accum; // expected-error{{'long long _Accum' is invalid}}
  9. _Sat unsigned long long _Accum sat_u_longlong_accum; // expected-error{{'long long _Accum' is invalid}}
  10. _Sat long long _Fract sat_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
  11. _Sat unsigned long long _Fract sat_u_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
  12. /* Although _Complex types work with floating point numbers, the extension
  13. * provides no info for complex fixed point types. */
  14. _Complex signed short _Accum cmplx_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
  15. _Complex signed _Accum cmplx_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
  16. _Complex signed long _Accum cmplx_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
  17. _Complex unsigned short _Accum cmplx_u_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
  18. _Complex unsigned _Accum cmplx_u_accum; // expected-error{{'_Complex _Accum' is invalid}}
  19. _Complex unsigned long _Accum cmplx_u_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
  20. _Complex short _Accum cmplx_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
  21. _Complex _Accum cmplx_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
  22. _Complex long _Accum cmplx_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
  23. _Complex signed short _Fract cmplx_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
  24. _Complex signed _Fract cmplx_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
  25. _Complex signed long _Fract cmplx_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
  26. _Complex unsigned short _Fract cmplx_u_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
  27. _Complex unsigned _Fract cmplx_u_fract; // expected-error{{'_Complex _Fract' is invalid}}
  28. _Complex unsigned long _Fract cmplx_u_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
  29. _Complex short _Fract cmplx_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
  30. _Complex _Fract cmplx_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
  31. _Complex long _Fract cmplx_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
  32. _Complex _Sat signed short _Accum cmplx_sat_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
  33. _Complex _Sat signed _Accum cmplx_sat_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
  34. _Complex _Sat signed long _Accum cmplx_sat_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
  35. _Complex _Sat unsigned short _Accum cmplx_sat_u_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
  36. _Complex _Sat unsigned _Accum cmplx_sat_u_accum; // expected-error{{'_Complex _Accum' is invalid}}
  37. _Complex _Sat unsigned long _Accum cmplx_sat_u_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
  38. _Complex _Sat short _Accum cmplx_sat_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
  39. _Complex _Sat _Accum cmplx_sat_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
  40. _Complex _Sat long _Accum cmplx_sat_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
  41. _Complex signed short _Fract cmplx_sat_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
  42. _Complex signed _Fract cmplx_sat_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
  43. _Complex signed long _Fract cmplx_sat_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
  44. _Complex unsigned short _Fract cmplx_sat_u_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
  45. _Complex unsigned _Fract cmplx_sat_u_fract; // expected-error{{'_Complex _Fract' is invalid}}
  46. _Complex unsigned long _Fract cmplx_sat_u_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
  47. _Complex short _Fract cmplx_sat_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
  48. _Complex _Fract cmplx_sat_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
  49. _Complex long _Fract cmplx_sat_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
  50. /* Bad combinations */
  51. float _Accum f_accum; // expected-error{{cannot combine with previous 'float' declaration specifier}}
  52. double _Accum d_accum; // expected-error{{cannot combine with previous 'double' declaration specifier}}
  53. _Bool _Accum b_accum; // expected-error{{cannot combine with previous '_Bool' declaration specifier}}
  54. char _Accum c_accum; // expected-error{{cannot combine with previous 'char' declaration specifier}}
  55. int _Accum i_accum; // expected-error{{cannot combine with previous 'int' declaration specifier}}
  56. float _Fract f_fract; // expected-error{{cannot combine with previous 'float' declaration specifier}}
  57. double _Fract d_fract; // expected-error{{cannot combine with previous 'double' declaration specifier}}
  58. _Bool _Fract b_fract; // expected-error{{cannot combine with previous '_Bool' declaration specifier}}
  59. char _Fract c_fract; // expected-error{{cannot combine with previous 'char' declaration specifier}}
  60. int _Fract i_fract; // expected-error{{cannot combine with previous 'int' declaration specifier}}
  61. /* Bad saturated combinations */
  62. _Sat float f; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'float'}}
  63. _Sat double d; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'double'}}
  64. _Sat _Bool b; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not '_Bool'}}
  65. _Sat char c; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'char'}}
  66. _Sat int i; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'int'}}
  67. _Sat _Sat _Fract fract; // expected-warning{{duplicate '_Sat' declaration specifier}}
  68. /* Literals that cannot fit into types */
  69. signed short _Accum s_short_accum = 256.0hk; // expected-error{{this value is too large for this fixed point type}}
  70. unsigned short _Accum u_short_accum = 256.0uhk; // expected-error{{this value is too large for this fixed point type}}
  71. signed _Accum s_accum = 65536.0k; // expected-error{{this value is too large for this fixed point type}}
  72. unsigned _Accum u_accum = 65536.0uk; // expected-error{{this value is too large for this fixed point type}}
  73. signed long _Accum s_long_accum = 4294967296.0lk; // expected-error{{this value is too large for this fixed point type}}
  74. unsigned long _Accum u_long_accum = 4294967296.0ulk; // expected-error{{this value is too large for this fixed point type}}
  75. // Large values from decimal exponents
  76. short _Accum short_accum_exp = 2.56e2hk; // expected-error{{this value is too large for this fixed point type}}
  77. _Accum accum_exp = 6.5536e4k; // expected-error{{this value is too large for this fixed point type}}
  78. long _Accum long_accum_exp = 4.294967296e9lk; // expected-error{{this value is too large for this fixed point type}}
  79. unsigned short _Accum u_short_accum_exp = 2.56e2uhk; // expected-error{{this value is too large for this fixed point type}}
  80. unsigned _Accum u_accum_exp = 6.5536e4uk; // expected-error{{this value is too large for this fixed point type}}
  81. unsigned long _Accum u_long_accum_exp = 4.294967296e9ulk; // expected-error{{this value is too large for this fixed point type}}
  82. // Large value from hexidecimal exponents
  83. short _Accum short_accum_hex_exp = 0x1p8hk; // expected-error{{this value is too large for this fixed point type}}
  84. _Accum accum_hex_exp = 0x1p16k; // expected-error{{this value is too large for this fixed point type}}
  85. long _Accum long_accum_hex_exp = 0x1p32lk; // expected-error{{this value is too large for this fixed point type}}
  86. unsigned short _Accum u_short_accum_hex_exp = 0x1p8uhk; // expected-error{{this value is too large for this fixed point type}}
  87. unsigned _Accum u_accum_hex_exp = 0x1p16uk; // expected-error{{this value is too large for this fixed point type}}
  88. unsigned long _Accum u_long_accum_hex_exp = 0x1p32ulk; // expected-error{{this value is too large for this fixed point type}}
  89. // Very large exponent
  90. _Accum x = 1e1000000000000000000000000000000000k; // expected-error{{this value is too large for this fixed point type}}
  91. /* Although _Fract's cannot equal 1, _Fract literals written as 1 are allowed
  92. * and the underlying value represents the max value for that _Fract type. */
  93. short _Fract short_fract_above_1 = 1.1hr; // expected-error{{this value is too large for this fixed point type}}
  94. _Fract fract_above_1 = 1.1r; // expected-error{{this value is too large for this fixed point type}}
  95. long _Fract long_fract_above_1 = 1.1lr; // expected-error{{this value is too large for this fixed point type}}
  96. unsigned short _Fract u_short_fract_above_1 = 1.1uhr; // expected-error{{this value is too large for this fixed point type}}
  97. unsigned _Fract u_fract_above_1 = 1.1ur; // expected-error{{this value is too large for this fixed point type}}
  98. unsigned long _Fract u_long_fract_above_1 = 1.1ulr; // expected-error{{this value is too large for this fixed point type}}
  99. short _Fract short_fract_hex_exp = 0x0.fp1hr; // expected-error{{this value is too large for this fixed point type}}
  100. _Fract fract_hex_exp = 0x0.fp1r; // expected-error{{this value is too large for this fixed point type}}
  101. long _Fract long_fract_hex_exp = 0x0.fp1lr; // expected-error{{this value is too large for this fixed point type}}
  102. unsigned short _Fract u_short_fract_hex_exp = 0x0.fp1uhr; // expected-error{{this value is too large for this fixed point type}}
  103. unsigned _Fract u_fract_hex_exp = 0x0.fp1ur; // expected-error{{this value is too large for this fixed point type}}
  104. unsigned long _Fract u_long_fract_hex_exp = 0x0.fp1ulr; // expected-error{{this value is too large for this fixed point type}}
  105. /* Do not allow typedef to be used with typedef'd types */
  106. typedef short _Fract shortfract_t;
  107. typedef short _Accum shortaccum_t;
  108. typedef _Fract fract_t;
  109. typedef _Accum accum_t;
  110. typedef long _Fract longfract_t;
  111. typedef long _Accum longaccum_t;
  112. _Sat shortfract_t td_sat_short_fract; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
  113. _Sat shortaccum_t td_sat_short_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
  114. _Sat fract_t td_sat_fract; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
  115. _Sat accum_t td_sat_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
  116. _Sat longfract_t td_sat_long_fract; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
  117. _Sat longaccum_t td_sat_long_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
  118. /* Bad suffixes */
  119. _Accum fk = 1.0fk; // expected-error{{invalid suffix 'fk' on integer constant}}
  120. _Accum kk = 1.0kk; // expected-error{{invalid suffix 'kk' on integer constant}}
  121. _Accum rk = 1.0rk; // expected-error{{invalid suffix 'rk' on integer constant}}
  122. _Accum rk = 1.0rr; // expected-error{{invalid suffix 'rr' on integer constant}}
  123. _Accum qk = 1.0qr; // expected-error{{invalid suffix 'qr' on integer constant}}
  124. /* Using wrong exponent notation */
  125. _Accum dec_with_hex_exp1 = 0.1p10k; // expected-error{{invalid suffix 'p10k' on integer constant}}
  126. _Accum dec_with_hex_exp2 = 0.1P10k; // expected-error{{invalid suffix 'P10k' on integer constant}}
  127. _Accum hex_with_dex_exp1 = 0x0.1e10k; // expected-error{{hexadecimal floating constant requires an exponent}}
  128. _Accum hex_with_dex_exp2 = 0x0.1E10k; // expected-error{{hexadecimal floating constant requires an exponent}}