Blame SOURCES/gcc44-c++-builtin-redecl.patch

f28b6a
2007-10-02  Jakub Jelinek  <jakub@redhat.com>
f28b6a
f28b6a
	* decl.c (duplicate_decls): When redeclaring a builtin function,
f28b6a
	keep the merged decl builtin whenever types match, even if new
f28b6a
	decl defines a function.
f28b6a
f28b6a
	* gcc.dg/builtins-65.c: New test.
f28b6a
	* g++.dg/ext/builtin10.C: New test.
f28b6a
f28b6a
--- gcc/cp/decl.c.jj	2007-10-01 22:11:09.000000000 +0200
f28b6a
+++ gcc/cp/decl.c	2007-10-02 11:39:46.000000000 +0200
f28b6a
@@ -2001,23 +2001,21 @@ duplicate_decls (tree newdecl, tree oldd
f28b6a
 	  DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
f28b6a
 	  DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
f28b6a
 	}
f28b6a
+      /* If redeclaring a builtin function, it stays built in.  */
f28b6a
+      if (types_match && DECL_BUILT_IN (olddecl))
f28b6a
+	{
f28b6a
+	  DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
f28b6a
+	  DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
f28b6a
+	  /* If we're keeping the built-in definition, keep the rtl,
f28b6a
+	     regardless of declaration matches.  */
f28b6a
+	  COPY_DECL_RTL (olddecl, newdecl);
f28b6a
+	}
f28b6a
       if (new_defines_function)
f28b6a
 	/* If defining a function declared with other language
f28b6a
 	   linkage, use the previously declared language linkage.  */
f28b6a
 	SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
f28b6a
       else if (types_match)
f28b6a
 	{
f28b6a
-	  /* If redeclaring a builtin function, and not a definition,
f28b6a
-	     it stays built in.  */
f28b6a
-	  if (DECL_BUILT_IN (olddecl))
f28b6a
-	    {
f28b6a
-	      DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
f28b6a
-	      DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
f28b6a
-	      /* If we're keeping the built-in definition, keep the rtl,
f28b6a
-		 regardless of declaration matches.  */
f28b6a
-	      COPY_DECL_RTL (olddecl, newdecl);
f28b6a
-	    }
f28b6a
-
f28b6a
 	  DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
f28b6a
 	  /* Don't clear out the arguments if we're just redeclaring a
f28b6a
 	     function.  */
f28b6a
--- gcc/testsuite/gcc.dg/builtins-65.c.jj	2007-10-02 11:23:51.000000000 +0200
f28b6a
+++ gcc/testsuite/gcc.dg/builtins-65.c	2007-10-02 11:24:12.000000000 +0200
f28b6a
@@ -0,0 +1,25 @@
f28b6a
+/* { dg-do compile } */
f28b6a
+/* { dg-options "-O2" } */
f28b6a
+
f28b6a
+typedef __SIZE_TYPE__ size_t;
f28b6a
+extern void __chk_fail (void);
f28b6a
+extern int snprintf (char *, size_t, const char *, ...);
f28b6a
+extern inline __attribute__((gnu_inline, always_inline)) int snprintf (char *a, size_t b, const char *fmt, ...)
f28b6a
+{
f28b6a
+  if (__builtin_object_size (a, 0) != -1UL && __builtin_object_size (a, 0) < b)
f28b6a
+    __chk_fail ();
f28b6a
+  return __builtin_snprintf (a, b, fmt, __builtin_va_arg_pack ());
f28b6a
+}
f28b6a
+extern int snprintf (char *, size_t, const char *, ...) __asm ("mysnprintf");
f28b6a
+
f28b6a
+char buf[10];
f28b6a
+
f28b6a
+int
f28b6a
+main (void)
f28b6a
+{
f28b6a
+  snprintf (buf, 10, "%d%d\n", 10, 10);
f28b6a
+  return 0;
f28b6a
+}
f28b6a
+
f28b6a
+/* { dg-final { scan-assembler "mysnprintf" } } */
f28b6a
+/* { dg-final { scan-assembler-not "__chk_fail" } } */
f28b6a
--- gcc/testsuite/g++.dg/ext/builtin10.C.jj	2007-10-02 11:19:45.000000000 +0200
f28b6a
+++ gcc/testsuite/g++.dg/ext/builtin10.C	2007-10-02 11:23:26.000000000 +0200
f28b6a
@@ -0,0 +1,27 @@
f28b6a
+// { dg-do compile }
f28b6a
+// { dg-options "-O2" }
f28b6a
+
f28b6a
+typedef __SIZE_TYPE__ size_t;
f28b6a
+extern "C" {
f28b6a
+extern void __chk_fail (void);
f28b6a
+extern int snprintf (char *, size_t, const char *, ...);
f28b6a
+extern inline __attribute__((gnu_inline, always_inline)) int snprintf (char *a, size_t b, const char *fmt, ...)
f28b6a
+{
f28b6a
+  if (__builtin_object_size (a, 0) != -1UL && __builtin_object_size (a, 0) < b)
f28b6a
+    __chk_fail ();
f28b6a
+  return __builtin_snprintf (a, b, fmt, __builtin_va_arg_pack ());
f28b6a
+}
f28b6a
+extern int snprintf (char *, size_t, const char *, ...) __asm ("mysnprintf");
f28b6a
+}
f28b6a
+
f28b6a
+char buf[10];
f28b6a
+
f28b6a
+int
f28b6a
+main (void)
f28b6a
+{
f28b6a
+  snprintf (buf, 10, "%d%d\n", 10, 10);
f28b6a
+  return 0;
f28b6a
+}
f28b6a
+
f28b6a
+// { dg-final { scan-assembler "mysnprintf" } }
f28b6a
+// { dg-final { scan-assembler-not "__chk_fail" } }