[clang] Fix erroneous `-Wmissing-prototypes` for Win32 entry points (PR #98105)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 8 19:22:13 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Max Winkler (MaxEW707)

<details>
<summary>Changes</summary>

Fixes https://github.com/llvm/llvm-project/issues/94366.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDecl.cpp (+3) 
- (modified) clang/test/Sema/no-warn-missing-prototype.c (+19) 


``````````diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b3bfdacb01790..b4d8d653616b1 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15214,6 +15214,9 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
       if (II->isStr("main") || II->isStr("efi_main"))
         return false;
 
+  if (FD->isMSVCRTEntryPoint())
+    return false;
+
   // Don't warn about inline functions.
   if (FD->isInlined())
     return false;
diff --git a/clang/test/Sema/no-warn-missing-prototype.c b/clang/test/Sema/no-warn-missing-prototype.c
index 6059b6aa0f146..1b6e8f059fc45 100644
--- a/clang/test/Sema/no-warn-missing-prototype.c
+++ b/clang/test/Sema/no-warn-missing-prototype.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes -x c -ffreestanding -verify %s
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes -x c++ -ffreestanding -verify %s
+// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -x c++ -ffreestanding -triple=x86_64-pc-win32 -verify -DMS %s
 // expected-no-diagnostics
 int main() {
   return 0;
@@ -8,3 +9,21 @@ int main() {
 int efi_main() {
   return 0;
 }
+
+#ifdef MS
+int wmain(int, wchar_t *[], wchar_t *[]) {
+  return 0;
+}
+
+int wWinMain(void*, void*, wchar_t*, int) {
+  return 0;
+}
+
+int WinMain(void*, void*, char*, int) {
+  return 0;
+}
+
+bool DllMain(void*, unsigned, void* {
+  return true;
+}
+#endif

``````````

</details>


https://github.com/llvm/llvm-project/pull/98105


More information about the cfe-commits mailing list