Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2562857imu; Mon, 19 Nov 2018 02:33:56 -0800 (PST) X-Google-Smtp-Source: AJdET5eGPNWDRs829QlLDSn3RlnkSD0GCcfvXHA3kaxJTEFl18I/T52+G5gau2fF7eHzPQTDSbTY X-Received: by 2002:a17:902:622:: with SMTP id 31-v6mr21947981plg.310.1542623636472; Mon, 19 Nov 2018 02:33:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542623636; cv=none; d=google.com; s=arc-20160816; b=XzVOry3ngJQgp7dnTE/k0urtLHI0EwvBFfqbDDQaIbuvOERpVeezMoIuHuQh2zQncn nVZhc6S/oczOfh23bdkARCVyqCkLvs2RHsQy7IBtW25Vi+OQFOU9R7xh4qNPvyJM9ov2 1TgodcNLe6aJ9IYXKE+5YngR8f8nrcCEibZsLJU3SraLgVzJruYGTiYtdhis6OKcrz6V VQwNHuCqx+pXAl7NxA3Pr4/QvsLdW8yRgzdKCToJ06qlu9oZfhuSAlHh64u1zE7iuJpe qeiUhV5YU9rNtHYjx9JYMwoblaDBz0dzgxILQKZpJmr5zyS+tAAihZTjk1BaTWM00gH7 qyIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=+LKuroFmzxn4Iv2kghmjy3Fv1P/6HtUAjZsqkO5MVRA=; b=fQzceRhcb1+WET0wA9koyzxbbFayT5HfFvtBG/ZPHysJnQphcj01nmDZUpXXGslfyC j4EpI22t8MyBYwOkU1PoIa6yzZ1lC4WPb3lH/m09vV4do2IUB/CTi9AZxlj4aGZv83wO S0ED4yb/5NPBnZwje43lUSy/giN3PR356NdqULhc1qgkHczxsEe8BbCv20/s/T8RksVb bkTRzx6t4fPPnHmsfY6wfgGtiDbDMycETtwjKWslRbJnMVqAu4QmOmvJoXJVZGYAVwI2 O4bX7nZry7L0ciJ9OmLwAW5obyK97nBCKkijYHsp9fLZouuG4c17xicEtB1CqNytvM7X XfcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="d8aQTDU/"; 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 u16si10217139plk.192.2018.11.19.02.33.41; Mon, 19 Nov 2018 02:33:56 -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="d8aQTDU/"; 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 S1727774AbeKSU4A (ORCPT + 99 others); Mon, 19 Nov 2018 15:56:00 -0500 Received: from conuserg-11.nifty.com ([210.131.2.78]:59555 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727352AbeKSUz7 (ORCPT ); Mon, 19 Nov 2018 15:55:59 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id wAJAVrOA009918; Mon, 19 Nov 2018 19:31:53 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com wAJAVrOA009918 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1542623513; bh=+LKuroFmzxn4Iv2kghmjy3Fv1P/6HtUAjZsqkO5MVRA=; h=From:To:Cc:Subject:Date:From; b=d8aQTDU/NnCbJq5jalDLUcMb2UiQovuCMj/IjNJ5UQNLASRDggGDCEDPn5dyVcKK3 We7Ydll0cr8h2P/91yTboxcU+ochBe6DlhOQCuDFIAs+TVHegFR5l/dWFgwXrLUNSz MxFV3e/YIZgTMyii7Rn+wvgukt4zxMRJxAvS8NER9gkCJ0UUfMbRvNFbnvnIIoYyji THUH3cFofmWWpJi3UjBS3J1vcdlWudY111h50gWE9MRTFSXtLREIm2mm24hGd3GJfi 8vqZleQT2N882diV6fYdWtRJFwgKvQGTiKaF09jDkNzyRaxVBN34ep7BivZGVDgCbl qXGrlm+hv/ZkQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Andrew Morton Cc: Luc Van Oostenryck , Nick Desaulniers , Kees Cook , Josh Triplett , Masahiro Yamada , Miguel Ojeda , Arnd Bergmann , linux-kernel@vger.kernel.org, Paul Burton Subject: [PATCH v3 1/3] compiler_types.h: make __builtin_types_compatible_p() noop for Sparse Date: Mon, 19 Nov 2018 19:31:41 +0900 Message-Id: <1542623503-3755-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Make it no-op. Signed-off-by: Masahiro Yamada --- Changes in v3: - New patch Changes in v2: None include/linux/compiler_types.h | 1 + 1 file changed, 1 insertion(+) 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) #else /* __CHECKER__ */ # ifdef STRUCTLEAK_PLUGIN # define __user __attribute__((user)) -- 2.7.4