[cfe-commits] r55761 - in /cfe/trunk/test/CodeGenObjC: ./ constant-strings.m dot-syntax-1.m dot-syntax.m hidden.m link-errors.m messages-2.m messages.m predefined-expr-in-method.m property.m

Daniel Dunbar daniel at zuster.org
Wed Sep 3 21:36:23 PDT 2008


Author: ddunbar
Date: Wed Sep  3 23:36:23 2008
New Revision: 55761

URL: http://llvm.org/viewvc/llvm-project?rev=55761&view=rev
Log:
Add some Objective-C code generation tests.
 - Note that these don't really test anything other than that code
   generation doesn't fail or crash. Better than nothing though!

Added:
    cfe/trunk/test/CodeGenObjC/   (with props)
    cfe/trunk/test/CodeGenObjC/constant-strings.m
    cfe/trunk/test/CodeGenObjC/dot-syntax-1.m
    cfe/trunk/test/CodeGenObjC/dot-syntax.m
    cfe/trunk/test/CodeGenObjC/hidden.m
    cfe/trunk/test/CodeGenObjC/link-errors.m
    cfe/trunk/test/CodeGenObjC/messages-2.m
    cfe/trunk/test/CodeGenObjC/messages.m
    cfe/trunk/test/CodeGenObjC/predefined-expr-in-method.m
    cfe/trunk/test/CodeGenObjC/property.m

Propchange: cfe/trunk/test/CodeGenObjC/

------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Sep  3 23:36:23 2008
@@ -0,0 +1 @@
+Output

Added: cfe/trunk/test/CodeGenObjC/constant-strings.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/constant-strings.m?rev=55761&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/constant-strings.m (added)
+++ cfe/trunk/test/CodeGenObjC/constant-strings.m Wed Sep  3 23:36:23 2008
@@ -0,0 +1,4 @@
+// RUN: clang -fnext-runtime -emit-llvm -o %t %s
+
+id a = @"Hello World!";
+

Added: cfe/trunk/test/CodeGenObjC/dot-syntax-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/dot-syntax-1.m?rev=55761&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/dot-syntax-1.m (added)
+++ cfe/trunk/test/CodeGenObjC/dot-syntax-1.m Wed Sep  3 23:36:23 2008
@@ -0,0 +1,264 @@
+// RUN: clang -fnext-runtime --emit-llvm -o %t %s
+
+#include <stdio.h>
+
+ at interface Root
+-(id) alloc;
+-(id) init;
+ at end
+
+// Property above methods...
+
+ at interface Top0 : Root
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at interface Bot0 : Top0
+-(int) x;
+-(void) setX: (int) arg;
+ at end
+
+ at implementation Top0
+-(int) _getX {
+  printf("-[ Top0 _getX ]\n");
+  return 0;
+}
+-(void) _setX: (int) arg {
+  printf("-[ Top0 _setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot0
+-(int) x {
+  printf("-[ Bot0 _getX ]\n");
+  return 0;
+}
+-(void) setX: (int) arg {
+  printf("-[ Bot0 _setX: %d ]\n", arg);
+}
+ at end
+
+// Methods above property...
+
+ at interface Top1 : Root
+-(int) x;
+-(void) setX: (int) arg;
+ at end
+
+ at interface Bot1 : Top1
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at implementation Top1
+-(int) x {
+  printf("-[ Top1 x ]\n");
+  return 0;
+}
+-(void) setX: (int) arg {
+  printf("-[ Top1 setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot1
+-(int) _getX {
+  printf("-[ Bot1 _getX ]\n");
+  return 0;
+}
+-(void) _setX: (int) arg {
+  printf("-[ Bot1 _setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed setter & getter (variant 1)
+
+ at interface Top2 : Root
+-(int) x;
+-(void) _setX: (int) arg;
+ at end
+
+ at interface Bot2 : Top2
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at implementation Top2
+-(int) x {
+  printf("-[ Top2 x ]\n");
+  return 0;
+}
+-(void) _setX: (int) arg {
+  printf("-[ Top2 _setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot2
+-(int) _getX {
+  printf("-[ Bot2 _getX ]\n");
+  return 0;
+}
+-(void) setX: (int) arg {
+  printf("-[ Bot2 setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed setter & getter (variant 2)
+
+ at interface Top3 : Root
+-(int) _getX;
+-(void) setX: (int) arg;
+ at end
+
+ at interface Bot3 : Top3
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at implementation Top3
+-(int) _getX {
+  printf("-[ Top3 _getX ]\n");
+  return 0;
+}
+-(void) setX: (int) arg {
+  printf("-[ Top3 setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot3
+-(int) x {
+  printf("-[ Bot3 x ]\n");
+  return 0;
+}
+-(void) _setX: (int) arg {
+  printf("-[ Bot3 _setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed setter & getter (variant 3)
+
+ at interface Top4 : Root
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at interface Bot4 : Top4
+-(int) _getX;
+-(void) setX: (int) arg;
+ at end
+
+ at implementation Top4
+-(int) x {
+  printf("-[ Top4 x ]\n");
+  return 0;
+}
+-(void) _setX: (int) arg {
+  printf("-[ Top4 _setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot4
+-(int) _getX {
+  printf("-[ Bot4 _getX ]\n");
+  return 0;
+}
+-(void) setX: (int) arg {
+  printf("-[ Bot4 setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed setter & getter (variant 4)
+
+ at interface Top5 : Root
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at interface Bot5 : Top5
+-(int) x;
+-(void) _setX: (int) arg;
+ at end
+
+ at implementation Top5
+-(int) _getX {
+  printf("-[ Top5 _getX ]\n");
+  return 0;
+}
+-(void) setX: (int) arg {
+  printf("-[ Top5 setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot5
+-(int) x {
+  printf("-[ Bot5 x ]\n");
+  return 0;
+}
+-(void) _setX: (int) arg {
+  printf("-[ Bot5 _setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed level calls (variant 1)
+
+ at interface Top6 : Root
+-(int) x;
+ at end
+
+ at interface Bot6 : Top6
+-(void) setX: (int) arg;
+ at end
+
+ at implementation Top6
+-(int) x {
+  printf("-[ Top6 x ]\n");
+  return 0;
+}
+ at end
+
+ at implementation Bot6
+-(void) setX: (int) arg {
+  printf("-[ Bot5 setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed level calls (variant 1)
+
+ at interface Top7 : Root
+-(void) setX: (int) arg;
+ at end
+
+ at interface Bot7 : Top7
+-(int) x;
+ at end
+
+ at implementation Top7
+-(void) setX: (int) arg {
+  printf("-[ Top7 setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot7
+-(int) x {
+  printf("-[ Bot7 x ]\n");
+  return 0;
+}
+ at end
+
+//
+
+// FIXME: Two more (thats it?) interesting cases. Method access on
+// getter w/o setter and method access on setter w/o getter.
+
+int main() {
+#define test(N) { \
+  Bot##N *ob = [[Bot##N alloc] init]; \
+  int x = ob.x; \
+  ob.x = 10; }
+
+  test(0);
+  test(1);
+  test(2);
+  test(3);
+  test(4);
+  test(5);
+  //  test(6);
+  //  test(7);
+
+  return 0;
+}
+

Added: cfe/trunk/test/CodeGenObjC/dot-syntax.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/dot-syntax.m?rev=55761&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/dot-syntax.m (added)
+++ cfe/trunk/test/CodeGenObjC/dot-syntax.m Wed Sep  3 23:36:23 2008
@@ -0,0 +1,98 @@
+// RUN: clang -fnext-runtime --emit-llvm -o %t %s
+
+#include <stdio.h>
+
+ at interface Root
+-(id) alloc;
+-(id) init;
+ at end
+
+typedef struct {
+  float x, y, z[2];
+} S;
+
+ at interface A : Root {
+  int myX;
+  //  __complex myY;
+  S myZ;
+}
+
+ at property int x;
+//@property __complex int y;
+ at property S z;
+ at end
+
+ at implementation A
+-(int) x {
+  printf("-[A x] = %d\n", myX);
+  return myX;
+}
+-(void) setX: (int) arg {
+  myX = arg;
+  printf("-[A setX: %d]\n", myX);
+}
+
+// FIXME: Add back
+#if 0
+-(__complex int) y {
+  printf("-[A y] = (%d, %d)\n", __real myY, __imag myY);
+  return myY;
+}
+-(void) setY: (__complex int) arg {
+  myY = arg;
+  printf("-[A setY: (%d, %d)]\n", __real myY, __imag myY);
+}
+#endif
+
+-(S) z {
+  printf("-[A z] = { %f, %f, { %f, %f } }\n", 
+         myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
+  return myZ;
+}
+-(void) setZ: (S) arg {
+  myZ = arg;
+  printf("-[A setZ: { %f, %f, { %f, %f } } ]\n", 
+         myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
+}
+
+ at end
+
+int main() {
+#define SWAP(T,a,b) { T a_tmp = a; a = b; b = a_tmp; }
+  A *a = [[A alloc] init];
+  A *b = [[A alloc] init];
+  int a0 = 23;
+  //  __complex a1 = 25 + 10i;
+  S a2 =  { 246, 458, {275, 12} };
+  int b0 = 42673;
+  //  __complex b1 = 15 + 13i;
+  S b2 =  { 26, 2, {367, 13} };
+
+  a.x = a0;
+  //  a.y = a1;
+  a.z = a2;
+
+  a.x += a0;
+  //  a.y += a1;
+  // Yay, no compound assign of structures. A GCC extension in the
+  // works, perhaps?
+
+  b.x = b0;
+  //  b.y = b1;
+  b.z = b2;
+
+  int x0 = (b.x = b0);
+  printf("(b.x = b0): %d\n", x0);
+
+  //  int x1 = __real (b.y = b1);
+  //  printf("__real (b.y = b1) = %d\n", x1);
+
+  float x2 = (b.z = b2).x;
+  printf("(b.z = b2).x: %f\n", x2);
+
+  SWAP(int, a.x, b.x);
+  //  SWAP(__complex int, a.y, b.y);
+  SWAP(S, a.z, b.z);
+
+  return 0;
+}

Added: cfe/trunk/test/CodeGenObjC/hidden.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/hidden.m?rev=55761&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/hidden.m (added)
+++ cfe/trunk/test/CodeGenObjC/hidden.m Wed Sep  3 23:36:23 2008
@@ -0,0 +1,19 @@
+// RUN: clang -fnext-runtime --emit-llvm -o %t %s
+
+__attribute__((visibility("hidden")))
+ at interface Hidden
++(void) bar;
+ at end
+
+ at implementation Hidden
++(void) bar {}
+ at end
+
+__attribute__((visibility("default")))
+ at interface Default
++(void) bar;
+ at end
+
+ at implementation Default
++(void) bar {}
+ at end

Added: cfe/trunk/test/CodeGenObjC/link-errors.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/link-errors.m?rev=55761&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/link-errors.m (added)
+++ cfe/trunk/test/CodeGenObjC/link-errors.m Wed Sep  3 23:36:23 2008
@@ -0,0 +1,39 @@
+// RUN: clang -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep '.lazy_reference .objc_class_name_A' %t | count 1 &&
+// RUN: grep '.lazy_reference .objc_class_name_Unknown' %t | count 1 &&
+// RUN: grep '.lazy_reference .objc_class_name_Protocol' %t | count 1 &&
+// RUN: clang -DWITH_IMPL -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep '.lazy_reference .objc_class_name_Root' %t | count 1
+
+ at interface Root
+-(id) alloc;
+-(id) init;
+ at end
+
+ at protocol P;
+
+ at interface A : Root
+ at end
+
+ at interface A (Category)
++(void) foo;
+ at end
+
+#ifdef WITH_IMPL
+ at implementation A
+ at end
+#endif
+
+ at interface Unknown
++test;
+ at end
+
+
+int main() {
+  id x = @protocol(P);
+  [ A alloc ];
+  [ A foo ];
+  [ Unknown test ];
+  return 0;
+}
+

Added: cfe/trunk/test/CodeGenObjC/messages-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/messages-2.m?rev=55761&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/messages-2.m (added)
+++ cfe/trunk/test/CodeGenObjC/messages-2.m Wed Sep  3 23:36:23 2008
@@ -0,0 +1,139 @@
+// RUN: clang -fnext-runtime --emit-llvm -o %t %s
+
+#include <stdio.h>
+
+ at interface Root
+ at end
+
+typedef struct {
+  int x, y, z[10];
+} MyPoint;
+typedef struct {
+  float width, height;
+} MySize;
+
+ at interface A : Root
++(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3;
++(float) returnAFloat;
++(double) returnADouble;
++(MyPoint) returnAPoint;
++(void) printThisSize: (MySize) arg0;
++(MySize) returnASize;
+
+-(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3;
+-(float) returnAFloat;
+-(double) returnADouble;
+-(MyPoint) returnAPoint;
+-(void) printThisSize: (MySize) arg0;
+-(MySize) returnASize;
+ at end
+ at interface B : A
+ at end
+
+ at implementation A
++(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+  printf("(CLASS) theInt: %d, theFloat: %f, theDouble: %f, thePoint: { %d, %d }\n",
+         arg0, arg1, arg2, arg3.x, arg3.y);
+}
++(float) returnAFloat {
+  return 15.;
+}
++(double) returnADouble {
+  return 25.;
+}
++(MyPoint) returnAPoint {
+  MyPoint x = { 35, 45 };
+  return x;
+}
++(void) printThisSize: (MySize) arg0 {
+  printf("(CLASS) theSize: { %f, %f }\n",
+         arg0.width, arg0.height);
+}
++(MySize) returnASize {
+  MySize x = { 32, 44 };
+  return x;
+}
+
+-(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+  printf("theInt: %d, theFloat: %f, theDouble: %f, thePoint: { %d, %d }\n",
+         arg0, arg1, arg2, arg3.x, arg3.y);
+}
+-(float) returnAFloat {
+  return 10.;
+}
+-(double) returnADouble {
+  return 20.;
+}
+-(MyPoint) returnAPoint {
+  MyPoint x = { 30, 40 };
+  return x;
+}
+-(void) printThisSize: (MySize) arg0 {
+  printf("theSize: { %f, %f }\n",
+         arg0.width, arg0.height);
+}
+-(MySize) returnASize {
+  MySize x = { 22, 34 };
+  return x;
+}
+ at end
+
+ at implementation B
++(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+  arg3.x *= 2;
+  arg3.y *= 2;
+  [ super printThisInt: arg0*2 andThatFloat: arg1*2 andADouble: arg2*2 andAPoint: arg3 ];
+}
++(void) printThisSize: (MySize) arg0 {
+  arg0.width *= 2;
+  arg0.height *= 2;
+  [ super printThisSize: arg0 ];
+}
++(float) returnAFloat {
+  return [ super returnAFloat ]*2;
+}
++(double) returnADouble {
+  return [ super returnADouble ]*2;
+}
++(MyPoint) returnAPoint {
+  MyPoint x = [ super returnAPoint ];
+  x.x *= 2;
+  x.y *= 2;
+  return x;
+}
++(MySize) returnASize {
+  MySize x = [ super returnASize ];
+  x.width *= 2;
+  x.height *= 2;
+  return x;
+}
+
+-(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+  arg3.x *= 2;
+  arg3.y *= 2;
+  [ super printThisInt: arg0*2 andThatFloat: arg1*2 andADouble: arg2*2 andAPoint: arg3 ];
+}
+-(void) printThisSize: (MySize) arg0 {
+  arg0.width *= 2;
+  arg0.height *= 2;
+  [ super printThisSize: arg0 ];
+}
+-(float) returnAFloat {
+  return [ super returnAFloat ]*2;
+}
+-(double) returnADouble {
+  return [ super returnADouble ]*2;
+}
+-(MyPoint) returnAPoint {
+  MyPoint x = [ super returnAPoint ];
+  x.x *= 2;
+  x.y *= 2;
+  return x;
+}
+-(MySize) returnASize {
+  MySize x = [ super returnASize ];
+  x.width *= 2;
+  x.height *= 2;
+  return x;
+}
+ at end

Added: cfe/trunk/test/CodeGenObjC/messages.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/messages.m?rev=55761&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/messages.m (added)
+++ cfe/trunk/test/CodeGenObjC/messages.m Wed Sep  3 23:36:23 2008
@@ -0,0 +1,21 @@
+// RUN: clang -fnext-runtime --emit-llvm -o %t %s
+
+typedef struct {
+  int x;
+  int y;
+  int z[10];
+} MyPoint;
+
+void f0(id a) {
+  int i;
+  MyPoint pt = { 1, 2};
+
+  [a print0];
+  [a print1: 10];
+  [a print2: 10 and: "hello" and: 2.2];
+  [a takeStruct: pt ];
+  
+  void *s = @selector(print0);
+  for (i=0; i<2; ++i)
+    [a performSelector:s];
+}

Added: cfe/trunk/test/CodeGenObjC/predefined-expr-in-method.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/predefined-expr-in-method.m?rev=55761&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/predefined-expr-in-method.m (added)
+++ cfe/trunk/test/CodeGenObjC/predefined-expr-in-method.m Wed Sep  3 23:36:23 2008
@@ -0,0 +1,17 @@
+// RUN: clang -fnext-runtime --emit-llvm -o %t %s
+
+ at interface A
+ at end
+ at implementation A
++(void) foo {
+  printf("__func__: %s\n", __func__);
+  printf("__FUNCTION__: %s\n", __FUNCTION__);
+  printf("__PRETTY_FUNCTION__: %s\n", __PRETTY_FUNCTION__);
+  return 0;
+}
+ at end
+
+int main() {
+  [A foo];
+  return 0;
+}

Added: cfe/trunk/test/CodeGenObjC/property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/property.m?rev=55761&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/property.m (added)
+++ cfe/trunk/test/CodeGenObjC/property.m Wed Sep  3 23:36:23 2008
@@ -0,0 +1,41 @@
+// RUN: clang -fnext-runtime --emit-llvm -o %t %s
+
+#include <stdio.h>
+
+ at interface Root
+-(id) alloc;
+-(id) init;
+ at end
+
+ at interface A : Root {
+  int x;
+}
+ at property int x;
+ at property int y;
+ at property int z;
+ at property(readonly) int ro;
+ at end
+
+ at implementation A
+ at dynamic x;
+ at synthesize x;
+ at synthesize y = x;
+ at synthesize z = x;
+ at synthesize ro = x;
+-(int) y {
+  return x + 1;
+}
+-(void) setZ: (int) arg {
+  x = arg - 1;
+}
+ at end
+
+ at interface A (Cat)
+ at property int dyn;
+ at end
+
+ at implementation A (Cat)
+-(int) dyn {
+  return 10;
+}
+ at end





More information about the cfe-commits mailing list