From: Martin Sebor Date: Fri, 29 Jun 2018 16:37:54 +0000 (+0000) Subject: strlenopt-46.c: Define strnlen for targets like Solaris 10 that don't define the... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0bcf7e67ab5a24029a60ba3dc734c4579dd37e7f;p=gcc.git strlenopt-46.c: Define strnlen for targets like Solaris 10 that don't define the function. gcc/testsuite/ChangeLog: * gcc.dg/strlenopt-46.c: Define strnlen for targets like Solaris 10 that don't define the function. From-SVN: r262255 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cc71d594739..063b271cd93 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-29 Martin Sebor + + * gcc.dg/strlenopt-46.c: Define strnlen for targets like Solaris 10 + that don't define the function. + 2018-06-29 Marek Polacek PR c++/86184 diff --git a/gcc/testsuite/gcc.dg/strlenopt-46.c b/gcc/testsuite/gcc.dg/strlenopt-46.c index dc6eef7ca53..170b901bb70 100644 --- a/gcc/testsuite/gcc.dg/strlenopt-46.c +++ b/gcc/testsuite/gcc.dg/strlenopt-46.c @@ -1,6 +1,6 @@ /* PR tree-optimization/86204 - wrong strlen result after prior strnlen { dg-do run } - { dg-options "-O2 -Wall" } */ + { dg-options "-O2 -Wall -fdump-tree-optimized" } */ #include "strlenopt.h" @@ -129,3 +129,20 @@ int main (void) gx (2); gx (7); } + + +/* For targets like Solaris 10 that don't define strnlen(). */ + +NOIPA size_t +strnlen (const char *s, size_t n) +{ + size_t len = 0; + while (*s++ && n--) + ++len; + return len; +} + +/* Verify that at least some of the 11 calls to strnlen have been + folded (this number of folded calls may need to be adjusted up + if the strnlen optimization improves, but it should not go down. + { dg-final { scan-tree-dump-times "= strnlen" 7 "optimized" } } */