[clang] Fix erroneous `-Wmissing-prototypes` for Win32 entry points (PR #98105)
Max Winkler via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 8 19:26:43 PDT 2024
https://github.com/MaxEW707 updated https://github.com/llvm/llvm-project/pull/98105
>From f9def27dcbfe6ce1a55fd5c41d15d55b05d9a056 Mon Sep 17 00:00:00 2001
From: MaxEW707 <max.enrico.winkler at gmail.com>
Date: Mon, 8 Jul 2024 19:14:11 -0700
Subject: [PATCH 1/3] Fix erroneous `-Wmissing-prototypes` for Win32 entry
points
---
clang/lib/Sema/SemaDecl.cpp | 3 +++
clang/test/Sema/no-warn-missing-prototype.c | 27 +++++++++++++++++++--
2 files changed, 28 insertions(+), 2 deletions(-)
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..577718c928e59 100644
--- a/clang/test/Sema/no-warn-missing-prototype.c
+++ b/clang/test/Sema/no-warn-missing-prototype.c
@@ -1,10 +1,33 @@
// 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;
+ return 0;
}
int efi_main() {
- return 0;
+ 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
\ No newline at end of file
>From 1143a06a4b4b7f435c19325bd3b2253cde02372c Mon Sep 17 00:00:00 2001
From: MaxEW707 <max.enrico.winkler at gmail.com>
Date: Mon, 8 Jul 2024 19:19:07 -0700
Subject: [PATCH 2/3] formatting
---
clang/test/Sema/no-warn-missing-prototype.c | 26 +++++++++------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/clang/test/Sema/no-warn-missing-prototype.c b/clang/test/Sema/no-warn-missing-prototype.c
index 577718c928e59..1b6e8f059fc45 100644
--- a/clang/test/Sema/no-warn-missing-prototype.c
+++ b/clang/test/Sema/no-warn-missing-prototype.c
@@ -3,31 +3,27 @@
// 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;
+ return 0;
}
int efi_main() {
- return 0;
+ return 0;
}
#ifdef MS
-int wmain(int, wchar_t *[], wchar_t *[])
-{
- return 0;
+int wmain(int, wchar_t *[], wchar_t *[]) {
+ return 0;
}
-int wWinMain(void*, void*, wchar_t*, int)
-{
- return 0;
+int wWinMain(void*, void*, wchar_t*, int) {
+ return 0;
}
-int WinMain(void*, void*, char*, int)
-{
- return 0;
+int WinMain(void*, void*, char*, int) {
+ return 0;
}
-bool DllMain(void*, unsigned, void*)
-{
- return true;
+bool DllMain(void*, unsigned, void* {
+ return true;
}
-#endif
\ No newline at end of file
+#endif
>From bc40af777e31df856de3c68fe749311c8011f21f Mon Sep 17 00:00:00 2001
From: MaxEW707 <max.enrico.winkler at gmail.com>
Date: Mon, 8 Jul 2024 19:26:29 -0700
Subject: [PATCH 3/3] fix unit test
---
clang/test/Sema/no-warn-missing-prototype.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/test/Sema/no-warn-missing-prototype.c b/clang/test/Sema/no-warn-missing-prototype.c
index 1b6e8f059fc45..17d69ac8913fa 100644
--- a/clang/test/Sema/no-warn-missing-prototype.c
+++ b/clang/test/Sema/no-warn-missing-prototype.c
@@ -1,6 +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
+// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -Wmissing-prototypes -x c++ -ffreestanding -triple=x86_64-pc-win32 -verify -DMS %s
// expected-no-diagnostics
int main() {
return 0;
@@ -23,7 +23,7 @@ int WinMain(void*, void*, char*, int) {
return 0;
}
-bool DllMain(void*, unsigned, void* {
+bool DllMain(void*, unsigned, void*) {
return true;
}
#endif
More information about the cfe-commits
mailing list