scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 0c5e2751bdf1b8db6700733e84b2887f7f38aabc
parent 4f3e4465ccb3e7c611c7996793abefe399787983
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 24 Jul 2015 14:03:59 +0200

Allow only integer expressions in switch

convert() can do some conversions that are not allowed in a switch,
like for example from a float to integer.

Diffstat:
cc1/stmt.c | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -219,8 +219,9 @@ Switch(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) expect(SWITCH); expect ('('); cond = expr(); - if ((cond = convert(cond, inttype, 0)) == NULL) + if (cond->type->op != INT) error("incorrect type in switch statement"); + cond = convert(cond, inttype, 0); expect (')'); lbreak = newsym(NS_LABEL);