[llvm-branch-commits] [mlir] release/18.x: [ODS][NFC] Cast range.size() to int32_t in accumulation (#85629) (PR #86677)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Mar 26 07:57:33 PDT 2024
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/86677
Backport bce17034157fdfe4d898d30366c1eeca3442fa3d
Requested by: @EugeneZelenko
>From 6b3fe351c9abe9fa9e97ee26628fc1a99fe47e12 Mon Sep 17 00:00:00 2001
From: Andrei Golubev <andrey.golubev at intel.com>
Date: Mon, 25 Mar 2024 23:47:39 +0200
Subject: [PATCH] [ODS][NFC] Cast range.size() to int32_t in accumulation
(#85629)
Using range.size() "as is" means we accumulate 'size_t' values into
'int32_t' variable. This may produce narrowing conversion warnings
(particularly, on MSVC). The surrounding code seems to cast <x>.size()
to 'int32_t' so following this practice seems safe enough.
Co-authored-by: Ovidiu Pintican <ovidiu.pintican at intel.com>
(cherry picked from commit bce17034157fdfe4d898d30366c1eeca3442fa3d)
---
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 71326049af0579..7f748cfbd31ad4 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -3058,7 +3058,7 @@ void OpEmitter::genCodeForAddingArgAndRegionForBuilder(
body << llvm::formatv(
"static_cast<int32_t>(std::accumulate({0}.begin(), {0}.end(), 0, "
"[](int32_t curSum, ::mlir::ValueRange range) {{ return curSum + "
- "range.size(); }))",
+ "static_cast<int32_t>(range.size()); }))",
operandName);
} else {
body << "static_cast<int32_t>(" << getArgumentName(op, i) << ".size())";
More information about the llvm-branch-commits
mailing list