dggccbug.c 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* NOCW */
  2. /* dggccbug.c */
  3. /* bug found by Eric Young (eay@cryptsoft.com) - May 1995 */
  4. #include <stdio.h>
  5. /* There is a bug in
  6. * gcc version 2.5.8 (88open OCS/BCS, DG-2.5.8.3, Oct 14 1994)
  7. * as shipped with DGUX 5.4R3.10 that can be bypassed by defining
  8. * DG_GCC_BUG in my code.
  9. * The bug manifests itself by the vaule of a pointer that is
  10. * used only by reference, not having it's value change when it is used
  11. * to check for exiting the loop. Probably caused by there being 2
  12. * copies of the valiable, one in a register and one being an address
  13. * that is passed. */
  14. /* compare the out put from
  15. * gcc dggccbug.c; ./a.out
  16. * and
  17. * gcc -O dggccbug.c; ./a.out
  18. * compile with -DFIXBUG to remove the bug when optimising.
  19. */
  20. void inc(a)
  21. int *a;
  22. {
  23. (*a)++;
  24. }
  25. main()
  26. {
  27. int p=0;
  28. #ifdef FIXBUG
  29. int dummy;
  30. #endif
  31. while (p<3)
  32. {
  33. fprintf(stderr,"%08X\n",p);
  34. inc(&p);
  35. #ifdef FIXBUG
  36. dummy+=p;
  37. #endif
  38. }
  39. }