[cfe-commits] r92128 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CXX/basic/basic.start/basic.start.main/p2f.cpp

John McCall rjmccall at apple.com
Thu Dec 24 01:58:39 PST 2009


Author: rjmccall
Date: Thu Dec 24 03:58:38 2009
New Revision: 92128

URL: http://llvm.org/viewvc/llvm-project?rev=92128&view=rev
Log:
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


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2f.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=92128&r1=92127&r2=92128&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Dec 24 03:58:38 2009
@@ -186,11 +186,12 @@
 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">;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=92128&r1=92127&r2=92128&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Dec 24 03:58:38 2009
@@ -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 @@
   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 @@
 
   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);

Modified: cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2f.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2f.cpp?rev=92128&r1=92127&r2=92128&view=diff

==============================================================================
--- cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2f.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2f.cpp Thu Dec 24 03:58:38 2009
@@ -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
 ) {
 }





More information about the cfe-commits mailing list