mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Kees Cook <keescook@chromium.org>,
	Josh Triplett <josh@joshtriplett.org>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-kernel@vger.kernel.org, Paul Burton <paul.burton@mips.com>
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	[thread overview]
Message-ID: <1542623503-3755-1-git-send-email-yamada.masahiro@socionext.com> (raw)

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 <yamada.masahiro@socionext.com>
---

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


             reply	other threads:[~2018-11-19 10:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-19 10:31 Masahiro Yamada [this message]
2018-11-19 10:31 ` [PATCH v3 2/3] build_bug.h: remove negative-array fallback for BUILD_BUG_ON() Masahiro Yamada
2018-11-19 18:10   ` Nick Desaulniers
2018-11-19 10:31 ` [PATCH v3 3/3] build_bug.h: remove most of dummy BUILD_BUG_ON stubs for sparse Masahiro Yamada
2018-11-19 12:37   ` Luc Van Oostenryck
2018-11-19 18:00     ` Nick Desaulniers
2018-11-20  1:30       ` Masahiro Yamada
2018-11-19 12:33 ` [PATCH v3 1/3] compiler_types.h: make __builtin_types_compatible_p() noop for Sparse Luc Van Oostenryck
2018-11-20  1:32   ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1542623503-3755-1-git-send-email-yamada.masahiro@socionext.com \
    --to=yamada.masahiro@socionext.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=josh@joshtriplett.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=ndesaulniers@google.com \
    --cc=paul.burton@mips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®