Bug 30479 - [4.1 Regression] Precompiled headers don't seem to work with GNU ObjC
Summary: [4.1 Regression] Precompiled headers don't seem to work with GNU ObjC
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: objc (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: 4.1.2
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2007-01-16 04:36 UTC by Nicola Pero
Modified: 2007-01-22 02:03 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.0.3 4.3.0 4.2.0 4.1.2
Known to fail: 4.1.0 4.1.1
Last reconfirmed: 2007-01-16 04:40:10


Attachments
test case (header) (141 bytes, text/x-chdr)
2007-01-16 04:36 UTC, Nicola Pero
Details
test case (ObjC file) (109 bytes, text/x-objcsrc)
2007-01-16 04:37 UTC, Nicola Pero
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicola Pero 2007-01-16 04:36:00 UTC
Consider the following files, test.h and test.m:

test.h:
-------

/* Contributed by Nicola Pero - Tue Jan 16 04:09:06 GMT 2007 */
#include <objc/objc.h>
#include <objc/Object.h>

@interface TestClass : Object
+ (int) test;
@end

test.m:
-------

#include "test.h"

@implementation TestClass
+ (int) test
{
  return 0;
}
@end

int main (void)
{
  return [TestClass test];
}


My compiler is 4.1.1 20070105 (Red Hat 4.1.1-51).

If I compile the files in the standard way --

 gcc test.m -lobjc

it all works.

If I first precompile test.h

 gcc -x objective-c-header test.h

I get the test.h.gch file, which looks ok, but then compiling fails --

 gcc test.m -lobjc

test.m:4: warning: cannot find interface declaration for &#65533;TestClass&#65533;
test.m:4: error: redefinition of &#65533;struct TestClass&#65533;
(compilation aborts)

(I also got a compiler internal error once)

Using the -H option to gcc you can indeed confirm that compilation fails iff the
precompiled ObjC header is used.

It seems that ObjC class declarations in ObjC headers are not read correctly/at all from precompiled headers (C stuff works fine instead!).  Very disappointing. :-(

I hope I'm missing an option / something, else it's a bug that needs fixing :-(

Thanks
Comment 1 Nicola Pero 2007-01-16 04:36:35 UTC
Created attachment 12908 [details]
test case (header)
Comment 2 Nicola Pero 2007-01-16 04:37:00 UTC
Created attachment 12909 [details]
test case (ObjC file)
Comment 3 Andrew Pinski 2007-01-16 04:40:10 UTC
Confirmed, a regression from 4.0.4 where this worked.
I will look into this more soon.
Comment 4 Nicola Pero 2007-01-16 04:55:53 UTC
Once fixed, it might be worthwhile adding testcases for this then ? :-)

Thanks
Comment 5 Andrew Pinski 2007-01-16 04:58:08 UTC
(In reply to comment #4)
> Once fixed, it might be worthwhile adding testcases for this then ? :-)
Yes and I am going to try to do that also.
Comment 6 Andrew Pinski 2007-01-16 06:25:29 UTC
Well this was caused by the objective-C++ merge.  This is also a classic example of why hashing on pointer values is not a good idea.

Working on a fix, should also simplify the code :).
Comment 7 Andrew Pinski 2007-01-16 07:43:21 UTC
I have a full fix and a semi working testsuite (semi working mean it will work for non remote testing).

This is just a good example of when you should not use pointer hashing, especially when there is already a hash for identifiers.
Comment 8 Andrew Pinski 2007-01-21 06:51:18 UTC
Subject: Bug 30479

Author: pinskia
Date: Sun Jan 21 06:51:07 2007
New Revision: 121024

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121024
Log:
2007-01-20  Andrew Pinski  <pinskia@gmail.com>

        PR objc/30479
        * objc-act.c (hash_interface): Use IDENTIFIER_HASH_VALUE instead
        of htab_hash_pointer.
        (lookup_interface): Likewise.
        (add_class): Likewise.

2007-01-20  Andrew Pinski  <pinskia@gmail.com>

        PR objc/30479
        * objc.dg/pch: New directory.
        * objc.dg/pch/pch.exp: New file.
        * objc.dg/pch/interface-1.m: New test.
        * objc.dg/pch/interface-1.hs: New include file.
        * lib/objc.exp (objc_target_compile): Add
        "-x objective-c-header" in front of the sources if this is
        a precompiled header being compiled.



Added:
    trunk/gcc/testsuite/objc.dg/pch/
    trunk/gcc/testsuite/objc.dg/pch/interface-1.hs
    trunk/gcc/testsuite/objc.dg/pch/interface-1.m
    trunk/gcc/testsuite/objc.dg/pch/pch.exp
Modified:
    trunk/gcc/objc/ChangeLog
    trunk/gcc/objc/objc-act.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/lib/objc.exp

Comment 9 Andrew Pinski 2007-01-21 23:33:57 UTC
Subject: Bug 30479

Author: pinskia
Date: Sun Jan 21 23:33:46 2007
New Revision: 121040

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121040
Log:
2007-01-20  Andrew Pinski  <pinskia@gmail.com>

        PR objc/30479
        * objc-act.c (hash_interface): Use IDENTIFIER_HASH_VALUE instead
        of htab_hash_pointer.
        (lookup_interface): Likewise.
        (add_class): Likewise.

2007-01-20  Andrew Pinski  <pinskia@gmail.com>

        PR objc/30479
        * objc.dg/pch: New directory.
        * objc.dg/pch/pch.exp: New file.
        * objc.dg/pch/interface-1.m: New test.
        * objc.dg/pch/interface-1.hs: New include file.
        * lib/objc.exp (objc_target_compile): Add
        "-x objective-c-header" in front of the sources if this is
        a precompiled header being compiled.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/objc.dg/pch/
      - copied from r121024, trunk/gcc/testsuite/objc.dg/pch/
Modified:
    branches/gcc-4_2-branch/gcc/objc/ChangeLog
    branches/gcc-4_2-branch/gcc/objc/objc-act.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/gcc/testsuite/lib/objc.exp

Comment 10 Andrew Pinski 2007-01-22 00:16:57 UTC
Testing on the 4.1 branch now.
Comment 11 Andrew Pinski 2007-01-22 02:03:09 UTC
Fixed in 4.1.2.
Comment 12 Andrew Pinski 2007-01-22 02:03:17 UTC
Subject: Bug 30479

Author: pinskia
Date: Mon Jan 22 02:03:02 2007
New Revision: 121048

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121048
Log:
2007-01-21  Andrew Pinski  <pinskia@gmail.com>

        PR objc/30479
        * objc-act.c (hash_interface): Use IDENTIFIER_HASH_VALUE instead
        of htab_hash_pointer.
        (lookup_interface): Likewise.
        (add_class): Likewise.

2007-01-21  Andrew Pinski  <pinskia@gmail.com>

        PR objc/30479
        * objc.dg/pch: New directory.
        * objc.dg/pch/pch.exp: New file.
        * objc.dg/pch/interface-1.m: New test.
        * objc.dg/pch/interface-1.hs: New include file.
        * lib/objc.exp (objc_target_compile): Add
        "-x objective-c-header" in front of the sources if this is
        a precompiled header being compiled.



Added:
    branches/gcc-4_1-branch/gcc/testsuite/objc.dg/pch/
      - copied from r121024, trunk/gcc/testsuite/objc.dg/pch/
Modified:
    branches/gcc-4_1-branch/gcc/objc/ChangeLog
    branches/gcc-4_1-branch/gcc/objc/objc-act.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/lib/objc.exp