Skip to content

[formatv][FmtAlign] Use fill count of type size_t instead of uint32_t #78459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

andrey-golubev
Copy link
Contributor

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.

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 <[email protected]>
@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2024

@llvm/pr-subscribers-llvm-support

Author: Andrei Golubev (andrey-golubev)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/78459.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Support/FormatCommon.h (+2-2)
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;
   }
 };

@andrey-golubev
Copy link
Contributor Author

@zturner0826 @labath please take a look (you seem to be the ones who worked on this before)!

@andrey-golubev
Copy link
Contributor Author

also, I guess @inglorion could have some experience with the surroundings.

Copy link
Member

@aganea aganea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aganea
Copy link
Member

aganea commented Jan 18, 2024

For the record, can you please post the compiler message that you see before this PR? (As well as compiler version)

@andrey-golubev
Copy link
Contributor Author

andrey-golubev commented Jan 18, 2024

For the record, can you please post the compiler message that you see before this PR? (As well as compiler version)

aha. this would be rather complicated since I'm not the original author (also, this patch was submitted ~1 year ago if not earlier). to the best of my knowledge, it fails on some MSVC version on x86. i can try to ping whoever brought it up in our downstream originally, maybe they still have something of the kind around.

@andrey-golubev
Copy link
Contributor Author

For the record, can you please post the compiler message that you see before this PR? (As well as compiler version)

aha. this would be rather complicated since I'm not the original author (also, this patch was submitted ~1 year ago if not earlier). to the best of my knowledge, it fails on some MSVC version on x86. i can try to ping whoever brought it up in our downstream originally, maybe they still have something of the kind around.

yeah, no luck. I found the original patch in our fork but the issues were fixed in bulk for MSVC 2019 so there's no special error for this :| from our internal chats I guess it is roughly "conversion from 'size_t' to 'uint32_t' requires a narrowing conversion".

@aganea
Copy link
Member

aganea commented Jan 18, 2024

No worries, thanks for investigating!

@aganea aganea merged commit 296a684 into llvm:main Jan 18, 2024
@andrey-golubev andrey-golubev deleted the size_t_in_formatter branch January 18, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants