diff mbox

fix: give a type to bad conditionnal expressions

Message ID 20170804001639.4823-1-luc.vanoostenryck@gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Luc Van Oostenryck Aug. 4, 2017, 12:16 a.m. UTC
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

Comments

Luc Van Oostenryck Aug. 4, 2017, 12:31 p.m. UTC | #1
Please ignore this patch as I must have forgot to recompile the last change.
The problem is there and the solution too but bad_ctype won't solve
the issue here.

I'll send another version which will effectively solve the issue but
I'm far from sure
we'll want it.

-- Luc
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christopher Li Aug. 4, 2017, 2:52 p.m. UTC | #2
On Fri, Aug 4, 2017 at 8:31 AM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> Please ignore this patch as I must have forgot to recompile the last change.
> The problem is there and the solution too but bad_ctype won't solve
> the issue here.
>
> I'll send another version which will effectively solve the issue but
> I'm far from sure
> we'll want it.
>
> -- Luc
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christopher Li Aug. 4, 2017, 2:53 p.m. UTC | #3
On Fri, Aug 4, 2017 at 8:31 AM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> Please ignore this patch as I must have forgot to recompile the last change.
> The problem is there and the solution too but bad_ctype won't solve
> the issue here.
>
> I'll send another version which will effectively solve the issue but
> I'm far from sure
> we'll want it.

Sorry I hit the send before I type up some reply in my last email.

I will wait for your new patch then.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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
+ */