7r-sign-extend.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. signed char global_c = -1;
  21. struct foo
  22. {
  23. signed char type;
  24. };
  25. int
  26. main ()
  27. {
  28. {
  29. signed char c = -1;
  30. int i = c;
  31. if (i != -1)
  32. return 1;
  33. }
  34. {
  35. int i = global_c;
  36. if (i != -1)
  37. return 2;
  38. }
  39. {
  40. signed char c = -1;
  41. int ints[2] = { c, 0 };
  42. if (ints[0] != -1)
  43. return 3;
  44. }
  45. {
  46. signed char c = -1;
  47. int i = c;
  48. if (i != -1)
  49. return 4;
  50. }
  51. {
  52. signed char c = -1;
  53. int i = c;
  54. if (i != -1)
  55. return 5;
  56. }
  57. {
  58. signed char a[2] = { -1, -129 };
  59. int i = a[0];
  60. if (i != -1)
  61. return 6;
  62. if (a[0] != -1)
  63. return 7;
  64. }
  65. {
  66. struct foo f = { -1 };
  67. int i = f.type;
  68. if (i != -1)
  69. return 8;
  70. struct foo *g = &f;
  71. i = g->type;
  72. if (i != -1)
  73. return 9;
  74. }
  75. {
  76. signed char c = -1;
  77. signed char *p = &c;
  78. int i = *p;
  79. if (i != -1)
  80. return 10;
  81. }
  82. {
  83. int i = -129;
  84. i = (signed char) i;
  85. if (i != 127)
  86. return 11;
  87. }
  88. {
  89. unsigned char b = -129;
  90. int i = b;
  91. if (i != 127)
  92. return 12;
  93. }
  94. return 0;
  95. }