From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- .../obj-c++.dg/strings/const-cfstring-2.mm | 27 +++++++++ .../obj-c++.dg/strings/const-cfstring-5.mm | 26 +++++++++ gcc/testsuite/obj-c++.dg/strings/const-str-1.mm | 25 ++++++++ gcc/testsuite/obj-c++.dg/strings/const-str-12.mm | 31 ++++++++++ gcc/testsuite/obj-c++.dg/strings/const-str-2.mm | 8 +++ gcc/testsuite/obj-c++.dg/strings/const-str-5.mm | 28 +++++++++ gcc/testsuite/obj-c++.dg/strings/const-str-6.mm | 28 +++++++++ gcc/testsuite/obj-c++.dg/strings/strings-1.mm | 33 +++++++++++ gcc/testsuite/obj-c++.dg/strings/strings-2.mm | 66 ++++++++++++++++++++++ gcc/testsuite/obj-c++.dg/strings/strings.exp | 45 +++++++++++++++ 10 files changed, 317 insertions(+) create mode 100644 gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm create mode 100644 gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm create mode 100644 gcc/testsuite/obj-c++.dg/strings/const-str-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/strings/const-str-12.mm create mode 100644 gcc/testsuite/obj-c++.dg/strings/const-str-2.mm create mode 100644 gcc/testsuite/obj-c++.dg/strings/const-str-5.mm create mode 100644 gcc/testsuite/obj-c++.dg/strings/const-str-6.mm create mode 100644 gcc/testsuite/obj-c++.dg/strings/strings-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/strings/strings-2.mm create mode 100644 gcc/testsuite/obj-c++.dg/strings/strings.exp (limited to 'gcc/testsuite/obj-c++.dg/strings') diff --git a/gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm b/gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm new file mode 100644 index 000000000..14ae68c6c --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm @@ -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 . */ + +/* 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 +#import + +#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/obj-c++.dg/strings/const-cfstring-5.mm b/gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm new file mode 100644 index 000000000..13cb78957 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm @@ -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 + +@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/obj-c++.dg/strings/const-str-1.mm b/gcc/testsuite/obj-c++.dg/strings/const-str-1.mm new file mode 100644 index 000000000..754c99bf1 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/strings/const-str-1.mm @@ -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/obj-c++.dg/strings/const-str-12.mm b/gcc/testsuite/obj-c++.dg/strings/const-str-12.mm new file mode 100644 index 000000000..921d05565 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/strings/const-str-12.mm @@ -0,0 +1,31 @@ +/* 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" + +@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 +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/obj-c++.dg/strings/const-str-2.mm b/gcc/testsuite/obj-c++.dg/strings/const-str-2.mm new file mode 100644 index 000000000..e9e2fc93d --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/strings/const-str-2.mm @@ -0,0 +1,8 @@ +/* Test the -fconstant-string-class flag error. */ +/* { dg-do compile } */ +/* { dg-options "-fconstant-string-class=" } */ +/* { 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/obj-c++.dg/strings/const-str-5.mm b/gcc/testsuite/obj-c++.dg/strings/const-str-5.mm new file mode 100644 index 000000000..8c12a0c11 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/strings/const-str-5.mm @@ -0,0 +1,28 @@ +/* Positive test case for constant string layout. */ +/* Contributed by Ziemowit Laski . */ + +/* { 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 equiv_u { + 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/obj-c++.dg/strings/const-str-6.mm b/gcc/testsuite/obj-c++.dg/strings/const-str-6.mm new file mode 100644 index 000000000..69954d9f4 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/strings/const-str-6.mm @@ -0,0 +1,28 @@ +/* Negative test case for constant string layout. */ +/* Contributed by Ziemowit Laski . */ + +/* { 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 equiv_u { + 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/obj-c++.dg/strings/strings-1.mm b/gcc/testsuite/obj-c++.dg/strings/strings-1.mm new file mode 100644 index 000000000..fc3f21185 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/strings/strings-1.mm @@ -0,0 +1,33 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do compile } */ + +#include "../../objc-obj-c++-shared/Object1.h" +#include "../../objc-obj-c++-shared/next-mapping.h" +#ifndef __NEXT_RUNTIME__ +#include +#endif + +/* The following are correct. */ +id test_valid1 = @"test"; +id test_valid2 = @"te" @"st"; +id test_valid3 = @"te" @"s" @"t"; +id test_valid4 = @ "t" @ "e" @ "s" @ "t"; + +/* The following are accepted too; you can concat an ObjC string to a + C string, the result being an ObjC string. */ +id test_valid5 = @"te" "st"; +id test_valid6 = @"te" "s" @"t"; +id test_valid7 = @"te" @"s" "t"; + +/* The following are not correct. */ +id test_invalid1 = @@"test"; /* { dg-error "stray .@. in program" } */ +const char *test_invalid2 = "test"@; /* { dg-error "stray .@. in program" } */ +const char *test_invalid3 = "test"@@; /* { dg-error "stray .@. in program" } */ +const char *test_invalid4 = "te" @"st"; /* { dg-error "expected" } */ +id test_invalid5 = @"te" @@"st"; /* { dg-error "repeated .@. before Objective-C string" } */ +id test_invalid6 = @@"te" @"st"; /* { dg-error "stray .@. in program" } */ +id test_invalid7 = @"te" @"s" @@"t"; /* { dg-error "repeated .@. before Objective-C string" } */ +id test_invalid8 = @"te" @@"s" @"t"; /* { dg-error "repeated .@. before Objective-C string" } */ +id test_invalid9 = @"te" @"s" @"t" @; /* { dg-error "stray .@. in program" } */ +id test_invalidA = @"te" @ st; /* { dg-error "stray .@. in program" } */ + /* { dg-error "expected" "" { target *-*-* } 32 } */ diff --git a/gcc/testsuite/obj-c++.dg/strings/strings-2.mm b/gcc/testsuite/obj-c++.dg/strings/strings-2.mm new file mode 100644 index 000000000..403cf7d3b --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/strings/strings-2.mm @@ -0,0 +1,66 @@ +/* Contributed by Nicola Pero , November 2010. */ + +/* { dg-do run } */ +/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ +/* { dg-options "-fconstant-string-class=MyTestString" } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyTestString" { target *-*-darwin* } } */ + +#include "../../objc-obj-c++-shared/objc-test-suite-types.h" + +#include /* For abort() */ + +@interface MyTestString +{ + void *dummy_class_ptr; + char *string; + unsigned int len; +} ++ initialize; +/* All strings should contain the C string 'test'. Call -check to + test that this is true. */ +- (void) check; +@end + +@implementation MyTestString ++ initialize {return self;} +- (void) check +{ + if (len != 4 || string[0] != 't' || string[1] != 'e' + || string[2] != 's' || string[3] != 't' || string[4] != '\0') + abort (); +} +@end + +TNS_STRING_REF_T _MyTestStringClassReference; /* Only used by NeXT. */ + +int main (void) +{ + MyTestString *test_valid1 = @"test"; + MyTestString *test_valid2 = @"te" @"st"; + MyTestString *test_valid3 = @"te" @"s" @"t"; + MyTestString *test_valid4 = @ "t" @ "e" @ "s" @ "t"; + MyTestString *test_valid5 = @ "t" "e" "s" "t"; + MyTestString *test_valid6 = @ "t" "e" "s" @ "t"; + + [test_valid1 check]; + [test_valid2 check]; + [test_valid3 check]; + [test_valid4 check]; + [test_valid5 check]; + [test_valid6 check]; + + return 0; +} + +#ifdef __NEXT_RUNTIME__ +#include +/* The MyTestString metaclass will need to be initialized before we can + send messages to strings. */ + +void testsuite_mytest_string_init (void) __attribute__((constructor)); +void testsuite_mytest_string_init (void) { + memcpy (&_MyTestStringClassReference, + objc_getClass ("MyTestString"), + sizeof (_MyTestStringClassReference)); +} +#endif \ No newline at end of file diff --git a/gcc/testsuite/obj-c++.dg/strings/strings.exp b/gcc/testsuite/obj-c++.dg/strings/strings.exp new file mode 100644 index 000000000..82cd925bb --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/strings/strings.exp @@ -0,0 +1,45 @@ +# 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 +# . + +# Load support procs. +load_lib obj-c++-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_OBJCXXFLAGS +if ![info exists DEFAULT_OBJCXXFLAGS] then { + set DEFAULT_OBJCXXFLAGS " -ansi -pedantic-errors -Wno-long-long" +} + +# Initialize `dg'. +dg-init + +# Gather a list of all tests. +set tests [lsort [glob -nocomplain $srcdir/$subdir/*.mm]] + +# Main loop. +dg-runtest $tests "-fgnu-runtime" $DEFAULT_OBJCXXFLAGS + +# darwin targets can also run code with the NeXT runtime. +if [istarget "*-*-darwin*" ] { + dg-runtest $tests "-fnext-runtime" $DEFAULT_OBJCXXFLAGS +} + +# All done. +dg-finish -- cgit v1.2.3