[backport from gcc-4.7.2 r190987 ] gcc/ 2012-09-05 Jakub Jelinek PR middle-end/54486 * builtins.c (fold_builtin_strspn, fold_builtin_strcspn): Use build_int_cst with size_type_node instead of size_int. gcc/testsuite/ 2012-09-05 Jakub Jelinek PR middle-end/54486 * c-c++-common/pr54486.c: New test. --- gcc-4.6.3/gcc/builtins.c.~1~ 2011-10-06 21:57:52.000000000 +0200 +++ gcc-4.6.3/gcc/builtins.c 2012-09-08 20:55:05.000000000 +0200 @@ -11575,7 +11575,7 @@ fold_builtin_strspn (location_t loc, tre if (p1 && p2) { const size_t r = strspn (p1, p2); - return size_int (r); + return build_int_cst (size_type_node, r); } /* If either argument is "", return NULL_TREE. */ @@ -11620,7 +11620,7 @@ fold_builtin_strcspn (location_t loc, tr if (p1 && p2) { const size_t r = strcspn (p1, p2); - return size_int (r); + return build_int_cst (size_type_node, r); } /* If the first argument is "", return NULL_TREE. */ --- gcc-4.6.3/gcc/testsuite/c-c++-common/pr54486.c.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.6.3/gcc/testsuite/c-c++-common/pr54486.c 2012-09-08 20:55:05.000000000 +0200 @@ -0,0 +1,32 @@ +/* PR middle-end/54486 */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#ifdef __cplusplus +extern "C" { +#endif +typedef __SIZE_TYPE__ size_t; +extern int printf (const char *, ...); +extern size_t strspn (const char *, const char *); +extern size_t strcspn (const char *, const char *); +extern size_t strlen (const char *); +#ifdef __cplusplus +} +#endif + +void +foo (void) +{ + printf ("%zu\n", strspn ("abc", "abcdefg")); + printf ("%zu\n", (size_t) strspn ("abc", "abcdefg")); + printf ("%zu\n", __builtin_strspn ("abc", "abcdefg")); + printf ("%zu\n", (size_t) __builtin_strspn ("abc", "abcdefg")); + printf ("%zu\n", strcspn ("abc", "abcdefg")); + printf ("%zu\n", (size_t) strcspn ("abc", "abcdefg")); + printf ("%zu\n", __builtin_strcspn ("abc", "abcdefg")); + printf ("%zu\n", (size_t) __builtin_strcspn ("abc", "abcdefg")); + printf ("%zu\n", strlen ("abc")); + printf ("%zu\n", (size_t) strlen ("abc")); + printf ("%zu\n", __builtin_strlen ("abc")); + printf ("%zu\n", (size_t) __builtin_strlen ("abc")); +}