Skip to content

[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

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

nickdesaulniers
Copy link
Member

@nickdesaulniers nickdesaulniers commented Jun 18, 2024

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:
    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.
@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (paternity leave) (nickdesaulniers)

Changes

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.


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

1 Files Affected:

  • (modified) libc/src/__support/OSUtil/linux/fcntl.cpp (+2-2)
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;
   }

@nickdesaulniers
Copy link
Member Author

cc @simonzgx

@simonzgx
Copy link
Contributor

Got, thanks a lot.

Copy link
Contributor

@SchrodingerZhu SchrodingerZhu left a 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.

@lntue
Copy link
Contributor

lntue commented Jun 18, 2024

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

if (static_cast<unsigned long>(retVal) <= -4096UL)
      return fex.type == F_OWNER_PGRP ? -fex.pid : fex.pid;

which will treat erroneous condition retval < -4096 the same as ok condition retval >= 0. We should continue the discussion of that one in #95570.

@SchrodingerZhu SchrodingerZhu merged commit fad2ad7 into llvm:main Jun 18, 2024
6 of 7 checks passed
@nickdesaulniers nickdesaulniers deleted the arm32_fcntl branch June 18, 2024 21:41
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants