Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp53233imu; Mon, 19 Nov 2018 17:35:08 -0800 (PST) X-Google-Smtp-Source: AFSGD/UA6dgVDxOjS49eIMJsYgy+mZswCasQjgQW4gNiyEgmaDBw/skYicyr+whUTMYqgIWsFZvr X-Received: by 2002:a17:902:9a81:: with SMTP id w1-v6mr53179plp.121.1542677708263; Mon, 19 Nov 2018 17:35:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542677708; cv=none; d=google.com; s=arc-20160816; b=Kv4O5AvQoy4YCg3oj5oaeOpZ4ZWA23NCBYGEGmJYJEiCODIDtYdL3nDKl7buHoXwob wORWOMaFzf8prO62hDO8EJiYkk8hkdSqq0EzrbUFFY0MAEZkmJjJ6j1D/hVBq+nXGLbf Xuq9+o/VvpsoCan1P/9KPUGsNo2MrWaRKUsSXCu5to8/heYywPUKdg+K/M3kIOEkWkua BHbLSZF9cS/sqp10JvLO2JiM5XGumyEzG+jIsnxtl+xY9JBB5VuS5mtD/lBS6KMGbobe RerxjHa+RbKXI1Hw8fsVhYlsKUejw8fifEO8RGANCYKDnyLdzHZ0VpaD565x0KfpRTm3 Hbhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature:dkim-filter; bh=PwZNHY2T5e6fraX8J2a9TUhGJWKSVLwRTSBfNlG6ytg=; b=rsdCIWUboU6Y7G7KmsyDkuAreYrXDTCCR1cPQUVuQFq20kx+fft0VPW3QUv04kFboK WEhnMH9yrKhSR0knSItb8RpQ7cFooYayNdtAK3zKskzRzcETfpfGHBqTL2a2fI6Ykkbv TiqpdcT3ghr1hxuXEAB8VzQAzUO1y3xzTSbKaWSSOIY0J4PL8oLA6tDqqArHjoBAN1eJ eW0E/EIXKO+UBBUBFojXyMm9DHoowH/Wl/A3+YZr7jObWU/ioSmrsRp1+NYW4vTok7w6 pdOnXGNjx0gTMy6yAp2h/lfPsYUI+nvKONZMf3SOcs3IGWbD0bvtExSa4k2RSGtmC26o m/6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=TstsiSgr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10si23782976pll.179.2018.11.19.17.34.50; Mon, 19 Nov 2018 17:35:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=TstsiSgr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730527AbeKTMAH (ORCPT + 99 others); Tue, 20 Nov 2018 07:00:07 -0500 Received: from conssluserg-02.nifty.com ([210.131.2.81]:25488 "EHLO conssluserg-02.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726119AbeKTMAG (ORCPT ); Tue, 20 Nov 2018 07:00:06 -0500 Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) (authenticated) by conssluserg-02.nifty.com with ESMTP id wAK1XGJm000409 for ; Tue, 20 Nov 2018 10:33:17 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com wAK1XGJm000409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1542677597; bh=PwZNHY2T5e6fraX8J2a9TUhGJWKSVLwRTSBfNlG6ytg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=TstsiSgr5RcClFrqlgD2V6RQMUMJE5EOJRD3VCEbVWep9zCPedl8s6fh/vOW7TIBC 8kRSIA1asoaLLoKH8K06iGL2+QwsR/LpkRMPFIx7oBr+a1IwNA8mjOi49PUYhenQpj 2Ex7IT2njVklGqXRQXzh2GpUJpMXUOcrnAnldb+GzcWgj8PiVkCNmSzNaYdaVLe2KI fm0Fx93/DXpgLPKyPodLIQ9S3hgLzWpQHAclc4UMgyG/n7tChhdfBV4WJEmj1KY6VO QUwLgO2GEPIkPTf6JtrxTEBhvf84X8t8eCkpvxaYVWTOGu9iH6VwkDNnJ9qpzgICLu NSoHZDvrShzbQ== X-Nifty-SrcIP: [209.85.217.44] Received: by mail-vs1-f44.google.com with SMTP id h18so160413vsj.4 for ; Mon, 19 Nov 2018 17:33:17 -0800 (PST) X-Gm-Message-State: AA+aEWa15m5m7XiRDQTMnTSDFIFbfSIqsfhkntBivMzsUIGxK/+vNEta 55hgvm/JT26OmXSCFF0YiAgLFwV+MAw0vuoQMZ8= X-Received: by 2002:a67:485:: with SMTP id 127mr28319vse.54.1542677596203; Mon, 19 Nov 2018 17:33:16 -0800 (PST) MIME-Version: 1.0 References: <1542623503-3755-1-git-send-email-yamada.masahiro@socionext.com> <20181119123334.6xr23ok4uy5cflzy@ltop.local> In-Reply-To: <20181119123334.6xr23ok4uy5cflzy@ltop.local> From: Masahiro Yamada Date: Tue, 20 Nov 2018 10:32:40 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 1/3] compiler_types.h: make __builtin_types_compatible_p() noop for Sparse To: Luc Van Oostenryck Cc: Andrew Morton , Nick Desaulniers , Kees Cook , Josh Triplett , Miguel Ojeda , Arnd Bergmann , Linux Kernel Mailing List , Paul Burton Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 19, 2018 at 9:35 PM Luc Van Oostenryck wrote: > > On Mon, Nov 19, 2018 at 07:31:41PM +0900, Masahiro Yamada wrote: > > When I tried to delete BUILD_BUG_ON stubs for sparse, the kbuild test > > robot reported lots of Sparse warnings from container_of(), which > > seem false positive. > > > > The following checker in container_of() seems to be causing something > > strange for Sparse. > > > > BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \ > > !__same_type(*(ptr), void), \ > > "pointer type mismatch in container_of()"); \ > > > > I narrowed down the problem into the following test code: > > > > --------------------(test_code.c begin)-------------------- > > struct foo { > > int (*callback)(void); > > }; > > > > void assert(int); > > > > static inline struct foo *get_foo(void) > > { > > assert(__builtin_types_compatible_p(void, void)); > > > > return (struct foo *)0; > > } > > > > int test(void); > > int test(void) > > { > > return get_foo()->callback(); > > } > > ---------------------(test_code.c end)--------------------- > > > > Of course, GCC (and Clang as well) can compile it: > > > > $ gcc -Wall -c -o test_code.o test_code.c > > > > However, Sparse complains about this obviously correct code: > > > > $ sparse test_code.c > > test_code.c:9:45: warning: unknown expression (4 0) > > test_code.c:9:51: warning: unknown expression (4 0) > > > > Interstingly, just removing the 'inline' keyword in the test code > > makes Sparse happy. > > > > I concluded that Sparse cannot handle __builtin_types_compatible_p() > > correctly. > > I think it's only caused by comparing 'void' (which is never > an l-value). > I'll investigate. Thanks for the small test-case. Yes, please. > > Make it no-op. > > ... > > > diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h > > index 4a3f9c0..9e7da0b 100644 > > --- a/include/linux/compiler_types.h > > +++ b/include/linux/compiler_types.h > > @@ -23,6 +23,7 @@ > > extern void __chk_user_ptr(const volatile void __user *); > > extern void __chk_io_ptr(const volatile void __iomem *); > > # define ACCESS_PRIVATE(p, member) (*((typeof((p)->member) __force *) &(p)->member)) > > +# define __builtin_types_compatible_p(t1, t2) (1) > > Now, BUILD_BUG_ON() becomes a no-op for sparse but all the other usages > of __builtin_types_compatible_p() become potentially wrong and can now > create their onw false warnings. You are right. This patch is probably a bad idea. Thanks. -- Best Regards Masahiro Yamada