From patchwork Thu Jun 8 02:47:36 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: 9773781 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 7ED0460350 for ; Thu, 8 Jun 2017 02:47:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77D6223B24 for ; Thu, 8 Jun 2017 02:47:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CAA225404; Thu, 8 Jun 2017 02:47:59 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 F21E323B24 for ; Thu, 8 Jun 2017 02:47:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751881AbdFHCr5 (ORCPT ); Wed, 7 Jun 2017 22:47:57 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34107 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751853AbdFHCr4 (ORCPT ); Wed, 7 Jun 2017 22:47:56 -0400 Received: by mail-wm0-f67.google.com with SMTP id 70so5113994wme.1 for ; Wed, 07 Jun 2017 19:47:55 -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=NRQPKpevH0JQfevTp9RkZcKCPoAbxqfmT+gotPLqqIw=; b=J1HTErPh3wIw56XwFbjVbjatTzFM3h8097D6ZSJU2KR8G+/uriFFRsm5LSiSFTr8+m IWakKU0vobDUgh0Iwtq2lvGj0mEPGYVhXrdhbj8teo2phfVj2xzCZ9pWByaSxY/MW9r0 eDlXX8Z3vGy2iL5u2CH3o/UF1Y3TtLnKhHZZOB1AKq7aA00sJIEUBESxsRBqDLLpMkar X4tuS7g/AyvQE+eLhD4RKxM3143HeVUxEft0+5roakpTW5w0xfzhRZ2Kh50d/rx1/6ty R5D5s47Fz9xP9xuxg8NQrKVjI6qTmdPx6A947sozbWRCpU9oug5s6YIhl8OzLTAjmNHq KtQw== 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=NRQPKpevH0JQfevTp9RkZcKCPoAbxqfmT+gotPLqqIw=; b=lKhBEAcnyotxXXEsT19NWZTf8hlYiBQuvkp142g7EkiMobBm4wqxIEyNaGXHd/48qP qetzTQQD/n0n3IEr8WslMY/yT334Cq5antQWQNx7jqNp0uTfll5BnluOvVbrMVReByzP ayFEHK1KQULN9BL2SffG48v0lcFGJecaVAKXV/vbRN2vrGca1G24G5cMxIhS0qKG4ZFd r03qUCQ9GQMyAKHxDmg9Jg1TU+2RVV5ULWZBtbChZafuZelodmQ/wXfFE+aww4EGM81A VJ7RbK5J4MZLogaGFshVe1taQCSNEThHDTlDokn6tDjPA5n/v0HfvWHH+ggu3W/t8XLL es6A== X-Gm-Message-State: AODbwcANMdCYCq4SyOE0Qx9xu/MCSf3OUHpN7Hq2cXV/1ZwDNqddkc4c iZ/HhnLJ/6vn2x5ntPE= X-Received: by 10.80.170.23 with SMTP id o23mr4296748edc.164.1496890074401; Wed, 07 Jun 2017 19:47:54 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:89c:5400:21b3:ee4b:e91a:4fb6]) by smtp.gmail.com with ESMTPSA id b36sm2057354edb.41.2017.06.07.19.47.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2017 19:47:53 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Chris Li , Luc Van Oostenryck Subject: [PATCH 2/2] ret-void: warn for implicit type Date: Thu, 8 Jun 2017 04:47:36 +0200 Message-Id: <20170608024736.49780-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170608024736.49780-1-luc.vanoostenryck@gmail.com> References: <20170608024736.49780-1-luc.vanoostenryck@gmail.com> 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 Currently, no warning is given for symbols for which no type is explicitely given. But for functions we received a pointless warning like here under if the returned type is effectively an int: warning: incorrect type in return expression (invalid types) expected incomplete type got int Fix this by issuing the warning. Also give an implicit type of int, as required by C89, to avoid pointless warning about the expected incomplete type. Signed-off-by: Luc Van Oostenryck --- parse.c | 9 +++++++++ validation/alias-mixed.c | 2 +- validation/badtype2.c | 1 + validation/implicit-ret-type.c | 15 +++++++++++++++ validation/implicit-type.c | 14 ++++++++++++++ validation/typedef_shadow.c | 1 + 6 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 validation/implicit-ret-type.c create mode 100644 validation/implicit-type.c diff --git a/parse.c b/parse.c index b08d4acef..214547904 100644 --- a/parse.c +++ b/parse.c @@ -2920,6 +2920,11 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis } } } else if (base_type && base_type->type == SYM_FN) { + if (base_type->ctype.base_type == &incomplete_ctype) { + warning(decl->pos, "'%s()' has implicit return type", + show_ident(decl->ident)); + base_type->ctype.base_type = &int_ctype; + } /* K&R argument declaration? */ if (lookup_type(token)) return parse_k_r_arguments(token, decl, list); @@ -2931,6 +2936,10 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis } else if (base_type == &void_ctype && !(decl->ctype.modifiers & MOD_EXTERN)) { sparse_error(token->pos, "void declaration"); } + if (base_type == &incomplete_ctype) { + warning(decl->pos, "'%s' has implicit type", show_ident(decl->ident)); + decl->ctype.base_type = &int_ctype;; + } for (;;) { if (!is_typedef && match_op(token, '=')) { diff --git a/validation/alias-mixed.c b/validation/alias-mixed.c index 429304774..0cfbe36b8 100644 --- a/validation/alias-mixed.c +++ b/validation/alias-mixed.c @@ -15,7 +15,7 @@ static int bar(int *p) return g == 1; } -static test(void) +static void test(void) { foo(&g); bar(&g); diff --git a/validation/badtype2.c b/validation/badtype2.c index 90a5fa1e4..49fec87ce 100644 --- a/validation/badtype2.c +++ b/validation/badtype2.c @@ -12,6 +12,7 @@ static undef foo(char *c) /* * check-name: missing type * check-error-start +badtype2.c:2:8: warning: 'undef' has implicit type badtype2.c:2:14: error: Expected ; at end of declaration badtype2.c:2:14: error: got bar badtype2.c:3:14: error: Expected ; at end of declaration diff --git a/validation/implicit-ret-type.c b/validation/implicit-ret-type.c new file mode 100644 index 000000000..784a28531 --- /dev/null +++ b/validation/implicit-ret-type.c @@ -0,0 +1,15 @@ +fun(void); + +foo(void) { return 1; } +static bar(void) { return 1; } + +/* + * check-name: implicit-ret-type.c + * check-command: sparse -Wno-decl $file + * + * check-error-start +implicit-ret-type.c:1:1: warning: 'fun()' has implicit return type +implicit-ret-type.c:3:1: warning: 'foo()' has implicit return type +implicit-ret-type.c:4:8: warning: 'bar()' has implicit return type + * check-error-end + */ diff --git a/validation/implicit-type.c b/validation/implicit-type.c new file mode 100644 index 000000000..724bab71e --- /dev/null +++ b/validation/implicit-type.c @@ -0,0 +1,14 @@ +extern a; +static b; +c; + +/* + * check-name: implicit-type.c + * check-command: sparse -Wno-decl $file + * + * check-error-start +implicit-type.c:1:8: warning: 'a' has implicit type +implicit-type.c:2:8: warning: 'b' has implicit type +implicit-type.c:3:1: warning: 'c' has implicit type + * check-error-end + */ diff --git a/validation/typedef_shadow.c b/validation/typedef_shadow.c index c72cec72d..e52de80f2 100644 --- a/validation/typedef_shadow.c +++ b/validation/typedef_shadow.c @@ -6,6 +6,7 @@ static void f(int T) /* * check-name: typedef shadowing * check-error-start: +typedef_shadow.c:4:16: warning: 'T' has implicit type typedef_shadow.c:4:18: error: Expected ; at end of declaration typedef_shadow.c:4:18: error: got a * check-error-end: