This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug in Objective-C compiler found



> > 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.
> 
> I'm not sure how your patch would work properly either.  It seems
> to me that it merely exchanges a bug in one direction (incorrectly
> considering keywords to be identifiers) with another bug in the 
> other direction (incorrectly considering identifiers to be keywords).

Well - my patch simply re-established the hack that gcc has used for a
long time to manage objective-c protocol qualifier keywords. 


> The reason I like Zack's patch is that one can collect the entire
> function (or even unit of translation) into parse trees and have
> something that makes sense.  That is, in the different contexts
> you have distinct identifiable objects -- as opposed to having one
> object with a uniform, and apparently random, setting of some bit.

Yes - thanks for the explanation - I get the concept - with Zack's path
the treatment of those keywords is simpler and more consistent. 

That seems to be quite an improvement, so I'm happy if his patches get
used instead of mines.  I was mainly worried that they could break
something - because the tests we have in the gcc objc testsuite only test
for syntax - that is, that putting the `oneway', `bycopy' etc keywords in
the correct place does not crash the compiler - but they do not check the
semantics/generated code, that is basically that for example the compiler
really outputs the _F_BYCOPY qualifier in the protocol selector when it
finds the `bycopy' keyword in the correct place.  Perhaps for you it's
obvious that this is not changed by the patches - but since I don't
understand much of the code itself (yet), I only believe to test cases for
now. :-) 

So - I took the time to write a test which checks for that - it's at the
end of the mail (I had to add some useless code to keep the other protocol
bug - the one showed in protocol.m - from getting in the way and crashing
the compiler when compiling this test).  Would you please add this test to
the testsuite - both for the main and the branch. 

And - to my delight - it seems that Zack's patches pass this test too - so
they are fine for me - please go ahead and apply them.  And - thanks Zack
for your work.  :-) 



New test follows - please commit it as
gcc/gcc/testsuite/objc/execute/bycopy-3.m: 

/*
 * Contributed by Nicola Pero <nicola@brainstorm.co.uk>
 * Wed Feb 28 12:27:03 CET 2001
 */

/*
 * This test contains some no-op code which is needed to keep it
 * compile on broken gcc 3.x.  Anyway, the no-op code does not
 * interfere with what we are testing, which is that the `bycopy'
 * keyword generates the _F_BYCOPY qualifier for the return type.  */

#include <objc/objc.h>
#include <objc/Object.h>
#include <objc/Protocol.h>
#include <objc/encoding.h>

@protocol MyProtocol
+ (bycopy id<MyProtocol>) bycopyMethod;
@end

/* This no-op class to keep it compile under broken gcc 3.x */
@interface MyObject : Object <MyProtocol> 
@end

@implementation MyObject
+ (bycopy id<MyProtocol>) bycopyMethod
{
  return [MyObject alloc];
}
@end

int main (void)
{
  struct objc_method_description *method;
  const char *method_types;
  unsigned qualifiers;
  Protocol *protocol;
  /* This no-op command is needed to keep the test compile on broken
     gcc 3.x */
  MyObject *object = [MyObject bycopyMethod];

  /* Get the protocol object */
  protocol = @protocol (MyProtocol);

  /* Ask to the protocol for the description of the method bycopyMethod */
  method = [protocol descriptionForClassMethod: @selector (bycopyMethod)];
  if (method == NULL)
    {
      printf ("Could not find method bycopyMethod in protocol!\n");
      exit (1);
    }

  /* Get the method types for the method - which encode return type,
     arguments etc. */
  method_types = method->types;

  /* Get the qualifiers for the return type */
  qualifiers = objc_get_type_qualifiers (method_types);

  /* If _F_BYCOPY is not there, the compiler is broken */
  if (! (qualifiers & _F_BYCOPY))
    {
      printf ("Failed - selector does not contain _F_BYCOPY qualifier!\n");
      exit (1);
    }

  /* Else, happy end */
  return 0;
}





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]