From 43014633b0b9f0e3d2646b6c4ecd75d3830a18b2 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 2 Feb 2009 12:27:50 +0100 Subject: [PATCH] * lib/target-supports.exp (check_effective_target_correct_iso_cpp_string_wchar_protos): New. * g++.dg/ext/builtin10.C: New test. * testsuite/21_strings/c_strings/char/3.cc: New test. * testsuite/21_strings/c_strings/wchar_t/3.cc: New test. From-SVN: r143865 --- gcc/testsuite/ChangeLog | 6 ++ gcc/testsuite/g++.dg/ext/builtin10.C | 56 +++++++++++++++++++ gcc/testsuite/lib/target-supports.exp | 19 ++++++- libstdc++-v3/ChangeLog | 5 ++ .../testsuite/21_strings/c_strings/char/3.cc | 37 ++++++++++++ .../21_strings/c_strings/wchar_t/3.cc | 35 ++++++++++++ 6 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ext/builtin10.C create mode 100644 libstdc++-v3/testsuite/21_strings/c_strings/char/3.cc create mode 100644 libstdc++-v3/testsuite/21_strings/c_strings/wchar_t/3.cc diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 249f717fd4d..c659971aa4a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2009-02-02 Jakub Jelinek + + * lib/target-supports.exp + (check_effective_target_correct_iso_cpp_string_wchar_protos): New. + * g++.dg/ext/builtin10.C: New test. + 2009-02-02 Richard Guenther PR tree-optimization/38937 diff --git a/gcc/testsuite/g++.dg/ext/builtin10.C b/gcc/testsuite/g++.dg/ext/builtin10.C new file mode 100644 index 00000000000..8742223a493 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin10.C @@ -0,0 +1,56 @@ +// { dg-do compile { target correct_iso_cpp_string_wchar_protos } } +// { dg-options "-O2 -fdump-tree-optimized" } + +#include + +const void *cv1; +const char *cc1, *cc2, *cc3, *cc4; +void *v1; +char *c1, *c2, *c3, *c4; + +void +f1 (void) +{ + cv1 = memchr ("abcba", 'b', 3); + cc1 = strchr ("abcba", 'b'); + cc2 = strrchr ("abcba", 'b'); + cc3 = strpbrk ("dabc", "abc"); + cc4 = strstr ("aaabc", "abc"); +} + +void +f2 (void) +{ + cv1 = std::memchr ("abcba", 'b', 3); + cc1 = std::strchr ("abcba", 'b'); + cc2 = std::strrchr ("abcba", 'b'); + cc3 = std::strpbrk ("dabc", "abc"); + cc4 = std::strstr ("aaabc", "abc"); +} + +void +f3 (void) +{ + v1 = memchr ((char *)"abcba", 'b', 3); + c1 = strchr ((char *)"abcba", 'b'); + c2 = strrchr ((char *)"abcba", 'b'); + c3 = strpbrk ((char *)"dabc", "abc"); + c4 = strstr ((char *)"aaabc", "abc"); +} + +void +f4 (void) +{ + v1 = std::memchr ((char *)"abcba", 'b', 3); + c1 = std::strchr ((char *)"abcba", 'b'); + c2 = std::strrchr ((char *)"abcba", 'b'); + c3 = std::strpbrk ((char *)"dabc", "abc"); + c4 = std::strstr ((char *)"aaabc", "abc"); +} + +// { dg-final { scan-tree-dump-not "memchr" "optimized" } } +// { dg-final { scan-tree-dump-not "strchr" "optimized" } } +// { dg-final { scan-tree-dump-not "strrchr" "optimized" } } +// { dg-final { scan-tree-dump-not "strpbrk" "optimized" } } +// { dg-final { scan-tree-dump-not "strstr" "optimized" } } +// { dg-final { cleanup-tree-dump "optimized" } } diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index aaefa60cbcb..12dc6852255 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -1,4 +1,4 @@ -# Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007, 2008 +# Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009 # Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify @@ -2815,3 +2815,20 @@ proc check_effective_target_hard_dfp {} { void foo (void) { z = x + y; } }] } + +# Return 1 if string.h and wchar.h headers provide C++ requires overloads +# for strchr etc. functions. + +proc check_effective_target_correct_iso_cpp_string_wchar_protos { } { + return [check_no_compiler_messages correct_iso_cpp_string_wchar_protos assembly { + #include + #include + #if !defined(__cplusplus) \ + || !defined(__CORRECT_ISO_CPP_STRING_H_PROTO) \ + || !defined(__CORRECT_ISO_CPP_WCHAR_H_PROTO) + ISO C++ correct string.h and wchar.h protos not supported. + #else + int i; + #endif + }] +} diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0a27ef9eba8..6839f557e32 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2009-02-02 Jakub Jelinek + + * testsuite/21_strings/c_strings/char/3.cc: New test. + * testsuite/21_strings/c_strings/wchar_t/3.cc: New test. + 2009-01-30 Ulrich Drepper Jakub Jelinek diff --git a/libstdc++-v3/testsuite/21_strings/c_strings/char/3.cc b/libstdc++-v3/testsuite/21_strings/c_strings/char/3.cc new file mode 100644 index 00000000000..5e5c514d776 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/c_strings/char/3.cc @@ -0,0 +1,37 @@ +// { dg-do compile { target correct_iso_cpp_string_wchar_protos } } +// { dg-options "-O2" } + +#include + +const char *cc1, *cc2; +char *c1, *c2; +const void *cv1, *cv2; +void *v1, *v2; + +void +test01 () +{ + v1 = std::memchr (v2, '/', 3); + c1 = std::strchr (c2, '/'); + c1 = std::strrchr (c2, 'c'); + c1 = std::strpbrk (c2, "abc"); + c1 = std::strstr (c2, "abc"); + + cv1 = std::memchr (v2, '/', 3); + cc1 = std::strchr (c2, '/'); + cc1 = std::strrchr (c2, 'c'); + cc1 = std::strpbrk (c2, "abc"); + cc1 = std::strstr (c2, "abc"); + + v1 = std::memchr (cv2, '/', 3); // { dg-error "invalid conversion" } + c1 = std::strchr (cc2, '/'); // { dg-error "invalid conversion" } + c1 = std::strrchr (cc2, 'c'); // { dg-error "invalid conversion" } + c1 = std::strpbrk (cc2, "abc"); // { dg-error "invalid conversion" } + c1 = std::strstr (cc2, "abc"); // { dg-error "invalid conversion" } + + cv1 = std::memchr (cv2, '/', 3); + cc1 = std::strchr (cc2, '/'); + cc1 = std::strrchr (cc2, 'c'); + cc1 = std::strpbrk (cc2, "abc"); + cc1 = std::strstr (cc2, "abc"); +} diff --git a/libstdc++-v3/testsuite/21_strings/c_strings/wchar_t/3.cc b/libstdc++-v3/testsuite/21_strings/c_strings/wchar_t/3.cc new file mode 100644 index 00000000000..47c653abbbd --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/c_strings/wchar_t/3.cc @@ -0,0 +1,35 @@ +// { dg-do compile { target correct_iso_cpp_string_wchar_protos } } +// { dg-options "-O2" } + +#include + +const wchar_t *cw1, *cw2; +wchar_t *w1, *w2; + +void +test01 () +{ + w1 = wmemchr (w2, L'/', 3); + w1 = wcschr (w2, L'/'); + w1 = wcspbrk (w2, L"abc"); + w1 = wcsrchr (w2, L'c'); + w1 = wcsstr (w2, L"abc"); + + cw1 = wmemchr (w2, L'/', 3); + cw1 = wcschr (w2, L'/'); + cw1 = wcspbrk (w2, L"abc"); + cw1 = wcsrchr (w2, L'c'); + cw1 = wcsstr (w2, L"abc"); + + w1 = wmemchr (cw2, L'/', 3); // { dg-error "invalid conversion" } + w1 = wcschr (cw2, L'/'); // { dg-error "invalid conversion" } + w1 = wcspbrk (cw2, L"abc"); // { dg-error "invalid conversion" } + w1 = wcsrchr (cw2, L'c'); // { dg-error "invalid conversion" } + w1 = wcsstr (cw2, L"abc"); // { dg-error "invalid conversion" } + + cw1 = wmemchr (cw2, L'/', 3); + cw1 = wcschr (cw2, L'/'); + cw1 = wcspbrk (cw2, L"abc"); + cw1 = wcsrchr (cw2, L'c'); + cw1 = wcsstr (cw2, L"abc"); +}