Bug 18255 - [GNU runtime] Protocols are not initialized correctly
Summary: [GNU runtime] Protocols are not initialized correctly
Alias: None
Product: gcc
Classification: Unclassified
Component: objc (show other bugs)
Version: 3.4.2
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: wrong-code
Depends on:
Reported: 2004-10-31 17:13 UTC by Tilo Prütz
Modified: 2010-10-18 08:21 UTC (History)
5 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2006-01-03 06:04:16


Note You need to log in before you can comment on or make changes to this bug.
Description Tilo Prütz 2004-10-31 17:13:51 UTC
Given this small Objective-C program:


#include <objc/Protocol.h>

@protocol a

- aMethod;


@protocol b <a>

- bMethod;


int main(int argc, char **argv)
    if ([@protocol(b) descriptionForInstanceMethod: @selector(aMethod)] != NULL)


Compiling with

gcc -lobjc



-> Segmentation fault

The segfault occurs in the libobjc when the Protocol tries to check it's
parents. The 'protocols'-Array contains a pointer which does _not_ point to the
parent protocol! That's why the prog crashes.

When inserting the line

    if ([@protocol(a) descriptionForInstanceMethod: @selector(aMethod)] != NULL)

as first line in the main-method all is good. The protocol 'a' (the parent) is
initialized and 'b' finds it's parent and the line that caused the crash before
is running without problems.

This is extremly critical to me and maybe a patch could be posted here so I can
patch my gcc?

P.S.: I set the component to 'libobjc' because I think that it's containing the
objc-runtime. Is this correct?
Comment 1 Andrew Pinski 2004-10-31 19:06:16 UTC
Confirmed, the problem is in the front-end, not marking the protocol a for being initialization.

Note this only effects the GNU runtime.
Comment 2 Andrew Pinski 2004-10-31 19:10:15 UTC
Comment 3 Andrew Pinski 2004-10-31 19:26:10 UTC
The bug is in objc_build_protocol_expr, I will figure out how to fix this.
Comment 4 Andrew Pinski 2004-10-31 22:47:36 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-10/msg02773.html>.  I don't know if it applies 
to the 3.4 branch at all.  And don't know if this is a regression (I will check tomorrow).
Comment 5 Tilo Prütz 2004-11-22 17:36:04 UTC
Will this get fixed in the 3.4 branch?
Comment 6 Andrew Pinski 2004-12-12 04:33:12 UTC
Most likely not as I think it was broke with 2.95.3 also (but I have to check).  I also need to update the 
patch for the comments.
Comment 7 Andrew Pinski 2005-08-03 13:50:23 UTC
*** Bug 23214 has been marked as a duplicate of this bug. ***
Comment 8 Tilo Prütz 2005-10-01 09:01:58 UTC
Is there any hope that this bug will be fixed in a GCC release?

It really sucks to have to patch every new installed release.

What can I do to make the fix do it's way into a GCC release?
Comment 9 Andrew Pinski 2005-10-04 19:29:56 UTC
I will try to update the patch tomorrow and submit it again for 4.1.
Comment 10 Andrew Pinski 2006-01-17 16:53:15 UTC
I have no time to update the patch right now, I might try to get to next week but I am going to unassign it for now.
Comment 11 Nicola Pero 2010-10-17 10:11:25 UTC
Author: nicola
Date: Sun Oct 17 10:11:23 2010
New Revision: 165579

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=165579
In gcc/testsuite/:
2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>

        PR objc/18255
        * objc.dg/pr18255.m: New.

Comment 12 Nicola Pero 2010-10-17 10:12:09 UTC
I fixed this in trunk (will be 4.6.0).  Testcase committed to the testsuite.

Comment 13 Tilo Prütz 2010-10-18 08:21:31 UTC
Thank you very much!