This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to fix K&R VA_* problems
- To: gcc-patches at gcc dot gnu dot org
- Subject: Patch to fix K&R VA_* problems
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Fri, 31 Aug 2001 12:10:23 -0400 (EDT)
The docs for VA_* in ansidecl.h state that the argument list goes out
of scope after VA_CLOSE when in K&R mode. Indeed when bootstrapping
with traditional C, I ran into a couple of problems where the argument
list was used in this way. This patch fixes it.
Tested on solaris2 with "cc -Xs" (traditional C).
Okay to install?
--Kaveh
2001-08-28 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* calls.c (emit_library_call_value): Don't use a fixed
argument after VA_CLOSE, i.e. out of scope in traditional C.
* emit-rtl.c (gen_rtvec): Likewise.
diff -rup orig/egcs-CVS20010828/gcc/calls.c egcs-CVS20010828/gcc/calls.c
--- orig/egcs-CVS20010828/gcc/calls.c Tue Aug 28 07:30:11 2001
+++ egcs-CVS20010828/gcc/calls.c Tue Aug 28 19:29:39 2001
@@ -4227,6 +4227,8 @@ emit_library_call_value VPARAMS((rtx org
enum libcall_type fn_type,
enum machine_mode outmode, int nargs, ...))
{
+ rtx result;
+
VA_OPEN (p, nargs);
VA_FIXEDARG (p, rtx, orgfun);
VA_FIXEDARG (p, rtx, value);
@@ -4234,11 +4236,12 @@ emit_library_call_value VPARAMS((rtx org
VA_FIXEDARG (p, enum machine_mode, outmode);
VA_FIXEDARG (p, int, nargs);
- value = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode, nargs, p);
+ result = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode,
+ nargs, p);
VA_CLOSE (p);
- return value;
+ return result;
}
#if 0
diff -rup orig/egcs-CVS20010828/gcc/emit-rtl.c egcs-CVS20010828/gcc/emit-rtl.c
--- orig/egcs-CVS20010828/gcc/emit-rtl.c Mon Aug 27 07:30:12 2001
+++ egcs-CVS20010828/gcc/emit-rtl.c Tue Aug 28 19:33:10 2001
@@ -517,7 +517,7 @@ gen_rtx VPARAMS ((enum rtx_code code, en
rtvec
gen_rtvec VPARAMS ((int n, ...))
{
- int i;
+ int i, save_n;
rtx *vector;
VA_OPEN (p, n);
@@ -530,9 +530,12 @@ gen_rtvec VPARAMS ((int n, ...))
for (i = 0; i < n; i++)
vector[i] = va_arg (p, rtx);
+
+ /* The definition of VA_* in K&R C causes `n' to go out of scope. */
+ save_n = n;
VA_CLOSE (p);
- return gen_rtvec_v (n, vector);
+ return gen_rtvec_v (save_n, vector);
}
rtvec