OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [objc.dg/] [encode-5.m] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
/* Check if array arguments of ObjC methods are decayed to pointer types
2
   in a proper fashion:
3
     (1) The _encodings_ for the array arguments should remain to be '[4i]' and
4
         such, since this has been the case since at least gcc 3.3.
5
     (2) However, when building the static C functions out of ObjC method signatures,
6
         we need to decay the arrays into pointers (as C does).
7
     (3) If array size is not known (e.g., 'int a[]'), then the type shall be
8
         encoded as a pointer.  */
9
 
10
/* Contributed by Alexander Malmberg <alexander@malmberg.org>  */
11
 
12
#include <objc/Object.h>
13
#include <stdlib.h>
14
#include <stdio.h>
15
#define CHECK_IF(expr) if(!(expr)) abort()
16
 
17
#ifdef __NEXT_RUNTIME__
18
#define METHOD Method
19
#define OBJC_GETCLASS objc_getClass
20
#define CLASS_GETINSTANCEMETHOD class_getInstanceMethod
21
#else
22
#include <objc/objc-api.h>
23
#define METHOD Method_t
24
#define OBJC_GETCLASS objc_get_class
25
#define CLASS_GETINSTANCEMETHOD class_get_instance_method
26
#endif
27
 
28
@interface Test : Object
29
{ float j; }
30
-(void) test2: (int [5])a with: (int [])b;
31
-(id) test3: (Test **)b; /* { dg-warning "previous declaration of .\\-\\(id\\)test3:\\(Test \\*\\*\\)b." } */
32
@end
33
 
34
@implementation Test
35
-(void) test2: (int [5])a with: (int [])b
36
{
37
  a[3] = *b;
38
}
39
-(void) test3: (Test [3][4])b {  /* { dg-warning "conflicting types for .\\-\\(void\\)test3:\\(Test \\\[3\\\]\\\[4\\\]\\)b." } */
40
}
41
@end
42
 
43
int bb[6] = { 0, 1, 2, 3, 4, 5 };
44
int *b = bb;
45
Test *cc[4];
46
Test **c = cc;
47
 
48
int offs1, offs2, offs3, offs4, offs5, offs6;
49
 
50
int main(int argc, char **argv)
51
{
52
  Class testClass = OBJC_GETCLASS("Test");
53
  METHOD meth;
54
 
55
  cc[0] = [Test new];
56
  CHECK_IF (bb[3] == 3);
57
  [*c test2: b with: bb + 4];
58
  CHECK_IF (bb[3] == 4);
59
  bb[3] = 0;
60
  [*c test2: bb with: bb + 5];
61
  CHECK_IF (bb[3] == 5);
62
 
63
  meth = CLASS_GETINSTANCEMETHOD(testClass, @selector(test2:with:));
64
  offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = -1;
65
  sscanf(meth->method_types, "v%d@%d:%d[%di]%d^i%d", &offs1, &offs2, &offs3,
66
      &offs4, &offs5, &offs6);
67
  CHECK_IF (!offs2 && offs4 == 5 && offs3 > 0);
68
  CHECK_IF (offs5 == 2 * offs3 && offs6 == 3 * offs3 && offs1 == 4 * offs3);
69
 
70
  meth = CLASS_GETINSTANCEMETHOD(testClass, @selector(test3:));
71
  offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = -1;
72
  sscanf(meth->method_types, "v%d@%d:%d[%d[%d{Test=#f}]]%d", &offs1, &offs2, &offs3,
73
      &offs4, &offs5, &offs6);
74
  CHECK_IF (!offs2 && offs4 == 3 && offs5 == 4 && offs3 > 0);
75
  CHECK_IF (offs6 == 2 * offs3 && offs1 == 3 * offs3);
76
 
77
  return 0;
78
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.