home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / gnu / gcc / bug / 2982 next >
Encoding:
Text File  |  1992-12-12  |  5.0 KB  |  196 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.umass.edu!pasieka%sureal
  3. From: pasieka%sureal@cs.umass.edu
  4. Subject: GCC 2.2.2 bug
  5. Message-ID: <9212111654.AA09707@sureal.cs.umass.edu>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Fri, 11 Dec 1992 16:54:13 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 183
  12.  
  13. Version of GCC: 2.2.2
  14. Machine Type: Vax (Sun3 equivalent)
  15.  
  16. Compiling the enclosed output of cpp and executing the program results
  17. in output which I believe illustrates a bug.
  18.  
  19. The problem occurs when I am setting up a single linked list's next
  20. pointers. The line:
  21.  
  22.     test_a->next = ++test_a;
  23.  
  24. results in an error when the location of the 'next' element of the
  25. structure is first. My guess is that the register allocation processing
  26. does not recognize that the register will be modified before it can be
  27. used to store the resulting value. In the case where the location of
  28. the 'next' element of the structure is not first, there is no problem.
  29.  
  30. I will be testing this with GCC 2.3.1 after I get the compiler
  31. compiled. This is not likely in the *immediate* future but likely
  32. within the next month.
  33.  
  34. The original C program is as follows:
  35.  
  36. /* Start ------------------------------------------------------------------- */
  37. struct a {
  38.   struct a *next;
  39.   int index;
  40. };
  41.  
  42. struct b {
  43.   int index;
  44.   struct b *next;
  45. };
  46.  
  47. main ()
  48. {
  49.   int i;
  50.   struct a *anchor_a, *test_a;
  51.   struct b *anchor_b, *test_b;
  52.  
  53.   /* malloc an array of 11 structs each */
  54.   anchor_a = test_a = (struct a *)malloc (11*sizeof (struct a));
  55.   anchor_b = test_b = (struct b *)malloc (11*sizeof (struct b));
  56.  
  57.   /* Initialize the nnext and index values */
  58.   for (i=0 ; i<11; i++) {
  59.     anchor_a[i].next = (struct a *)0;
  60.     anchor_a[i].index = -1;
  61.     anchor_b[i].index = -1;
  62.     anchor_b[i].next = (struct b *)0;
  63.   }
  64.  
  65.   /* Link the first 10 of struct a's together in a single linked list */
  66.   for (i=0 ; i<10; i++) {
  67.     test_a->index = i;
  68.     test_a->next = ++test_a;
  69.   }
  70.  
  71.   /* Link the first 10 of struct b's together in a single linked list */
  72.   for (i=0 ; i<10; i++) {
  73.     test_b->index = i;
  74.     test_b->next = ++test_b;
  75.   }
  76.  
  77.   /* Print out the structs index and the index of the next */
  78.  
  79.   printf ("For structs where the first element is the next pointer:\n");
  80.   for (i=0, test_a=anchor_a ; i<10; i++, test_a++) {
  81.     printf ("\t0x%x (%d) -> 0x%x (%d)\n",
  82.         (int)test_a, i,
  83.         (int)test_a->next, test_a->next->index);
  84.   }
  85.   printf("\n");
  86.   printf ("For structs where the next pointer is not the first element:\n");
  87.   for (i=0, test_b=anchor_b ; i<10; i++, test_b++) {
  88.     printf ("\t0x%x (%d) -> 0x%x (%d)\n",
  89.         (int)test_b, i,
  90.         (int)test_b->next, test_b->next->index);
  91.   }
  92.  
  93.   return 0;
  94. }
  95. /* End --------------------------------------------------------------------- */
  96.  
  97. The program after cpp (not much different):
  98.  
  99. /* Start ------------------------------------------------------------------- */
  100. # 1 "../../../test/bugs/preincrement.c"
  101.  
  102. struct a {
  103.   struct a *next;
  104.   int index;
  105. };
  106.  
  107. struct b {
  108.   int index;
  109.   struct b *next;
  110. };
  111.  
  112. main ()
  113. {
  114.   int i;
  115.   struct a *anchor_a, *test_a;
  116.   struct b *anchor_b, *test_b;
  117.  
  118.    
  119.   anchor_a = test_a = (struct a *)malloc (11*sizeof (struct a));
  120.   anchor_b = test_b = (struct b *)malloc (11*sizeof (struct b));
  121.  
  122.    
  123.   for (i=0 ; i<11; i++) {
  124.     anchor_a[i].next = (struct a *)0;
  125.     anchor_a[i].index = -1;
  126.     anchor_b[i].index = -1;
  127.     anchor_b[i].next = (struct b *)0;
  128.   }
  129.  
  130.    
  131.   for (i=0 ; i<10; i++) {
  132.     test_a->index = i;
  133.     test_a->next = ++test_a;
  134.   }
  135.  
  136.    
  137.   for (i=0 ; i<10; i++) {
  138.     test_b->index = i;
  139.     test_b->next = ++test_b;
  140.   }
  141.  
  142.    
  143.  
  144.   printf ("For structs where the first element is the next pointer:\n");
  145.   for (i=0, test_a=anchor_a ; i<10; i++, test_a++) {
  146.     printf ("\t0x%x (%d) -> 0x%x (%d)\n",
  147.         (int)test_a, i,
  148.         (int)test_a->next, test_a->next->index);
  149.   }
  150.   printf("\n");
  151.   printf ("For structs where the next pointer is not the first element:\n");
  152.   for (i=0, test_b=anchor_b ; i<10; i++, test_b++) {
  153.     printf ("\t0x%x (%d) -> 0x%x (%d)\n",
  154.         (int)test_b, i,
  155.         (int)test_b->next, test_b->next->index);
  156.   }
  157.  
  158.   return 0;
  159. }
  160. /* End --------------------------------------------------------------------- */
  161.  
  162. The output I get is:
  163.  
  164. For structs where the first element is the next pointer:
  165.     0x1c04 (0) -> 0x0 (-1051042096)
  166.     0x1c0c (1) -> 0x1c0c (1)
  167.     0x1c14 (2) -> 0x1c14 (2)
  168.     0x1c1c (3) -> 0x1c1c (3)
  169.     0x1c24 (4) -> 0x1c24 (4)
  170.     0x1c2c (5) -> 0x1c2c (5)
  171.     0x1c34 (6) -> 0x1c34 (6)
  172.     0x1c3c (7) -> 0x1c3c (7)
  173.     0x1c44 (8) -> 0x1c44 (8)
  174.     0x1c4c (9) -> 0x1c4c (9)
  175.  
  176. For structs where the next pointer is not the first element:
  177.     0x1c84 (0) -> 0x1c8c (1)
  178.     0x1c8c (1) -> 0x1c94 (2)
  179.     0x1c94 (2) -> 0x1c9c (3)
  180.     0x1c9c (3) -> 0x1ca4 (4)
  181.     0x1ca4 (4) -> 0x1cac (5)
  182.     0x1cac (5) -> 0x1cb4 (6)
  183.     0x1cb4 (6) -> 0x1cbc (7)
  184.     0x1cbc (7) -> 0x1cc4 (8)
  185.     0x1cc4 (8) -> 0x1ccc (9)
  186.     0x1ccc (9) -> 0x1cd4 (-1)
  187.  
  188. Notice that in the first set of output, the next pointers are incorrectly set.
  189.  
  190. Please feel free to contact me about this if I can provide more
  191. information. I can be reached via email at pasieka@cs.umass.edu or by
  192. phone at 413/545-2447.
  193.  
  194. -- Michael
  195.  
  196.