summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-12-24 09:58:38 +0000
committerJohn McCall <rjmccall@apple.com>2009-12-24 09:58:38 +0000
commit0e21fccfae98a40abf001df304553a86efc186b0 (patch)
tree489b711a95393869bf67cfadf8e80fbf41b26e89
parent53b93a091e9f9a7a00917d8c6248de474bd57cad (diff)
downloadbcm5719-llvm-0e21fccfae98a40abf001df304553a86efc186b0.tar.gz
bcm5719-llvm-0e21fccfae98a40abf001df304553a86efc186b0.zip
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
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td9
-rw-r--r--clang/lib/Sema/SemaDecl.cpp14
-rw-r--r--clang/test/CXX/basic/basic.start/basic.start.main/p2f.cpp2
3 files changed, 18 insertions, 7 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index bb507d17a74..b9754f4e247 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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">;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b7584c311ed..9ed4fba66e5 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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);
diff --git a/clang/test/CXX/basic/basic.start/basic.start.main/p2f.cpp b/clang/test/CXX/basic/basic.start/basic.start.main/p2f.cpp
index e346d318b18..a3d6a79a4fa 100644
--- a/clang/test/CXX/basic/basic.start/basic.start.main/p2f.cpp
+++ b/clang/test/CXX/basic/basic.start/basic.start.main/p2f.cpp
@@ -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
) {
}
OpenPOWER on IntegriCloud