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 From patchwork Sun Jan 20 00:13:50 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: 10772237 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 D976D13B4 for ; Sun, 20 Jan 2019 00:14:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9AE1289E1 for ; Sun, 20 Jan 2019 00:14:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDCF928A5A; Sun, 20 Jan 2019 00:14:02 +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 19575289E1 for ; Sun, 20 Jan 2019 00:14:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729889AbfATAOB (ORCPT ); Sat, 19 Jan 2019 19:14:01 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34417 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729895AbfATAOA (ORCPT ); Sat, 19 Jan 2019 19:14:00 -0500 Received: by mail-wr1-f65.google.com with SMTP id j2so19387216wrw.1 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=JR41//v1drAz7wBCE89dGfV709T41RW8lIrAWUeCFeA=; b=CXBAusnYcyL4j+jvOHC+ETFP+3r5k9iICcFsnIpMv3ihijEnpQDj/43OsSfaPLhFl5 AgvowDMn2Z3Cf0Fz9Wa+OPkr5ds+Nb687onz2t9RWiQrykCmz9Dj/opsoz/5/JFmpzIC sTNcnaMboqaCLS3A9XkwDMTVENfw4oICwzx4xL4Kq9qir+IvFIYfs0oq/dQ1OAfFRTUz CNtu8KjPMakWMnSwexic59WEueZZqwLmQl5ZFGglfwUjNBGH7qsuxFbbnXXkKeaXpzoQ 1ndv9QAf3+x03IxMv7tR2WCaacOHzpEUASA1fQl53NBy5AS+dSaNuJGvSLERY/Q6zE8U mDBw== 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=JR41//v1drAz7wBCE89dGfV709T41RW8lIrAWUeCFeA=; b=T+6Wra0zyUu/Q6q9SCmdkLdsz6J/Ucah0YuLQ9h3+Bt5nX5UjJOM9rvRosjMj8YS65 XgKAZzzWk8UG2oCExcCxjrfl9vFC0SbDi7cDNGq00ccH4ZZyuP36jTxFcjQartJaIOYd gJUlHIXSEIbtrl/ZbxwWPOEmEEjcjqWBLfz5hXu+0N6S13/saidgbCXkzSEXHZ6LUS2v a4RPRUlB3b0tZV+kwLwrLk6iXklrZigdMal3tL5+zhBjy4M8spUGq+B48kl/GFsTXfU7 G4TS2A9br6Wir/wrLbHw5v3mTmJI3xLQmk++MequX6TqRNGHmx18GMu7GeMo6DWvdEUU FoaQ== X-Gm-Message-State: AJcUukdBtnOHQhw4YEMT6KDT1uMM5VFoNVKckDTq4EWt9vz4OccV+kOW Hnmwjq8UWnQwhdROhO/oFgM8rf4l X-Google-Smtp-Source: ALg8bN7chLy/eGw4FTEE5IwwkYync/2t5UkQO/xZON8vKveIRygOxnjiUS0JHfGO/4ZCsZ+C3tojeA== X-Received: by 2002:adf:e407:: with SMTP id g7mr11604103wrm.277.1547943236945; 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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Jan 2019 16:13:56 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 2/2] more consistent type info in error messages Date: Sun, 20 Jan 2019 01:13:50 +0100 Message-Id: <20190120001350.19987-3-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 Some error messages are displayed with auxillary information about the concerned type(s). However, this type information is displayed in various way: just the type, "[left/right] side has type ...", "got ...", ... Make these more consistent and simpler by simply dipslaying type(s) when the error message is unambigous about the fact that the problem is a type problem (and/or make the message unambiguous when possible). Signed-off-by: Luc Van Oostenryck --- evaluate.c | 20 ++++++++++---------- validation/bad-type-twice0.c | 4 ++-- validation/bad-type-twice1.c | 6 +++--- validation/compare-null-to-int.c | 6 +++--- validation/cond_expr.c | 4 ++-- validation/conditional-type.c | 32 ++++++++++++++++---------------- validation/enum-mismatch.c | 6 +++--- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/evaluate.c b/evaluate.c index efe6d28b8..4d5748562 100644 --- a/evaluate.c +++ b/evaluate.c @@ -283,9 +283,9 @@ warn_for_different_enum_types (struct position pos, return; if (typea->type == SYM_ENUM && typeb->type == SYM_ENUM) { - warning(pos, "mixing different enum types"); - info(pos, " %s versus", show_typename(typea)); - info(pos, " %s", show_typename(typeb)); + warning(pos, "mixing different enum types:"); + info(pos, " %s", show_typename(typea)); + info(pos, " %s", show_typename(typeb)); } } @@ -413,16 +413,16 @@ static struct symbol *bad_expr_type(struct expression *expr) case EXPR_COMPARE: if (!valid_subexpr_type(expr)) break; - sparse_error(expr->pos, "incompatible types for operation (%s)", show_special(expr->op)); - info(expr->pos, " left side has type %s", show_typename(expr->left->ctype)); - info(expr->pos, " right side has type %s", show_typename(expr->right->ctype)); + sparse_error(expr->pos, "incompatible types for operation (%s):", show_special(expr->op)); + info(expr->pos, " %s", show_typename(expr->left->ctype)); + info(expr->pos, " %s", show_typename(expr->right->ctype)); break; case EXPR_PREOP: case EXPR_POSTOP: if (!valid_expr_type(expr->unop)) break; - sparse_error(expr->pos, "incompatible types for operation (%s)", show_special(expr->op)); - info(expr->pos, " argument has type %s", show_typename(expr->unop->ctype)); + sparse_error(expr->pos, "incompatible type for operation (%s):", show_special(expr->op)); + info(expr->pos, " %s", show_typename(expr->unop->ctype)); break; default: break; @@ -910,8 +910,8 @@ static struct symbol *evaluate_conditional(struct expression *expr, int iterator if (Waddress) warning(expr->pos, "the address of %s will always evaluate as true", "an array"); } else if (!is_scalar_type(ctype)) { - sparse_error(expr->pos, "incorrect type in conditional"); - info(expr->pos, " got %s", show_typename(ctype)); + sparse_error(expr->pos, "incorrect type in conditional:"); + info(expr->pos, " %s", show_typename(ctype)); return NULL; } diff --git a/validation/bad-type-twice0.c b/validation/bad-type-twice0.c index 7a9073c52..84e0f25a4 100644 --- a/validation/bad-type-twice0.c +++ b/validation/bad-type-twice0.c @@ -7,7 +7,7 @@ static int foo(a) * check-name: bad-type-twice0 * * check-error-start -bad-type-twice0.c:3:16: error: incorrect type in conditional -bad-type-twice0.c:3:16: got incomplete type a +bad-type-twice0.c:3:16: error: incorrect type in conditional: +bad-type-twice0.c:3:16: incomplete type a * check-error-end */ diff --git a/validation/bad-type-twice1.c b/validation/bad-type-twice1.c index cc81662af..a9ba182cb 100644 --- a/validation/bad-type-twice1.c +++ b/validation/bad-type-twice1.c @@ -9,8 +9,8 @@ static unsigned long foo(unsigned long val, void *ref) * check-name: bad-type-twice1 * * check-error-start -bad-type-twice1.c:3:17: error: incompatible types for operation (>=) -bad-type-twice1.c:3:17: left side has type unsigned long val -bad-type-twice1.c:3:17: right side has type void *ref +bad-type-twice1.c:3:17: error: incompatible types for operation (>=): +bad-type-twice1.c:3:17: unsigned long val +bad-type-twice1.c:3:17: void *ref * check-error-end */ diff --git a/validation/compare-null-to-int.c b/validation/compare-null-to-int.c index 08e556b32..336c724de 100644 --- a/validation/compare-null-to-int.c +++ b/validation/compare-null-to-int.c @@ -4,8 +4,8 @@ static unsigned int comparison = (void *)0 == 1; * check-description: Sparse used to allow this. * * check-error-start -compare-null-to-int.c:1:44: error: incompatible types for operation (==) -compare-null-to-int.c:1:44: left side has type void * -compare-null-to-int.c:1:44: right side has type int +compare-null-to-int.c:1:44: error: incompatible types for operation (==): +compare-null-to-int.c:1:44: void * +compare-null-to-int.c:1:44: int * check-error-end */ diff --git a/validation/cond_expr.c b/validation/cond_expr.c index e55711cce..9b8105c1c 100644 --- a/validation/cond_expr.c +++ b/validation/cond_expr.c @@ -13,7 +13,7 @@ int a(void) * check-name: Two-argument conditional expression types * * check-error-start -cond_expr.c:10:16: error: incompatible types for operation (~) -cond_expr.c:10:16: argument has type double +cond_expr.c:10:16: error: incompatible type for operation (~): +cond_expr.c:10:16: double * check-error-end */ diff --git a/validation/conditional-type.c b/validation/conditional-type.c index a14c05ec1..7cd5672dc 100644 --- a/validation/conditional-type.c +++ b/validation/conditional-type.c @@ -79,21 +79,21 @@ static int good_if_ptr(void *ptr) * check-name: conditional-type * * check-error-start -conditional-type.c:18:18: error: incorrect type in conditional -conditional-type.c:18:18: got void -conditional-type.c:19:13: error: incorrect type in conditional -conditional-type.c:19:13: got struct state s -conditional-type.c:24:18: error: incorrect type in conditional -conditional-type.c:24:18: got void -conditional-type.c:29:21: error: incorrect type in conditional -conditional-type.c:29:21: got void -conditional-type.c:30:16: error: incorrect type in conditional -conditional-type.c:30:16: got struct state s -conditional-type.c:34:21: error: incorrect type in conditional -conditional-type.c:34:21: got void -conditional-type.c:36:20: error: incorrect type in conditional -conditional-type.c:36:20: got void -conditional-type.c:40:21: error: incorrect type in conditional -conditional-type.c:40:21: got void +conditional-type.c:18:18: error: incorrect type in conditional: +conditional-type.c:18:18: void +conditional-type.c:19:13: error: incorrect type in conditional: +conditional-type.c:19:13: struct state s +conditional-type.c:24:18: error: incorrect type in conditional: +conditional-type.c:24:18: void +conditional-type.c:29:21: error: incorrect type in conditional: +conditional-type.c:29:21: void +conditional-type.c:30:16: error: incorrect type in conditional: +conditional-type.c:30:16: struct state s +conditional-type.c:34:21: error: incorrect type in conditional: +conditional-type.c:34:21: void +conditional-type.c:36:20: error: incorrect type in conditional: +conditional-type.c:36:20: void +conditional-type.c:40:21: error: incorrect type in conditional: +conditional-type.c:40:21: void * check-error-end */ diff --git a/validation/enum-mismatch.c b/validation/enum-mismatch.c index 1bdb1d6c2..a6e5d72db 100644 --- a/validation/enum-mismatch.c +++ b/validation/enum-mismatch.c @@ -12,8 +12,8 @@ static enum eb foo(enum ea a) * check-command: sparse -Wenum-mismatch $file * * check-error-start -enum-mismatch.c:7:16: warning: mixing different enum types -enum-mismatch.c:7:16: unsigned int enum ea versus -enum-mismatch.c:7:16: unsigned int enum eb +enum-mismatch.c:7:16: warning: mixing different enum types: +enum-mismatch.c:7:16: unsigned int enum ea +enum-mismatch.c:7:16: unsigned int enum eb * check-error-end */