https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85724
Bug ID: 85724 Summary: strspn of one-element arrays can be assumed to return zero Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- GCC folds strlen() calls with one-element array arguments to zero but it doesn't do that same for calls to strspn and strcspn with the same arguments even though they too must return zero (they return the length of a substring in the first argument). $ cat u.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout u.c extern char a[1]; int f (void) { return __builtin_strlen (a); // folded to 0 } int g (const char *s) { return __builtin_strspn (a, s); // not folded } int h (const char *s) { return __builtin_strcspn (a, s); // not folded } ;; Function f (f, funcdef_no=0, decl_uid=1957, cgraph_uid=0, symbol_order=0) f () { <bb 2> [local count: 1073741825]: return 0; } ;; Function g (g, funcdef_no=1, decl_uid=1960, cgraph_uid=1, symbol_order=1) g (const char * s) { long unsigned int _1; int _4; <bb 2> [local count: 1073741825]: _1 = __builtin_strspn (&a, s_3(D)); _4 = (int) _1; return _4; } ;; Function h (h, funcdef_no=2, decl_uid=1963, cgraph_uid=2, symbol_order=2) h (const char * s) { long unsigned int _1; int _4; <bb 2> [local count: 1073741825]: _1 = __builtin_strcspn (&a, s_3(D)); _4 = (int) _1; return _4; }