keep the merged decl builtin whenever types match, even if new
decl defines a function.
- * gcc.dg/builtins-65.c: New test.
- * g++.dg/ext/builtin10.C: New test.
+ * gcc.dg/builtins-85.c: New test.
+ * g++.dg/ext/builtin30.C: New test.
--- gcc/cp/decl.c.jj 2007-10-01 22:11:09.000000000 +0200
+++ gcc/cp/decl.c 2007-10-02 11:39:46.000000000 +0200
-@@ -2001,23 +2001,21 @@ duplicate_decls (tree newdecl, tree oldd
+@@ -2137,39 +2137,37 @@ duplicate_decls (tree newdecl, tree oldd
DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
}
+ /* If we're keeping the built-in definition, keep the rtl,
+ regardless of declaration matches. */
+ COPY_DECL_RTL (olddecl, newdecl);
++ if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
++ {
++ enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
++ switch (fncode)
++ {
++ /* If a compatible prototype of these builtin functions
++ is seen, assume the runtime implements it with the
++ expected semantics. */
++ case BUILT_IN_STPCPY:
++ if (builtin_decl_explicit_p (fncode))
++ set_builtin_decl_implicit_p (fncode, true);
++ break;
++ default:
++ break;
++ }
++ }
+ }
if (new_defines_function)
/* If defining a function declared with other language
- /* If we're keeping the built-in definition, keep the rtl,
- regardless of declaration matches. */
- COPY_DECL_RTL (olddecl, newdecl);
+- if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
+- {
+- enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
+- switch (fncode)
+- {
+- /* If a compatible prototype of these builtin functions
+- is seen, assume the runtime implements it with the
+- expected semantics. */
+- case BUILT_IN_STPCPY:
+- if (builtin_decl_explicit_p (fncode))
+- set_builtin_decl_implicit_p (fncode, true);
+- break;
+- default:
+- break;
+- }
+- }
- }
-
DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
/* Don't clear out the arguments if we're just redeclaring a
function. */
---- gcc/testsuite/gcc.dg/builtins-65.c.jj 2007-10-02 11:23:51.000000000 +0200
-+++ gcc/testsuite/gcc.dg/builtins-65.c 2007-10-02 11:24:12.000000000 +0200
+--- gcc/testsuite/gcc.dg/builtins-85.c.jj 2007-10-02 11:23:51.000000000 +0200
++++ gcc/testsuite/gcc.dg/builtins-85.c 2007-10-02 11:24:12.000000000 +0200
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+/* { dg-final { scan-assembler "mysnprintf" } } */
+/* { dg-final { scan-assembler-not "__chk_fail" } } */
---- gcc/testsuite/g++.dg/ext/builtin10.C.jj 2007-10-02 11:19:45.000000000 +0200
-+++ gcc/testsuite/g++.dg/ext/builtin10.C 2007-10-02 11:23:26.000000000 +0200
+--- gcc/testsuite/g++.dg/ext/builtin30.C.jj 2007-10-02 11:19:45.000000000 +0200
++++ gcc/testsuite/g++.dg/ext/builtin30.C 2007-10-02 11:23:26.000000000 +0200
@@ -0,0 +1,27 @@
+// { dg-do compile }
+// { dg-options "-O2" }