From nobody Fri Dec 19 17:26:46 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 125D9274FF7 for ; Wed, 30 Apr 2025 17:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746035467; cv=none; b=B9fXQ7OmsAOnLHOG3h4azfPZ+F2bwB/g+HJ/I9/lJ6xqEIduetx0eMFZTEflinbJfshNybFyBYatE+QfxJR2GFMGf7Wahud0YlBzVI0eG3ZlRSScdO7Tp8TCnF9AX59uQ3kUCnElD7T6WoSPt4XtQBCA9IWPjl3O8NXTZiE598U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746035467; c=relaxed/simple; bh=wvPkR6JZ40YC3ZLi/ZNFhDlpszrlzYFVfEEp4+Utc68=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gU+KSgYpeWJ7pixIL5ZieeX/qohQi5U36V+2Hij/ceG+j+rrKneppZzDd0VMztyRtJ5LDGvITSQwfJfXp4hIeAr5Shi0GMpwLX1/KiGDqrUxikMoI5u9TpHfYZTz6NJ91c/q7IL/wES+p2zsae4cEXl4vzPxrg9I76viFklAOxU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nOL5v0cY; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nOL5v0cY" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-af5310c1ac1so57266a12.2 for ; Wed, 30 Apr 2025 10:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746035464; x=1746640264; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=exCmcwFz1TnRVt9YW9mscke0lfHrA+2a3D89/Ss7eyo=; b=nOL5v0cYGGouad5lzGuf41XNVslwMWz4DMBG6RduAw4dFEYBHdq4gAzEW+i6Sq14s8 KZWNZ6TvvwhEZwnqlUNirbUCjbj3lJBX10hp3DbZrSbwKRyU6uAzYhJxyJwFXEC/LveF UHrSk2oUAUmhnvOJimXP13ssDj6SKDRPZw+ajklxtLZnLfG/Cj8DWD4HifmU/F5MyQcp knUb7XpSBP98gmbYKwRqOlM1IWXGiZoI7WsjS4+oHlC695PkoKp8S2TTXaAnx43gG1aM tI3RvQHq5rAfeee7oulZ+xPp76YxiK3lr9o/UrBkdgBzcwCyoVi1y5IcyclsDL0xV4/4 cmZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746035464; x=1746640264; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=exCmcwFz1TnRVt9YW9mscke0lfHrA+2a3D89/Ss7eyo=; b=Zvtotahp0L5HKsB+7fP0QqAB5QBEdz/hMHk6cCaoWWsJI19nxLW0a8qbmTL168uUyI lQ/CYcQxoNDRs8NvRE/n1bmFob0ed7P+kZuUPdWUglOwWRCkT2KxfJWA8CSJYt0bf19O kAMcmjoy/jq6lS4GMcH27DNXo3GVBqlAoOQKLW9nQrBz3dbyUG9nsDbNWKwlY4qpRCBL RH6SL+EDokmZjQMg3Zkt/LCZ2RcPucVihGyQosA8tB9ppW8X728sjhJxZjF+kVI3f1TA OVkWc2HRbgb9viI5cF0BMRxzwBYmrQBsxScYH2EfISTdY3HPJC42sItQAFklUh5wqAse ikGw== X-Forwarded-Encrypted: i=1; AJvYcCU3Lv9Tf+irjoZ639nEt7VVGm1vho5K+YPtVBtBnIc/LGe/mep1nkN43cXU+pA6dFg/qcH/L1DcEtoQ6wI=@vger.kernel.org X-Gm-Message-State: AOJu0YxQkttoPhN/ov/uURT3jfJ2DbdX5tn9tFYO02kJJKZQuBaHbpk+ 2VMDU29gFiGA2xZ4C0dxHB0pcEnNHsy81LdQPoCRIysH0wDapdmOL8C3+J5JUU+RvWOgWDq5EKi 6So+MEA== X-Google-Smtp-Source: AGHT+IHDYtyNnHjQBwlQxtxVb4VlmrdxYhNH/PCNA7NGRCgPdcAR8KCkhPOzPMdO4mNYyXsSz9a43q4TYyVy X-Received: from pjbeu4.prod.google.com ([2002:a17:90a:f944:b0:301:1bf5:2f07]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d647:b0:2fe:955d:cdb1 with SMTP id 98e67ed59e1d1-30a33356127mr4815552a91.23.1746035464136; Wed, 30 Apr 2025 10:51:04 -0700 (PDT) Date: Wed, 30 Apr 2025 10:49:51 -0700 In-Reply-To: <20250430175036.184610-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430175036.184610-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430175036.184610-4-irogers@google.com> Subject: [PATCH v2 03/47] perf ui: Silence -Wshorten-64-to-32 warnings From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , Yury Norov , Rasmus Villemoes , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Jonathan Cameron , Nathan Chancellor , Bill Wendling , Justin Stitt , Josh Poimboeuf , Al Viro , Kyle Meyer , Ben Gainey , Athira Rajeev , Kajol Jain , Aditya Gupta , Eder Zulian , Dapeng Mi , Kuan-Wei Chiu , He Zhe , Dirk Gouders , Brian Geffon , Ravi Bangoria , Howard Chu , Charlie Jenkins , Colin Ian King , Dominique Martinet , Jann Horn , Masahiro Yamada , Arnd Bergmann , Yang Jihong , Dmitry Vyukov , Andi Kleen , Graham Woodward , Ilkka Koskinen , Anshuman Khandual , Zhongqiu Han , Hao Ge , Tengda Wu , Gabriele Monaco , Chun-Tse Shao , Casey Chen , "Dr. David Alan Gilbert" , Li Huafei , "Steinar H. Gunderson" , Levi Yun , Weilin Wang , Thomas Falcon , Thomas Richter , Andrew Kreimer , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , Christophe Leroy , Jean-Philippe Romain , Junhao He , "Masami Hiramatsu (Google)" , Xu Yang , Steve Clevenger , Zixian Cai , Stephen Brennan , Yujie Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev Cc: Ian Rogers Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The clang warning -Wshorten-64-to-32 can be useful to catch inadvertent truncation. In some instances this truncation can lead to changing the sign of a result, for example, truncation to return an int to fit a sort routine. Silence the warning by making the implicit truncation explicit. Signed-off-by: Ian Rogers --- tools/perf/ui/hist.c | 18 ++++++++---------- tools/perf/ui/stdio/hist.c | 5 ++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 3ffce69fc823..fcbfa6700464 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -233,7 +233,7 @@ static int __hpp__group_sort_idx(struct hist_entry *a, = struct hist_entry *b, static int __hpp__sort(struct hist_entry *a, struct hist_entry *b, hpp_field_fn get_field) { - s64 ret; + int ret; int i, nr_members; struct evsel *evsel; u64 *fields_a, *fields_b; @@ -272,7 +272,7 @@ static int __hpp__sort(struct hist_entry *a, struct his= t_entry *b, static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b, hpp_field_fn get_field) { - s64 ret =3D 0; + int ret =3D 0; =20 if (symbol_conf.cumulate_callchain) { /* @@ -287,7 +287,7 @@ static int __hpp__sort_acc(struct hist_entry *a, struct= hist_entry *b, !hist_entry__has_callchains(a) || !symbol_conf.use_callchain) return 0; =20 - ret =3D b->callchain->max_depth - a->callchain->max_depth; + ret =3D field_cmp(b->callchain->max_depth, a->callchain->max_depth); if (callchain_param.order =3D=3D ORDER_CALLER) ret =3D -ret; } @@ -299,6 +299,7 @@ static int hpp__width_fn(struct perf_hpp_fmt *fmt, struct hists *hists) { int len =3D fmt->user_len ?: fmt->len; + int fmt_len =3D (int)strlen(fmt->name); struct evsel *evsel =3D hists_to_evsel(hists); =20 if (symbol_conf.event_group) { @@ -314,10 +315,7 @@ static int hpp__width_fn(struct perf_hpp_fmt *fmt, len =3D max(len, nr * fmt->len); } =20 - if (len < (int)strlen(fmt->name)) - len =3D strlen(fmt->name); - - return len; + return len < fmt_len ? fmt_len : len; } =20 static int hpp__header_fn(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, @@ -341,7 +339,7 @@ int hpp_color_scnprintf(struct perf_hpp *hpp, const cha= r *fmt, ...) ret =3D percent_color_len_snprintf(hpp->buf, hpp->size, fmt, len, percent= ); va_end(args); =20 - return (ret >=3D ssize) ? (ssize - 1) : ret; + return (ret >=3D ssize) ? (int)(ssize - 1) : ret; } =20 static int hpp_entry_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) @@ -354,7 +352,7 @@ static int hpp_entry_scnprintf(struct perf_hpp *hpp, co= nst char *fmt, ...) ret =3D vsnprintf(hpp->buf, hpp->size, fmt, args); va_end(args); =20 - return (ret >=3D ssize) ? (ssize - 1) : ret; + return (ret >=3D ssize) ? (int)(ssize - 1) : ret; } =20 #define __HPP_COLOR_PERCENT_FN(_type, _field, _fmttype) \ @@ -945,7 +943,7 @@ void perf_hpp__set_user_width(const char *width_list_st= r) perf_hpp_list__for_each_format(&perf_hpp_list, fmt) { char *p; =20 - int len =3D strtol(ptr, &p, 10); + int len =3D (int)strtol(ptr, &p, 10); fmt->user_len =3D len; =20 if (*p =3D=3D ',') diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 7ac4b98e28bc..6a981f95b4ec 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -450,7 +450,7 @@ int __hist_entry__snprintf(struct hist_entry *he, struc= t perf_hpp *hpp, advance_hpp(hpp, ret); } =20 - return hpp->buf - start; + return (int)(hpp->buf - start); } =20 static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hp= p) @@ -612,8 +612,7 @@ static int hist_entry__fprintf(struct hist_entry *he, s= ize_t size, ret =3D fprintf(fp, "%s\n", bf); =20 if (hist_entry__has_callchains(he) && !ignore_callchains) - callchain_ret =3D hist_entry_callchain__fprintf(he, total_period, - 0, fp); + callchain_ret =3D (int)hist_entry_callchain__fprintf(he, total_period, 0= , fp); =20 ret +=3D callchain_ret; =20 --=20 2.49.0.906.g1f30a19c02-goog