home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / gcc / bug / 3226 < prev    next >
Encoding:
Text File  |  1993-01-21  |  5.2 KB  |  138 lines

  1. Path: sparky!uunet!cis.ohio-state.edu!tv.tv.tek.COM!t1markm
  2. From: t1markm@tv.tv.tek.COM (Mark Mason)
  3. Newsgroups: gnu.gcc.bug
  4. Subject: bug in limbo code in gcc 2.3.3
  5. Date: 21 Jan 1993 18:18:25 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 125
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-gcc@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <199301211706.AA07320@soul.tv.tek.com>
  12.  
  13. Hello,
  14.  
  15. I seem to have found a bug in the limbo code in gcc 2.3.3 (running
  16. on a sparc, cross-compiling to a m68k, -version information in the
  17. debugger run below - but the bug seems to be target independent).
  18.  
  19. Basically, some of the type information stored for an extern decl
  20. in block scope has been allocated from function_maybepermanent_obstack
  21. rather than permanent_obstack. We found this because in some other
  22. code (which I cannot provide because of licensing problems) spurious
  23. warnings where generated about 'type mismatch with previous extern decl'.
  24.  
  25. At least one of the culprits is in grokdeclarator at line 4154 (below),
  26. where a call to build_array_type() is made, but we have not yet detected
  27. the case where the declaration in question is extern (and
  28. end_temporary_allocation() has not been called to switch
  29. to permanent_obstack).
  30.  
  31.   /* Detect the case of an array type of unspecified size
  32.      which came, as such, direct from a typedef name.
  33.      We must copy the type, so that each identifier gets
  34.      a distinct type, so that each identifier's size can be
  35.      controlled separately by its own initializer.  */
  36.  
  37.   if (type != 0 && typedef_type != 0
  38.       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type)
  39.       && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0)
  40.     {
  41.       type = build_array_type (TREE_TYPE (type), 0);
  42.       if (size_varies)
  43.     C_TYPE_VARIABLE_SIZE (type) = 1;
  44.     }
  45.  
  46. Below is a simple test case, with a demonstration in the debugger of which
  47. piece of type information is in the wrong obstack. This example itself does
  48. not generate a spurious warning (which happens when the limbo'd type decl
  49. is stomped on by something else, and is then later checked by a following
  50. function definition who duplicated the extern decl).
  51.  
  52. Script started on Thu Jan 21 08:21:46 1993
  53. soul.tv.tek.com[1]=> cat x.c
  54. int
  55. foo()
  56. {
  57.         extern char _sdata[];
  58. }
  59. soul.tv.tek.com[2]=> gdb /tv/lib/gcc/Vsystem/2.3.3/cc1
  60. GDB 3.5, Copyright (C) 1989 Free Software Foundation, Inc.
  61. There is ABSOLUTELY NO WARRANTY for GDB; type "info warranty" for details.
  62. GDB is free software and you are welcome to distribute copies of it
  63.  under certain conditions; type "info copying" to see the conditions.
  64. Reading symbol data from /tv/lib/gcc/Vsystem/2.3.3/cc1...done.
  65. Function abort not defined.
  66. Type "help" for a list of commands.
  67. (gdb) l pushdecl
  68. Reading in symbols for ../c-decl.c...done.
  69. Source file is more recent than executable.
  70. 1677       to agree with what X says.  */
  71. 1678    
  72. 1679    tree
  73. 1680    pushdecl (x)
  74. 1681         tree x;
  75. 1682    {
  76. 1683      register tree t;
  77. l1684     register tree name = DECL_NAME (x);
  78. 1685      register struct binding_level *b = current_binding_level;
  79. 1686    
  80. (gdb) l 2009
  81. 2004                     Only save it once.  This prevents temporary decls created in
  82. 2005                     expand_inline_function from being used here, since this
  83. 2006                     will have been set when the inline function was parsed.
  84. 2007                     It also helps give slightly better warnings.  */
  85. 2008                  if (IDENTIFIER_LIMBO_VALUE (name) == 0)
  86. 2009                    IDENTIFIER_LIMBO_VALUE (name) = x;
  87. 2010                }
  88. 2011    
  89. 2012              /* Warn if shadowing an argument at the top level of the body.  */
  90. 2013              if (oldlocal != 0 && !DECL_EXTERNAL (x)
  91. (gdb) b 2009
  92. Breakpoint 1 at 0x11750: file ../c-decl.c, line 2009.
  93. (gdb) r x.c -o x.s -version
  94. The program being debugged has been started already.
  95. Start it from the beginning? (y or n) y
  96. Starting program: /tv/lib/gcc/Vsystem/2.3.3/cc1 x.c -o x.s -version
  97. GNU C version 2.3.3 (68k, MIT syntax) compiled by GNU C version 2.2.2.
  98. enabled: -fdefer-pop -fpeephole -ffunction-cse -fcommon -fgnu-linker
  99.          -m68020 -mc68020 -m68881 -mbitfield -m68030
  100.  foo
  101. Bpt 1, pushdecl (x=(tree) 0x12b758) (../c-decl.c line 2009)
  102. 2009                    IDENTIFIER_LIMBO_VALUE (name) = x;
  103. (gdb) p debug_obstack(x)
  104. Reading in symbols for ../tree.c...done.
  105. object allocated from permanent_obstack.
  106. $1 = void
  107. (gdb) p debug_obstack(x->common.type)
  108. object allocated from function maybepermanent obstack.
  109. $2 = void
  110. (gdb) quit
  111. The program is running.  Quit anyway? (y or n) y
  112. script done on Thu Jan 21 08:24:34 1993
  113.  
  114. I don't claim to fully understand the mystries of grokdeclarator and the
  115. type system, but it seems that a similar problem could arise from the
  116. following abusive code:
  117.  
  118. bar()
  119. {
  120.     struct foo {
  121.         int x[4];
  122.     };
  123.     extern struct foo y;
  124. }
  125.  
  126. Because the type information for 'struct foo' would be placed in the
  127. function_maybepermanent_obstack at first. When the extern decl is
  128. handled, it seems that the type information for struct foo would
  129. have to be copied to the permanent_obstack (so the limbo entry for
  130. 'y' could refer to it). Or did I just wander off into the woodwork?
  131.  
  132. Thanks for your time,
  133.  
  134. Mark Mason
  135. t1markm@sol.tv.tek.com    <- my current work email address.
  136. mason@reed.edu    <- for personal contacts
  137.  
  138.