Bug 45763 - incorrect @encode(BOOL *)
Summary: incorrect @encode(BOOL *)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: objc (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Nicola Pero
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-23 15:51 UTC by Nicola Pero
Modified: 2010-09-27 19:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-09-26 16:43:36


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicola Pero 2010-09-23 15:51:36 UTC
This was reported to me by David Chisnall via email - he mentioned -

@encode(BOOL*) - it should return ^c or ^C (depending on whether BOOL is defined as signed or unsigned), but instead it returns *.  This is inconsistent with clang and with Apple GCC.

I also noticed that we already have a testcase (objc.dg/encode-1.m) but it is only compiled with the NeXT runtime.  We should fix it and enable the test on the GNU runtime as well. ;-)

Thanks
Comment 1 Nicola Pero 2010-09-26 16:43:36 UTC
Posted a patch to gcc-patches that fixes this.

Thanks
Comment 2 Nicola Pero 2010-09-27 19:22:17 UTC
Author: nicola
Date: Mon Sep 27 19:22:13 2010
New Revision: 164659

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=164659
Log:
In gcc/:
2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>

        * doc/objc.texi (Type encoding): Added the new 'long double' (D)
        code.  Added byref, which was missing in the list of codes.
        Explain that enumeration values are encoded as the integer type
        that the compiler uses to store them.  Explain and make examples
        of how 'const' interacts with pointers, and the complication of
        the encoding of 'const char *'.
        (Legacy type encoding): New subsection, explaining that GCC emits
        incorrect type encodings for the NeXT runtime for compatibility
        reasons.
        (@@encode): New subsection, explaining @encode and particularly
        that protocol qualifiers are not recognized inside an @encode()
        expression.
        (Method signatures): New subsection, explaining how method
        signatures are encoded.

In gcc/objc/:
2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>

        PR objc/45763
        PR objc/25450
        PR objc/25464
        * objc-act.c: Improved comments for encoding functions.
        (encode_aggregate_within): For the GNU runtime, rewritten some
        obsfuscated code to clarify the various cases.
        (encode_aggregate): Function removed.
        (encode_array): Generate an error if asked to encode an incomplete
        array as part of generating instance variables.  Else, when
        encoding an incomplete array inside a structure, encode it as an
        array of zero size.
        (encode_pointer): For the GNU runtime, fixed encoding 'BOOL *' as
        '^c' instead of '*'.
        (encode_gnu_bitfield): Encode enumerated types exactly in the same
        type as integer types instead of using a hardcoded 'i'.  If asked
        to encode a non-integer type as a bitfield, do not abort
        compilation immediately; instead generate an error, then skip the
        type.
        (encode_type): Use a 'switch' instead of a sequence of 'if's.
        Added a 'default' clause that gets executed if the type can not be
        matched, and that encodes it as '?' (unknown) and produces a
        warning.  For the GNU runtime, encode enumerated types exactly in
        the same way as integer types instead of using a hardcoded 'i'.
        Encode long double as 'D'.  Encode 128-bit integers as 'T' or 't'.
        Encode C++ reference types as pointers.  Call encode_vector to
        encode vectors.
        (encode_vector): New function.

2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>

        Merge from 'apple/trunk' branch on FSF servers.  I modified the
        changes to be used only when compiling for the NeXT runtime.

        2005-10-10  Fariborz Jahanian <fjahanian@apple.com>

        Radar 4301047

        * objc-act.c (encode_type): Remove the hack.

        2005-07-20  Ziemowit Laski  <zlaski@apple.com>

        Radar 4136935
        * objc-act.c (pointee_is_readonly): New function.
        (encode_pointer, encode_aggregate_within, encode_type):
        Attempt to emulate GCC 3.3 when generating type encodings.

In gcc/testsuite/:
2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>

        PR objc/25464
        * objc.dg/type-size-3.m: New test.

2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>

        PR objc/45763
        * objc.dg/encode-1.m: Execute the test with the GNU runtime as
        well.

2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>

        PR objc/25450
        * objc.dg/encode-3.m: Updated for fix of encoding of enums.
        * objc.dg/type-size-2.m: Same change.
        * obj-c++.dg/encode-5.mm: Same change.

2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>

        Merge from 'apple/trunk' branch on FSF servers.  The original
        Changelogs are below.

        * objc.dg/encode-6.m: Execute the test only with the GNU runtime.
        * objc.dg/encode-6-next.m: New file (from encode-6.m in the
        branch).
        * objc.dg/encode-7-next.m: New file (from encode-7.m in the
        branch).
        * objc.dg/encode-7-next-64bit.m: New file (from encode-7-64bit.m
        in the branch).
        * objc.dg/proto-qual-1.m: Test the 3.3 ABI on NeXT (from
        proto-qual-1.m in the branch) and the normal ABI on GNU.
        * objc.dg/threedotthree-abi-1.m: New file (from the branch).  Run
        the test only with the NeXT runtime.
        * obj-c++/encode-1.mm: Execute the test only with the GNU runtime.
        * obj-c++/encode-1-next.mm: New file (from encode-1.mm in the
        branch).
        * obj-c++.dg/threedotthree-abi-1.mm: New file (from the branch).
        Run the test only with the NeXT runtime.

        2006-03-30 Fariborz Jahanian <fjahanian@apple.com>

        Radar 4492973
        * objc.dg/encode-7-64bit.m: New.
        * objc.dg/encode-7.m: Skip if -m64.

        2005-10-19  Fariborz Jahanian <fjahanian@apple.com>

        Radar 4301047
        * objc.dg/proto-qual-1.m: Fix test to match 3.3 ABI
        * obj-c++.dg/threedotthree-abi-1.mm: New
        * objc.dg/threedotthree-abi-1.m: New

        2005-07-20  Ziemowit Laski  <zlaski@apple.com>

        Radar 4136935
        * obj-c++.dg/encode-1.mm: Tweak encodings to match fix.
        * objc.dg/encode-6.m: Likewise.
        * objc.dg/encode-7.m: New test case.

In libobjc/:
2010-09-26  Nicola Pero  <nicola.pero@meta-innovation.com>

        * encoding.c (objc_sizeof_type): Added support for vector type and
        for double long types.
        (objc_alignof_type): Same change.
        (objc_skip_typespec): Same change.
        * objc/encoding.h (_C_GCINVISIBLE): Use '|' for _C_GCINVISIBLE
        instead of '!' since '!' is already used for _C_VECTOR.
        * objc/objc-api.h (_C_LNG_DBL): Added.

Added:
    trunk/gcc/testsuite/obj-c++.dg/encode-1-next.mm
    trunk/gcc/testsuite/obj-c++.dg/threedotthree-abi-1.mm
    trunk/gcc/testsuite/objc.dg/encode-6-next.m
    trunk/gcc/testsuite/objc.dg/encode-7-next-64bit.m
    trunk/gcc/testsuite/objc.dg/encode-7-next.m
    trunk/gcc/testsuite/objc.dg/threedotthree-abi-1.m
    trunk/gcc/testsuite/objc.dg/type-size-3.m
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/doc/objc.texi
    trunk/gcc/objc/ChangeLog
    trunk/gcc/objc/objc-act.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/obj-c++.dg/encode-1.mm
    trunk/gcc/testsuite/obj-c++.dg/encode-5.mm
    trunk/gcc/testsuite/objc.dg/encode-1.m
    trunk/gcc/testsuite/objc.dg/encode-3.m
    trunk/gcc/testsuite/objc.dg/encode-6.m
    trunk/gcc/testsuite/objc.dg/proto-qual-1.m
    trunk/gcc/testsuite/objc.dg/type-size-2.m
    trunk/libobjc/ChangeLog
    trunk/libobjc/encoding.c
    trunk/libobjc/objc/encoding.h
    trunk/libobjc/objc/objc-api.h
Comment 3 Nicola Pero 2010-09-27 19:33:55 UTC
Fixed on trunk, including a testcase to test that it is fixed. ;-)

Thanks