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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [testsuite/] [objc.dg/] [encode-5.m] - Blame information for rev 826

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 309 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-obj-c++-shared/Object1.h"
13
#include "../objc-obj-c++-shared/next-mapping.h"
14
#include <stdlib.h>
15
#include <stdio.h>
16
#define CHECK_IF(expr) if(!(expr)) abort()
17
 
18
#ifdef __NEXT_RUNTIME__
19
#define METHOD Method
20
#else
21
#include <objc/objc-api.h>
22
#define METHOD Method_t
23
#define method_get_types(M) (M)->method_types
24
#endif
25
 
26
@interface Test : Object
27
{ float j; }
28
-(void) test2: (int [5])a with: (int [])b;
29
-(id) test3: (Test **)b; /* { dg-message "previous declaration of .\\-\\(id\\)test3:\\(Test \\*\\*\\)b." } */
30
@end
31
 
32
@implementation Test
33
-(void) test2: (int [5])a with: (int [])b
34
{
35
  a[3] = *b;
36
}
37
-(void) test3: (Test [3][4])b {  /* { dg-warning "conflicting types for .\\-\\(void\\)test3:\\(Test \\\[3\\\]\\\[4\\\]\\)b." } */
38
}
39
@end
40
 
41
int bb[6] = { 0, 1, 2, 3, 4, 5 };
42
int *b = bb;
43
Test *cc[4];
44
Test **c = cc;
45
 
46
int offs1, offs2, offs3, offs4, offs5, offs6;
47
 
48
int main(int argc, char **argv)
49
{
50
  Class testClass = objc_get_class("Test");
51
  METHOD meth;
52
 
53
  cc[0] = [Test new];
54
  CHECK_IF (bb[3] == 3);
55
  [*c test2: b with: bb + 4];
56
  CHECK_IF (bb[3] == 4);
57
  bb[3] = 0;
58
  [*c test2: bb with: bb + 5];
59
  CHECK_IF (bb[3] == 5);
60
 
61
  meth = class_get_instance_method(testClass, @selector(test2:with:));
62
  offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = -1;
63
  sscanf(method_get_types(meth), "v%d@%d:%d[%di]%d^i%d", &offs1, &offs2, &offs3,
64
      &offs4, &offs5, &offs6);
65
  CHECK_IF (!offs2 && offs4 == 5 && offs3 > 0);
66
  CHECK_IF (offs5 == 2 * offs3 && offs6 == 3 * offs3 && offs1 == 4 * offs3);
67
 
68
  meth = class_get_instance_method(testClass, @selector(test3:));
69
  offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = -1;
70
  sscanf(method_get_types(meth), "v%d@%d:%d[%d[%d{Test=#f}]]%d", &offs1, &offs2, &offs3,
71
      &offs4, &offs5, &offs6);
72
  CHECK_IF (!offs2 && offs4 == 3 && offs5 == 4 && offs3 > 0);
73
  CHECK_IF (offs6 == 2 * offs3 && offs1 == 3 * offs3);
74
 
75
  return 0;
76
}

powered by: WebSVN 2.1.0

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