-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc][fcntl] fix -Wshorten-64-to-32 for 32b ARM #95945
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
Conversation
Fixes: llvm-project/libc/src/__support/OSUtil/linux/fcntl.cpp:63:26: error: implicit conversion loses integer precision: '__off64_t' (aka 'long long') to '__off_t' (aka 'long') [-Werror,-Wshorten-64-to-32] flk->l_start = flk64.l_start; ~ ~~~~~~^~~~~~~ llvm-project/libc/src/__support/OSUtil/linux/fcntl.cpp:64:24: error: implicit conversion loses integer precision: '__off64_t' (aka 'long long') to '__off_t' (aka 'long') [-Werror,-Wshorten-64-to-32] flk->l_len = flk64.l_len; ~ ~~~~~~^~~~~ We already have an overflow check, just need the cast to be explicit. This warning was observed on the 32b ARM build in overlay mode.
@llvm/pr-subscribers-libc Author: Nick Desaulniers (paternity leave) (nickdesaulniers) ChangesFixes: We already have an overflow check, just need the cast to be explicit. This Full diff: https://github.com/llvm/llvm-project/pull/95945.diff 1 Files Affected:
diff --git a/libc/src/__support/OSUtil/linux/fcntl.cpp b/libc/src/__support/OSUtil/linux/fcntl.cpp
index 7dc416a7916df..b087f898c395d 100644
--- a/libc/src/__support/OSUtil/linux/fcntl.cpp
+++ b/libc/src/__support/OSUtil/linux/fcntl.cpp
@@ -60,8 +60,8 @@ int fcntl(int fd, int cmd, void *arg) {
// Now copy back into flk, in case flk64 got modified
flk->l_type = flk64.l_type;
flk->l_whence = flk64.l_whence;
- flk->l_start = flk64.l_start;
- flk->l_len = flk64.l_len;
+ flk->l_start = static_cast<decltype(flk->l_start)>(flk64.l_start);
+ flk->l_len = static_cast<decltype(flk->l_len)>(flk64.l_len);
flk->l_pid = flk64.l_pid;
return retVal;
}
|
cc @simonzgx |
Got, thanks a lot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch LGTM.
But @lntue mentioned there may be other problems.
The fix for this part is fine for me. The other problem in the same function that I have question is
which will treat erroneous condition |
Fixes: llvm-project/libc/src/__support/OSUtil/linux/fcntl.cpp:63:26: error: implicit conversion loses integer precision: '__off64_t' (aka 'long long') to '__off_t' (aka 'long') [-Werror,-Wshorten-64-to-32] flk->l_start = flk64.l_start; ~ ~~~~~~^~~~~~~ llvm-project/libc/src/__support/OSUtil/linux/fcntl.cpp:64:24: error: implicit conversion loses integer precision: '__off64_t' (aka 'long long') to '__off_t' (aka 'long') [-Werror,-Wshorten-64-to-32] flk->l_len = flk64.l_len; ~ ~~~~~~^~~~~ We already have an overflow check, just need the cast to be explicit. This warning was observed on the 32b ARM build in overlay mode.
Fixes:
We already have an overflow check, just need the cast to be explicit. This
warning was observed on the 32b ARM build in overlay mode.