88_codeopt.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Check some way in where code suppression caused various
  2. miscompilations. */
  3. extern int printf (const char *, ...);
  4. typedef unsigned long size_t;
  5. size_t _brk_start, _brk_end;
  6. void * extend_brk(size_t size, size_t align)
  7. {
  8. size_t mask = align - 1;
  9. void *ret = 0;
  10. do {
  11. if (__builtin_expect(!!(_brk_start == 0), 0))
  12. do {
  13. printf("wrong1\n");
  14. } while (0);
  15. } while (0);
  16. _brk_end = (_brk_end + mask) & ~mask;
  17. ret = (void *)_brk_end;
  18. _brk_end += size;
  19. return ret;
  20. }
  21. static void get_args (int a, int b)
  22. {
  23. if (a != 1)
  24. printf("wrong2\n");
  25. else
  26. printf("okay\n");
  27. }
  28. void bla(void)
  29. {
  30. int __ret = 42;
  31. ({
  32. if (__builtin_expect(!!(0), 0)) {
  33. if (__builtin_expect(!!__ret, 0))
  34. printf("wrong3\n");
  35. int x = !!(__ret);
  36. }
  37. __ret;
  38. });
  39. get_args(!!__ret, sizeof(__ret));
  40. }
  41. _Bool chk(unsigned long addr, unsigned long limit, unsigned long size)
  42. {
  43. _Bool ret;
  44. /* This just needs to compile, no runtime test. (And it doesn't compile
  45. only with certain internal checking added that's not committed). */
  46. if (0)
  47. ret = 0 != (!!(addr > limit - size));
  48. }
  49. int main()
  50. {
  51. void *r;
  52. _brk_start = 1024;
  53. _brk_end = 1024;
  54. r = extend_brk (4096, 16);
  55. if (!r)
  56. printf("wrong4\n");
  57. else
  58. printf("okay\n");
  59. bla();
  60. return 0;
  61. }