aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.c-torture/execute/string-opt-5.c
diff options
context:
space:
mode:
authorBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
committerBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
commit1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch)
treec607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/gcc/testsuite/gcc.c-torture/execute/string-opt-5.c
parent283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff)
downloadtoolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/gcc/testsuite/gcc.c-torture/execute/string-opt-5.c')
-rw-r--r--gcc-4.9/gcc/testsuite/gcc.c-torture/execute/string-opt-5.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/gcc.c-torture/execute/string-opt-5.c b/gcc-4.9/gcc/testsuite/gcc.c-torture/execute/string-opt-5.c
new file mode 100644
index 000000000..178812226
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/gcc.c-torture/execute/string-opt-5.c
@@ -0,0 +1,107 @@
+/* Copyright (C) 2000 Free Software Foundation.
+
+ Ensure builtin strlen, strcmp, strchr, strrchr and strncpy
+ perform correctly.
+
+ Written by Jakub Jelinek, 11/7/2000. */
+
+extern void abort (void);
+extern __SIZE_TYPE__ strlen (const char *);
+extern int strcmp (const char *, const char *);
+extern char *strchr (const char *, int);
+extern char *strrchr (const char *, int);
+extern char *strncpy (char *, const char *, __SIZE_TYPE__);
+extern void *memset (void *, int, __SIZE_TYPE__);
+extern int memcmp (const void *, const void *, __SIZE_TYPE__);
+
+int x = 6;
+int y = 1;
+char *bar = "hi world";
+char buf [64];
+
+int main()
+{
+ const char *const foo = "hello world";
+ char dst [64];
+
+ if (strlen (bar) != 8)
+ abort ();
+ if (strlen (bar + (++x & 2)) != 6)
+ abort ();
+ if (x != 7)
+ abort ();
+ if (strlen (foo + (x++, 6)) != 5)
+ abort ();
+ if (x != 8)
+ abort ();
+ if (strlen (foo + (++x & 1)) != 10)
+ abort ();
+ if (x != 9)
+ abort ();
+ if (strcmp (foo + (x -= 6), "lo world"))
+ abort ();
+ if (x != 3)
+ abort ();
+ if (strcmp (foo, bar) >= 0)
+ abort ();
+ if (strcmp (foo, bar + (x++ & 1)) >= 0)
+ abort ();
+ if (x != 4)
+ abort ();
+ if (strchr (foo + (x++ & 7), 'l') != foo + 9)
+ abort ();
+ if (x != 5)
+ abort ();
+ if (strchr (bar, 'o') != bar + 4)
+ abort ();
+ if (strchr (bar, '\0') != bar + 8)
+ abort ();
+ if (strrchr (bar, 'x'))
+ abort ();
+ if (strrchr (bar, 'o') != bar + 4)
+ abort ();
+ if (strcmp (foo + (x++ & 1), "ello world" + (--y & 1)))
+ abort ();
+ if (x != 6 || y != 0)
+ abort ();
+ dst[5] = ' ';
+ dst[6] = '\0';
+ x = 5;
+ y = 1;
+ if (strncpy (dst + 1, foo + (x++ & 3), 4) != dst + 1
+ || x != 6
+ || strcmp (dst + 1, "ello "))
+ abort ();
+ memset (dst, ' ', sizeof dst);
+ if (strncpy (dst + (++x & 1), (y++ & 3) + "foo", 10) != dst + 1
+ || x != 7
+ || y != 2
+ || memcmp (dst, " oo\0\0\0\0\0\0\0\0 ", 12))
+ abort ();
+ memset (dst, ' ', sizeof dst);
+ if (strncpy (dst, "hello", 8) != dst || memcmp (dst, "hello\0\0\0 ", 9))
+ abort ();
+ x = '!';
+ memset (buf, ' ', sizeof buf);
+ if (memset (buf, x++, ++y) != buf
+ || x != '!' + 1
+ || y != 3
+ || memcmp (buf, "!!!", 3))
+ abort ();
+ if (memset (buf + y++, '-', 8) != buf + 3
+ || y != 4
+ || memcmp (buf, "!!!--------", 11))
+ abort ();
+ x = 10;
+ if (memset (buf + ++x, 0, y++) != buf + 11
+ || x != 11
+ || y != 5
+ || memcmp (buf + 8, "---\0\0\0", 7))
+ abort ();
+ if (memset (buf + (x += 4), 0, 6) != buf + 15
+ || x != 15
+ || memcmp (buf + 10, "-\0\0\0\0\0\0\0\0\0", 11))
+ abort ();
+
+ return 0;
+}