revised the type checking of expr in "switch (expr)"

This commit is contained in:
erikb 1986-05-28 08:40:06 +00:00
parent f56f8f56f3
commit 441ba991fa
2 changed files with 14 additions and 4 deletions

View file

@ -252,6 +252,9 @@ init()
pa_type = long_type; pa_type = long_type;
else else
fatal("pointer size incompatible with any integral size"); fatal("pointer size incompatible with any integral size");
if (int_size != word_size)
fatal("int_size and word_size are not equal");
if (short_size > int_size || int_size > long_size) if (short_size > int_size || int_size > long_size)
fatal("sizes of short/int/long decreasing"); fatal("sizes of short/int/long decreasing");

View file

@ -24,6 +24,14 @@ extern char options[];
static struct switch_hdr *switch_stack = 0; static struct switch_hdr *switch_stack = 0;
/* (EB 86.05.20) The following rules hold for switch statements:
- the expression E in "switch(E)" is cast to 'int' (RM 9.7)
- the expression E in "case E:" must be 'int' (RM 9.7)
- the values in the CSA/CSB tables are words (EM 7.4)
For simplicity, we suppose int_size == word_size.
*/
code_startswitch(expr) code_startswitch(expr)
struct expr *expr; struct expr *expr;
{ {
@ -38,7 +46,8 @@ code_startswitch(expr)
switch (fund) { switch (fund) {
case LONG: case LONG:
if (options['R']) if (options['R'])
warning("long in switch"); warning("long in switch (cast to int)");
int2int(&expr, int_type);
break; break;
case DOUBLE: case DOUBLE:
error("float/double in switch"); error("float/double in switch");
@ -129,13 +138,11 @@ code_case(expr)
error("case statement not in switch"); error("case statement not in switch");
return; return;
} }
if (expr->ex_flags & EX_ERROR) { if (expr->ex_flags & EX_ERROR) {
/* is probably 0 anyway */ /* is probably 0 anyway */
return; return;
} }
expr->ex_type = sh->sh_type; ch7cast(&expr, SWITCH, sh->sh_type);
cut_size(expr);
ce = new_case_entry(); ce = new_case_entry();
C_df_ilb(ce->ce_label = text_label()); C_df_ilb(ce->ce_label = text_label());
ce->ce_value = val = expr->VL_VALUE; ce->ce_value = val = expr->VL_VALUE;