Fix: previous version did not work with variable # of args

This commit is contained in:
ceriel 1993-01-28 11:45:38 +00:00
parent de58173e36
commit 6f8002f540
4 changed files with 16 additions and 13 deletions

View file

@ -46,7 +46,6 @@
label lab_count = 1; label lab_count = 1;
label datlab_count = 1; label datlab_count = 1;
arith fbytes;
int fp_used; int fp_used;
extern arith NewLocal(); /* util.c */ extern arith NewLocal(); /* util.c */
@ -318,7 +317,8 @@ begin_proc(ds, idf) /* to be called when entering a procedure */
#endif #endif
} }
end_proc() end_proc(fbytes)
arith fbytes;
{ {
/* end_proc() deals with the code to be generated at the end of /* end_proc() deals with the code to be generated at the end of
a function, as there is: a function, as there is:
@ -347,7 +347,7 @@ end_proc()
prc_exit(); prc_exit();
if (return_expr_occurred) { if (return_expr_occurred) {
if (struct_return != 0) { if (struct_return != 0) {
LoadLocal(fbytes, pointer_size); LoadLocal((arith) 0, pointer_size);
C_ret(pointer_size); C_ret(pointer_size);
} }
else else
@ -366,7 +366,6 @@ end_proc()
C_beginpart(pro_id); C_beginpart(pro_id);
C_pro(func_name, nbytes); C_pro(func_name, nbytes);
#endif #endif
if (struct_return) fbytes += pointer_size;
if (fbytes > max_int) { if (fbytes > max_int) {
error("%s has more than %ld parameter bytes", error("%s has more than %ld parameter bytes",
func_name, (long) max_int); func_name, (long) max_int);
@ -411,7 +410,7 @@ do_return_expr(expr)
ch3cast(&expr, RETURN, func_type); ch3cast(&expr, RETURN, func_type);
code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL);
if (struct_return != 0) { if (struct_return != 0) {
LoadLocal(fbytes, pointer_size); LoadLocal((arith) 0, pointer_size);
store_block(func_size, func_type->tp_align); store_block(func_size, func_type->tp_align);
} }
C_bra(return_label); C_bra(return_label);

View file

@ -489,12 +489,6 @@ EVAL(expr, val, code, true_label, false_label)
ParSize += pointer_size; ParSize += pointer_size;
} }
} }
if (is_struct_or_union(tp->tp_fund)) {
retspace = NewLocal(tp->tp_size, tp->tp_align,
-1, 0);
C_lal(retspace);
ParSize += pointer_size;
}
if ((ex = right) != NILEXPR) { if ((ex = right) != NILEXPR) {
/* function call with parameters*/ /* function call with parameters*/
while ( ex->ex_class == Oper && while ( ex->ex_class == Oper &&
@ -508,6 +502,12 @@ EVAL(expr, val, code, true_label, false_label)
EVAL(ex, RVAL, TRUE, NO_LABEL, NO_LABEL); EVAL(ex, RVAL, TRUE, NO_LABEL, NO_LABEL);
ParSize += ATW(ex->ex_type->tp_size); ParSize += ATW(ex->ex_type->tp_size);
} }
if (is_struct_or_union(tp->tp_fund)) {
retspace = NewLocal(tp->tp_size, tp->tp_align,
-1, 0);
C_lal(retspace);
ParSize += pointer_size;
}
if (ISNAME(left)) { if (ISNAME(left)) {
/* e.g., main() { (*((int (*)())0))(); } */ /* e.g., main() { (*((int (*)())0))(); } */
C_cal(left->VL_IDF->id_text); C_cal(left->VL_IDF->id_text);

View file

@ -522,6 +522,10 @@ declare_formals(idf, fp)
if (options['t']) if (options['t'])
dumpidftab("start declare_formals", 0); dumpidftab("start declare_formals", 0);
#endif /* DEBUG */ #endif /* DEBUG */
if (is_struct_or_union(idf->id_def->df_type->tp_up->tp_fund)) {
/* create space for address of return value */
f_offset = pointer_size;
}
while (se) { while (se) {
register struct def *def = se->se_idf->id_def; register struct def *def = se->se_idf->id_def;

View file

@ -67,7 +67,6 @@
extern arith ifval; extern arith ifval;
#endif /* NOPP */ #endif /* NOPP */
extern arith fbytes;
extern error(); extern error();
} }
@ -198,6 +197,7 @@ non_function(register struct decspecs *ds; register struct declarator *dc;)
/* 3.7.1 */ /* 3.7.1 */
function(struct decspecs *ds; struct declarator *dc;) function(struct decspecs *ds; struct declarator *dc;)
{ {
arith fbytes;
register struct idf *idf = dc->dc_idf; register struct idf *idf = dc->dc_idf;
} }
: :
@ -222,7 +222,7 @@ function(struct decspecs *ds; struct declarator *dc;)
} }
compound_statement compound_statement
{ {
end_proc(); end_proc(fbytes);
#ifdef LINT #ifdef LINT
lint_implicit_return(); lint_implicit_return();
#endif /* LINT */ #endif /* LINT */