[PATCH] D70588: Don't report "main" as missing a prototype in freestanding mode
Bill Wendling via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 22 01:35:06 PST 2019
void created this revision.
void added a reviewer: efriedma.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
A user may want to use freestanding mode with the standard "main" entry
point. It's not useful to warn about a missing prototype as it's not
typical to have a prototype for "main".
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D70588
Files:
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/no-warn-missing-prototype.c
Index: clang/test/Sema/no-warn-missing-prototype.c
===================================================================
--- /dev/null
+++ clang/test/Sema/no-warn-missing-prototype.c
@@ -0,0 +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
+// expected-no-diagnostics
+int main() {
+ return 0;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13319,8 +13319,10 @@
return false;
// Don't warn about 'main'.
- if (FD->isMain())
- return false;
+ if (isa<TranslationUnitDecl>(FD->getDeclContext()->getRedeclContext()))
+ if (IdentifierInfo *II = FD->getIdentifier())
+ if (II->isStr("main"))
+ return false;
// Don't warn about inline functions.
if (FD->isInlined())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70588.230610.patch
Type: text/x-patch
Size: 958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191122/906f11d7/attachment.bin>
More information about the cfe-commits
mailing list