[clang] 9180f8a - Don't report "main" as missing a prototype in freestanding mode

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 22 12:36:47 PST 2019


Author: Bill Wendling
Date: 2019-11-22T12:35:43-08:00
New Revision: 9180f8a57436da0ce91d9d4885702a10f89571bc

URL: https://github.com/llvm/llvm-project/commit/9180f8a57436da0ce91d9d4885702a10f89571bc
DIFF: https://github.com/llvm/llvm-project/commit/9180f8a57436da0ce91d9d4885702a10f89571bc.diff

LOG: Don't report "main" as missing a prototype in freestanding mode

Summary:
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".

Reviewers: efriedma, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70588

Added: 
    clang/test/Sema/no-warn-missing-prototype.c

Modified: 
    clang/lib/Sema/SemaDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6d857e832c4b..47c05d5d2eaa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13319,8 +13319,10 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
     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())

diff  --git a/clang/test/Sema/no-warn-missing-prototype.c b/clang/test/Sema/no-warn-missing-prototype.c
new file mode 100644
index 000000000000..2361677a5f73
--- /dev/null
+++ b/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;
+}


        


More information about the cfe-commits mailing list