aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/evaluate.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-01-29 12:34:09 +0100
committerChristopher Li <sparse@chrisli.org>2017-02-13 09:34:45 +0800
commit7e9d18754cf8ebc6bc24f4d744720282d62531ad (patch)
tree850ccf8465e50ac50a23d776a62d4f74159a6105 /evaluate.c
parent05adbae426c87e6f644ebb7eca95a2d66a190048 (diff)
downloadsparse-dev-7e9d18754cf8ebc6bc24f4d744720282d62531ad.tar.gz
validate expression's type in conditionals
This wasn't done yet, in particular void values was accepted inside if statements, which lead to strange situations after linearization. Implement this simply by calling the newly created is_scalar_type() in evaluate_conditional() and issuing an appropriate diagnostic when the check fail. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'evaluate.c')
-rw-r--r--evaluate.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/evaluate.c b/evaluate.c
index e2489ef6..6ab39ed7 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -869,6 +869,11 @@ static struct symbol *evaluate_conditional(struct expression *expr, int iterator
if (ctype) {
if (is_safe_type(ctype))
warning(expr->pos, "testing a 'safe expression'");
+ if (!is_scalar_type(ctype)) {
+ sparse_error(expr->pos, "incorrect type in conditional");
+ info(expr->pos, " got %s", show_typename(ctype));
+ ctype = NULL;
+ }
}
return ctype;