From patchwork Sun Nov 16 10:13:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 5313191 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9C126C11AC for ; Sun, 16 Nov 2014 10:13:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DA879201B9 for ; Sun, 16 Nov 2014 10:13:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CCE4F20176 for ; Sun, 16 Nov 2014 10:13:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755279AbaKPKNb (ORCPT ); Sun, 16 Nov 2014 05:13:31 -0500 Received: from mail-wi0-f180.google.com ([209.85.212.180]:36626 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755274AbaKPKNa (ORCPT ); Sun, 16 Nov 2014 05:13:30 -0500 Received: by mail-wi0-f180.google.com with SMTP id hi2so6359970wib.13 for ; Sun, 16 Nov 2014 02:13:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=qk9LEy5yzgL4sO9hifjkmIzdYzdUWm03WFvgZ/+GpdQ=; b=UlBHZ6bsskwJNzg8gtEzh3sG0LGFZlvSEtKZGFAKC0hQr90zp+oXPGs2vBNv9kc7Qy tw8SB/W0uhNYit3tNHTv1D0o7TaNznIMmSngtiUVQ6BevxFzX2m331mobscHKgr+vFtY uk59s73jWEJETgj4jcBelCPeGIpzdcoJDP9OjEUoTSEISHndSHSJg7pq1h0NrtHRKaE9 OoYaGiZeCSueCm+NJ5WfDYSbdebz22A0roHrtNXDmJYuIadOVjSrBTfdIDZL7hnTmX3u h3vKzBDrSkeiUuOGJSUZFhG3Sp1Zr28Ltzr7ZcVJprWdu2dGQJ2jqiSwNvaQ+oXGHMPx /dRQ== MIME-Version: 1.0 X-Received: by 10.194.81.70 with SMTP id y6mr28280176wjx.113.1416132809019; Sun, 16 Nov 2014 02:13:29 -0800 (PST) Received: by 10.27.10.219 with HTTP; Sun, 16 Nov 2014 02:13:28 -0800 (PST) In-Reply-To: References: <201411120724.PdeIjimc%fengguang.wu@intel.com> <1415799312.14686.332.camel@mfleming-mobl1.ger.corp.intel.com> Date: Sun, 16 Nov 2014 18:13:28 +0800 X-Google-Sender-Auth: PnqntdQ8gePOAN5b0LADbt_n2Dg Message-ID: Subject: Re: [efi:next 2/3] arch/x86/boot/compressed/eboot.c:26:16: sparse: incorrect type in return expression (different modifiers) From: Christopher Li To: Ard Biesheuvel Cc: Matt Fleming , "linux-efi@vger.kernel.org" , Linux-Sparse , "fengguang.wu" Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Nov 12, 2014 at 11:34 PM, Ard Biesheuvel wrote: > > Well, I spent some time playing around with this: > > This one is accepted: > > static __attribute__((__pure__)) int pure1(void) > { > int i = 0; > return i; > } > > This one is not accepted: > > static __attribute__((__pure__)) void *pure2(void) > { > void *i = (void *)0; > return i; > } > Thanks for the test case. I have commit your test case with a bit more test case regarding function pointer assign. The change is in chrisl repository reveiw-pure-attr branch: https://git.kernel.org/cgit/devel/sparse/chrisl/sparse.git/log/?h=review-pure-attr I purpose this fix for it. It can pass your test case. This patch limit the pure attribute to functions. The pure bit should not be a modifier in the first place. But that is a much bigger change. Can you please help me test and review the change? Chris --- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/evaluate.c b/evaluate.c index 035e448..4c8b64a 100644 --- a/evaluate.c +++ b/evaluate.c @@ -632,6 +632,8 @@ const char *type_difference(struct ctype *c1, struct ctype *c2, struct symbol *t1 = c1->base_type; struct symbol *t2 = c2->base_type; int move1 = 1, move2 = 1; + unsigned long ignore = ~MOD_PURE; + mod1 |= c1->modifiers; mod2 |= c2->modifiers; for (;;) { @@ -728,6 +730,7 @@ const char *type_difference(struct ctype *c1, struct ctype *c2, as1 = t1->ctype.as; mod2 = t2->ctype.modifiers; as2 = t2->ctype.as; + ignore = ~0; if (base1->variadic != base2->variadic) return "incompatible variadic arguments"; @@ -778,7 +781,7 @@ const char *type_difference(struct ctype *c1, struct ctype *c2, } if (as1 != as2) return "different address spaces"; - if ((mod1 ^ mod2) & ~MOD_IGNORE & ~MOD_SIGNEDNESS) + if ((mod1 ^ mod2) & ~MOD_IGNORE & ~MOD_SIGNEDNESS & ignore) return "different modifiers"; return NULL; } diff --git a/show-parse.c b/show-parse.c index fb54375..f274431 100644 --- a/show-parse.c +++ b/show-parse.c @@ -326,6 +326,7 @@ deeper: was_ptr = 0; } append(name, "( ... )"); + mod = sym->ctype.modifiers; break; case SYM_STRUCT: