From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH] fix: give a type to bad conditionnal expressions
Date: Fri, 4 Aug 2017 02:16:39 +0200 [thread overview]
Message-ID: <20170804001639.4823-1-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170804001122.4ivc2sktypvg2w3i@ltop.local>
Bad conditional expressions used to have no type (NULL)
this in turn makes that some further processing are
not done. In particular, here, the expansion of the
operands are not done.
Fix this by giving to such expression a type 'bad_type'.
Note: nor gcc, not clang seems to emit a warning for the
the testcase here which is not conform to the standard.
OTOH, sparse complains and this was the cause of the
non-expansion of the builtin.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
evaluate.c | 1 +
validation/cond-err-expand.c | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 validation/cond-err-expand.c
diff --git a/evaluate.c b/evaluate.c
index cf3cf244d..5b4abdb6a 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -1220,6 +1220,7 @@ static struct symbol *evaluate_conditional_expression(struct expression *expr)
Err:
expression_error(expr, "incompatible types in conditional expression (%s)", typediff);
+ expr->ctype = &bad_ctype;
return NULL;
out:
diff --git a/validation/cond-err-expand.c b/validation/cond-err-expand.c
new file mode 100644
index 000000000..72af8d4b1
--- /dev/null
+++ b/validation/cond-err-expand.c
@@ -0,0 +1,27 @@
+static inline void f(void)
+{
+ __builtin_constant_p(0);
+}
+
+int foo(int a)
+{
+ return 0 ? 0 : f();
+}
+
+int bar(int a)
+{
+ return 1 ? f() : 0;
+}
+
+/*
+ * check-name: cond-err-expand.c
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-error-start
+cond-err-expand.c:8:18: error: incompatible types in conditional expression (different base types)
+cond-err-expand.c:13:18: error: incompatible types in conditional expression (different base types)
+ * check-error-end
+ *
+ * check-output-ignore
+ * check-excludes: call.* __builtin_constant_p
+ */
--
2.13.2
next prev parent reply other threads:[~2017-08-04 0:18 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-27 15:05 ptrlist-iterator performance on one wine source file Christopher Li
2017-07-29 13:01 ` Luc Van Oostenryck
2017-07-29 15:53 ` Christopher Li
2017-07-29 16:04 ` Luc Van Oostenryck
2017-07-29 16:25 ` Christopher Li
2017-07-29 16:30 ` Christopher Li
2017-07-29 16:35 ` Luc Van Oostenryck
2017-07-29 19:33 ` Christopher Li
2017-07-29 21:47 ` Luc Van Oostenryck
2017-07-30 4:15 ` Christopher Li
2017-07-30 15:12 ` Luc Van Oostenryck
2017-07-30 15:49 ` Christopher Li
2017-07-30 16:16 ` Luc Van Oostenryck
2017-08-01 20:33 ` Luc Van Oostenryck
2017-08-01 21:09 ` Christopher Li
2017-08-01 21:46 ` Luc Van Oostenryck
2017-08-01 23:37 ` Christopher Li
2017-08-02 0:42 ` Christopher Li
[not found] ` <CANeU7QmzundH7qpdYhQqDJgBv+5pPemwft+1uH5oVQ1POnoQDw@mail.gmail.com>
2017-08-02 22:50 ` Luc Van Oostenryck
2017-08-03 21:49 ` Luc Van Oostenryck
2017-08-03 22:29 ` Luc Van Oostenryck
2017-08-03 22:35 ` Linus Torvalds
2017-08-04 0:04 ` Christopher Li
2017-08-04 0:11 ` Luc Van Oostenryck
2017-08-04 0:16 ` Luc Van Oostenryck [this message]
2017-08-04 12:31 ` [PATCH] fix: give a type to bad conditionnal expressions Luc Van Oostenryck
2017-08-04 14:52 ` Christopher Li
2017-08-04 14:53 ` Christopher Li
2017-08-04 11:33 ` ptrlist-iterator performance on one wine source file Luc Van Oostenryck
2017-08-04 14:51 ` Christopher Li
2017-08-04 22:26 ` Luc Van Oostenryck
2017-08-05 0:23 ` Christopher Li
2017-08-05 10:05 ` Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170804001639.4823-1-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).