From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 63E21213E7B for ; Tue, 1 Apr 2025 18:25:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743531927; cv=none; b=I32ExN4hFBeBcxnetB0EjvMOsAVUQ2tP8tXfjmjvUBLjCEbiHE1A9O95yCdwI2Q08vnmd99ki+RjXBPNcYzWgzGQEG5XIjmfvnyG8ANbcnDJRhT2G3u3RWcb42e/BTOoS46qOyz97wGGLia5o0y2jXUh7jEf36rSzRwBLpTmLvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743531927; c=relaxed/simple; bh=OHSwmVRTG0HD488JeBe67A2CUxy+O0gCaGl1hO/MrlY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Lj0AmS6I8tvKRWPhqFXGZdynxyFqI55kjRtp62Q13ZtFpn80uUFeXqXY/iMJr2gsQelJCujlnDPQCMXK3LFPKuIo92AU6n4CEcdbLToU+JtMAc88loego54ii2qkspfaiZXIXXIGPhsNkOiydKQr3/sILjhy6PN1SIA6E9sChxk= 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=Mkg7Jcim; arc=none smtp.client-ip=209.85.214.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="Mkg7Jcim" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-22650077995so161755955ad.3 for ; Tue, 01 Apr 2025 11:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743531925; x=1744136725; darn=lists.linux.dev; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=maDKewcfrTN/pXEuAvy1eHGZYrBP9VzStu+Vbun6bP0=; b=Mkg7JcimxhOg6watzBukj+JIHAmgi8rYyLIyoe1Ceswa9Bj0G/UJ1/eg3LAP91Ifj2 oXLoHCmHQbYOzXKwLrZnvsi0eRygsz7dhcfVdUyscG0E4q1aFxjr03+fuUJ3DnI/Q/H7 2jcj5O6yrQdyoS5nWi0bvGb/+14r49hgO+Tkt7YdmqF853YtyPNC3x5crvTcmro/lBtT xdU8ABCisSgdeB95pzcrxjfvwF7dBzkmNcFA7Y5Yj/B4d1kGoPykhSM0IMQbPNdjkprg 4DA/S+n4xFfCWEtHxwU/3AJziCdoboeVfTTDo5lkyy1RmzXAwjC6Xx8YQTCRgD0fCD0H 6pVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743531925; x=1744136725; h=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=maDKewcfrTN/pXEuAvy1eHGZYrBP9VzStu+Vbun6bP0=; b=LtnkQEmiH0tYWr7MxajBwXzF9nFskvvP10tkYnTyvOisG8f4/JZtP35fGyarX/ZQ4G C5LNsuaEiSedca+pgdwea71GOhkbdUhjcc/vNYcWK5UmdRz8rLurUOF5a0G2lZLNlVmo cwps+1FTPOLKFlPh9L6BJddG1ufkmpR7yxGm1LZAvl3Fsd3gtARGfD2uezVurLhGQ6B4 OAaxJ+XwkNbXSWV6ErThJ/r+OfAW5l+vNznON39UPWkANfZ6HzMyzPzdAQpNcW/fjQAr v7CkftljHBkvItXZFRfPzYvzEZDW2BUdKR1QAnecKBDCDortnj5Hzyqy2sbqCwhJ7qc0 nwhQ== X-Forwarded-Encrypted: i=1; AJvYcCVZNsNYceaEFANV2OtqcVhq1JOUCmw1nJ0A/2rCW1OtSskGVQld9jN6ZPlnwXm5Q+HO7rXF@lists.linux.dev X-Gm-Message-State: AOJu0YwmfRVKhu3oWoUw1cQ3lHTCgqSXysjCIzBsOZwMj+DiVXvxez+a 3gKUCXYPtLIgz1ao8BmmrwC6odeVh9L7GhCek5BafSg2wJ22V/QiozoXLXVCLgiRd+DWfvV+wal D4XvdOw== X-Google-Smtp-Source: AGHT+IFNI0r4xdlVep8eZmgL2ok0j2hkk8AtyWpy1qsBmfszW0qOT/+uO0dTUbBWJ2V47z6JGjdY7ibJE2zJ X-Received: from plpf4.prod.google.com ([2002:a17:903:3c44:b0:223:58e2:570d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ebc6:b0:224:c76:5e57 with SMTP id d9443c01a7336-2292f9e8652mr220203935ad.39.1743531924561; Tue, 01 Apr 2025 11:25:24 -0700 (PDT) Date: Tue, 1 Apr 2025 11:23:22 -0700 In-Reply-To: <20250401182347.3422199-1-irogers@google.com> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250401182347.3422199-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250401182347.3422199-25-irogers@google.com> Subject: [PATCH v1 24/48] perf report: Silence -Wshorten-64-to-32 warnings From: Ian Rogers To: Yury Norov , Rasmus Villemoes , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , 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 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/builtin-report.c | 4 ++-- tools/perf/util/callchain.c | 12 ++++++------ tools/perf/util/callchain.h | 2 +- tools/perf/util/srccode.c | 6 +++--- tools/perf/util/srcline.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index b030ce72e13e..fff8f3db788e 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -800,7 +800,7 @@ static int count_lost_samples_event(const struct perf_tool *tool, evsel = evlist__id2evsel(rep->session->evlist, sample->id); if (evsel) { struct hists *hists = evsel__hists(evsel); - u32 count = event->lost_samples.lost; + u32 count = (u32)event->lost_samples.lost; if (event->header.misc & PERF_RECORD_MISC_LOST_SAMPLES_BPF) hists__inc_nr_dropped_samples(hists, count); @@ -1602,7 +1602,7 @@ int cmd_report(int argc, const char **argv) session = perf_session__new(&data, &report.tool); if (IS_ERR(session)) { - ret = PTR_ERR(session); + ret = (int)PTR_ERR(session); goto exit; } diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index d7b7eef740b9..c3206b9d7b52 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -214,7 +214,7 @@ __parse_callchain_report_opt(const char *arg, bool allow_record_opt) if (get_stack_size(tok, &size) < 0) return -1; - callchain_param.dump_size = size; + callchain_param.dump_size = (u32)size; try_stack_size = false; } else if (!minpcnt_set) { /* try to get the min percent */ @@ -224,7 +224,7 @@ __parse_callchain_report_opt(const char *arg, bool allow_record_opt) minpcnt_set = true; } else { /* try print limit at last */ - callchain_param.print_limit = strtoul(tok, &endptr, 0); + callchain_param.print_limit = (u32)strtoul(tok, &endptr, 0); if (tok == endptr) return -1; } @@ -295,7 +295,7 @@ int parse_callchain_record(const char *arg, struct callchain_param *param) unsigned long size = 0; ret = get_stack_size(tok, &size); - param->dump_size = size; + param->dump_size = (u32)size; } } else if (!strncmp(name, "lbr", sizeof("lbr"))) { if (!strtok_r(NULL, ",", &saveptr)) { @@ -332,7 +332,7 @@ int perf_callchain_config(const char *var, const char *value) int ret; ret = get_stack_size(value, &size); - callchain_param.dump_size = size; + callchain_param.dump_size = (u32)size; return ret; } @@ -817,7 +817,7 @@ split_add_child(struct callchain_node *parent, { struct callchain_node *new; struct list_head *old_tail; - unsigned int idx_total = idx_parents + idx_local; + u64 idx_total = idx_parents + idx_local; /* split */ new = create_child(parent, true); @@ -1027,7 +1027,7 @@ merge_chain_branch(struct callchain_cursor *cursor, struct callchain_node *child; struct callchain_list *list, *next_list; struct rb_node *n; - int old_pos = cursor->nr; + u64 old_pos = cursor->nr; int err = 0; list_for_each_entry_safe(list, next_list, &src->val, list) { diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 86ed9e4d04f9..7a2abff6d0a5 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -65,7 +65,7 @@ struct callchain_node { struct rb_node rb_node; /* to sort nodes in an output tree */ struct rb_root rb_root_in; /* input tree of children */ struct rb_root rb_root; /* sorted output tree of children */ - unsigned int val_nr; + u64 val_nr; unsigned int count; unsigned int children_count; u64 hit; diff --git a/tools/perf/util/srccode.c b/tools/perf/util/srccode.c index 476e99896d5e..f5f8cdfd00c1 100644 --- a/tools/perf/util/srccode.c +++ b/tools/perf/util/srccode.c @@ -37,7 +37,7 @@ static LIST_HEAD(srcfile_list); static long map_total_sz; static int num_srcfiles; -static int countlines(char *map, int maplen) +static int countlines(char *map, size_t maplen) { int numl; char *end = map + maplen; @@ -136,7 +136,7 @@ static struct srcfile *find_srcfile(char *fn) h->lines = calloc(h->numlines, sizeof(char *)); if (!h->lines) goto out_map; - fill_lines(h->lines, h->numlines, h->map, h->maplen); + fill_lines(h->lines, h->numlines, h->map, (int)h->maplen); list_add(&h->nd, &srcfile_list); hlist_add_head(&h->hash_nd, &srcfile_htab[hval]); map_total_sz += h->maplen; @@ -166,6 +166,6 @@ char *find_sourceline(char *fn, unsigned line, int *lenp) if (!l) return NULL; p = memchr(l, '\n', sf->map + sf->maplen - l); - *lenp = p - l; + *lenp = (int)(p - l); return l; } diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c index f32d0d4f4bc9..b2003c5490a2 100644 --- a/tools/perf/util/srcline.c +++ b/tools/perf/util/srcline.c @@ -443,7 +443,7 @@ static int filename_split(char *filename, unsigned int *line_nr) sep = strchr(filename, ':'); if (sep) { *sep++ = '\0'; - *line_nr = strtoul(sep, NULL, 0); + *line_nr = (unsigned int)strtoul(sep, NULL, 0); return 1; } pr_debug("addr2line missing ':' in filename split\n"); -- 2.49.0.504.g3bcea36a83-goog