Hi!
fold_builtin_str*spn in this case returns sizetype typed constant instead of
size_t, which makes -Wformat warn. Fixed thusly, bootstrapped/regtested on
x86_64-linux and i686-linux, ok for trunk/4.7?
2012-09-05 Jakub Jelinek ja...@redhat.com
PR middle-end/54486
* builtins.c (fold_builtin_strspn, fold_builtin_strcspn): Use
build_int_cst with size_type_node instead of size_int.
* c-c++-common/pr54486.c: New test.
--- gcc/builtins.c.jj 2012-08-10 12:57:21.0 +0200
+++ gcc/builtins.c 2012-09-05 09:00:50.640530273 +0200
@@ -11890,7 +11890,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. */
@@ -11935,7 +11935,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/testsuite/c-c++-common/pr54486.c.jj 2012-09-05 09:14:13.017748249
+0200
+++ gcc/testsuite/c-c++-common/pr54486.c2012-09-05 09:13:35.0
+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));
+}
Jakub