From patchwork Fri Sep 6 14:53:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Triplett X-Patchwork-Id: 2854558 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 26029C0AB5 for ; Fri, 6 Sep 2013 16:46:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 718C92011E for ; Fri, 6 Sep 2013 16:46:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23EEE20108 for ; Fri, 6 Sep 2013 16:46:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753584Ab3IFOx2 (ORCPT ); Fri, 6 Sep 2013 10:53:28 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:44738 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752922Ab3IFOx1 (ORCPT ); Fri, 6 Sep 2013 10:53:27 -0400 Received: from mfilter27-d.gandi.net (mfilter27-d.gandi.net [217.70.178.155]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id C21441720B3; Fri, 6 Sep 2013 16:53:25 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter27-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter27-d.gandi.net (mfilter27-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 5Pmx80opYRmu; Fri, 6 Sep 2013 16:53:24 +0200 (CEST) X-Originating-IP: 50.43.39.152 Received: from leaf (static-50-43-39-152.bvtn.or.frontiernet.net [50.43.39.152]) (Authenticated sender: josh@joshtriplett.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 283DA172080; Fri, 6 Sep 2013 16:53:22 +0200 (CEST) Date: Fri, 6 Sep 2013 07:53:21 -0700 From: Josh Triplett To: linux-sparse@vger.kernel.org Cc: paulmck@linux.vnet.ibm.com Subject: Bug: "typeof(*p) *" drops const Message-ID: <20130906145320.GA26549@leaf> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 The following test case compiles via GCC with no errors or warnings, but generates a type warning with sparse: void f(void); void f(void) { const int *pc; typeof(*pc) *pc2 = pc; } Sparse says: typeof-const.c:5:24: warning: incorrect type in initializer (different modifiers) typeof-const.c:5:24: expected int *pc2 typeof-const.c:5:24: got int const *pc Since pc has type "const int *", "typeof(*pc) *" should also have type "const int *", not "int *". The actual use case for which this came up occurred in the kernel when using the equivalent of: typeof(*p) __attribute__((address_space(0),force)) * to generate the same type as p but in address space 0 rather than whatever address space p had. That worked fine for non-const pointers, but const pointers lost their constness, resulting in constness warnings. The following patch adds a test case for this; please apply once sparse handles this case correctly: ---------->8---------- From: Josh Triplett Subject: [PATCH] validation: Add new test case for typeof(*ptr) preserving const If ptr has type "const foo *", then "typeof(*ptr) *" should also have type "const foo *", not "foo *". Add a test to ensure that. Signed-off-by: Josh Triplett --- validation/typeof-const.c | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 validation/typeof-const.c diff --git a/validation/typeof-const.c b/validation/typeof-const.c new file mode 100644 index 0000000..d02d39a --- /dev/null +++ b/validation/typeof-const.c @@ -0,0 +1,9 @@ +void f(void); +void f(void) +{ + const int *pc; + typeof(*pc) *pc2 = pc; +} +/* + * check-name: typeof-const.c + */