Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / objc.dg / proto-qual-1.m
blob6e908727678a3770188528761ae39d95f133ad5c
1 /* Check that protocol qualifiers are compiled and encoded properly.  */
2 /* Author: Ziemowit Laski <zlaski@apple.com>  */
4 /* { dg-do run } */
5 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
6 /* { dg-additional-options "-Wno-objc-root-class" } */
8 #include "../objc-obj-c++-shared/runtime.h"
9 #include <objc/Protocol.h>
11 /* The encoded parameter sizes will be rounded up to match pointer alignment.  */
12 #define ROUND(s,a) (a * ((s + a - 1) / a))
13 #define aligned_sizeof(T) ROUND(sizeof(T),__alignof(void *))
15 extern int sscanf(const char *str, const char *format, ...);
16 extern void abort(void);
17 #define CHECK_IF(expr) if(!(expr)) abort()
19 @protocol Retain
20 + (oneway void)retainArgument:(out bycopy id)arg1 with:(in signed char **)arg2;
21 - (bycopy) address:(byref inout id)location with:(out short unsigned **)arg2;
22 @end
24 @interface Foo <Retain>
25 + (oneway void)retainArgument:(out bycopy id)arg with:(in signed char **)arg2;
26 @end
28 @implementation Foo
29 + (oneway void)retainArgument:(out bycopy id)arg1 with:(in signed char **)arg2 { }
30 - (bycopy) address:(byref inout id)location with:(out short unsigned **)arg2 { return nil; }
31 @end
33 Protocol *proto;
34 struct objc_method_description *meth;
35 struct objc_method_description meth_object;
36 unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7;
38 static void scan_initial(const char *pattern) {
39   totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1;
40   sscanf(meth->types, pattern, &totsize, &offs0, &offs1, &offs2, &offs3,
41       &offs4, &offs5, &offs6, &offs7);
42   CHECK_IF(!offs0 && offs1 == aligned_sizeof(id) && offs2 == offs1 + aligned_sizeof(SEL) && totsize >= offs2);
45 int main(void) {
46   proto = @protocol(Retain);
48   meth_object = protocol_getMethodDescription (proto,
49                   @selector(address:with:), YES, YES);
50   meth = &meth_object;
52   scan_initial("O@%u@%u:%uNR@%uo^^S%u");
53   CHECK_IF(offs3 == offs2 + aligned_sizeof(id) && totsize == offs3 + aligned_sizeof(unsigned));
55   meth_object = protocol_getMethodDescription (proto,
56                   @selector(retainArgument:with:), YES, NO);
57   meth = &meth_object;
59   scan_initial("Vv%u@%u:%uOo@%un^*%u");
60   CHECK_IF(offs3 == offs2 + aligned_sizeof(id) && totsize == offs3 + aligned_sizeof(char **));
61   return 0;