mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-16 16:50:21 +02:00
Give GCC more control flow information, so it can be sure that
variables aren't used uninitialized. * error.h (scm_error, scm_syserror, scm_syserror_msg, scm_sysmissing, scm_num_overflow, scm_out_of_range, scm_wrong_num_args, scm_wrong_type_arg, scm_memory_error, scm_misc_error): Tell GCC that these functions never return. * struct.c (scm_struct_ref, scm_struct_set_x): If we can't figure out the field type, call abort if SCM_ASSERT returns, to placate the optimizer. * stacks.c (scm_make_stack, scm_last_stack_frame): abort if scm_wta ever returns. We can't handle this case anyway, and this gives the optimizer more information. * unif.c (scm_uniform_vector_ref, scm_array_set_x): Abort if scm_wta ever returns. In some cases, the code is fine, but GCC isn't smart enough to figure that out; this usually happens when one variable is only initialized and used when a particular condition holds true, and we know that condition will never change within a given invocation of the function. In this case, we simply initialize the variables to placate the compiler, hopefully to a value which will cause a crash if it is ever actually used. * print.c (scm_iprin1): Initialize mw_pos. * read.c (scm_lreadrecparen): Initialize tl2, ans2. * throw.c (scm_ithrow): Initialize dynpair. * unif.c (scm_uniform_vector_ref): Initialize cra. * struct.c (init_struct): Initialize prot. * mbstrings.c (scm_print_mb_symbol): Initialize mw_pos and inc.
This commit is contained in:
parent
407775cb81
commit
35de7ebe4a
2 changed files with 25 additions and 16 deletions
|
@ -142,7 +142,7 @@ init_struct (handle, tail_elts, inits)
|
||||||
SCM layout;
|
SCM layout;
|
||||||
SCM * data;
|
SCM * data;
|
||||||
unsigned char * fields_desc;
|
unsigned char * fields_desc;
|
||||||
unsigned char prot;
|
unsigned char prot = 0;
|
||||||
int n_fields;
|
int n_fields;
|
||||||
SCM * mem;
|
SCM * mem;
|
||||||
int tailp = 0;
|
int tailp = 0;
|
||||||
|
@ -456,6 +456,7 @@ scm_struct_ref (handle, pos)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SCM_ASSERT (0, pos, "ref denied", s_struct_ref);
|
SCM_ASSERT (0, pos, "ref denied", s_struct_ref);
|
||||||
|
abort ();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (field_type)
|
switch (field_type)
|
||||||
|
@ -532,6 +533,7 @@ scm_struct_set_x (handle, pos, val)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SCM_ASSERT (0, pos, "set_x denied", s_struct_ref);
|
SCM_ASSERT (0, pos, "set_x denied", s_struct_ref);
|
||||||
|
abort ();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (field_type)
|
switch (field_type)
|
||||||
|
|
|
@ -469,7 +469,6 @@ scm_aind (ra, args, what)
|
||||||
register scm_sizet k = SCM_ARRAY_NDIM (ra);
|
register scm_sizet k = SCM_ARRAY_NDIM (ra);
|
||||||
scm_array_dim *s = SCM_ARRAY_DIMS (ra);
|
scm_array_dim *s = SCM_ARRAY_DIMS (ra);
|
||||||
if (SCM_INUMP (args))
|
if (SCM_INUMP (args))
|
||||||
|
|
||||||
{
|
{
|
||||||
SCM_ASSERT (1 == k, scm_makfrom0str (what), SCM_WNA, NULL);
|
SCM_ASSERT (1 == k, scm_makfrom0str (what), SCM_WNA, NULL);
|
||||||
return pos + (SCM_INUM (args) - s->lbnd) * (s->inc);
|
return pos + (SCM_INUM (args) - s->lbnd) * (s->inc);
|
||||||
|
@ -1041,14 +1040,13 @@ scm_uniform_vector_ref (v, args)
|
||||||
SCM args;
|
SCM args;
|
||||||
{
|
{
|
||||||
long pos;
|
long pos;
|
||||||
if (SCM_IMP (v))
|
|
||||||
|
|
||||||
|
if (SCM_IMP (v))
|
||||||
{
|
{
|
||||||
SCM_ASRTGO (SCM_NULLP (args), badarg);
|
SCM_ASRTGO (SCM_NULLP (args), badarg);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
else if (SCM_ARRAYP (v))
|
else if (SCM_ARRAYP (v))
|
||||||
|
|
||||||
{
|
{
|
||||||
pos = scm_aind (v, args, s_uniform_vector_ref);
|
pos = scm_aind (v, args, s_uniform_vector_ref);
|
||||||
v = SCM_ARRAY_V (v);
|
v = SCM_ARRAY_V (v);
|
||||||
|
@ -1075,7 +1073,9 @@ scm_uniform_vector_ref (v, args)
|
||||||
default:
|
default:
|
||||||
if (SCM_NULLP (args))
|
if (SCM_NULLP (args))
|
||||||
return v;
|
return v;
|
||||||
badarg:scm_wta (v, (char *) SCM_ARG1, s_uniform_vector_ref);
|
badarg:
|
||||||
|
scm_wta (v, (char *) SCM_ARG1, s_uniform_vector_ref);
|
||||||
|
abort ();
|
||||||
outrng:scm_out_of_range (s_uniform_vector_ref, SCM_MAKINUM (pos));
|
outrng:scm_out_of_range (s_uniform_vector_ref, SCM_MAKINUM (pos));
|
||||||
wna: scm_wrong_num_args (scm_makfrom0str (s_uniform_vector_ref));
|
wna: scm_wrong_num_args (scm_makfrom0str (s_uniform_vector_ref));
|
||||||
case scm_tc7_smob:
|
case scm_tc7_smob:
|
||||||
|
@ -1236,7 +1236,6 @@ scm_array_set_x (v, obj, args)
|
||||||
long pos;
|
long pos;
|
||||||
SCM_ASRTGO (SCM_NIMP (v), badarg1);
|
SCM_ASRTGO (SCM_NIMP (v), badarg1);
|
||||||
if (SCM_ARRAYP (v))
|
if (SCM_ARRAYP (v))
|
||||||
|
|
||||||
{
|
{
|
||||||
pos = scm_aind (v, args, s_array_set_x);
|
pos = scm_aind (v, args, s_array_set_x);
|
||||||
v = SCM_ARRAY_V (v);
|
v = SCM_ARRAY_V (v);
|
||||||
|
@ -1244,7 +1243,6 @@ scm_array_set_x (v, obj, args)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (SCM_NIMP (args))
|
if (SCM_NIMP (args))
|
||||||
|
|
||||||
{
|
{
|
||||||
SCM_ASSERT (SCM_CONSP (args) && SCM_INUMP (SCM_CAR (args)), args, SCM_ARG2, s_array_set_x);
|
SCM_ASSERT (SCM_CONSP (args) && SCM_INUMP (SCM_CAR (args)), args, SCM_ARG2, s_array_set_x);
|
||||||
pos = SCM_INUM (SCM_CAR (args));
|
pos = SCM_INUM (SCM_CAR (args));
|
||||||
|
@ -1259,8 +1257,9 @@ scm_array_set_x (v, obj, args)
|
||||||
}
|
}
|
||||||
switch (SCM_TYP7 (v))
|
switch (SCM_TYP7 (v))
|
||||||
{
|
{
|
||||||
default:
|
default: badarg1:
|
||||||
badarg1:scm_wta (v, (char *) SCM_ARG1, s_array_set_x);
|
scm_wta (v, (char *) SCM_ARG1, s_array_set_x);
|
||||||
|
abort ();
|
||||||
outrng:scm_out_of_range (s_array_set_x, SCM_MAKINUM (pos));
|
outrng:scm_out_of_range (s_array_set_x, SCM_MAKINUM (pos));
|
||||||
wna: scm_wrong_num_args (scm_makfrom0str (s_array_set_x));
|
wna: scm_wrong_num_args (scm_makfrom0str (s_array_set_x));
|
||||||
case scm_tc7_smob: /* enclosed */
|
case scm_tc7_smob: /* enclosed */
|
||||||
|
@ -1439,18 +1438,20 @@ scm_uniform_array_read_x (ra, port)
|
||||||
SCM ra;
|
SCM ra;
|
||||||
SCM port;
|
SCM port;
|
||||||
{
|
{
|
||||||
SCM cra, v = ra;
|
SCM cra = SCM_UNDEFINED, v = ra;
|
||||||
long sz, len, ans;
|
long sz, len, ans;
|
||||||
long start = 0;
|
long start = 0;
|
||||||
|
|
||||||
if (SCM_UNBNDP (port))
|
if (SCM_UNBNDP (port))
|
||||||
port = scm_cur_inp;
|
port = scm_cur_inp;
|
||||||
else
|
else
|
||||||
SCM_ASSERT (SCM_NIMP (port) && SCM_OPINFPORTP (port), port, SCM_ARG2, s_uniform_array_read_x);
|
SCM_ASSERT (SCM_NIMP (port) && SCM_OPINFPORTP (port), port, SCM_ARG2,
|
||||||
|
s_uniform_array_read_x);
|
||||||
SCM_ASRTGO (SCM_NIMP (v), badarg1);
|
SCM_ASRTGO (SCM_NIMP (v), badarg1);
|
||||||
|
|
||||||
len = SCM_LENGTH (v);
|
len = SCM_LENGTH (v);
|
||||||
loop:
|
loop:
|
||||||
switch SCM_TYP7
|
switch SCM_TYP7 (v)
|
||||||
(v)
|
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
badarg1:scm_wta (v, (char *) SCM_ARG1, s_uniform_array_read_x);
|
badarg1:scm_wta (v, (char *) SCM_ARG1, s_uniform_array_read_x);
|
||||||
|
@ -1495,19 +1496,25 @@ loop:
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An ungetc before an fread will not work on some systems if setbuf(0).
|
/* An ungetc before an fread will not work on some systems if setbuf(0).
|
||||||
do #define NOSETBUF in scmfig.h to fix this. */
|
do #define NOSETBUF in scmfig.h to fix this. */
|
||||||
if (SCM_CRDYP (port))
|
if (SCM_CRDYP (port))
|
||||||
|
|
||||||
{ /* UGGH!!! */
|
{ /* UGGH!!! */
|
||||||
ungetc (SCM_CGETUN (port), (FILE *)SCM_STREAM (port));
|
ungetc (SCM_CGETUN (port), (FILE *)SCM_STREAM (port));
|
||||||
SCM_CLRDY (port); /* Clear ungetted char */
|
SCM_CLRDY (port); /* Clear ungetted char */
|
||||||
}
|
}
|
||||||
SCM_SYSCALL (ans = fread (SCM_CHARS (v) + start * sz, (scm_sizet) sz, (scm_sizet) len, (FILE *)SCM_STREAM (port)));
|
|
||||||
|
SCM_SYSCALL (ans = fread (SCM_CHARS (v) + start * sz,
|
||||||
|
(scm_sizet) sz, (scm_sizet) len,
|
||||||
|
(FILE *)SCM_STREAM (port)));
|
||||||
|
|
||||||
if (SCM_TYP7 (v) == scm_tc7_bvect)
|
if (SCM_TYP7 (v) == scm_tc7_bvect)
|
||||||
ans *= SCM_LONG_BIT;
|
ans *= SCM_LONG_BIT;
|
||||||
|
|
||||||
if (v != ra && cra != ra)
|
if (v != ra && cra != ra)
|
||||||
scm_array_copy_x (cra, ra);
|
scm_array_copy_x (cra, ra);
|
||||||
|
|
||||||
return SCM_MAKINUM (ans);
|
return SCM_MAKINUM (ans);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue