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())
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())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits