diff mbox

[c*,testsuite,darwin] CFString tests for darwin.

Message ID 8AA45D60-AC78-449F-A31F-511D41239F3D@sandoe-acoustics.co.uk
State New
Headers show

Commit Message

Iain Sandoe Oct. 22, 2010, 10:52 a.m. UTC
for some reason, the mailer dropped the attachment...

On 22 Oct 2010, at 11:49, IainS wrote:

> I wonder if Mike can review/approve these, since they are all darwin- 
> specific?
> Or do I need to seek approval from an RM or the C/C++ maintainers  
> individually?
>
> cheers
> Iain
>
> gcc/testsuite:
>
> 	Based on the CFString implementation in FSF apple/trunk branch.
>
> 	* gcc.dg/darwin-cfstring-1.c: New.
> 	* gcc.dg/darwin-cfstring-2.c: New.
> 	* gcc.dg/torture/darwin-cfstring-3.c: New.
> 	* g++.dg/other/darwin-cfstring1.C: New.
> 	* g++.dg/torture/darwin-cfstring-3.C: New.
diff mbox

Patch

Index: gcc/testsuite/gcc.dg/darwin-cfstring-1.c
===================================================================
--- gcc/testsuite/gcc.dg/darwin-cfstring-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/darwin-cfstring-1.c	(revision 0)
@@ -0,0 +1,28 @@ 
+/* Test whether the __builtin__CFStringMakeConstantString 
+   "function" fails gracefully when handed a non-constant
+   argument.  This will only work on MacOS X 10.1.2 and later.  */
+/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
+
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+typedef const struct __CFString *CFStringRef;
+
+#ifdef __CONSTANT_CFSTRINGS__
+#define CFSTR(STR)  ((CFStringRef) __builtin___CFStringMakeConstantString (STR))
+#else
+#error __CONSTANT_CFSTRINGS__ not defined
+#endif
+
+extern int cond;
+extern const char *func(void);
+
+const CFStringRef s0 = CFSTR("Hello" "there");
+
+int main(void) {
+  CFStringRef s1 = CFSTR("Str1");
+  CFStringRef s2 = CFSTR(cond? "Str2": "Str3"); /* { dg-error "CFString literal expression is not a string constant" } */
+  CFStringRef s3 = CFSTR(func());  /* { dg-error "CFString literal expression is not a string constant" } */
+
+  return 0;
+}
Index: gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c	(revision 0)
@@ -0,0 +1,30 @@ 
+/* Test whether the __builtin__CFStringMakeConstantString 
+   "function" generates compile-time objects with the correct layout. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
+
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+typedef const struct __CFString *CFStringRef;
+
+#ifdef __CONSTANT_CFSTRINGS__
+#define CFSTR(STR)  ((CFStringRef) __builtin___CFStringMakeConstantString (STR))
+#else
+#error __CONSTANT_CFSTRINGS__ not defined
+#endif
+
+extern int cond;
+extern const char *func(void);
+
+CFStringRef s0 = CFSTR("Hello" "there");
+
+void foo(void) {
+  const CFStringRef s1 = CFSTR("Str1");
+
+  s0 = s1;
+}
+
+/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+4\n" { target { *-*-darwin* && { ! lp64 } } } } } */
+/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+10\n" { target { *-*-darwin* && { ! lp64 } } } } } */
+/* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t4\n" { target { *-*-darwin* && {  lp64 } } } } } */
+/* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t10\n" { target { *-*-darwin* && {  lp64 } } } } } */
Index: gcc/testsuite/gcc.dg/darwin-cfstring-2.c
===================================================================
--- gcc/testsuite/gcc.dg/darwin-cfstring-2.c	(revision 0)
+++ gcc/testsuite/gcc.dg/darwin-cfstring-2.c	(revision 0)
@@ -0,0 +1,12 @@ 
+/* Test whether the __builtin__CFStringMakeConstantString 
+   "function" fails gracefully when used without the
+   -mconstant-cfstrings flag.  */
+/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
+
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mno-constant-cfstrings" } */
+
+typedef const struct __CFString *CFStringRef;
+
+const CFStringRef S = ((CFStringRef)__builtin___CFStringMakeConstantString("Testing"));
+/* { dg-error "built-in" "built-in function .* requires .* flag" { target *-*-* } 11 } */
Index: gcc/testsuite/g++.dg/other/darwin-cfstring1.C
===================================================================
--- gcc/testsuite/g++.dg/other/darwin-cfstring1.C	(revision 0)
+++ gcc/testsuite/g++.dg/other/darwin-cfstring1.C	(revision 0)
@@ -0,0 +1,25 @@ 
+/* Test whether the __builtin__CFStringMakeConstantString 
+   "function" fails gracefully when handed a non-constant
+   argument.  This will only work on MacOS X 10.1.2 and later.  */
+/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
+
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+#include <CoreFoundation/CFString.h>
+
+#ifdef __CONSTANT_CFSTRINGS__
+#undef CFSTR
+#define CFSTR(STR)  ((CFStringRef) __builtin___CFStringMakeConstantString (STR))
+#endif
+
+extern int cond;
+extern const char *func(void);
+
+int main(void) {
+  CFStringRef s1 = CFSTR("Str1");
+  CFStringRef s2 = CFSTR(cond? "Str2": "Str3"); /* { dg-error "CFString literal expression is not a string constant" } */
+  CFStringRef s3 = CFSTR(func());  /* { dg-error "CFString literal expression is not a string constant" } */
+
+  return 0;
+}
Index: gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C
===================================================================
--- gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C	(revision 0)
+++ gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C	(revision 0)
@@ -0,0 +1,30 @@ 
+/* Test whether the __builtin__CFStringMakeConstantString 
+   "function" generates compile-time objects with the correct layout. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
+
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+typedef const struct __CFString *CFStringRef;
+
+#ifdef __CONSTANT_CFSTRINGS__
+#define CFSTR(STR)  ((CFStringRef) __builtin___CFStringMakeConstantString (STR))
+#else
+#error __CONSTANT_CFSTRINGS__ not defined
+#endif
+
+extern int cond;
+extern const char *func(void);
+
+CFStringRef s0 = CFSTR("Hello" "there");
+
+void foo(void) {
+  const CFStringRef s1 = CFSTR("Str1");
+
+  s0 = s1;
+}
+
+/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+4\n" { target { *-*-darwin* && { ! lp64 } } } } } */
+/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+10\n" { target { *-*-darwin* && { ! lp64 } } } } } */
+/* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t4\n" { target { *-*-darwin* && {  lp64 } } } } } */
+/* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t10\n" { target { *-*-darwin* && {  lp64 } } } } } */