forked from OSchip/llvm-project
Tweak the text of several main() diagnostics and punch a hole specifically for
Darwin's sekrit fourth argument. This should probably be factored to let targets make target-specific decisions about what main() should look like. Fixes rdar://problem/7414990 or if different platforms have radically different ideas of what they want in llvm-svn: 92128
This commit is contained in:
parent
53b93a091e
commit
0e21fccfae
|
@ -186,11 +186,12 @@ def warn_unusual_main_decl : Warning<"'main' should not be declared "
|
|||
def err_unusual_main_decl : Error<"'main' is not allowed to be declared "
|
||||
"%select{static|inline|static or inline}0">;
|
||||
def err_main_returns_nonint : Error<"'main' must return 'int'">;
|
||||
def err_main_surplus_args : Error<"%0 is too many arguments for 'main': "
|
||||
def err_main_surplus_args : Error<"too many parameters (%0) for 'main': "
|
||||
"must be 0, 2, or 3">;
|
||||
def warn_main_one_arg : Warning<"one-argument 'main' is usually a mistake">;
|
||||
def err_main_arg_wrong : Error<"%select{first|second|third}0 argument of "
|
||||
"'main' should be of type %1">;
|
||||
def warn_main_one_arg : Warning<"only one parameter on 'main' declaration">;
|
||||
def err_main_arg_wrong : Error<"%select{first|second|third|fourth}0 "
|
||||
"parameter of 'main' (%select{argument count|argument array|environment|"
|
||||
"platform-specific data}0) must be of type %1">;
|
||||
|
||||
/// parser diagnostics
|
||||
def ext_typedef_without_a_name : ExtWarn<"typedef requires a name">;
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "clang/Lex/HeaderSearch.h"
|
||||
#include "llvm/ADT/BitVector.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
|
@ -3398,7 +3399,16 @@ void Sema::CheckMain(FunctionDecl* FD) {
|
|||
unsigned nparams = FTP->getNumArgs();
|
||||
assert(FD->getNumParams() == nparams);
|
||||
|
||||
if (nparams > 3) {
|
||||
bool HasExtraParameters = (nparams > 3);
|
||||
|
||||
// Darwin passes an undocumented fourth argument of type char**. If
|
||||
// other platforms start sprouting these, the logic below will start
|
||||
// getting shifty.
|
||||
if (nparams == 4 &&
|
||||
Context.Target.getTriple().getOS() == llvm::Triple::Darwin)
|
||||
HasExtraParameters = false;
|
||||
|
||||
if (HasExtraParameters) {
|
||||
Diag(FD->getLocation(), diag::err_main_surplus_args) << nparams;
|
||||
FD->setInvalidDecl(true);
|
||||
nparams = 3;
|
||||
|
@ -3409,7 +3419,7 @@ void Sema::CheckMain(FunctionDecl* FD) {
|
|||
|
||||
QualType CharPP =
|
||||
Context.getPointerType(Context.getPointerType(Context.CharTy));
|
||||
QualType Expected[] = { Context.IntTy, CharPP, CharPP };
|
||||
QualType Expected[] = { Context.IntTy, CharPP, CharPP, CharPP };
|
||||
|
||||
for (unsigned i = 0; i < nparams; ++i) {
|
||||
QualType AT = FTP->getArgType(i);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
||||
|
||||
void // expected-error {{error: 'main' must return 'int'}}
|
||||
main( // expected-error {{error: first argument of 'main' should be of type 'int'}}
|
||||
main( // expected-error {{error: first parameter of 'main' (argument count) must be of type 'int'}}
|
||||
float a
|
||||
) {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue