From patchwork Sun Jan 20 00:13:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 10772235 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8695217FB for ; Sun, 20 Jan 2019 00:14:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77051289E1 for ; Sun, 20 Jan 2019 00:14:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AC1128A5A; Sun, 20 Jan 2019 00:14:00 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 0F419289E1 for ; Sun, 20 Jan 2019 00:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727188AbfATAN6 (ORCPT ); Sat, 19 Jan 2019 19:13:58 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39024 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729889AbfATAN6 (ORCPT ); Sat, 19 Jan 2019 19:13:58 -0500 Received: by mail-wr1-f66.google.com with SMTP id t27so19307350wra.6 for ; Sat, 19 Jan 2019 16:13:57 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=28K0Ik7iGrjAWKvUK1mCXu3LgGNY48W0y7TllOEIqHg=; b=tx6vA06+yviJQYb4oDsqA0KyO9pydOUutp4VYxiUz5KwiEHvgxKivWm96ygkzhOjXr UNaJOhtUEdl+mCxagDgAXE5O0+fFppVVjwnwODUoK+BvtIUG0l7PCVa1fDH5JxKCAX1A J2pSuWa1FDJkgDc8px7JIjhvt1KF1Hqbk1TfiX60OxzzkGONokW2cKs8hfwUDEG4RzwD roz77qKyslieH6JgBj9ZQs2Ep4hIGSdW3sWcAdkAW65UwxCj7OuYLRhF9CcmyLcmfjX/ dWZz5LtZjDKJ8bzZC4gZ4ZTsHW6yPLrCjN04Qfv4S/0OiLVT7AQsdGQ6Nb2coRjU5Nou cFsA== 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:mime-version:content-transfer-encoding; bh=28K0Ik7iGrjAWKvUK1mCXu3LgGNY48W0y7TllOEIqHg=; b=cgEN6ntUszmNRYt+vmuXxPgfMFXva/SSvZy/Nab/AUVoL1Fu/HCjTalGLCCmy2bq5W 9oYl1INA4YJDYh5fjIHNEfauYhyMtn66lO2iayjnK5KltdNSjvjboKZ4CU6rSCjO3Dsg 9m/9aH7FAM5fakqt2nGcN3iMblqGq36XqXIxMijHWIMMoo/q0q15td8HoCTTu8pxo+rX VyaZToY8e+7Khw5vdkyj/Z1oTqg97OLbF7g+iaeO/hVaHbxDdEIDhIZE95yTMGtNbayq D5n62h/QxHY40bG3yBW49zP1Q+y53XjV3KR6MHI8dMw/A3txdo0C8PTaMhON2/tVYVyW 4KDQ== X-Gm-Message-State: AJcUukfuuFxFCMBiozy0/Yc12pOyanvFShPAZAFiHxC6hQTQDddXQYT6 jBqZgQFW+sdlBRECoCPZec7gzsxj X-Google-Smtp-Source: ALg8bN5p+BRb0GstV9nxw76cGEgvCVj5v0sBtkgUNpKgeuGQ4xBx5mfO71pNeFHRUVcM2MZs/KBfdw== X-Received: by 2002:adf:81c6:: with SMTP id 64mr22975908wra.186.1547943236062; Sat, 19 Jan 2019 16:13:56 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40eb:400:dc79:225f:308a:97fa]) by smtp.gmail.com with ESMTPSA id x15sm100991673wrs.27.2019.01.19.16.13.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Jan 2019 16:13:55 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 1/2] display extra info for type errors in compare & conditional Date: Sun, 20 Jan 2019 01:13:49 +0100 Message-Id: <20190120001350.19987-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20190120001350.19987-1-luc.vanoostenryck@gmail.com> References: <20190120001350.19987-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 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 For "incompatible types in comparison expression" errors, only the kind of type difference is displayed. Displaying the types would make eaiser to find the cause of the problem. The same is true for ternary conditionals. So, also display the left & right types. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 8 ++++++-- validation/cond-err-expand.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/evaluate.c b/evaluate.c index 947b121f4..efe6d28b8 100644 --- a/evaluate.c +++ b/evaluate.c @@ -1132,7 +1132,9 @@ static struct symbol *evaluate_compare(struct expression *expr) if (!typediff) goto OK; - expression_error(expr, "incompatible types in comparison expression (%s)", typediff); + expression_error(expr, "incompatible types in comparison expression (%s):", typediff); + info(expr->pos, " %s", show_typename(ltype)); + info(expr->pos, " %s", show_typename(rtype)); return NULL; OK: @@ -1268,7 +1270,9 @@ static struct symbol *evaluate_conditional_expression(struct expression *expr) typediff = "different base types"; Err: - expression_error(expr, "incompatible types in conditional expression (%s)", typediff); + expression_error(expr, "incompatible types in conditional expression (%s):", typediff); + info(expr->pos, " %s", show_typename(ltype)); + info(expr->pos, " %s", show_typename(rtype)); /* * if the condition is constant, the type is in fact known * so use it, as gcc & clang do. diff --git a/validation/cond-err-expand.c b/validation/cond-err-expand.c index 7936a2d00..b52624bc9 100644 --- a/validation/cond-err-expand.c +++ b/validation/cond-err-expand.c @@ -18,8 +18,12 @@ void bar(void) * check-command: test-linearize -Wno-decl $file * * check-error-start -cond-err-expand.c:8:11: error: incompatible types in conditional expression (different base types) -cond-err-expand.c:13:11: error: incompatible types in conditional expression (different base types) +cond-err-expand.c:8:11: error: incompatible types in conditional expression (different base types): +cond-err-expand.c:8:11: int +cond-err-expand.c:8:11: void +cond-err-expand.c:13:11: error: incompatible types in conditional expression (different base types): +cond-err-expand.c:13:11: void +cond-err-expand.c:13:11: int * check-error-end * * check-output-ignore