Skip to content

Conversation

@mstorsjo
Copy link
Member

This fixes the following build warnings in a mingw environment:

../../lldb/source/Host/windows/MainLoopWindows.cpp:226:50: warning: format specifies type 'int' but the argument has type 'IOObject::WaitableHandle' (aka 'void *') [-Wformat]
  226 |         "File descriptor %d already monitored.", waitable_handle);
      |                          ~~                      ^~~~~~~~~~~~~~~
../../lldb/source/Host/windows/MainLoopWindows.cpp:239:49: warning: format specifies type 'int' but the argument has type 'DWORD' (aka 'unsigned long') [-Wformat]
  238 |       error = Status::FromErrorStringWithFormat("Unsupported file type %d",
      |                                                                        ~~
      |                                                                        %lu
  239 |                                                 file_type);
      |                                                 ^~~~~~~~~
2 warnings generated.

This fixes the following build warnings in a mingw environment:

    ../../lldb/source/Host/windows/MainLoopWindows.cpp:226:50: warning: format specifies type 'int' but the argument has type 'IOObject::WaitableHandle' (aka 'void *') [-Wformat]
      226 |         "File descriptor %d already monitored.", waitable_handle);
          |                          ~~                      ^~~~~~~~~~~~~~~
    ../../lldb/source/Host/windows/MainLoopWindows.cpp:239:49: warning: format specifies type 'int' but the argument has type 'DWORD' (aka 'unsigned long') [-Wformat]
      238 |       error = Status::FromErrorStringWithFormat("Unsupported file type %d",
          |                                                                        ~~
          |                                                                        %lu
      239 |                                                 file_type);
          |                                                 ^~~~~~~~~
    2 warnings generated.
@llvmbot
Copy link
Member

llvmbot commented Jul 28, 2025

@llvm/pr-subscribers-lldb

Author: Martin Storsjö (mstorsjo)

Changes

This fixes the following build warnings in a mingw environment:

../../lldb/source/Host/windows/MainLoopWindows.cpp:226:50: warning: format specifies type 'int' but the argument has type 'IOObject::WaitableHandle' (aka 'void *') [-Wformat]
  226 |         "File descriptor %d already monitored.", waitable_handle);
      |                          ~~                      ^~~~~~~~~~~~~~~
../../lldb/source/Host/windows/MainLoopWindows.cpp:239:49: warning: format specifies type 'int' but the argument has type 'DWORD' (aka 'unsigned long') [-Wformat]
  238 |       error = Status::FromErrorStringWithFormat("Unsupported file type %d",
      |                                                                        ~~
      |                                                                        %lu
  239 |                                                 file_type);
      |                                                 ^~~~~~~~~
2 warnings generated.

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

1 Files Affected:

  • (modified) lldb/source/Host/windows/MainLoopWindows.cpp (+2-2)
diff --git a/lldb/source/Host/windows/MainLoopWindows.cpp b/lldb/source/Host/windows/MainLoopWindows.cpp
index c1a018238432d..f7f65a82f726f 100644
--- a/lldb/source/Host/windows/MainLoopWindows.cpp
+++ b/lldb/source/Host/windows/MainLoopWindows.cpp
@@ -223,7 +223,7 @@ MainLoopWindows::RegisterReadObject(const IOObjectSP &object_sp,
 
   if (m_read_fds.find(waitable_handle) != m_read_fds.end()) {
     error = Status::FromErrorStringWithFormat(
-        "File descriptor %d already monitored.", waitable_handle);
+        "File descriptor %p already monitored.", waitable_handle);
     return nullptr;
   }
 
@@ -236,7 +236,7 @@ MainLoopWindows::RegisterReadObject(const IOObjectSP &object_sp,
     DWORD file_type = GetFileType(waitable_handle);
     if (file_type != FILE_TYPE_PIPE) {
       error = Status::FromErrorStringWithFormat("Unsupported file type %d",
-                                                file_type);
+                                                static_cast<int>(file_type));
       return nullptr;
     }
 

@DavidSpickett
Copy link
Collaborator

Should you use %lu instead of casting? https://learn.microsoft.com/en-gb/windows/win32/winprog/windows-data-types?redirectedfrom=MSDN:

A 32-bit unsigned integer. The range is 0 through 4294967295 decimal.
This type is declared in IntSafe.h as follows:
typedef unsigned long DWORD;

I assume since they didn't note it, it's the same size on x86 and x86_64.

@DavidSpickett
Copy link
Collaborator

Oh but is there a Mingw detail here that means the cast is better?

@mstorsjo
Copy link
Member Author

Oh but is there a Mingw detail here that means the cast is better?

No, mingw should conform quite closely regarding such details. I just didn't feel like assuming such details about the type of DWORD, but you're right, and it should be fine to do that instead. Will update.

@mstorsjo
Copy link
Member Author

Tested that this still silences the warnings, on both 32 and 64 bit.

Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

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

Looks good, though personally, I'd use FromErrorStringWithFormatv and let it deduce the format.

@mstorsjo mstorsjo merged commit 98ec927 into llvm:main Jul 28, 2025
9 checks passed
@mstorsjo mstorsjo deleted the lldb-win-format-warnings branch July 28, 2025 10:10
@mstorsjo mstorsjo added this to the LLVM 21.x Release milestone Jul 28, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Jul 28, 2025
@mstorsjo
Copy link
Member Author

/cherry-pick 98ec927

@llvmbot
Copy link
Member

llvmbot commented Jul 28, 2025

/pull-request #150919

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Jul 28, 2025
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 29, 2025
This fixes the following build warnings in a mingw environment:

../../lldb/source/Host/windows/MainLoopWindows.cpp:226:50: warning:
format specifies type 'int' but the argument has type
'IOObject::WaitableHandle' (aka 'void *') [-Wformat]
226 | "File descriptor %d already monitored.", waitable_handle);
| ~~ ^~~~~~~~~~~~~~~
../../lldb/source/Host/windows/MainLoopWindows.cpp:239:49: warning:
format specifies type 'int' but the argument has type 'DWORD' (aka
'unsigned long') [-Wformat]
238 | error = Status::FromErrorStringWithFormat("Unsupported file type
%d",
| ~~
| %lu
      239 |                                                 file_type);
          |                                                 ^~~~~~~~~
    2 warnings generated.

(cherry picked from commit 98ec927)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Development

Successfully merging this pull request may close these issues.

4 participants