1 /* Copyright (C) 2001 Free Software Foundation. 2 3 Ensure all builtin strlen comparisons against zero are optimized 4 and perform correctly. The multiple calls to strcpy are to prevent 5 the potentially "pure" strlen calls from being removed by CSE. 6 7 Written by Roger Sayle, 11/02/2001. */ 8 9 extern void abort (void); 10 typedef __SIZE_TYPE__ size_t; 11 extern size_t strlen (const char *); 12 extern char *strcpy (char *, const char *); 13 14 int main()15main () 16 { 17 char str[8]; 18 char *ptr; 19 20 ptr = str; 21 strcpy (ptr, "nts"); 22 if (strlen (ptr) == 0) 23 abort (); 24 25 strcpy (ptr, "nts"); 26 if (strlen (ptr) < 1) 27 abort (); 28 29 strcpy (ptr, "nts"); 30 if (strlen (ptr) <= 0) 31 abort (); 32 33 strcpy (ptr, "nts"); 34 if (strlen (ptr+3) != 0) 35 abort (); 36 37 strcpy (ptr, "nts"); 38 if (strlen (ptr+3) > 0) 39 abort (); 40 41 strcpy (ptr, "nts"); 42 if (strlen (str+3) >= 1) 43 abort (); 44 45 return 0; 46 } 47 48 #ifdef __OPTIMIZE__ 49 /* When optimizing, all the above cases should be transformed into 50 something else. So any remaining calls to the original function 51 should abort. */ 52 static size_t strlen(const char * s)53strlen (const char *s) 54 { 55 abort (); 56 } 57 #endif 58 59