Bug in Objective-C compiler found

Nicola Pero n.pero@mi.flashnet.it
Mon Feb 26 07:47:00 GMT 2001


>> The compiler seems to have been broken on 7 September 2000 by zack, with
>> the change 1.152 to gcc/c-decl.c.
>>
>> Reverting a tiny amount of his changes, as follows, seem to fix the
>> problems:
>> 
>> Index: c-decl.c
>> ===================================================================
>> RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
>> retrieving revision 1.207.2.1
>> diff -u -r1.207.2.1 c-decl.c
>> --- c-decl.c  2001/02/16 13:02:14     1.207.2.1
>> +++ c-decl.c  2001/02/20 13:59:45
>> @@ -3912,7 +3912,7 @@
>>        if (id == ridpointers[(int) RID_CHAR])
>>       explicit_char = 1;
>>  
>> -      if (TREE_CODE (id) == IDENTIFIER_NODE && C_IS_RESERVED_WORD
(id))
>> +      if (TREE_CODE (id) == IDENTIFIER_NODE)// && C_IS_RESERVED_WORD
(id))
>>       {
>>         enum rid i = C_RID_CODE (id);
>>         if (i <= RID_LAST_MODIFIER)
>>
>[N.B. this is in grokdeclarator]
>
>This is probably not safe.  IDENTIFIER_NODEs without
>C_IS_RESERVED_WORD set cannot be trusted to have a meaningful
>C_RID_CODE field.  If it can be proved that the declspecs argument to
>grokdeclarator never contains an IDENTIFIER_NODE which is not a
>reserved word, then it's safe; otherwise we need another solution.

Then, the other simple fix is to make an exception for the protocol
keywords.  Here is a patch which works in this way - 

diff -u -r1.211 c-decl.c
--- c-decl.c    2001/02/23 20:38:54     1.211
+++ c-decl.c    2001/02/26 15:43:05
@@ -3787,6 +3787,22 @@
   return value;
 }
 ^L
+/* Return non-zero if node (which is assumed to be an IDENTIFIER_NODE)
+   represents one of the special Objective-C keywords `in', `out',
+   `inout', `bycopy', `byref', `oneway'.  This is needed by
+   grokdeclarator because these keywords need special treatment. */
+static int
+is_objc_protocol_qualifier (node)
+     tree node;
+{
+  return (node == ridpointers [(int) RID_IN]
+         || node == ridpointers [(int) RID_OUT]
+         || node == ridpointers [(int) RID_INOUT]
+         || node == ridpointers [(int) RID_BYCOPY]
+         || node == ridpointers [(int) RID_BYREF]
+         || node == ridpointers [(int) RID_ONEWAY]);
+}
+
 /* Given declspecs and a declarator,
    determine the name and type of the object declared
    and construct a ..._DECL node for it.
@@ -3918,7 +3934,8 @@
       if (id == ridpointers[(int) RID_CHAR])
        explicit_char = 1;
 
-      if (TREE_CODE (id) == IDENTIFIER_NODE && C_IS_RESERVED_WORD (id))
+      if (TREE_CODE (id) == IDENTIFIER_NODE 
+         && (C_IS_RESERVED_WORD (id) || is_objc_protocol_qualifier (id)))
        {
          enum rid i = C_RID_CODE (id);
          if (i <= RID_LAST_MODIFIER)


>I have an alternate fix in which the objc front end maintains separate
>IDENTIFIER_NODEs for these keywords in their reserved capacity, and
>swaps those in when it enters the appropriate context.  Then we don't
>have to fiddle their bits, and when grokdeclarator sees them they will
>be treated as keywords.  Patch is appended.

Perhaps/probably your patch is better - I don't know :-) - I have the
impression mine is safer only because I don't completely understand
the implications of the changes you propose...  But if Ovidiu does, I
trust his opinion.


> This does not fix protocol.m; that's a separate bug.  

Yep - that is a separate outstanding bug which needs to be fixed too
before gcc 3.0 is released. 




More information about the Gcc-patches mailing list