From: erikb Date: Wed, 28 May 1986 08:40:06 +0000 (+0000) Subject: revised the type checking of expr in "switch (expr)" X-Git-Tag: release-5-5~5289 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=441ba991fad78d87e7daa11fafc3f077d2ead838;p=ack.git revised the type checking of expr in "switch (expr)" --- diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index feb464914..79bc29c7c 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -252,6 +252,9 @@ init() pa_type = long_type; else 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) fatal("sizes of short/int/long decreasing"); diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 3999206f7..acc44e89e 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -24,6 +24,14 @@ extern char options[]; 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) struct expr *expr; { @@ -38,7 +46,8 @@ code_startswitch(expr) switch (fund) { case LONG: if (options['R']) - warning("long in switch"); + warning("long in switch (cast to int)"); + int2int(&expr, int_type); break; case DOUBLE: error("float/double in switch"); @@ -129,13 +138,11 @@ code_case(expr) error("case statement not in switch"); return; } - if (expr->ex_flags & EX_ERROR) { /* is probably 0 anyway */ return; } - expr->ex_type = sh->sh_type; - cut_size(expr); + ch7cast(&expr, SWITCH, sh->sh_type); ce = new_case_entry(); C_df_ilb(ce->ce_label = text_label()); ce->ce_value = val = expr->VL_VALUE;