Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2905555ybv; Mon, 24 Feb 2020 14:07:10 -0800 (PST) X-Google-Smtp-Source: APXvYqxC3OECOH5sgh3I2Xi5sm+zY7JZvyEHQEtD220PFoVdPiG9afNCh7hOdRcMcUnsL6RifdCs X-Received: by 2002:aca:4f8e:: with SMTP id d136mr947476oib.61.1582582029860; Mon, 24 Feb 2020 14:07:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582582029; cv=none; d=google.com; s=arc-20160816; b=wxgGB2W+02AZK9KdT4DcAOU/jKW0u48Ej+TI9Seqv7J8gWbELbYoU+/dX8EFkc7Mr3 BCYaVrbaGH/mtukJRjMJbdT+HGmdY0jeBOhGJ3/1l+xvfdEbgCE4e7MqxgrG64DyeTNo PWZdH29ffvutHj9/ppQhInlqpO8D9paINH5M1Gg/4JIzkCMn4ejKl8Sgs7tX3aTnfp0r 2qlHpee9xsV+tx8QgbrJXR0rv6X+BN59zwRn5SI02Q9hrEE/HtzJcL8G1y0dpVLvX4tE yl+VlQW2qt8+UbS4zebHTlJP+coZHFxt/jQpoX8BcLejumUP1rmhe4/9XEe42gXvAm76 mMiw== 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=b83M3bsEx4cU3BGUQLKP/zLTl/hQm5rCLWYZzAWmz7c=; b=LLG/uT3OmsGMrqnupD77BmF3SapQNDGjJs75HCSb9EIDLBN935EgNaBxpNe7jLxqny rdoQU6gH+/fUK1dlg9SEXabg5gb7OpowVqLQ1nuiqBApiW3kPEWpaB3evCRA0q2vH5JP jMeTVGTy3+2/ISIpBrl9nj5Ps+ZocHS442YV84mjGjPD/LlMfecI80rEwP8Kw0/YO4lo UofL2QskDcjnbqDdWcl0HElnb36rO7vHzJOC3jLN+CRd8NkPzrOwXe4CjZG8uu1CMF0O SZXPLIKmq1pPh0sxiuJhn7kVnNVo2jCtg6b/kIGoXBqCPg4HFEeerA8qL8BgPZfv2Y3k q+3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=K9UeQctv; 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 t3si6629072oth.247.2020.02.24.14.06.55; Mon, 24 Feb 2020 14:07:09 -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=K9UeQctv; 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 S1727896AbgBXWFu (ORCPT + 99 others); Mon, 24 Feb 2020 17:05:50 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:40333 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727421AbgBXWFu (ORCPT ); Mon, 24 Feb 2020 17:05:50 -0500 Received: by mail-pj1-f66.google.com with SMTP id 12so347179pjb.5 for ; Mon, 24 Feb 2020 14:05:49 -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=b83M3bsEx4cU3BGUQLKP/zLTl/hQm5rCLWYZzAWmz7c=; b=K9UeQctvOKAr9WMKVSqSAMKdSu8dM43OR9N63pX86FvgxFPlzz5hgWYJvLG0dYy8OO VKNCcfrMwxDHiH/fnXUvdYN/pzdUYSHkyLss/qxlbbpzsE7gEZy2Y76wT9WzL/p3u49y leCrgfNvSHEK+ialeQO7sDlyjr73jNpOavW6GPIBUI2upS7pU/ihZm3EyvwVfMopTMb9 lMW8BcaIRh+Zk3IJkgNl3/mysUk28kjcG/EudMZgYYXpuIXEOANdaqNPvpkayuFf39hB 5E6y+omeR5/XIsNCzSDATMqYysRQ8nvoMndODW/k/6NxQmQTlL4ttwxGugUOXxzX/1x/ zw8A== 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=b83M3bsEx4cU3BGUQLKP/zLTl/hQm5rCLWYZzAWmz7c=; b=nkdDdfZGErmERaWEb18cXBgeYww1jllXijPIyTXvpYlw+Wq+5PnDvE9ZpoIlP8FdwL KHTmOkpjk/EYNgbKCFEwa4p8O1FbMB2YmBJhvPbNZZyZITFRUYYlnxl5RwwY6RNDxU3c XMXYr1o1STHP6ZKyBKlrjoeDMhswvXjJz16lTyUjAGww0fWxoWgWeRiKkC8KEzxCae5A ujI/z4a9r+EfyheMh76cMna2rY7Idjwqd9k4bItarDUPSPvOs30Uv6GMwciohE7/upMC JttvFHSDUFP8oyoDio1FMvIRqdj3bJS1Pe/DPVJkBF04qSB7JIZ6ktkaHMUo0VTllDaH LgoQ== X-Gm-Message-State: APjAAAUsHqRaCfEuUWe2y29MVp6iDmftxFI8lUs99q9r945gLdeE7tVG CvzUI5JgrLliL+jtIIRaOJd87nPzQPdP4bQv/VyG7w== X-Received: by 2002:a17:90a:7784:: with SMTP id v4mr1391652pjk.134.1582581949080; Mon, 24 Feb 2020 14:05:49 -0800 (PST) MIME-Version: 1.0 References: <20200223193456.25291-1-nick.desaulniers@gmail.com> In-Reply-To: From: Nick Desaulniers Date: Mon, 24 Feb 2020 14:05:38 -0800 Message-ID: Subject: Re: [PATCH] perf: fix -Wstring-compare To: Ian Rogers , David Laight , Arnaldo Carvalho de Melo Cc: Nick Desaulniers , 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 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? -- Thanks, ~Nick Desaulniers