From: David Laight <David.Laight@ACULAB.COM>
To: 'Nick Desaulniers' <ndesaulniers@google.com>,
Ian Rogers <irogers@google.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Nick Desaulniers <nick.desaulniers@gmail.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
clang-built-linux <clang-built-linux@googlegroups.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
Jin Yao <yao.jin@linux.intel.com>,
Changbin Du <changbin.du@intel.com>,
John Keeping <john@metanate.com>,
Song Liu <songliubraving@fb.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] perf: fix -Wstring-compare
Date: Tue, 25 Feb 2020 09:35:27 +0000 [thread overview]
Message-ID: <7fe0ca3e6fb64ca59986584fffa824e6@AcuMS.aculab.com> (raw)
In-Reply-To: <CAKwvOdko+Qb=h_Pm=oFUnsiBg7Am9u=Z83g8cNyY1QZQS=Mh7g@mail.gmail.com>
From: Nick Desaulniers
> Sent: 24 February 2020 22:06
> On Mon, Feb 24, 2020 at 10:20 AM 'Ian Rogers' via Clang Built Linux
> <clang-built-linux@googlegroups.com> wrote:
> >
> > On Mon, Feb 24, 2020 at 8:03 AM David Laight <David.Laight@aculab.com> wrote:
> > >
> > > From: Ian Rogers
> > > > Sent: 24 February 2020 05:56
> > > > On Sun, Feb 23, 2020 at 11:35 AM Nick Desaulniers
> > > > <nick.desaulniers@gmail.com> wrote:
> > > > >
> > > > > Clang warns:
> > > > >
> > > > > util/block-info.c:298:18: error: result of comparison against a string
> > > > > literal is unspecified (use an explicit string comparison function
> > > > > instead) [-Werror,-Wstring-compare]
> > > > > if ((start_line != SRCLINE_UNKNOWN) && (end_line != SRCLINE_UNKNOWN)) {
> > > > > ^ ~~~~~~~~~~~~~~~
> > > > > util/block-info.c:298:51: error: result of comparison against a string
> > > > > literal is unspecified (use an explicit string comparison function
> > > > > instead) [-Werror,-Wstring-compare]
> > > > > if ((start_line != SRCLINE_UNKNOWN) && (end_line != SRCLINE_UNKNOWN)) {
> > > > > ^ ~~~~~~~~~~~~~~~
> > > > > util/block-info.c:298:18: error: result of comparison against a string
> > > > > literal is unspecified (use an explicit string
> > > > > comparison function instead) [-Werror,-Wstring-compare]
> > > > > if ((start_line != SRCLINE_UNKNOWN) && (end_line != SRCLINE_UNKNOWN)) {
> > > > > ^ ~~~~~~~~~~~~~~~
> > > > > util/block-info.c:298:51: error: result of comparison against a string
> > > > > literal is unspecified (use an explicit string comparison function
> > > > > instead) [-Werror,-Wstring-compare]
> > > > > if ((start_line != SRCLINE_UNKNOWN) && (end_line != SRCLINE_UNKNOWN)) {
> > > > > ^ ~~~~~~~~~~~~~~~
> > > > > util/map.c:434:15: error: result of comparison against a string literal
> > > > > is unspecified (use an explicit string comparison function instead)
> > > > > [-Werror,-Wstring-compare]
> > > > > if (srcline != SRCLINE_UNKNOWN)
> > > > > ^ ~~~~~~~~~~~~~~~
> > > > >
> > > > > Link: https://github.com/ClangBuiltLinux/linux/issues/900
> > > > > Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
> > > > > ---
> > > > > Note: was generated off of mainline; can rebase on -next if it doesn't
> > > > > apply cleanly.
> >
> > Reviewed-by: Ian Rogers <irogers@google.com>
> >
> > > > Looks good to me. Some more context:
> > > > https://clang.llvm.org/docs/DiagnosticsReference.html#wstring-compare
> > > > The spec says:
> > > > J.1 Unspecified behavior
> > > > The following are unspecified:
> > > > .. Whether two string literals result in distinct arrays (6.4.5).
> > >
> > > Just change the (probable):
> > > #define SRCLINE_UNKNOWN "unknown"
> > > with
> > > static const char SRC_LINE_UNKNOWN[] = "unk";
> > >
> > > David
> >
> >
> > The SRCLINE_UNKNOWN is used to convey information. Having multiple
> > distinct pointers (static) would mean the compiler could likely remove
> > all comparisons as the compiler could prove that pointer is never
> > returned by a function - ie comparisons are either known to be true
> > (!=) or false (==).
>
> I wouldn't define a static string in a header. Though I could:
> 1. forward declare it in the header with extern linkage.
> 2. define it in *one* .c source file.
>
> Thoughts on that vs the current approach?
The string compares are just stupid.
If the 'fake' strings are not printed you could use:
#define SRCLINE_UNKNOWN ((const char *)1)
Otherwise defining the strings in one of the C files is better.
Relying on the linker to merge the strings from different compilation
units is so broken...
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2020-02-25 9:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-23 19:34 [PATCH] perf: fix -Wstring-compare Nick Desaulniers
2020-02-24 5:55 ` Ian Rogers
2020-02-24 16:03 ` David Laight
2020-02-24 18:19 ` Ian Rogers
2020-02-24 22:05 ` Nick Desaulniers
2020-02-25 9:35 ` David Laight [this message]
2020-02-25 21:28 ` Nick Desaulniers
2020-03-03 20:06 ` Arnaldo Carvalho de Melo
2020-03-07 7:36 ` [tip: perf/urgent] perf diff: Fix undefined string comparision spotted by clang's -Wstring-compare tip-bot2 for Nick Desaulniers
2020-03-19 14:10 ` [tip: perf/core] perf diff: Fix undefined string comparison " tip-bot2 for Nick Desaulniers
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=7fe0ca3e6fb64ca59986584fffa824e6@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=changbin.du@intel.com \
--cc=clang-built-linux@googlegroups.com \
--cc=irogers@google.com \
--cc=john@metanate.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=ndesaulniers@google.com \
--cc=nick.desaulniers@gmail.com \
--cc=peterz@infradead.org \
--cc=songliubraving@fb.com \
--cc=yao.jin@linux.intel.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