]> git.ipfire.org Git - ipfire-2.x.git/blob - src/patches/gcc/gcc44-c++-builtin-redecl.patch
glibc: Fix headers to build with new GCC
[ipfire-2.x.git] / src / patches / gcc / gcc44-c++-builtin-redecl.patch
1 2007-10-02 Jakub Jelinek <jakub@redhat.com>
2
3 * decl.c (duplicate_decls): When redeclaring a builtin function,
4 keep the merged decl builtin whenever types match, even if new
5 decl defines a function.
6
7 * gcc.dg/builtins-65.c: New test.
8 * g++.dg/ext/builtin10.C: New test.
9
10 --- gcc/cp/decl.c.jj 2007-10-01 22:11:09.000000000 +0200
11 +++ gcc/cp/decl.c 2007-10-02 11:39:46.000000000 +0200
12 @@ -2001,23 +2001,21 @@ duplicate_decls (tree newdecl, tree oldd
13 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
14 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
15 }
16 + /* If redeclaring a builtin function, it stays built in. */
17 + if (types_match && DECL_BUILT_IN (olddecl))
18 + {
19 + DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
20 + DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
21 + /* If we're keeping the built-in definition, keep the rtl,
22 + regardless of declaration matches. */
23 + COPY_DECL_RTL (olddecl, newdecl);
24 + }
25 if (new_defines_function)
26 /* If defining a function declared with other language
27 linkage, use the previously declared language linkage. */
28 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
29 else if (types_match)
30 {
31 - /* If redeclaring a builtin function, and not a definition,
32 - it stays built in. */
33 - if (DECL_BUILT_IN (olddecl))
34 - {
35 - DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
36 - DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
37 - /* If we're keeping the built-in definition, keep the rtl,
38 - regardless of declaration matches. */
39 - COPY_DECL_RTL (olddecl, newdecl);
40 - }
41 -
42 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
43 /* Don't clear out the arguments if we're just redeclaring a
44 function. */
45 --- gcc/testsuite/gcc.dg/builtins-65.c.jj 2007-10-02 11:23:51.000000000 +0200
46 +++ gcc/testsuite/gcc.dg/builtins-65.c 2007-10-02 11:24:12.000000000 +0200
47 @@ -0,0 +1,25 @@
48 +/* { dg-do compile } */
49 +/* { dg-options "-O2" } */
50 +
51 +typedef __SIZE_TYPE__ size_t;
52 +extern void __chk_fail (void);
53 +extern int snprintf (char *, size_t, const char *, ...);
54 +extern inline __attribute__((gnu_inline, always_inline)) int snprintf (char *a, size_t b, const char *fmt, ...)
55 +{
56 + if (__builtin_object_size (a, 0) != -1UL && __builtin_object_size (a, 0) < b)
57 + __chk_fail ();
58 + return __builtin_snprintf (a, b, fmt, __builtin_va_arg_pack ());
59 +}
60 +extern int snprintf (char *, size_t, const char *, ...) __asm ("mysnprintf");
61 +
62 +char buf[10];
63 +
64 +int
65 +main (void)
66 +{
67 + snprintf (buf, 10, "%d%d\n", 10, 10);
68 + return 0;
69 +}
70 +
71 +/* { dg-final { scan-assembler "mysnprintf" } } */
72 +/* { dg-final { scan-assembler-not "__chk_fail" } } */
73 --- gcc/testsuite/g++.dg/ext/builtin10.C.jj 2007-10-02 11:19:45.000000000 +0200
74 +++ gcc/testsuite/g++.dg/ext/builtin10.C 2007-10-02 11:23:26.000000000 +0200
75 @@ -0,0 +1,27 @@
76 +// { dg-do compile }
77 +// { dg-options "-O2" }
78 +
79 +typedef __SIZE_TYPE__ size_t;
80 +extern "C" {
81 +extern void __chk_fail (void);
82 +extern int snprintf (char *, size_t, const char *, ...);
83 +extern inline __attribute__((gnu_inline, always_inline)) int snprintf (char *a, size_t b, const char *fmt, ...)
84 +{
85 + if (__builtin_object_size (a, 0) != -1UL && __builtin_object_size (a, 0) < b)
86 + __chk_fail ();
87 + return __builtin_snprintf (a, b, fmt, __builtin_va_arg_pack ());
88 +}
89 +extern int snprintf (char *, size_t, const char *, ...) __asm ("mysnprintf");
90 +}
91 +
92 +char buf[10];
93 +
94 +int
95 +main (void)
96 +{
97 + snprintf (buf, 10, "%d%d\n", 10, 10);
98 + return 0;
99 +}
100 +
101 +// { dg-final { scan-assembler "mysnprintf" } }
102 +// { dg-final { scan-assembler-not "__chk_fail" } }