From: Nick Desaulniers <ndesaulniers@google.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Markus Elfring <Markus.Elfring@web.de>,
kernel-janitors@vger.kernel.org,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Joe Perches <joe@perches.com>, Kees Cook <keescook@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] string.h: Mark 34 functions with __must_check
Date: Wed, 9 Oct 2019 09:31:41 -0700 [thread overview]
Message-ID: <CAKwvOd=Jkd_qJULB+i1u31VJAex6KB=wFAyXO04V0UcAAEZeXw@mail.gmail.com> (raw)
In-Reply-To: <20191009143000.GD13286@kadam>
On Wed, Oct 9, 2019 at 7:30 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> On Wed, Oct 09, 2019 at 04:21:20PM +0200, Rasmus Villemoes wrote:
> > On 09/10/2019 15.56, Dan Carpenter wrote:
> > > That's because glibc strlen is annotated with __attribute_pure__ which
> > > means it has no side effects.
> >
> > I know, except it has nothing to do with glibc headers. Just try the
> > same thing in the kernel. gcc itself knows this about __builtin_strlen()
> > etc. If anything, we could annotate some of our non-standard functions
> > (say, memchr_inv) with __pure - then we'd both get the Wunused-value in
> > the nonsense cases, and allow gcc to optimize or reorder the calls.
>
> Huh. You're right. GCC already knows. So this patch is pointless like
> you say.
Is it? None of the functions in include/linux/string.h are currently
marked __pure today. (Side note, I'm surprised that any function that
accepts a pointer could be considered pure. I could reassign pointed
to value without changing the pointers value. I can see strlen being
"pure" for string literals, but not for char[]. This is something
I'll play with more, I've already spotted one missed optimization in
LLVM: https://bugs.llvm.org/show_bug.cgi?id=43624).
I think it would be an interesting study to see how often functions
that have return codes are ok to not check vs aren't ok (in a large
production codebase like the Linux kernel), similar to how 97% of
cases fallthrough is unintentional (which to me sounds like maybe the
default behavior of the language is incorrect).
--
Thanks,
~Nick Desaulniers
next prev parent reply other threads:[~2019-10-09 16:31 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-09 12:14 [PATCH] string.h: Mark 34 functions with __must_check Markus Elfring
2019-10-09 13:26 ` Rasmus Villemoes
2019-10-09 13:56 ` Dan Carpenter
2019-10-09 14:21 ` Rasmus Villemoes
2019-10-09 14:30 ` Dan Carpenter
2019-10-09 16:31 ` Nick Desaulniers [this message]
2019-10-09 18:45 ` Dan Carpenter
2019-10-10 7:20 ` Rasmus Villemoes
2019-10-09 16:37 ` Nick Desaulniers
2019-10-09 16:42 ` Markus Elfring
2019-10-11 5:15 ` Searching for missing variable checks Markus Elfring
2019-10-09 15:09 ` [PATCH] string.h: Mark 34 functions with __must_check Steven Rostedt
2019-10-09 16:13 ` Nick Desaulniers
2019-10-09 16:27 ` Steven Rostedt
2019-10-09 16:40 ` Nick Desaulniers
2019-10-09 17:04 ` Markus Elfring
2019-10-09 17:33 ` Nick Desaulniers
2019-10-09 18:06 ` Markus Elfring
2019-10-09 16:38 ` [PATCH] " Joe Perches
2019-10-09 17:33 ` Nick Desaulniers
2019-10-10 14:27 ` David Sterba
2019-10-10 14:34 ` Joe Perches
2019-10-11 5:00 ` Markus Elfring
2019-10-10 15:46 ` [PATCH] " David Laight
2019-10-09 20:06 ` Markus Elfring
2019-10-10 5:29 ` Andy Shevchenko
2019-10-10 7:25 ` Markus Elfring
2019-12-21 9:30 ` Markus Elfring
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='CAKwvOd=Jkd_qJULB+i1u31VJAex6KB=wFAyXO04V0UcAAEZeXw@mail.gmail.com' \
--to=ndesaulniers@google.com \
--cc=Markus.Elfring@web.de \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dan.carpenter@oracle.com \
--cc=joe@perches.com \
--cc=keescook@chromium.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=rostedt@goodmis.org \
/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;
as well as URLs for NNTP newsgroup(s).