96_nodata_wanted.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*****************************************************************************/
  2. /* test 'nodata_wanted' data output suppression */
  3. #if defined test_static_data_error
  4. void foo() {
  5. if (1) {
  6. static short w = (int)&foo; /* initializer not computable */
  7. }
  8. }
  9. #elif defined test_static_nodata_error
  10. void foo() {
  11. if (0) {
  12. static short w = (int)&foo; /* initializer not computable */
  13. }
  14. }
  15. #elif defined test_global_data_error
  16. void foo();
  17. static short w = (int)&foo; /* initializer not computable */
  18. #elif defined test_local_data_noerror
  19. void foo() {
  20. short w = &foo; /* 2 cast warnings */
  21. }
  22. #elif defined test_data_suppression_off || defined test_data_suppression_on
  23. #if defined test_data_suppression_on
  24. # define SKIP 1
  25. #else
  26. # define SKIP 0
  27. #endif
  28. #include <stdio.h>
  29. /* some gcc headers #define __attribute__ to empty if it's not gcc */
  30. #undef __attribute__
  31. int main()
  32. {
  33. __label__ ts0, te0, ts1, te1;
  34. int tl, dl;
  35. static char ds0 = 0;
  36. static char de0 = 0;
  37. /* get reference size of empty jmp */
  38. ts0:;
  39. if (!SKIP) {}
  40. te0:;
  41. dl = -(&de0 - &ds0);
  42. tl = -(&&te0 - &&ts0);
  43. /* test data and code suppression */
  44. static char ds1 = 0;
  45. ts1:;
  46. if (!SKIP) {
  47. static void *p = (void*)&main;
  48. static char cc[] = "static string";
  49. static double d = 8.0;
  50. static struct __attribute__((packed)) {
  51. unsigned x : 12;
  52. unsigned char y : 7;
  53. unsigned z : 28, a: 4, b: 5;
  54. } s = { 0x333,0x44,0x555555,6,7 };
  55. printf("data:\n");
  56. printf(" %d - %.1f - %.1f - %s - %s\n",
  57. sizeof 8.0, 8.0, d, __FUNCTION__, cc);
  58. printf(" %x %x %x %x %x\n",
  59. s.x, s.y, s.z, s.a, s.b);
  60. }
  61. te1:;
  62. static char de1 = 0;
  63. dl += &de1 - &ds1;
  64. tl += &&te1 - &&ts1;
  65. printf("size of data/text:\n %s/%s\n",
  66. dl ? "non-zero":"zero", tl ? "non-zero":"zero");
  67. /*printf("# %d/%d\n", dl, tl);*/
  68. }
  69. #endif