]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[ObjC] Recognise 'instancetype' as equivalent to 'id'.
authorIain Sandoe <iain@sandoe.co.uk>
Thu, 5 Sep 2019 19:06:44 +0000 (19:06 +0000)
committerIain Sandoe <iains@gcc.gnu.org>
Thu, 5 Sep 2019 19:06:44 +0000 (19:06 +0000)
This is primarily about fixing a number of testsuite fails, it
implements the parsing of 'instancetype' but doesn't alter the
code gen (relative to using id in the same position). It is
part of the work-arounds for PR90709.

gcc/objc/

2019-09-05  Iain Sandoe  <iain@sandoe.co.uk>

Backport from mainline.
2019-05-18  Iain Sandoe  <iain@sandoe.co.uk>

* objc/objc-act.h (OCTI_INSTANCE_TYPE, OCTI_INSTANCETYPE_NAME): New.
(objc_global_trees): Add instance type and name.
(INSTANCE_TYPEDEF_NAME): New.
* objc/objc-act.c (synth_module_prologue): Build decls for
objc_instancetype_type and objc_instancetype_name.

gcc/testsuite/

2019-09-05  Iain Sandoe  <iain@sandoe.co.uk>

Backport from mainline.
2019-05-18  Iain Sandoe  <iain@sandoe.co.uk>

* objc.dg/instancetype-0.m: New.

From-SVN: r275428

gcc/objc/ChangeLog
gcc/objc/objc-act.c
gcc/objc/objc-act.h
gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/instancetype-0.m [new file with mode: 0644]

index b9a5e0790c94c84757ca3e1cc098cbef9706cd91..f0ff89d979cce51355f90a5cba099c274cfb045b 100644 (file)
@@ -1,3 +1,14 @@
+2019-09-05  Iain Sandoe  <iain@sandoe.co.uk>
+
+       Backport from mainline.
+       2019-05-18  Iain Sandoe  <iain@sandoe.co.uk>
+
+       * objc/objc-act.h (OCTI_INSTANCE_TYPE, OCTI_INSTANCETYPE_NAME): New.
+       (objc_global_trees): Add instance type and name.
+       (INSTANCE_TYPEDEF_NAME): New.
+       * objc/objc-act.c (synth_module_prologue): Build decls for
+       objc_instancetype_type and objc_instancetype_name.
+
 2018-12-06  Release Manager
 
        * GCC 7.4.0 released.
index 5f70961e7d79c90afa44d4c0ecc6c63030e5cf18..61d8f7ea20bc1a63f55586f630f2b3745ed437c5 100644 (file)
@@ -2944,18 +2944,26 @@ synth_module_prologue (void)
   objc_class_reference = xref_tag (RECORD_TYPE, objc_class_id);
 
   objc_object_type = build_pointer_type (objc_object_reference);
+  objc_instancetype_type = build_pointer_type (objc_object_reference);
   objc_class_type = build_pointer_type (objc_class_reference);
 
   objc_object_name = get_identifier (OBJECT_TYPEDEF_NAME);
+  objc_instancetype_name = get_identifier (INSTANCE_TYPEDEF_NAME);
   objc_class_name = get_identifier (CLASS_TYPEDEF_NAME);
 
-  /* Declare the 'id' and 'Class' typedefs.  */
+  /* Declare the 'id', 'instancetype' and 'Class' typedefs.  */
   type = lang_hooks.decls.pushdecl (build_decl (input_location,
                                                TYPE_DECL,
                                                objc_object_name,
                                                objc_object_type));
   TREE_NO_WARNING (type) = 1;
 
+  type = lang_hooks.decls.pushdecl (build_decl (input_location,
+                                               TYPE_DECL,
+                                               objc_instancetype_name,
+                                               objc_instancetype_type));
+  TREE_NO_WARNING (type) = 1;
+
   type = lang_hooks.decls.pushdecl (build_decl (input_location,
                                                TYPE_DECL,
                                                objc_class_name,
index 05ee968036ba7eb508ef40c50fc911312a669aa9..0cd192c5aff9abfaa7b7912f29191b656c9662e7 100644 (file)
@@ -313,6 +313,7 @@ enum objc_tree_index
     OCTI_SUPER_TYPE,
     OCTI_SEL_TYPE,
     OCTI_ID_TYPE,
+    OCTI_INSTANCE_TYPE,
     OCTI_CLS_TYPE,
     OCTI_NST_TYPE,
     OCTI_PROTO_TYPE,
@@ -368,6 +369,7 @@ enum objc_tree_index
     OCTI_OBJ_ID,
     OCTI_CLS_ID,
     OCTI_ID_NAME,
+    OCTI_INSTANCETYPE_NAME,
     OCTI_CLASS_NAME,
     OCTI_CNST_STR_ID,
     OCTI_CNST_STR_TYPE,
@@ -443,6 +445,7 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX];
 #define objc_super_type                objc_global_trees[OCTI_SUPER_TYPE]
 #define objc_selector_type             objc_global_trees[OCTI_SEL_TYPE]
 #define objc_object_type       objc_global_trees[OCTI_ID_TYPE]
+#define objc_instancetype_type objc_global_trees[OCTI_INSTANCE_TYPE]
 #define objc_class_type                objc_global_trees[OCTI_CLS_TYPE]
 #define objc_instance_type     objc_global_trees[OCTI_NST_TYPE]
 #define objc_protocol_type     objc_global_trees[OCTI_PROTO_TYPE]
@@ -570,7 +573,8 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX];
 
 #define objc_object_id         objc_global_trees[OCTI_OBJ_ID]
 #define objc_class_id          objc_global_trees[OCTI_CLS_ID]
-#define objc_object_name               objc_global_trees[OCTI_ID_NAME]
+#define objc_object_name        objc_global_trees[OCTI_ID_NAME]
+#define objc_instancetype_name objc_global_trees[OCTI_INSTANCETYPE_NAME]
 #define objc_class_name                objc_global_trees[OCTI_CLASS_NAME]
 
 /* Constant string classes.  */
@@ -608,6 +612,7 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX];
 /* Reserved tag definitions.  */
 
 #define OBJECT_TYPEDEF_NAME            "id"
+#define INSTANCE_TYPEDEF_NAME          "instancetype"
 #define CLASS_TYPEDEF_NAME             "Class"
 
 #define TAG_OBJECT                     "objc_object"
index ebc3a5be798e1a0fc69546b5d4e66612d2f68515..b88d7a6e6b59971682de5437a4d8af6a6e0109b1 100644 (file)
@@ -1,3 +1,10 @@
+2019-09-05  Iain Sandoe  <iain@sandoe.co.uk>
+
+       Backport from mainline.
+       2019-05-18  Iain Sandoe  <iain@sandoe.co.uk>
+
+       * objc.dg/instancetype-0.m: New.
+
 2019-09-05  Richard Biener  <rguenther@suse.de>
 
        Backport from mainline
diff --git a/gcc/testsuite/objc.dg/instancetype-0.m b/gcc/testsuite/objc.dg/instancetype-0.m
new file mode 100644 (file)
index 0000000..32cafdf
--- /dev/null
@@ -0,0 +1,30 @@
+/* Contributed by Iain Sandoe <iain@sandoe.co.uk>, May 2019.  */
+/* { dg-do compile } */
+
+/* Basic check of parsing instancetype.  */
+
+extern id class_createInstance (id, int);
+extern id class_getSuperclass (id);
+
+@interface MyObject
+{
+  Class isa;
+}
++ (instancetype)alloc;
+- (instancetype)init;
++ (instancetype)initialize;
++ (instancetype)factoryMethodA;
++ (id)factoryMethodB;
++ (Class) class;
++ (Class) superclass;
+@end
+
+@implementation MyObject
++ (instancetype)alloc { return class_createInstance (self, 0); }
+- (instancetype)init  { return self; }
++ (instancetype)initialize { return self; }
++ (instancetype)factoryMethodA { return [[[self class] alloc] init]; }
++ (id)factoryMethodB { return [[[self class] alloc] init]; }
++ (Class) class { return self; }
++ (Class) superclass { return class_getSuperclass (self); }
+@end