aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorXi Wang <xi.wang@gmail.com>2013-05-24 09:30:35 -0400
committerPekka Enberg <penberg@kernel.org>2013-05-27 14:15:24 +0300
commit99bdda1a38a6e3622cb72f422b2fb05045c29df7 (patch)
tree681909c499341fc77af7ed3d11c7dabfdb57a171 /validation
parent469e5d6ea3353fb3039747f52fb506c9ba983d8b (diff)
downloadsparse-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.c17
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
+ */