From patchwork Fri Aug 4 00:16:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9880189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D2FB460360 for ; Fri, 4 Aug 2017 00:18:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B85BE28963 for ; Fri, 4 Aug 2017 00:18:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD19928968; Fri, 4 Aug 2017 00:18:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5696128963 for ; Fri, 4 Aug 2017 00:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751940AbdHDASt (ORCPT ); Thu, 3 Aug 2017 20:18:49 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:36026 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751887AbdHDASs (ORCPT ); Thu, 3 Aug 2017 20:18:48 -0400 Received: by mail-wr0-f195.google.com with SMTP id y67so1983811wrb.3 for ; Thu, 03 Aug 2017 17:18:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sOwtcnO0JFyi6mcsS/Br+i5vp8v0PWAXG+kbsCBofvs=; b=f0LPOjojtKZ8et+6IfpRq098k+ymeZdd0Dij38Y2ZMhncED/B/wCJdhnYAE8g6eZm0 +m/tuHRH8V0ivEDu2A8FfBWfNtYGRdPrKMLd4wiYTmvK/p2iXeEws/oXdvmJ8TaTbCPK 8X/BM95CP/gMmNIpjZkVWBjT++JcXWwkKZWrCB4EL1pJffI4rfRDABDaQvb/c+0pMAtY z6iopL1zAPYDsm+bru35qO+B1zxHcRVgiidmLikyEpQz4uWvGH4gvdQ0gWCScwcMCa0U zgeuZ+6tkAkLAlyvL1Q/rv4mqRPYzepSLyA9TD98fSc54/w90vO46f6Qefy3LcLobLpL 6TBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sOwtcnO0JFyi6mcsS/Br+i5vp8v0PWAXG+kbsCBofvs=; b=O/3d+3muPmsyVborvvSWa53V/NflPxxMG13t+TF8C0wAfkko1bTUS9g3ae1rfC8JXh xmUUU+hpyzDF6CREe1XAnwMJ3MDX1jtUf6PdDOy8vNRw4fkM4WgVg6/gkeKVxv+iE0TW iWywlFCVCZbY+0Czk+15FBSKslYDxVnE3iBEC3IKURl5tr4miTcHRrFCFt7kcMgOfC1b 10JQZwnIFSfj5gVACZ6PZ9yVTRtb3IG09WfGH3b2q9vyNUPVjKItu+2XvpDpDbI2Axne EfcQpmA58Cdm+X4aOJx5ZOiWuvi9W27Jl49JG9rk0iJvkPB8ddfZ2SBaPfnD2tU3jhE2 84Mg== X-Gm-Message-State: AIVw113QZs/uLPzWImUE9yi8f3NQ+PvegbE1paGv4Fpr3+x9yszM871A JMKmrxTqNkU0k2mt/Dw= X-Received: by 10.223.157.4 with SMTP id k4mr406406wre.270.1501805927115; Thu, 03 Aug 2017 17:18:47 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:40c4:ab00:9c75:94b6:86ff:601e]) by smtp.gmail.com with ESMTPSA id n184sm2771639wme.33.2017.08.03.17.18.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Aug 2017 17:18:46 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Linus Torvalds , Luc Van Oostenryck Subject: [PATCH] fix: give a type to bad conditionnal expressions Date: Fri, 4 Aug 2017 02:16:39 +0200 Message-Id: <20170804001639.4823-1-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170804001122.4ivc2sktypvg2w3i@ltop.local> References: <20170804001122.4ivc2sktypvg2w3i@ltop.local> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 + */