Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3831699ybf; Tue, 3 Mar 2020 13:46:05 -0800 (PST) X-Google-Smtp-Source: ADFU+vvzGzmQXjs/oZs6+ECFB+QRwAQvDUcr4cNZ12pEBm44mcIuPP84fLVHr50UW+WayqJdeS/9 X-Received: by 2002:aca:1903:: with SMTP id l3mr421493oii.178.1583271965039; Tue, 03 Mar 2020 13:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583271965; cv=none; d=google.com; s=arc-20160816; b=f1s1hlCsT6MJLjn1zkDo+71YkdUYKuk8wMZWAoCaY3okKEki/RuQ7nsqzxoaahAJaj rbUdq6ik3fSYcRMbiGOOph1nYZZ+x82evBZa+EGdoW9tUz0xfd6I2+g6xKWmse8s5KMo T/fDxQvbqP9zYEsDVTdHGSfFITrKCzihSZpyQ3oQz9bgDfOjrM/9QKCspyojXOHFaAr4 Sw0xTYFV2kWD+gJpL+lWiLtf1yzDUPPqcGheDXrBhfTeB1t58WMqfvwPtk5yQ872pCwq OtLW1y386AKF8rdVpxMuYRrQDYGNQvU6uehXr2cu+Q0XtR3T8HcErnZwfkrfsBIMmUhY 3b2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=jEKaLTA95LrXk5siOJJk3w+e3Hyr7fPl8lCKPh+BAqc=; b=AFOtVJViMbMH9HFoFH35f2mOa1jwayC2er6MAnfAo+U002+XYyMN297MN1VBf4GKzk 6nILUqRNSH+daJjZID9VD0NOuQMWynQErQjL9mk3aRIjafXVwyYa6BMfqTJLskEPooug Y+2Zxef5Oc49zCSG6vDjnXr97Qy6g3MMbuOXlv8QxMbDLjkrT6HsnPjnqCgSX7XiHD1c cb9/SGedBoB6LPXVOLg6gpzGxxUjavnFTnKisKWJU09Hp9cxMAx4Z2ibWydMjlOnVZNz OFzsJ7F0mus7sJ7Z7iGrSjmAmdQTWZwhsvYg5BkXwJPnKRobDggAwaDxTYBqn0qyVcli ZrYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DUMndEeI; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si8098839otc.130.2020.03.03.13.45.53; Tue, 03 Mar 2020 13:46:05 -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=@gmail.com header.s=20161025 header.b=DUMndEeI; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731230AbgCCUGS (ORCPT + 99 others); Tue, 3 Mar 2020 15:06:18 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:40485 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbgCCUGR (ORCPT ); Tue, 3 Mar 2020 15:06:17 -0500 Received: by mail-qt1-f193.google.com with SMTP id o10so3851888qtr.7 for ; Tue, 03 Mar 2020 12:06:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jEKaLTA95LrXk5siOJJk3w+e3Hyr7fPl8lCKPh+BAqc=; b=DUMndEeIxpM99nIo3TWkBJDrwb1cnlC6lN6/7J2b6o7Mb7bEDhVWUcJq6w4rlVxW/M 4ggPKtcYTGDSHv6K6yEc6gIz2pI6VXkq01fdXLaNQg77MC1VYR2AHItycoDdA4j4nYr+ VCNlRIqGeVu5EDBKzXGfTB+wz1mwtOmVnFio0JkDjSOIxNNLGlNVh2QND8uE0OllTJht wzEsky62hb29iOW+H6SbYD4puoNhB+QfCnh22IqyD44xdAC1qW9mEbUsHFFaZoNgRn85 peOLaCONtY3t01zAPHIcIhxx6ZkxCrRkchPaqp1apndgEY08DxsT+fDMofDKNBB/5P84 M/Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jEKaLTA95LrXk5siOJJk3w+e3Hyr7fPl8lCKPh+BAqc=; b=FSgWHKfFp/PNP+i97Pifo7PRRRuyZRCzre5AMxM+sjnE22Q/qgk/rwSXgRPBeeumGC 2LR66A9qzZzXX/80iYpFWt1AVsPIaKgxj2W6wuVqWigEP41pusyUVcu+EOc1YM4kgtkn CI+BtB6op5CrlLphULKW6osE/jaib3NLMEGIah8bEp9LiRpVouHoiTHcJATljTx3CpVf 59tZhZcJO+vPr4wXVuWcXrjjZdL5jUvxshdHq7FuwDcf1vJ4je0FO5BXWl1osLYHp+xu IfdkAi17PucjqE6EJM4Xnvvu2PDuDb8qDoOIjBunKS0f3LLGpkV8ABRs6xdKz62Ccx5u Q3mw== X-Gm-Message-State: ANhLgQ0w1n9Uuk6ywP+7nL8wALFFUheSR7azqTbeibJpnQlK3nmlXUhj FZnVsiLOso4mWd8i7yvm1Sk= X-Received: by 2002:ac8:40ca:: with SMTP id f10mr6136727qtm.377.1583265974981; Tue, 03 Mar 2020 12:06:14 -0800 (PST) Received: from quaco.ghostprotocols.net ([179.97.37.151]) by smtp.gmail.com with ESMTPSA id n74sm12811814qke.63.2020.03.03.12.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 12:06:14 -0800 (PST) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id E489A403AD; Tue, 3 Mar 2020 17:06:11 -0300 (-03) Date: Tue, 3 Mar 2020 17:06:11 -0300 To: Nick Desaulniers Cc: Peter Zijlstra , Ingo Molnar , 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 Subject: Re: [PATCH] perf: fix -Wstring-compare Message-ID: <20200303200611.GB5550@kernel.org> References: <20200223193456.25291-1-nick.desaulniers@gmail.com> <7fe0ca3e6fb64ca59986584fffa824e6@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Tue, Feb 25, 2020 at 01:28:50PM -0800, Nick Desaulniers escreveu: > 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. Fair enough, applying it with Ian's reviewed-by, - Arnaldo