Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4114192ybv; Tue, 25 Feb 2020 13:29:31 -0800 (PST) X-Google-Smtp-Source: APXvYqwh74KJn5VQqc2sQiwupem2Ex5oJ9Rnz4YH2fhJJC29v8r8ZeHHJS+taLUSp5UVLJ5fEduu X-Received: by 2002:aca:cf94:: with SMTP id f142mr685189oig.31.1582666171332; Tue, 25 Feb 2020 13:29:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582666171; cv=none; d=google.com; s=arc-20160816; b=S5uYrt+vtbCsKrr6d1BIbyop/LHvKVreiOdwsGkuuxpZN+w5SeWCZNhRYCGUMw9qw4 hJtAQjP23npdTzr2ibc+cBt9hww/CS2mZ3ltmqdzaCc7x2aMpldyCS+rpmb/b0yaaX7W Qv8BXOzANrcgzWCf5r0Se8ExuZyI5rwdS2M1YG4iWRwJ5tzVSccagmpAoKPBxufo69i8 jRgTCKCAxqEwMFtvtoAitT5G+ZJSdYxutB7D4yFMWct20cDbpuA2eACUXqTXh8+zOe+Z q/QSWoXsuwrgindrvCmUIxOHz5A5bE1FHhpionssP9CjlV5Dn5eTOme+dJd0S7UfAu4O 2IOg== 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=ujUpzqbtLOMFnK2x85J2zOksd9pIKrwiWoiPZU2Tngg=; b=CMBNFrf4mmiby17W3r2RyBCJY9fOVCkXSX2Te9Mx9niG3l8qAnat0XJOrha6MfjqNw qDlNotWBnNuG985nFnLyg3dHbbd8WbfydCjSWaid/0TGEmbDhswx06Li7hHQjVHRhnqN GS/WRdTCyGqsOQyj/UiC2FN002HkxRf8TcBIYmTgMS0CXgjwnEvEqaCRB3Lhi0a37qLo g2beafDTKxvbYcQsxzQaX/ortxZU1eHhRUuviVX4b5KCC9Ny71eZHonxu8+mDL8XUOUs OMEG73om991qP9CtO/0mlxXKXjUxtIkkOv6YLzh8q5Az7vAMNJGrSgWDoSYzulTt448h +Gtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XZGCX7ya; 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 n11si42360otf.36.2020.02.25.13.29.19; Tue, 25 Feb 2020 13:29:31 -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=XZGCX7ya; 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 S1728688AbgBYV3D (ORCPT + 99 others); Tue, 25 Feb 2020 16:29:03 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:33314 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbgBYV3D (ORCPT ); Tue, 25 Feb 2020 16:29:03 -0500 Received: by mail-pf1-f194.google.com with SMTP id n7so257833pfn.0 for ; Tue, 25 Feb 2020 13:29:02 -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=ujUpzqbtLOMFnK2x85J2zOksd9pIKrwiWoiPZU2Tngg=; b=XZGCX7ya5N43l4cINdtLO4xwCLE0LYTZLl84nPMiZykNGXk/wy1xP55IkR9gYcctA3 Qix/hcO5KzHnPuiu+EeLaXXBHcIATbpdTbq9TIXvcg3ixXjAIzvH6qRtdmASA23Q8N5u OUS1jaUJEqCZnpeC4eH9qaiCdwwHcrSgMztlvbepV52uADPV4Hfckrs4hbBeKlAzteSY hyKlTUlPbFKpixU0GY3+YV1qdCehLiUGSco3lhsEDCD/exwlg53fEsyQMhRaLVR0IA7z T0NbeIqMmI0tBnOImo8+rgITlZWzw+U6SipWy6doO1v7zeZp8xlVcIBvcyKHai28utCs ff/A== 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=ujUpzqbtLOMFnK2x85J2zOksd9pIKrwiWoiPZU2Tngg=; b=d/v/HKHS5wFE3wNGGnRQeACIh+6bOf3o9tdujhU2xoZlbuB07rqZWQ0O2NmQY3DG7Y CxmrfU/Dd0SepudrY7pP1EbjpEr9QQYxsZP33j2IRhoZp+1/itOF94qFK19jhxN2SeuX rdceA4HjdmubxOnyX+pn7wK9hfhTtujH+/soj8hB5EFEgZ1s2VMsIHO+A1VXF2ncVP6w NuYOmjmHDTKO8V8FSskhuqeSyCFEIePywUyvATpzGYZ/KuRlYn53z7poki8yYDKwdrEH jg80g9bIo/HPKXRLZ5V74q69bVA1alWh0ksmsnMU1l/3dpgK9eDTXIJ79ayRyjsNBEGW CFnw== X-Gm-Message-State: APjAAAVRlpRGIz2w1788PDuN/9P8seAPlX1yKjMA29a2iozrfx3EQXXG /EmirZzpWz+lg2wgD+GGIymUKv1cgPXtntQLmV4dAw== X-Received: by 2002:a65:6412:: with SMTP id a18mr502177pgv.10.1582666141590; Tue, 25 Feb 2020 13:29:01 -0800 (PST) MIME-Version: 1.0 References: <20200223193456.25291-1-nick.desaulniers@gmail.com> <7fe0ca3e6fb64ca59986584fffa824e6@AcuMS.aculab.com> In-Reply-To: <7fe0ca3e6fb64ca59986584fffa824e6@AcuMS.aculab.com> From: Nick Desaulniers Date: Tue, 25 Feb 2020 13:28:50 -0800 Message-ID: Subject: Re: [PATCH] perf: fix -Wstring-compare To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar Cc: Ian Rogers , Nick Desaulniers , clang-built-linux , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Jin Yao , Changbin Du , John Keeping , Song Liu , LKML , David Laight 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 Tue, Feb 25, 2020 at 1:35 AM David Laight wrote: > > From: Nick Desaulniers > > Sent: 24 February 2020 22:06 > > On Mon, Feb 24, 2020 at 10:20 AM 'Ian Rogers' via Clang Built Linux > > wrote: > > > > > > On Mon, Feb 24, 2020 at 8:03 AM David Laight wrote: > > > > > > > > From: Ian Rogers > > > > > Sent: 24 February 2020 05:56 > > > > > 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. > > > > > > Reviewed-by: Ian Rogers > > > > > > > > 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... Note: it looks like free_srcline() already does strcmp, so my patch basically does a more consistent job for string comparisons. Forward declaring then defining in tools/perf/util/srcline.c involves changing the function signatures and struct members to `const char*` rather than `char*`, which is of questionable value. I wouldn't mind changing my patch to just use strcmp instead of strncmp, or convert free_srcline() to use strncmp instead, if folks felt strongly about being consistent. Otherwise I think my patch with Ian's Reviewed-by is the best approach. -- Thanks, ~Nick Desaulniers