diff options
| author | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-11-27 05:00:06 +0000 |
|---|---|---|
| committer | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-11-27 05:00:06 +0000 |
| commit | ed09096dfbcb5f8b6958f7b75183566e83ba095d (patch) | |
| tree | 415bfe1eb788d734afb9ccfea25ebbb397482eff /gcc/testsuite/gcc.c-torture/execute/string-opt-8.c | |
| parent | f9e78c9f5a4a049340bf7c9e6856cdf1275aaeee (diff) | |
| download | ppe42-gcc-ed09096dfbcb5f8b6958f7b75183566e83ba095d.tar.gz ppe42-gcc-ed09096dfbcb5f8b6958f7b75183566e83ba095d.zip | |
* builtins.c (expand_builtin_strncmp, expand_builtin_strncpy): New
functions.
(expand_builtin): Handle BUILT_IN_STRNCPY and BUILT_IN_STRNCMP.
* builtins.def (BUILT_IN_STRNCPY, BUILT_IN_STRNCMP): New entries.
* c-common.c (c_common_nodes_and_builtins): Declare builtin
strncpy and strncmp.
* extend.texi (strncmp, strncpy): Document new builtins.
testsuite:
* gcc.c-torture/execute/string-opt-7.c: New test.
* gcc.c-torture/execute/string-opt-8.c: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@37777 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.c-torture/execute/string-opt-8.c')
| -rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/string-opt-8.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c new file mode 100644 index 00000000000..ca386f0ab37 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c @@ -0,0 +1,60 @@ +/* Copyright (C) 2000 Free Software Foundation. + + Ensure all expected transformations of builtin strncmp occur and + perform correctly. + + Written by Kaveh R. Ghazi, 11/26/2000. */ + +extern void abort (void); +typedef __SIZE_TYPE__ size_t; +extern int strncmp (const char *, const char *, size_t); + +int main () +{ + const char *const s1 = "hello world"; + const char *s2, *s3; + + if (strncmp (s1, "hello world", 12) != 0) + abort(); + if (strncmp ("hello world", s1, 12) != 0) + abort(); + if (strncmp ("hello", "hello", 6) != 0) + abort(); + if (strncmp ("hello", "hello", 2) != 0) + abort(); + if (strncmp ("hello", "hello", 100) != 0) + abort(); + if (strncmp (s1+10, "d", 100) != 0) + abort(); + if (strncmp (10+s1, "d", 100) != 0) + abort(); + if (strncmp ("d", s1+10, 1) != 0) + abort(); + if (strncmp ("d", 10+s1, 1) != 0) + abort(); + if (strncmp ("hello", "aaaaa", 100) <= 0) + abort(); + if (strncmp ("aaaaa", "hello", 100) >= 0) + abort(); + if (strncmp ("hello", "aaaaa", 1) <= 0) + abort(); + if (strncmp ("aaaaa", "hello", 1) >= 0) + abort(); + + s2 = s1; s3 = s1+4; + if (strncmp (++s2, ++s3, 0) != 0 || s2 != s1+1 || s3 != s1+5) + abort(); + + return 0; +} + +#ifdef __OPTIMIZE__ +/* When optimizing, all the above cases should be transformed into + something else. So any remaining calls to the original function + should abort. */ +static char * +strncmp(const char *s1, const char *s2, size_t n) +{ + abort(); +} +#endif |

