diff options
| author | Xi Wang <xi.wang@gmail.com> | 2013-05-24 09:30:35 -0400 |
|---|---|---|
| committer | Pekka Enberg <penberg@kernel.org> | 2013-05-27 14:15:24 +0300 |
| commit | 99bdda1a38a6e3622cb72f422b2fb05045c29df7 (patch) | |
| tree | 681909c499341fc77af7ed3d11c7dabfdb57a171 /validation | |
| parent | 469e5d6ea3353fb3039747f52fb506c9ba983d8b (diff) | |
| download | sparse-dev-99bdda1a38a6e3622cb72f422b2fb05045c29df7.tar.gz | |
Fix result type of relational and logical operators
The result type of relational operators (e.g., x < y) and logical
operators (e.g., x && y) in C should be int, rather than bool.
For example, sparse incorrectly evaluates sizeof(x < y) to 1 (i.e.,
sizeof(int)), which should have been sizeof(int).
This patch fixes the result type of these operators in evaluation,
linearization, and the LLVM backend.
Acked-by: Christopher Li <sparse@chrisli.org>
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/cond_expr3.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/validation/cond_expr3.c b/validation/cond_expr3.c new file mode 100644 index 00000000..748409e6 --- /dev/null +++ b/validation/cond_expr3.c @@ -0,0 +1,17 @@ +static int icmp = 1 / (sizeof(int) - sizeof(1 > 0)); +static int fcmp = 1 / (sizeof(int) - sizeof(1.0 == 2.0 - 1.0)); +static int lnot = 1 / (sizeof(int) - sizeof(!!1.0)); +static int land = 1 / (sizeof(int) - sizeof(2 && 3)); +static int lor = 1 / (sizeof(int) - sizeof('c' || 1.0f)); + +/* + * check-name: result type of relational and logical operators + * + * check-error-start +cond_expr3.c:1:21: warning: division by zero +cond_expr3.c:2:21: warning: division by zero +cond_expr3.c:3:21: warning: division by zero +cond_expr3.c:4:21: warning: division by zero +cond_expr3.c:5:21: warning: division by zero + * check-error-end + */ |
