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@xxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html