Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: "Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	"Kan Liang" <kan.liang@linux.intel.com>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"André Almeida" <andrealmeid@igalia.com>,
	"John Garry" <john.g.garry@oracle.com>,
	"Will Deacon" <will@kernel.org>,
	"James Clark" <james.clark@linaro.org>,
	"Mike Leach" <mike.leach@linaro.org>,
	"Leo Yan" <leo.yan@linux.dev>,
	"Yicong Yang" <yangyicong@hisilicon.com>,
	"Jonathan Cameron" <jonathan.cameron@huawei.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	"Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Kyle Meyer" <kyle.meyer@hpe.com>,
	"Ben Gainey" <ben.gainey@arm.com>,
	"Athira Rajeev" <atrajeev@linux.vnet.ibm.com>,
	"Kajol Jain" <kjain@linux.ibm.com>,
	"Aditya Gupta" <adityag@linux.ibm.com>,
	"Eder Zulian" <ezulian@redhat.com>,
	"Dapeng Mi" <dapeng1.mi@linux.intel.com>,
	"Kuan-Wei Chiu" <visitorckw@gmail.com>,
	"He Zhe" <zhe.he@windriver.com>,
	"Dirk Gouders" <dirk@gouders.net>,
	"Brian Geffon" <bgeffon@google.com>,
	"Ravi Bangoria" <ravi.bangoria@amd.com>,
	"Howard Chu" <howardchu95@gmail.com>,
	"Charlie Jenkins" <charlie@rivosinc.com>,
	"Colin Ian King" <colin.i.king@gmail.com>,
	"Dominique Martinet" <asmadeus@codewreck.org>,
	"Jann Horn" <jannh@google.com>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Yang Jihong" <yangjihong@bytedance.com>,
	"Dmitry Vyukov" <dvyukov@google.com>,
	"Andi Kleen" <ak@linux.intel.com>,
	"Graham Woodward" <graham.woodward@arm.com>,
	"Ilkka Koskinen" <ilkka@os.amperecomputing.com>,
	"Anshuman Khandual" <anshuman.khandual@arm.com>,
	"Zhongqiu Han" <quic_zhonhan@quicinc.com>,
	"Hao Ge" <gehao@kylinos.cn>,
	"Tengda Wu" <wutengda@huaweicloud.com>,
	"Gabriele Monaco" <gmonaco@redhat.com>,
	"Chun-Tse Shao" <ctshao@google.com>,
	"Casey Chen" <cachen@purestorage.com>,
	"Dr. David Alan Gilbert" <linux@treblig.org>,
	"Li Huafei" <lihuafei1@huawei.com>,
	"Steinar H. Gunderson" <sesse@google.com>,
	"Levi Yun" <yeoreum.yun@arm.com>,
	"Weilin Wang" <weilin.wang@intel.com>,
	"Thomas Falcon" <thomas.falcon@intel.com>,
	"Thomas Richter" <tmricht@linux.ibm.com>,
	"Andrew Kreimer" <algonell@gmail.com>,
	"Krzysztof Łopatowski" <krzysztof.m.lopatowski@gmail.com>,
	"Christophe Leroy" <christophe.leroy@csgroup.eu>,
	"Jean-Philippe Romain" <jean-philippe.romain@foss.st.com>,
	"Junhao He" <hejunhao3@huawei.com>,
	"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
	"Xu Yang" <xu.yang_2@nxp.com>,
	"Steve Clevenger" <scclevenger@os.amperecomputing.com>,
	"Zixian Cai" <fzczx123@gmail.com>,
	"Stephen Brennan" <stephen.s.brennan@oracle.com>,
	"Yujie Liu" <yujie.liu@intel.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev
Cc: Ian Rogers <irogers@google.com>
Subject: [PATCH v2 11/47] perf arm-spe: Silence -Wshorten-64-to-32 warnings
Date: Wed, 30 Apr 2025 10:49:59 -0700	[thread overview]
Message-ID: <20250430175036.184610-12-irogers@google.com> (raw)
In-Reply-To: <20250430175036.184610-1-irogers@google.com>

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 <irogers@google.com>
---
 .../util/arm-spe-decoder/arm-spe-decoder.c    |  4 ++--
 .../arm-spe-decoder/arm-spe-pkt-decoder.c     |  2 +-
 tools/perf/util/arm-spe.c                     | 24 +++++++++----------
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-decoder.c
index 688fe6d75244..58107970b215 100644
--- a/tools/perf/util/arm-spe-decoder/arm-spe-decoder.c
+++ b/tools/perf/util/arm-spe-decoder/arm-spe-decoder.c
@@ -117,7 +117,7 @@ static int arm_spe_get_data(struct arm_spe_decoder *decoder)
 	if (!decoder->len)
 		pr_debug("No more data\n");
 
-	return decoder->len;
+	return (int)decoder->len;
 }
 
 static int arm_spe_get_next_packet(struct arm_spe_decoder *decoder)
@@ -187,7 +187,7 @@ static int arm_spe_read_record(struct arm_spe_decoder *decoder)
 			break;
 		case ARM_SPE_COUNTER:
 			if (idx == SPE_CNT_PKT_HDR_INDEX_TOTAL_LAT)
-				decoder->record.latency = payload;
+				decoder->record.latency = (u32)payload;
 			break;
 		case ARM_SPE_CONTEXT:
 			decoder->record.context_id = payload;
diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
index 13cadb2f1cea..a6d04ad50db6 100644
--- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
+++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
@@ -63,7 +63,7 @@ static int arm_spe_get_payload(const unsigned char *buf, size_t len,
 	default: return ARM_SPE_BAD_PACKET;
 	}
 
-	return 1 + ext_hdr + payload_len;
+	return 1 + ext_hdr + (int)payload_len;
 }
 
 static int arm_spe_get_pad(struct arm_spe_pkt *packet)
diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 2a9775649cc2..561bef7b4628 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -786,7 +786,7 @@ static bool arm_spe__synth_ds(struct arm_spe_queue *speq,
 	}
 
 	for (i = 0; i < ARRAY_SIZE(data_source_handles); i++) {
-		if (is_midr_in_range_list(midr, data_source_handles[i].midr_ranges)) {
+		if (is_midr_in_range_list((u32)midr, data_source_handles[i].midr_ranges)) {
 			data_source_handles[i].ds_synth(record, data_src);
 			return true;
 		}
@@ -956,7 +956,7 @@ static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp)
 		 */
 		record = &speq->decoder->record;
 		if (!spe->timeless_decoding && record->context_id != (u64)-1) {
-			ret = arm_spe_set_tid(speq, record->context_id);
+			ret = arm_spe_set_tid(speq, (pid_t)record->context_id);
 			if (ret)
 				return ret;
 
@@ -1344,8 +1344,8 @@ static u64 **arm_spe__alloc_metadata(struct perf_record_auxtrace_info *info,
 	}
 
 	*ver = ptr[ARM_SPE_HEADER_VERSION];
-	hdr_sz = ptr[ARM_SPE_HEADER_SIZE];
-	*nr_cpu = ptr[ARM_SPE_CPUS_NUM];
+	hdr_sz = (int)ptr[ARM_SPE_HEADER_SIZE];
+	*nr_cpu = (int)ptr[ARM_SPE_CPUS_NUM];
 
 	metadata = calloc(*nr_cpu, sizeof(*metadata));
 	if (!metadata)
@@ -1353,7 +1353,7 @@ static u64 **arm_spe__alloc_metadata(struct perf_record_auxtrace_info *info,
 
 	/* Locate the start address of per CPU metadata */
 	ptr += hdr_sz;
-	per_cpu_sz = (metadata_size - (hdr_sz * sizeof(u64))) / (*nr_cpu);
+	per_cpu_sz = (int)((metadata_size - (hdr_sz * sizeof(u64))) / (*nr_cpu));
 
 	for (i = 0; i < *nr_cpu; i++) {
 		metadata[i] = arm_spe__alloc_per_cpu_metadata(ptr, per_cpu_sz);
@@ -1405,7 +1405,7 @@ static void arm_spe_free(struct perf_session *session)
 	auxtrace_heap__free(&spe->heap);
 	arm_spe_free_events(session);
 	session->auxtrace = NULL;
-	arm_spe__free_metadata(spe->metadata, spe->metadata_nr_cpu);
+	arm_spe__free_metadata(spe->metadata, (int)spe->metadata_nr_cpu);
 	free(spe);
 }
 
@@ -1451,8 +1451,8 @@ static void arm_spe_print_info(struct arm_spe *spe, __u64 *arr)
 		hdr_size = ARM_SPE_AUXTRACE_V1_PRIV_MAX;
 		hdr_fmts = metadata_hdr_v1_fmts;
 	} else {
-		cpu_num = arr[ARM_SPE_CPUS_NUM];
-		hdr_size = arr[ARM_SPE_HEADER_SIZE];
+		cpu_num = (unsigned int)arr[ARM_SPE_CPUS_NUM];
+		hdr_size = (unsigned int)arr[ARM_SPE_HEADER_SIZE];
 		hdr_fmts = metadata_hdr_fmts;
 	}
 
@@ -1466,7 +1466,7 @@ static void arm_spe_print_info(struct arm_spe *spe, __u64 *arr)
 		 * are fixed. The sequential parameter size is decided by the
 		 * field 'ARM_SPE_CPU_NR_PARAMS'.
 		 */
-		cpu_size = (ARM_SPE_CPU_NR_PARAMS + 1) + arr[ARM_SPE_CPU_NR_PARAMS];
+		cpu_size = (unsigned int)((ARM_SPE_CPU_NR_PARAMS + 1) + arr[ARM_SPE_CPU_NR_PARAMS]);
 		for (i = 0; i < cpu_size; i++)
 			fprintf(stdout, metadata_per_cpu_fmts[i], arr[i]);
 		arr += cpu_size;
@@ -1731,9 +1731,9 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
 	spe->machine = &session->machines.host; /* No kvm support */
 	spe->auxtrace_type = auxtrace_info->type;
 	if (metadata_ver == 1)
-		spe->pmu_type = auxtrace_info->priv[ARM_SPE_PMU_TYPE];
+		spe->pmu_type = (u32)auxtrace_info->priv[ARM_SPE_PMU_TYPE];
 	else
-		spe->pmu_type = auxtrace_info->priv[ARM_SPE_PMU_TYPE_V2];
+		spe->pmu_type = (u32)auxtrace_info->priv[ARM_SPE_PMU_TYPE_V2];
 	spe->metadata = metadata;
 	spe->metadata_ver = metadata_ver;
 	spe->metadata_nr_cpu = nr_cpu;
@@ -1752,7 +1752,7 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
 	 * "time_cycles" only if they are contained in the event.
 	 */
 	spe->tc.time_shift = tc->time_shift;
-	spe->tc.time_mult = tc->time_mult;
+	spe->tc.time_mult = (u32)tc->time_mult;
 	spe->tc.time_zero = tc->time_zero;
 
 	if (event_contains(*tc, time_cycles)) {
-- 
2.49.0.906.g1f30a19c02-goog


  parent reply	other threads:[~2025-04-30 17:51 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
2025-04-30 17:49 ` [PATCH v2 01/47] perf build: Avoid building libbpf/bpftool with LIBBPF_DYNAMIC Ian Rogers
2025-04-30 17:49 ` [PATCH v2 02/47] perf tests: Silence -Wshorten-64-to-32 warnings Ian Rogers
2025-04-30 17:49 ` [PATCH v2 03/47] perf ui: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 04/47] perf bench: " Ian Rogers
2025-04-30 20:23   ` Dirk Gouders
2025-04-30 21:04     ` Ian Rogers
2025-04-30 22:18       ` Dirk Gouders
2025-04-30 22:22         ` Ian Rogers
2025-04-30 23:11           ` Dirk Gouders
2025-05-02 12:06             ` David Laight
2025-05-02 14:12               ` Dirk Gouders
2025-05-03 10:05                 ` David Laight
2025-05-03 12:22                   ` Dirk Gouders
2025-04-30 17:49 ` [PATCH v2 05/47] arm64: cputype: " Ian Rogers
2025-05-09 12:56   ` Mark Rutland
2025-04-30 17:49 ` [PATCH v2 06/47] x86/insn: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 07/47] tools lib: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 08/47] libperf: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 09/47] tools subcmd: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 10/47] perf arch x86: " Ian Rogers
2025-04-30 17:49 ` Ian Rogers [this message]
2025-04-30 17:50 ` [PATCH v2 12/47] perf trace: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 13/47] perf trace-event: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 14/47] perf jvmti: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 15/47] perf pmu: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 16/47] perf annotate powerpc: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 17/47] perf s390: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 18/47] perf cs-etm: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 19/47] perf stat: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 20/47] perf dlfilter: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 21/47] perf demangle: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 22/47] perf annotate: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 23/47] perf report: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 24/47] perf help: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 25/47] perf hisi-ptt: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 26/47] perf probe: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 27/47] perf kwork: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 28/47] perf buildid: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 29/47] perf lock: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 30/47] perf mem: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 31/47] perf script: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 32/47] perf evlist: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 33/47] perf bpf_counter: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 34/47] perf ftrace: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 35/47] perf record: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 36/47] perf inject: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 37/47] perf sched: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 38/47] perf timechart: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 39/47] perf list: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 40/47] perf kvm: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 41/47] perf diff: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 42/47] perf daemon: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 43/47] perf zlib: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 44/47] perf symbol: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 45/47] perf util: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 46/47] perf hashmap: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 47/47] perf: " Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250430175036.184610-12-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adityag@linux.ibm.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=algonell@gmail.com \
    --cc=andrealmeid@igalia.com \
    --cc=anshuman.khandual@arm.com \
    --cc=arnd@arndb.de \
    --cc=asmadeus@codewreck.org \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=ben.gainey@arm.com \
    --cc=bgeffon@google.com \
    --cc=cachen@purestorage.com \
    --cc=charlie@rivosinc.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=colin.i.king@gmail.com \
    --cc=ctshao@google.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=dave@stgolabs.net \
    --cc=dirk@gouders.net \
    --cc=dvhart@infradead.org \
    --cc=dvyukov@google.com \
    --cc=ezulian@redhat.com \
    --cc=fzczx123@gmail.com \
    --cc=gehao@kylinos.cn \
    --cc=gmonaco@redhat.com \
    --cc=graham.woodward@arm.com \
    --cc=hejunhao3@huawei.com \
    --cc=howardchu95@gmail.com \
    --cc=ilkka@os.amperecomputing.com \
    --cc=james.clark@linaro.org \
    --cc=jannh@google.com \
    --cc=jean-philippe.romain@foss.st.com \
    --cc=john.g.garry@oracle.com \
    --cc=jolsa@kernel.org \
    --cc=jonathan.cameron@huawei.com \
    --cc=jpoimboe@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kan.liang@linux.intel.com \
    --cc=kjain@linux.ibm.com \
    --cc=krzysztof.m.lopatowski@gmail.com \
    --cc=kyle.meyer@hpe.com \
    --cc=leo.yan@linux.dev \
    --cc=lihuafei1@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=linux@treblig.org \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=masahiroy@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mike.leach@linaro.org \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=peterz@infradead.org \
    --cc=quic_zhonhan@quicinc.com \
    --cc=ravi.bangoria@amd.com \
    --cc=scclevenger@os.amperecomputing.com \
    --cc=sesse@google.com \
    --cc=stephen.s.brennan@oracle.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.falcon@intel.com \
    --cc=tmricht@linux.ibm.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=visitorckw@gmail.com \
    --cc=weilin.wang@intel.com \
    --cc=will@kernel.org \
    --cc=wutengda@huaweicloud.com \
    --cc=xu.yang_2@nxp.com \
    --cc=yangjihong@bytedance.com \
    --cc=yangyicong@hisilicon.com \
    --cc=yeoreum.yun@arm.com \
    --cc=yujie.liu@intel.com \
    --cc=yury.norov@gmail.com \
    --cc=zhe.he@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox