Skip to content

Fix erroneous -Wmissing-prototypes for Win32 entry points #98105

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

Conversation

MaxEW707
Copy link
Contributor

@MaxEW707 MaxEW707 commented Jul 9, 2024

Fixes #94366.

@MaxEW707 MaxEW707 requested review from Endilll and efriedma-quic July 9, 2024 02:21
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2024

@llvm/pr-subscribers-clang

Author: Max Winkler (MaxEW707)

Changes

Fixes #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 --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

@Endilll Endilll requested a review from AaronBallman July 9, 2024 10:25
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@MaxEW707 MaxEW707 merged commit b0b96fb into llvm:main Jul 10, 2024
8 checks passed
@MaxEW707 MaxEW707 deleted the mwinkler/fix-missing-prototypes-win32-mains branch July 10, 2024 01:38
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang-cl] Provide implicit declarations of wmain
5 participants