Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2065054ybv; Sun, 23 Feb 2020 21:56:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxexKe2JegiAjZpl8LD59FcnZ3LnNEsGFMb2st+SILS1kL96deNgERb22hhbvFEErfFN1lU X-Received: by 2002:a9d:f26:: with SMTP id 35mr36893729ott.31.1582523798788; Sun, 23 Feb 2020 21:56:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582523798; cv=none; d=google.com; s=arc-20160816; b=BxiI3vUfZtOWaMecz0JZ0a2IxsgoqdmZV/68+rxh4307Z9SGCIkDch4Wdfd4Y+sqKM g7xjPuu3CNu1QX575DOxh1/82zN+f8nl9Co2BjD9IXFFsYLP1xyaq8sS2rawpDk4YCal 9S6YVslfNnTXFXdpsDRySkBYvRG/BBjgfJNMSRSYTD+JAZE/7gHFlEn6jYZR5QjQecXC Fph7CKZI9nowJ7uB07SpNgH6P02s7ddd9uUaSZjbh6FRIqa/85wv3eb8AaoJSPbORCwQ lXCxCYcMX5hHTxYIxdhlX/nEWaA+O9pcYqOsVkY72auV2K+YK5xPbKkiOqtMTB5GC2nR HWvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=b50opdvh9jm466J7F1sa7QuBxXpc5U92ofilJPUB76Y=; b=PzrcAHHYcroSCNLJnfQ4BWMak2UtjkstwXfu81VLvn2b5BjzJ7J4ujZDaT8CmniFmp MhKvsDkArGQ9DtBiB2KrweVd43EBEMEc7NI7K6oNKdsd6A04Mbu2yW2jyIq/pB1kPJIA xWkXNrqIOuWHGA1oh1k3v1Xqr1og+vZuPouY/g+b/nzaZ4+2REjj/WUwIR/f+IIqg5QG GRm5974IC7yKV+HkipE1zGCxq9QveoMsjEmJtrxO8Hg8OJdYxDUo9O/+jt4X5fHNYZ6I SJN+wPSxaiZU8eT04VOK5KpX7CZzhGaSMA8+rc+heSpLMZ4SrTrXXCJhtnMtpjg2Cp8N DtoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vMtEDPiR; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w13si5486842oti.291.2020.02.23.21.56.26; Sun, 23 Feb 2020 21:56:38 -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=@google.com header.s=20161025 header.b=vMtEDPiR; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726543AbgBXFzw (ORCPT + 99 others); Mon, 24 Feb 2020 00:55:52 -0500 Received: from mail-yw1-f65.google.com ([209.85.161.65]:42992 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725535AbgBXFzw (ORCPT ); Mon, 24 Feb 2020 00:55:52 -0500 Received: by mail-yw1-f65.google.com with SMTP id b81so4716391ywe.9 for ; Sun, 23 Feb 2020 21:55:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=b50opdvh9jm466J7F1sa7QuBxXpc5U92ofilJPUB76Y=; b=vMtEDPiRSrn97MCHsZemUW67l00xqKMpFOP9SgWcFfp44cStOUr2x0NzA0emhvsCYg FNnOQEgL81YSrQgR5UTLu9GPE8m+x7vdAdn4OdQwEKh2Rec+ABhVqw8evDVswTmR9e7f mgKI1y+DYHmsUuAVT7jZ+cCmNMJeA6hSlRaFi8SCxke72cCBuRxr75yoMbsULSc2D55q 7kw7tzqBXKYpctw0tp3CJycVHF6a9/PMtBNLKqheJvosiDwo3pJeAILgbV5domqx2zuz uQoTGk8r8MzZwtbm/YA0vyQNzWqA1XLGDf8xXO4sJq0JwH2dzmwBy3uBfISBo8vmBslJ wTpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=b50opdvh9jm466J7F1sa7QuBxXpc5U92ofilJPUB76Y=; b=fsBIF1n92yseSstOkWmGjEEAQNrx9rrbMLydTM6fNrHHjShEQqA7iqrJnMDtg+4F7M OvLzbNxwsRfy69i6JCNnCx4RulXU0Wwphk4/1YA2tKazKbHJ5O2hRxtOK4bOSDIH0xaP Sm9I1NTphHIPof/2TouAMIGjBXgt/HbcHUnCT+jEgxr74PS2lLAdC42uUE5jEajZXcmO OtUmI4PJd6SgMEBp80dHsE/xdj8/w/XLFdHqnYloIdzSITaXlO4ajdTc7NahF2ONpLV0 xxnx8PI82W2kFAdQp6KA7nPQvxlJE4jeaR96/3kSfKabdLftwlJR6DMuliRZMOXEirTk SYwg== X-Gm-Message-State: APjAAAVzPizLG10Oo6Dr7K2qoDRgNf0PtONUiQqP5La/RkxHCRE9Gkir /CZcQ9OF5Opoyivx3qbJl1i/q+0RP8W9wZcioANLZA== X-Received: by 2002:a81:3694:: with SMTP id d142mr39726193ywa.392.1582523749424; Sun, 23 Feb 2020 21:55:49 -0800 (PST) MIME-Version: 1.0 References: <20200223193456.25291-1-nick.desaulniers@gmail.com> In-Reply-To: <20200223193456.25291-1-nick.desaulniers@gmail.com> From: Ian Rogers Date: Sun, 23 Feb 2020 21:55:38 -0800 Message-ID: Subject: Re: [PATCH] perf: fix -Wstring-compare To: Nick Desaulniers Cc: Arnaldo Carvalho de Melo , Ingo Molnar , Peter Zijlstra , clang-built-linux , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Jin Yao , Changbin Du , John Keeping , Song Liu , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 23, 2020 at 11:35 AM Nick Desaulniers 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 > --- > Note: was generated off of mainline; can rebase on -next if it doesn't > apply cleanly. 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). > tools/perf/builtin-diff.c | 3 ++- > tools/perf/util/block-info.c | 3 ++- > tools/perf/util/map.c | 2 +- > 3 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c > index f8b6ae557d8b..c03c36fde7e2 100644 > --- a/tools/perf/builtin-diff.c > +++ b/tools/perf/builtin-diff.c > @@ -1312,7 +1312,8 @@ static int cycles_printf(struct hist_entry *he, struct hist_entry *pair, > end_line = map__srcline(he->ms.map, bi->sym->start + bi->end, > he->ms.sym); > > - if ((start_line != SRCLINE_UNKNOWN) && (end_line != SRCLINE_UNKNOWN)) { > + if ((strncmp(start_line, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0) && > + (strncmp(end_line, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)) { > scnprintf(buf, sizeof(buf), "[%s -> %s] %4ld", > start_line, end_line, block_he->diff.cycles); > } else { > diff --git a/tools/perf/util/block-info.c b/tools/perf/util/block-info.c > index c4b030bf6ec2..fbbb6d640dad 100644 > --- a/tools/perf/util/block-info.c > +++ b/tools/perf/util/block-info.c > @@ -295,7 +295,8 @@ static int block_range_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, > end_line = map__srcline(he->ms.map, bi->sym->start + bi->end, > he->ms.sym); > > - if ((start_line != SRCLINE_UNKNOWN) && (end_line != SRCLINE_UNKNOWN)) { > + if ((strncmp(start_line, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0) && > + (strncmp(end_line, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)) { > scnprintf(buf, sizeof(buf), "[%s -> %s]", > start_line, end_line); > } else { > diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c > index a08ca276098e..95428511300d 100644 > --- a/tools/perf/util/map.c > +++ b/tools/perf/util/map.c > @@ -431,7 +431,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, > > if (map && map->dso) { > char *srcline = map__srcline(map, addr, NULL); > - if (srcline != SRCLINE_UNKNOWN) > + if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0) > ret = fprintf(fp, "%s%s", prefix, srcline); > free_srcline(srcline); > } > -- > 2.17.1 > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200223193456.25291-1-nick.desaulniers%40gmail.com.