diff options
Diffstat (limited to 'gcc/testsuite/objc.dg/strings')
-rw-r--r-- | gcc/testsuite/objc.dg/strings/const-cfstring-2.m | 27 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/strings/const-cfstring-5.m | 26 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/strings/const-str-1.m | 25 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/strings/const-str-12.m | 16 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/strings/const-str-12b.m | 32 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/strings/const-str-2.m | 8 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/strings/const-str-5.m | 28 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/strings/const-str-6.m | 28 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/strings/strings.exp | 46 |
9 files changed, 236 insertions, 0 deletions
diff --git a/gcc/testsuite/objc.dg/strings/const-cfstring-2.m b/gcc/testsuite/objc.dg/strings/const-cfstring-2.m new file mode 100644 index 00000000000..14ae68c6c50 --- /dev/null +++ b/gcc/testsuite/objc.dg/strings/const-cfstring-2.m @@ -0,0 +1,27 @@ +/* Test the -Wnonportable-cfstrings option, which should give + warnings if non-ASCII characters are embedded in constant + CFStrings. This will only work on MacOS X 10.2 and later. */ +/* Developed by Ziemowit Laski <zlaski@apple.com>. */ + +/* So far, CFString is darwin-only. */ +/* { dg-do compile { target *-*-darwin* } } */ +/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */ +/* { dg-options "-mconstant-cfstrings -Wnonportable-cfstrings" } */ + +#import <Foundation/NSString.h> +#import <CoreFoundation/CFString.h> + +#ifndef __CONSTANT_CFSTRINGS__ +#error The -fconstant-cfstrings option is not functioning properly +#endif + +void foo(void) { + NSString *s1 = @"Compile-time string literal"; + CFStringRef s2 = CFSTR("Compile-time string literal"); + NSString *s3 = @"Non-ASCII literal - \222"; /* { dg-warning "non-ASCII character in CFString literal" } */ + CFStringRef s4 = CFSTR("\222 - Non-ASCII literal"); /* { dg-warning "non-ASCII character in CFString literal" } */ + CFStringRef s5 = CFSTR("Non-ASCII (\222) literal"); /* { dg-warning "non-ASCII character in CFString literal" } */ + NSString *s6 = @"\0Embedded NUL"; /* { dg-warning "embedded NUL in CFString literal" } */ + CFStringRef s7 = CFSTR("Embedded \0NUL"); /* { dg-warning "embedded NUL in CFString literal" } */ + CFStringRef s8 = CFSTR("Embedded NUL\0"); /* { dg-warning "embedded NUL in CFString literal" } */ +} diff --git a/gcc/testsuite/objc.dg/strings/const-cfstring-5.m b/gcc/testsuite/objc.dg/strings/const-cfstring-5.m new file mode 100644 index 00000000000..13cb7895779 --- /dev/null +++ b/gcc/testsuite/objc.dg/strings/const-cfstring-5.m @@ -0,0 +1,26 @@ +/* Test if constant CFStrings may be passed back as ObjC strings. */ +/* Author: Ziemowit Laski */ + +/* So far, CFString is darwin-only. */ +/* { dg-do compile { target *-*-darwin* } } */ +/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */ +/* { dg-options "-mconstant-cfstrings" } */ + +#include <objc/Object.h> + +@interface Foo: Object { + char *cString; + unsigned int len; +} ++ (Foo *)description; +@end + +@interface Bar: Object ++ (Foo *) getString: (int) which; +@end + +@implementation Bar ++ (Foo *) getString: (int) which { + return which? [Foo description]: @"Hello"; +} +@end diff --git a/gcc/testsuite/objc.dg/strings/const-str-1.m b/gcc/testsuite/objc.dg/strings/const-str-1.m new file mode 100644 index 00000000000..754c99bf1ae --- /dev/null +++ b/gcc/testsuite/objc.dg/strings/const-str-1.m @@ -0,0 +1,25 @@ +/* Test errors for constant strings. */ +/* { dg-do compile } */ +/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ + +#ifdef __cplusplus +extern void baz(...); +#endif + +void foo() +{ + baz(@"hiya"); /* { dg-error "annot find interface declaration" } */ +} + +@interface NXConstantString +{ + void *isa; + char *str; + int len; +} +@end + +void bar() +{ + baz(@"howdah"); +} diff --git a/gcc/testsuite/objc.dg/strings/const-str-12.m b/gcc/testsuite/objc.dg/strings/const-str-12.m new file mode 100644 index 00000000000..93059018647 --- /dev/null +++ b/gcc/testsuite/objc.dg/strings/const-str-12.m @@ -0,0 +1,16 @@ +/* { dg-options "-Wall -funit-at-a-time" } */ +/* { dg-do compile } */ +/* PR objc/27438, make sure that the decl produced by the front-end + does not cause a warning to be produced. */ +/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */ + +@interface NXConstantString +{ + void *isa; + const char * const nxcsptr; + const unsigned int nxcslen; +} +@end +NXConstantString *a = @"NSInconsistentArchiveException"; /* { dg-bogus "defined but not used" } */ + + diff --git a/gcc/testsuite/objc.dg/strings/const-str-12b.m b/gcc/testsuite/objc.dg/strings/const-str-12b.m new file mode 100644 index 00000000000..cad481e15a0 --- /dev/null +++ b/gcc/testsuite/objc.dg/strings/const-str-12b.m @@ -0,0 +1,32 @@ +/* Test if ObjC types play nice in conditional expressions. */ +/* Author: Ziemowit Laski */ + +/* { dg-do compile } */ +/* { dg-options "-fconstant-string-class=Foo" } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */ + +#include "../../objc-obj-c++-shared/Object1.h" +#import "../../objc-obj-c++-shared/next-mapping.h" + +@interface Foo: Object { + char *cString; + unsigned int len; +} ++ (id)description; +@end + +@interface Bar: Object ++ (Foo *) getString: (int) which; +@end + +#ifdef NEXT_OBJC_USE_NEW_INTERFACE +struct fudge_objc_class _FooClassReference; +#else +struct objc_class _FooClassReference; +#endif + +@implementation Bar ++ (Foo *) getString: (int) which { + return which? [Foo description]: @"Hello"; +} +@end diff --git a/gcc/testsuite/objc.dg/strings/const-str-2.m b/gcc/testsuite/objc.dg/strings/const-str-2.m new file mode 100644 index 00000000000..49ab0630433 --- /dev/null +++ b/gcc/testsuite/objc.dg/strings/const-str-2.m @@ -0,0 +1,8 @@ +/* Test the -fconstant-string-class flag error. */ +/* { dg-do compile } */ +/* { dg-options "-fconstant-string-class=" { target *-*-* } } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=" { target *-*-darwin* } } */ + +{ dg-error "no class name specified|missing argument" "" { target *-*-* } 0 } + +void foo () {} diff --git a/gcc/testsuite/objc.dg/strings/const-str-5.m b/gcc/testsuite/objc.dg/strings/const-str-5.m new file mode 100644 index 00000000000..42071767adb --- /dev/null +++ b/gcc/testsuite/objc.dg/strings/const-str-5.m @@ -0,0 +1,28 @@ +/* Positive test case for constant string layout. */ +/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ + +/* { dg-do compile } */ +/* { dg-options "-fconstant-string-class=MyConstantString" } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */ + +@interface MyBase { + const char *p; +} +@end + +@interface MyConstantString: MyBase { + union { + void *u; + unsigned char *c; + } _contents; + unsigned int _count; +} +@end + +/* The NeXT runtime initializes the 'isa' pointer of string constants at + compile time. */ +#ifdef __NEXT_RUNTIME__ +extern void *_MyConstantStringClassReference; +#endif + +MyConstantString *str = @"Hello"; diff --git a/gcc/testsuite/objc.dg/strings/const-str-6.m b/gcc/testsuite/objc.dg/strings/const-str-6.m new file mode 100644 index 00000000000..fca7643af37 --- /dev/null +++ b/gcc/testsuite/objc.dg/strings/const-str-6.m @@ -0,0 +1,28 @@ +/* Negative test case for constant string layout. */ +/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ + +/* { dg-do compile } */ +/* { dg-options "-fconstant-string-class=MyConstantString" } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */ + +@interface MyBase { + char p; +} +@end + +@interface MyConstantString: MyBase { + union { + void *u; + unsigned char *c; + } _contents; + char _count; +} +@end + +/* The NeXT runtime initializes the 'isa' pointer of string constants at + compile time. */ +#ifdef __NEXT_RUNTIME__ +extern void *_MyConstantStringClassReference; +#endif + +MyConstantString *str = @"Hello"; /* { dg-error "interface .MyConstantString. does not have valid constant string layout" } */ diff --git a/gcc/testsuite/objc.dg/strings/strings.exp b/gcc/testsuite/objc.dg/strings/strings.exp new file mode 100644 index 00000000000..823c2871a57 --- /dev/null +++ b/gcc/testsuite/objc.dg/strings/strings.exp @@ -0,0 +1,46 @@ +# String tests that only need to run at default optimization. + +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# Load support procs. + +load_lib objc-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_CFLAGS +if ![info exists DEFAULT_CFLAGS] then { + set DEFAULT_CFLAGS "" +} + +# Initialize `dg'. +dg-init + +# Gather a list of all tests. +set tests [lsort [glob -nocomplain $srcdir/$subdir/*.m]] + +# Main loop. +dg-runtest $tests "-fgnu-runtime" $DEFAULT_CFLAGS + +# darwin targets can also run code with the NeXT runtime. +if [istarget "*-*-darwin*" ] { + dg-runtest $tests "-fnext-runtime" $DEFAULT_CFLAGS +} + +# All done. +dg-finish |