[gcc r10-9534] testsuite, Objective-C : Backport test fixes.

Iain D Sandoe iains@gcc.gnu.org
Wed Mar 24 22:07:22 GMT 2021


https://gcc.gnu.org/g:b233b73326350f17d506aa9e12f02773ecf8aaa3

commit r10-9534-gb233b73326350f17d506aa9e12f02773ecf8aaa3
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Sun Oct 4 00:05:17 2020 +0100

    testsuite, Objective-C : Backport  test fixes.
    
            Backport f2ac4fc035b327ab8ccf562a7667f6d13758c72b,
            bae828f7bbf49709df96cb264aae2c38a0cca807,
            40330e70770d1c42ca51f6d84b70b04537687bc5,
            b1b7599ca52f3ba94deea842c80286194d516210,
            b292746ff7cfe708d3311ea41242c44ccbbe2693,
            5505a9eab9bc3b170fc9f22e8a7292464efe88f6 and
            406b452dc0e1254684365e3cec026258a39ba6c1
    
    gcc/testsuite/ChangeLog:
    
            * objc.dg/objc-gc-4.m: Disable for macOS 10.15 and 11.x.
            * objc.dg/gnu-api-2-class-meta.m: Add a flag to cause NeXT
            headers to expose prototypes for messaging. Mark the root
            class if the objc_root_class attribute is available. Use
            char ** as the second arg to main.
            * objc.dg/gnu-api-2-class.m: Use dispatch prototype.
            * objc.dg/gnu-api-2-objc.m: Skip on NeXT because of extra
            prototypes pulled in by headers.
            * objc.dg/ivar-scope-4.m: Add inititialize method to the
            root class.
            * objc.dg/torture/forward-1.m: Implement forwarding using the
            native NeXT (NSInvocation) method for Darwin.
            * objc.dg/call-super-2.m: Remove inclusion of runtime.h.
            Add a FIXME about the test portability.
            * objc.dg/plugin/diagnostic-test-expressions-1.m: Use assignment
            expressions for @selector and @protocol to obtain a useful
            diagnostic range.
            * objc.dg/pr23214.m: Use Object as the root object before
            Darwin12 (and NSObject after).

Diff:
---
 gcc/testsuite/objc.dg/call-super-2.m               |  6 ++-
 gcc/testsuite/objc.dg/gnu-api-2-class-meta.m       |  6 ++-
 gcc/testsuite/objc.dg/gnu-api-2-class.m            |  1 +
 gcc/testsuite/objc.dg/gnu-api-2-objc.m             |  8 +++-
 gcc/testsuite/objc.dg/ivar-scope-4.m               |  6 +++
 gcc/testsuite/objc.dg/objc-gc-4.m                  |  2 +-
 .../objc.dg/plugin/diagnostic-test-expressions-1.m | 25 +++++++++---
 gcc/testsuite/objc.dg/pr23214.m                    |  2 +-
 gcc/testsuite/objc.dg/torture/forward-1.m          | 46 ++++++++++++++++++++--
 9 files changed, 86 insertions(+), 16 deletions(-)

diff --git a/gcc/testsuite/objc.dg/call-super-2.m b/gcc/testsuite/objc.dg/call-super-2.m
index 0a3765f07fb..836cad92126 100644
--- a/gcc/testsuite/objc.dg/call-super-2.m
+++ b/gcc/testsuite/objc.dg/call-super-2.m
@@ -3,7 +3,8 @@
 /* { dg-do compile } */
 
 #include "../objc-obj-c++-shared/TestsuiteObject.h"
-#include "../objc-obj-c++-shared/runtime.h"
+/* NOTE: we are relying on the built-in type for objc_getClass being used
+   rather than the one that might come from including <objc/runtime.h>.  */
 #include <stddef.h>
 
 /* FIXME: This is temporary.  At the moment, the compiler, when
@@ -14,6 +15,9 @@
 # define objc_getClass(C) objc_get_class(C)
 #endif
 
+/* FIXME: casting of super is not permitted by clang, so that many of the
+   tests here are testing non-portable code.  */
+
 @protocol Func
 + (int) class_func0;
 - (int) instance_func0;
diff --git a/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m b/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m
index 07e0ba2884a..3a85b163c91 100644
--- a/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m
+++ b/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m
@@ -20,6 +20,7 @@
 /* { dg-do run } */
 /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-options "-DOBJC_OLD_DISPATCH_PROTOTYPES" { target { *-*-darwin* } } } */
 
 /* To get the modern GNU Objective-C Runtime API, you include
    objc/runtime.h.  */
@@ -28,6 +29,9 @@
 #include <stdio.h>
 #include <string.h>
 
+#if __has_attribute(objc_root_class)
+__attribute__((objc_root_class))
+#endif
 @interface MyRootClass
 { Class isa; }
 + alloc;
@@ -65,7 +69,7 @@ static id static_variable = nil;
 + (id) mySelf;
 @end
 
-int main(int argc, void **args)
+int main(int argc, char **args)
 {
   /* Functions are tested in alphabetical order.  */
 
diff --git a/gcc/testsuite/objc.dg/gnu-api-2-class.m b/gcc/testsuite/objc.dg/gnu-api-2-class.m
index 341952969e8..eade0dcbbfa 100644
--- a/gcc/testsuite/objc.dg/gnu-api-2-class.m
+++ b/gcc/testsuite/objc.dg/gnu-api-2-class.m
@@ -7,6 +7,7 @@
 /* { dg-do run } */
 /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-options "-DOBJC_OLD_DISPATCH_PROTOTYPES" { target { *-*-darwin* } } } */
 
 /* To get the modern GNU Objective-C Runtime API, you include
    objc/runtime.h.  */
diff --git a/gcc/testsuite/objc.dg/gnu-api-2-objc.m b/gcc/testsuite/objc.dg/gnu-api-2-objc.m
index d65c120455e..1b4ce8e4799 100644
--- a/gcc/testsuite/objc.dg/gnu-api-2-objc.m
+++ b/gcc/testsuite/objc.dg/gnu-api-2-objc.m
@@ -3,8 +3,12 @@
   This is test 'objc', covering all functions starting with 'objc'.  */
 
 /* { dg-do run } */
-/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
-/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* Although this works with the NeXT runtime in a sub-set of cases, some
+   versions of the runtime header pulls in a number of system protocols,
+   which causes the objc_copyProtocolList test to fail (in addition to those
+   systems that don't have the V2 APis).  XFAILing the run is not useful
+   since it will XPASS on the sub-set that works.  */
+/* { dg-skip-if "Incompatible" { *-*-darwin* } { "-fnext-runtime" } { "" } } */
 
 /* To get the modern GNU Objective-C Runtime API, you include
    objc/runtime.h.  */
diff --git a/gcc/testsuite/objc.dg/ivar-scope-4.m b/gcc/testsuite/objc.dg/ivar-scope-4.m
index f7209724be9..5fc29f90bdc 100644
--- a/gcc/testsuite/objc.dg/ivar-scope-4.m
+++ b/gcc/testsuite/objc.dg/ivar-scope-4.m
@@ -18,6 +18,7 @@ int someivar = 1;
   int someivar;
 }
 
++ (id) initialize;
 + (id) alloc;
 - (id) init;
 - (int) getGlobal;
@@ -26,6 +27,11 @@ int someivar = 1;
 @end
 
 @implementation MyClass
++ (id) initialize
+{
+  return self;
+}
+
 + (id) alloc
 {
   return class_createInstance (self, 0);
diff --git a/gcc/testsuite/objc.dg/objc-gc-4.m b/gcc/testsuite/objc.dg/objc-gc-4.m
index 96c32788dfe..8102a5a532f 100644
--- a/gcc/testsuite/objc.dg/objc-gc-4.m
+++ b/gcc/testsuite/objc.dg/objc-gc-4.m
@@ -3,7 +3,7 @@
 /* Contributed by Ziemowit Laski <zlaski@apple.com>  */
 
 /* { dg-do compile } */
-/* { dg-skip-if "GC API is an error from Darwin16." { *-*-darwin1[6-8]* } { "-fnext-runtime" } { "" } } */
+/* { dg-skip-if "GC API is an error from Darwin16." { *-*-darwin1[6-9]* *-*-darwin2[0-9]* } { "-fnext-runtime" } { "" } } */
 /* { dg-options "-fobjc-gc" } */
 /* { dg-prune-output "cc1obj: warning: '-fobjc-gc' is ignored for '-fgnu-runtime'" } */
 
diff --git a/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m b/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m
index ed7aca39a28..23a93021e83 100644
--- a/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m
+++ b/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m
@@ -5,6 +5,8 @@
    (see the notes in that file); this file adds test
    coverage for various Objective C constructs. */
 
+#include <objc/runtime.h> /* for SEL, Protocol */
+
 extern void __emit_expression_range (int dummy, ...);
 
 @protocol prot
@@ -55,22 +57,33 @@ extern void __emit_expression_range (int dummy, ...);
                                 ~~~~~~~~~~~
    { dg-end-multiline-output "" } */
 }
+
 - (void) test_at_selector
 {
-  __emit_expression_range ( 0, @selector(func0) ); /* { dg-warning "range" } */
+  /* For the NeXT runtime, @selector() generates a a var decl which (a) isn't
+     handled by the plugin, and (b) if it was would not necessarily have the
+     right location (there is only one var decl uniqued to each selector 
+     spelling, so the location would be that of the first occurrence).  Use an
+     assignment expression to test the operation.   */
+  SEL aSel;
+  __emit_expression_range ( 0, aSel = @selector(foo) ); /* { dg-warning "range" } */
 /* { dg-begin-multiline-output "" }
-   __emit_expression_range ( 0, @selector(func0) );
-                                ^~~~~~~~~~~~~~~~
+   __emit_expression_range ( 0, aSel = @selector(foo) );
+                                ~~~~~^~~~~~~~~~~~~~~~
    { dg-end-multiline-output "" } */
 }
 - (void) test_at_protocol
 {
-  __emit_expression_range ( 0, @protocol(prot) ); /* { dg-warning "range" } */
+  /* As for @selector(), the NeXT runtime generates a a var decl for
+     @protocol() handle this in a similar way.  */
+  Protocol *aProt;
+  __emit_expression_range ( 0, aProt = @protocol(prot) ); /* { dg-warning "range" "" } */
 /* { dg-begin-multiline-output "" }
-   __emit_expression_range ( 0, @protocol(prot) );
-                                ~~~~~~~~~~~~~~~
+   __emit_expression_range ( 0, aProt = @protocol(prot) );
+                                ~~~~~~^~~~~~~~~~~~~~~~~
    { dg-end-multiline-output "" } */
 }
+
 - (void) test_at_encode:(int)i
 {
   /* @encode() generates a STRING_CST which doesn't retain a location
diff --git a/gcc/testsuite/objc.dg/pr23214.m b/gcc/testsuite/objc.dg/pr23214.m
index 341a2837da5..56cdc025161 100644
--- a/gcc/testsuite/objc.dg/pr23214.m
+++ b/gcc/testsuite/objc.dg/pr23214.m
@@ -7,7 +7,7 @@
 
 #if defined (__NEXT_RUNTIME__) && defined(__OBJC2__) \
     && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) \
-    && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1070
+    && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1080
 #include <objc/Protocol.h>
 #define OBJECT NSObject
 #else
diff --git a/gcc/testsuite/objc.dg/torture/forward-1.m b/gcc/testsuite/objc.dg/torture/forward-1.m
index b45f1b444ed..a25012de25c 100644
--- a/gcc/testsuite/objc.dg/torture/forward-1.m
+++ b/gcc/testsuite/objc.dg/torture/forward-1.m
@@ -1,32 +1,53 @@
 /* { dg-do run } */
 /* See if -forward:: is able to work. */
 /* { dg-skip-if "Needs OBJC2 Implementation" { *-*-darwin8* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
-
+/* { dg-additional-options "-Wl,-framework,Foundation" { target *-*-darwin* } } */
 #include <stdio.h>
 #include <stdlib.h>
 
+/* Versions of the runtime after 10.13 no longer support the original
+   'forward:' mechanism, so we make a stripped down representation of
+   NSInvocation and need to link with -framework Foundation.  */
+#if __NEXT_RUNTIME__
+@class  NSInvocation, NSMethodSignature;
+# include "../../objc-obj-c++-shared/F-NSObject.h"
+@interface NSInvocation : NSObject
++ (NSInvocation *)invocationWithMethodSignature:(NSMethodSignature *)sig;
+@property SEL selector;
+- (void)invoke;
+- (void)invokeWithTarget:(id)target;
+@end
+# define OBJECT NSObject
+#else
 #include "../../objc-obj-c++-shared/TestsuiteObject.m"
+#define OBJECT TestsuiteObject
+#endif
 
 #define VALUETOUSE 1234567890
 
 id forwarder, receiver;
 
-@interface Forwarder: TestsuiteObject
+@interface Forwarder : OBJECT
 {
     id receiver;
 }
 
 -initWithReceiver:theReceiver;
+#if __NEXT_RUNTIME__
+- (void)forwardInvocation:(NSInvocation *)anInvocation;
+- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
+#endif
 
 @end
 
-@interface Receiver:TestsuiteObject
+@interface Receiver : OBJECT
 {
     int foo;
 }
 -display;
 -initWithFoo:(int)theFoo;
 @end
+
 @implementation Receiver
 
 -initWithFoo: (int)theFoo
@@ -56,7 +77,22 @@ id forwarder, receiver;
     receiver = theReceiver;
     return self;
 }
--(void *) forward: (SEL)theSel: (void *)theArgFrame
+
+#if __NEXT_RUNTIME__
+- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSel
+{
+ return [receiver methodSignatureForSelector:aSel];
+}
+- (void)forwardInvocation:(NSInvocation *)anInvocation
+{
+    if ([receiver respondsToSelector:[anInvocation selector]]) {
+        [anInvocation invokeWithTarget:receiver];
+    }
+    else {
+    }
+}
+#else
+-(void *) forward:(SEL)theSel : (void *)theArgFrame
 {
   /* If we have a reciever try to perform on that object */
     if (receiver)
@@ -75,6 +111,8 @@ id forwarder, receiver;
     printf ("Unrecognized selector\n");
     return NULL;
 }
+#endif
+
 @end
 int main()
 {


More information about the Gcc-cvs mailing list