* 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
This commit is contained in:
Jakub Jelinek 2009-02-02 12:27:50 +01:00 committed by Jakub Jelinek
parent ab05897240
commit 43014633b0
6 changed files with 157 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2009-02-02 Jakub Jelinek <jakub@redhat.com>
* 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 <rguenther@suse.de>
PR tree-optimization/38937

View File

@ -0,0 +1,56 @@
// { dg-do compile { target correct_iso_cpp_string_wchar_protos } }
// { dg-options "-O2 -fdump-tree-optimized" }
#include <cstring>
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" } }

View File

@ -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 <string.h>
#include <wchar.h>
#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
}]
}

View File

@ -1,3 +1,8 @@
2009-02-02 Jakub Jelinek <jakub@redhat.com>
* 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 <drepper@redhat.com>
Jakub Jelinek <jakub@redhat.com>

View File

@ -0,0 +1,37 @@
// { dg-do compile { target correct_iso_cpp_string_wchar_protos } }
// { dg-options "-O2" }
#include <cstring>
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");
}

View File

@ -0,0 +1,35 @@
// { dg-do compile { target correct_iso_cpp_string_wchar_protos } }
// { dg-options "-O2" }
#include <cwchar>
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");
}