modernc.org/ccgo/v3@v3.16.14/lib/testdata/gcc-9.1.0/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2.c (about) 1 /* Copyright (C) 2003 Free Software Foundation. 2 3 Test strlen optimizations on conditional expressions. 4 5 Written by Jakub Jelinek, June 23, 2003. */ 6 7 typedef __SIZE_TYPE__ size_t; 8 extern size_t strlen (const char *); 9 extern char *strcpy (char *, const char *); 10 extern int memcmp (const void *, const void *, size_t); 11 extern void abort (void); 12 extern int inside_main; 13 14 size_t g, h, i, j, k, l; 15 16 size_t 17 foo (void) 18 { 19 if (l) 20 abort (); 21 return ++l; 22 } 23 24 void 25 main_test (void) 26 { 27 if (strlen (i ? "foo" + 1 : j ? "bar" + 1 : "baz" + 1) != 2) 28 abort (); 29 if (strlen (g++ ? "foo" : "bar") != 3 || g != 1) 30 abort (); 31 if (strlen (h++ ? "xfoo" + 1 : "bar") != 3 || h != 1) 32 abort (); 33 if (strlen ((i++, "baz")) != 3 || i != 1) 34 abort (); 35 /* The following calls might not optimize strlen call away. */ 36 inside_main = 0; 37 if (strlen (j ? "foo" + k++ : "bar" + k++) != 3 || k != 1) 38 abort (); 39 if (strlen (foo () ? "foo" : "bar") != 3 || l != 1) 40 abort (); 41 }