diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-01-29 12:34:09 +0100 |
|---|---|---|
| committer | Christopher Li <sparse@chrisli.org> | 2017-02-13 09:34:45 +0800 |
| commit | 7e9d18754cf8ebc6bc24f4d744720282d62531ad (patch) | |
| tree | 850ccf8465e50ac50a23d776a62d4f74159a6105 /evaluate.c | |
| parent | 05adbae426c87e6f644ebb7eca95a2d66a190048 (diff) | |
| download | sparse-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.c | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -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; |
