@@ -1156,6 +1156,16 @@ decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
tree r2 = fndecl_declared_return_type (olddecl);
tree r1 = fndecl_declared_return_type (newdecl);
+ /* For memchr et al, allow const void* return type (as specified by C++)
+ when we expect void* (as in C). */
+ if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
+ && DECL_EXTERN_C_P (olddecl)
+ && !same_type_p (r1, r2)
+ && TREE_CODE (r1) == POINTER_TYPE
+ && TREE_CODE (r2) == POINTER_TYPE
+ && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
+ r2 = r1;
+
tree p1 = TYPE_ARG_TYPES (f1);
tree p2 = TYPE_ARG_TYPES (f2);
@@ -27,5 +27,4 @@ main ()
return 0;
}
-/* See PR c++/113706 for the xfail. */
-/* { dg-final { scan-assembler-not "memchr" { xfail { c++ && { *-*-solaris2* *-*-vxworks* } } } } } */
+/* { dg-final { scan-assembler-not "memchr" } } */
new file mode 100644
@@ -0,0 +1,33 @@
+// PR c++/113706
+/* A variant of the pr103798-2.c test with const void * memchr return type, as
+ specified by the C++ standard. */
+/* { dg-do run } */
+/* { dg-options "-O2 -fdump-tree-optimized -save-temps" } */
+
+extern "C" const void *memchr (const void *, int, __SIZE_TYPE__); // { dg-bogus "built-in" }
+
+__attribute__ ((weak))
+int
+f (int a)
+{
+ return memchr ("aE", a, 2) != 0;
+}
+
+__attribute__ ((weak))
+int
+g (char a)
+{
+ return a == 'a' || a == 'E';
+}
+
+int
+main ()
+{
+ for (int i = 0; i < 255; i++)
+ if (f (i + 256) != g (i + 256))
+ __builtin_abort ();
+
+ return 0;
+}
+
+/* { dg-final { scan-assembler-not "memchr" } } */