[llvm] [formatv][FmtAlign] Use fill count of type size_t instead of uint32_t (PR #78459)

Andrei Golubev via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 08:07:21 PST 2024


https://github.com/andrey-golubev created https://github.com/llvm/llvm-project/pull/78459

FmtAlign::fill() accepts a uint32_t variable while the usages operate on size_t values. On some platform / compiler combinations, this ends up being a narrowing conversion. Fix this by changing the function's signature.

>From 3189fbc273eeb098dd7df2c48c0a740784478a17 Mon Sep 17 00:00:00 2001
From: "Golubev, Andrey" <andrey.golubev at intel.com>
Date: Wed, 17 Jan 2024 15:51:09 +0000
Subject: [PATCH] [formatv][FmtAlign] Use fill count of type size_t instead of
 uint32_t

FmtAlign::fill() accepts a uint32_t variable while the usages operate on size_t
values. On some platform / compiler combinations, this ends up being a narrowing
conversion. Fix this by changing the function's signature.

Co-authored-by: Orest Chura <orest.chura at intel.com>
---
 llvm/include/llvm/Support/FormatCommon.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/Support/FormatCommon.h b/llvm/include/llvm/Support/FormatCommon.h
index 3c119d12529aeed..24a40c325e13148 100644
--- a/llvm/include/llvm/Support/FormatCommon.h
+++ b/llvm/include/llvm/Support/FormatCommon.h
@@ -66,8 +66,8 @@ struct FmtAlign {
   }
 
 private:
-  void fill(llvm::raw_ostream &S, uint32_t Count) {
-    for (uint32_t I = 0; I < Count; ++I)
+  void fill(llvm::raw_ostream &S, size_t Count) {
+    for (size_t I = 0; I < Count; ++I)
       S << Fill;
   }
 };



More information about the llvm-commits mailing list