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

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