From: Bill Wendling Date: Fri, 22 Nov 2019 20:35:14 +0000 (-0800) Subject: Don't report "main" as missing a prototype in freestanding mode X-Git-Tag: llvmorg-11-init~3587 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9180f8a57436da0ce91d9d4885702a10f89571bc;p=platform%2Fupstream%2Fllvm.git 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 --- diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6d857e8..47c05d5 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(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 0000000..2361677 --- /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; +}