diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2020-05-17 06:52:02 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2020-05-17 06:52:14 -0700 |
commit | cc558e28014f0d85247398c89e7cf75d92df1bd3 (patch) | |
tree | a118dc18e40c36e892c820e9ff756e1ca194ae14 /gcc | |
parent | e7e785dfec360573c2e8a700ef570a22359410c5 (diff) | |
download | gcc-cc558e28014f0d85247398c89e7cf75d92df1bd3.zip gcc-cc558e28014f0d85247398c89e7cf75d92df1bd3.tar.gz gcc-cc558e28014f0d85247398c89e7cf75d92df1bd3.tar.bz2 |
x86: Add gcc.target/i386/strncmp-1.c
Add a strncmp test for the cmpstrn pattern with neither of the strings
is a constant string. We can expand the cmpstrn pattern to "repz cmpsb"
only if one of the strings is a constant so that expand_builtin_strncmp()
can write the length argument to be the minimum of the const string
length and the actual length argument. Otherwise, "repz cmpsb" may pass
the 0 byte.
* gcc.target/i386/strncmp-1.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/strncmp-1.c | 47 |
2 files changed, 51 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9d757c4..fa3d018 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-05-17 H.J. Lu <hongjiu.lu@intel.com> + + * gcc.target/i386/strncmp-1.c: New test. + 2020-05-16 Iain Sandoe <iain@sandoe.co.uk> * g++.dg/coroutines/co-return-syntax-10-movable.C: New test. diff --git a/gcc/testsuite/gcc.target/i386/strncmp-1.c b/gcc/testsuite/gcc.target/i386/strncmp-1.c new file mode 100644 index 0000000..044fc5c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/strncmp-1.c @@ -0,0 +1,47 @@ +/* { dg-do run { target mmap } } */ +/* { dg-options "-O2" } */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/mman.h> + +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif + +int +__attribute__ ((noclone, noinline)) +compare (char *d, char *s, unsigned int l) +{ + return __builtin_strncmp (d, s, l); +} + +int +main () +{ + size_t page_size = sysconf(_SC_PAGESIZE); + char *buf = mmap (0, 2 * page_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (buf == MAP_FAILED) + { + perror ("mmap"); + abort (); + } + + if (mprotect (buf + page_size, page_size, PROT_NONE)) + { + perror ("mprotect"); + abort (); + } + + char *src1 = buf + page_size - sizeof ("foo"); + char *src2 = buf; + memcpy (src1, "foo", sizeof ("foo")); + memcpy (src2, "foo", sizeof ("foo")); + int result = compare (src1, src2, sizeof ("foo") + 16); + if (result != 0) + abort (); + return 0; +} |