Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2683467imu; Mon, 19 Nov 2018 04:35:08 -0800 (PST) X-Google-Smtp-Source: AJdET5dI61tFUrbhH2Fcfg91soCi3Mwyspi8L5WDEg6rsJoTJePnWakKiRR+cuLyS1cjRaHEqxj3 X-Received: by 2002:a65:6684:: with SMTP id b4mr20012362pgw.55.1542630908428; Mon, 19 Nov 2018 04:35:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542630908; cv=none; d=google.com; s=arc-20160816; b=btOgWoJHdEqGq0YvQo/Uc2k5pOWF3BwVSWjoru3H5A3hSyZWYnwejTt7ObLVrQIqCZ Lx88eL5pN4LJu5BHIF27UXlcf2JPQSoG5L0cDYmYXlLvUya8e7nlKt7Z06nUO++nae5Y X2KkehplAbC3OfNfa5E7y1UhAQCaLPAJPX9msUa0MN/lUYrdF+tD2U0O9WE1HbTL8nkP WSZXt0/x+He6SJ5jhu6Z1zP2b8GUBPVAm/QgoTDyY/oOPOJ6w7ow+BSlK3Da/Dd65DN0 4ps4S9mJNMFrzQ2Durd+0XZfoASwNtgTTFSWPGA20/9yQJM0iXqTU1WSu/r9YmnBD2yG ZMGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=P4erMxhSlJRHXScbxu8vIKD/vSBKXPVjgIvKfS8Ijts=; b=gDOMR3TkTh4JOwgTkxqsBgKA0ihvK2Ek2lXhKCr+wNC+ps7NFPKtXE7+Xfmpue89rU 7tDa4KHA3DlgFnKv8IvQEL3X80d+i5ReCJzTWwjHp4NMkWUtRhJxLQsh9M3ccEJ7vkLK fhuN5IdDL50/HR3Q6ob8dNngt4yko2LOks8Wiz930xdqrj61TRu9dMpnKy1SZiYi7/sJ IL7O1Eu7KthUnnX3ouEkMQhHWx6sDC6rOG5a96f88Xdqt7XKgjts/IoyroXc95Nn2tAw B0eEm8JMA0XNDKm1CMpuAuDQzQ2JOohJJ2bHb9oKU0jLsvYJOqM9mWgMEC58peuwGt5f IOog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YodFXbBT; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gn7si20944585plb.321.2018.11.19.04.34.53; Mon, 19 Nov 2018 04: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=@gmail.com header.s=20161025 header.b=YodFXbBT; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728812AbeKSW5J (ORCPT + 99 others); Mon, 19 Nov 2018 17:57:09 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:33278 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728721AbeKSW5J (ORCPT ); Mon, 19 Nov 2018 17:57:09 -0500 Received: by mail-ed1-f66.google.com with SMTP id r27so22259289eda.0 for ; Mon, 19 Nov 2018 04:33:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=P4erMxhSlJRHXScbxu8vIKD/vSBKXPVjgIvKfS8Ijts=; b=YodFXbBTQ2ZanMQVqU8ai4IiO685Ihr5vU5mZLnBHBeWDGmRcktqUxUAnwaOMil1RL BO2JHTf7UmE49WqY4jWaUrYVqmZveq9F1Htw5Pb3V2GxoxTvotSqNjNdCgkk6ExzeKae PXxo4p5f8FwNiYvpI/pQS4tj8D43BEdqXloAFCv5WYYY2AGSzFOnoRlTekmM11wakBU8 +OCD4L6Qt0omCYbznhfA8QMufn+jfGckpxGVZn0tVLAacZ2oONMKLE92GQxMDBbBrf9M E1nfdJSV3nzQMTHPiFJuiSQ8zWGV2AuTRHYVIMXlDJ2c/H7rykw+A7s2i67iPZrszyGq 4kWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=P4erMxhSlJRHXScbxu8vIKD/vSBKXPVjgIvKfS8Ijts=; b=RDb6dGEr0YkUtTMwTk+kX+G2c/lQSoxDuTN5zwVuYoL4lHZCdf3Rgn6J1u2PwFhvCR dpOB7T/i2t+/BBKnQSuOaU6YOdKBMNMi/vtwYzpbXCH/u3tX7CGQBvr8vuUmIFA6xgmZ aBreqWi61IAsbt/3pgNimQL9+h5RCGErf3OqEeJD2Lj0XSGao8UzARL/xH0NkMpKlFmT twhkuhxI8i/wNfOvQDPP5UHezNk+pHtpdDDymCTIYDCKBxnRUh7Zw07boJEByE2zHUX0 7JhlSxjcT5XFm3CfqVDsZro6fipv9YZpBaiqgXCuUpyS/L12wNczzdWDBx03byQIOQQm cFLw== X-Gm-Message-State: AGRZ1gKxF+j67btUYEqD1wgfjDCWvDChBiwrw9ywYGEmEz1fhE3q0MD8 Bv+icGUuAjL/Ykj2NBr4Akk= X-Received: by 2002:a17:906:2452:: with SMTP id a18-v6mr16304675ejb.17.1542630817836; Mon, 19 Nov 2018 04:33:37 -0800 (PST) Received: from ltop.local ([2a02:a03f:40bc:4d00:b8ae:204:75e7:9858]) by smtp.gmail.com with ESMTPSA id x58sm9840318edm.10.2018.11.19.04.33.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 04:33:37 -0800 (PST) Date: Mon, 19 Nov 2018 13:33:36 +0100 From: Luc Van Oostenryck To: Masahiro Yamada Cc: Andrew Morton , Nick Desaulniers , Kees Cook , Josh Triplett , Miguel Ojeda , Arnd Bergmann , linux-kernel@vger.kernel.org, Paul Burton Subject: Re: [PATCH v3 1/3] compiler_types.h: make __builtin_types_compatible_p() noop for Sparse Message-ID: <20181119123334.6xr23ok4uy5cflzy@ltop.local> References: <1542623503-3755-1-git-send-email-yamada.masahiro@socionext.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1542623503-3755-1-git-send-email-yamada.masahiro@socionext.com> User-Agent: NeoMutt/20180622 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 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. > 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. Regards, -- Luc