]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blame - gcc/patches/gcc47-c++-builtin-redecl.patch0
Merge branch 'master' of ssh://git.ipfire.org/pub/git/ipfire-3.x
[people/ms/ipfire-3.x.git] / gcc / patches / gcc47-c++-builtin-redecl.patch0
CommitLineData
3c926509
MT
12007-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
4de56d3e
MT
7 * gcc.dg/builtins-85.c: New test.
8 * g++.dg/ext/builtin30.C: New test.
3c926509
MT
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
4de56d3e 12@@ -2137,39 +2137,37 @@ duplicate_decls (tree newdecl, tree oldd
3c926509
MT
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);
4de56d3e
MT
24+ if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
25+ {
26+ enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
27+ switch (fncode)
28+ {
29+ /* If a compatible prototype of these builtin functions
30+ is seen, assume the runtime implements it with the
31+ expected semantics. */
32+ case BUILT_IN_STPCPY:
33+ if (builtin_decl_explicit_p (fncode))
34+ set_builtin_decl_implicit_p (fncode, true);
35+ break;
36+ default:
37+ break;
38+ }
39+ }
3c926509
MT
40+ }
41 if (new_defines_function)
42 /* If defining a function declared with other language
43 linkage, use the previously declared language linkage. */
44 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
45 else if (types_match)
46 {
47- /* If redeclaring a builtin function, and not a definition,
48- it stays built in. */
49- if (DECL_BUILT_IN (olddecl))
50- {
51- DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
52- DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
53- /* If we're keeping the built-in definition, keep the rtl,
54- regardless of declaration matches. */
55- COPY_DECL_RTL (olddecl, newdecl);
4de56d3e
MT
56- if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
57- {
58- enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
59- switch (fncode)
60- {
61- /* If a compatible prototype of these builtin functions
62- is seen, assume the runtime implements it with the
63- expected semantics. */
64- case BUILT_IN_STPCPY:
65- if (builtin_decl_explicit_p (fncode))
66- set_builtin_decl_implicit_p (fncode, true);
67- break;
68- default:
69- break;
70- }
71- }
3c926509
MT
72- }
73-
74 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
75 /* Don't clear out the arguments if we're just redeclaring a
76 function. */
4de56d3e
MT
77--- gcc/testsuite/gcc.dg/builtins-85.c.jj 2007-10-02 11:23:51.000000000 +0200
78+++ gcc/testsuite/gcc.dg/builtins-85.c 2007-10-02 11:24:12.000000000 +0200
3c926509
MT
79@@ -0,0 +1,25 @@
80+/* { dg-do compile } */
81+/* { dg-options "-O2" } */
82+
83+typedef __SIZE_TYPE__ size_t;
84+extern void __chk_fail (void);
85+extern int snprintf (char *, size_t, const char *, ...);
86+extern inline __attribute__((gnu_inline, always_inline)) int snprintf (char *a, size_t b, const char *fmt, ...)
87+{
88+ if (__builtin_object_size (a, 0) != -1UL && __builtin_object_size (a, 0) < b)
89+ __chk_fail ();
90+ return __builtin_snprintf (a, b, fmt, __builtin_va_arg_pack ());
91+}
92+extern int snprintf (char *, size_t, const char *, ...) __asm ("mysnprintf");
93+
94+char buf[10];
95+
96+int
97+main (void)
98+{
99+ snprintf (buf, 10, "%d%d\n", 10, 10);
100+ return 0;
101+}
102+
103+/* { dg-final { scan-assembler "mysnprintf" } } */
104+/* { dg-final { scan-assembler-not "__chk_fail" } } */
4de56d3e
MT
105--- gcc/testsuite/g++.dg/ext/builtin30.C.jj 2007-10-02 11:19:45.000000000 +0200
106+++ gcc/testsuite/g++.dg/ext/builtin30.C 2007-10-02 11:23:26.000000000 +0200
3c926509
MT
107@@ -0,0 +1,27 @@
108+// { dg-do compile }
109+// { dg-options "-O2" }
110+
111+typedef __SIZE_TYPE__ size_t;
112+extern "C" {
113+extern void __chk_fail (void);
114+extern int snprintf (char *, size_t, const char *, ...);
115+extern inline __attribute__((gnu_inline, always_inline)) int snprintf (char *a, size_t b, const char *fmt, ...)
116+{
117+ if (__builtin_object_size (a, 0) != -1UL && __builtin_object_size (a, 0) < b)
118+ __chk_fail ();
119+ return __builtin_snprintf (a, b, fmt, __builtin_va_arg_pack ());
120+}
121+extern int snprintf (char *, size_t, const char *, ...) __asm ("mysnprintf");
122+}
123+
124+char buf[10];
125+
126+int
127+main (void)
128+{
129+ snprintf (buf, 10, "%d%d\n", 10, 10);
130+ return 0;
131+}
132+
133+// { dg-final { scan-assembler "mysnprintf" } }
134+// { dg-final { scan-assembler-not "__chk_fail" } }