-Rename -Wargument-larger-than -> -Wlarge-by-value-copy
-Improve the diagnostic message
-Add some comments

Suggestions by Chris.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119594 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td
index 1010e84..711380f 100644
--- a/include/clang/Basic/DiagnosticGroups.td
+++ b/include/clang/Basic/DiagnosticGroups.td
@@ -158,7 +158,7 @@
 def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
 def : DiagGroup<"write-strings">;
 def CharSubscript : DiagGroup<"char-subscripts">;
-def ArgumentSizeLargerThan : DiagGroup<"argument-larger-than">;
+def LargeByValueCopy : DiagGroup<"large-by-value-copy">;
 
 // Aggregation warning settings.
 
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index f2cd0ce..198f0e1 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -113,10 +113,12 @@
 def warn_used_but_marked_unused: Warning<"%0 was marked unused but was used">,
   InGroup<UsedButMarkedUnused>, DefaultIgnore;
 
-def warn_parameter_size: Warning<"size of %0 is %1 bytes">,
-  InGroup<ArgumentSizeLargerThan>;
-def warn_return_value_size: Warning<"return value of %0 is %1 bytes">,
-  InGroup<ArgumentSizeLargerThan>;
+def warn_parameter_size: Warning<
+  "%0 is a large (%1 bytes) pass-by-value argument; "
+  "pass it by reference instead ?">, InGroup<LargeByValueCopy>;
+def warn_return_value_size: Warning<
+  "return value of %0 is a large (%1 bytes) pass-by-value object; "
+  "pass it by reference instead ?">, InGroup<LargeByValueCopy>;
 
 def warn_implicit_function_decl : Warning<
   "implicit declaration of function %0">,
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index 558d6dc..2fef7ba 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -122,7 +122,7 @@
 
 public:
   unsigned InstantiationDepth;    // Maximum template instantiation depth.
-  unsigned ArgumentLargerThan;    // Warn if parameter/return value is larger
+  unsigned NumLargeByValueCopy;   // Warn if parameter/return value is larger
                                   // in bytes than this setting. 0 is no check.
 
   // Version of Microsoft Visual C/C++ we are pretending to be. This is
@@ -177,7 +177,7 @@
 
     InstantiationDepth = 1024;
 
-    ArgumentLargerThan = 0;
+    NumLargeByValueCopy = 0;
 
     Optimize = 0;
     OptimizeSize = 0;
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 78f79c1..87a7680 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -500,11 +500,11 @@
   HelpText<"Give inline C++ member functions default visibility by default">;
 def ftemplate_depth : Separate<"-ftemplate-depth">,
   HelpText<"Maximum depth of recursive template instantiation">;
-def Wargument_larger_than : Separate<"-Wargument-larger-than">,
+def Wlarge_by_value_copy : Separate<"-Wlarge-by-value-copy">,
   HelpText<"Warn if a function definition returns or accepts an object larger "
            "in bytes that a given value">;
-def Wargument_larger_than_EQ : Joined<"-Wargument-larger-than=">,
-  Alias<Wargument_larger_than>;
+def Wlarge_by_value_copy_EQ : Joined<"-Wlarge-by-value-copy=">,
+  Alias<Wlarge_by_value_copy>;
 def trigraphs : Flag<"-trigraphs">,
   HelpText<"Process trigraph sequences">;
 def fwritable_strings : Flag<"-fwritable-strings">,
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index 51c3665..0198f34 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -401,8 +401,8 @@
 def ftemplate_depth_ : Joined<"-ftemplate-depth-">, Group<f_Group>;
 def ftemplate_backtrace_limit_EQ : Joined<"-ftemplate-backtrace-limit=">,
                                    Group<f_Group>;
-def Wargument_larger_than_def : Flag<"-Wargument-larger-than">;
-def Wargument_larger_than_EQ : Joined<"-Wargument-larger-than=">;
+def Wlarge_by_value_copy_def : Flag<"-Wlarge-by-value-copy">;
+def Wlarge_by_value_copy_EQ : Joined<"-Wlarge-by-value-copy=">;
 def fterminated_vtables : Flag<"-fterminated-vtables">, Group<f_Group>;
 def fthreadsafe_statics : Flag<"-fthreadsafe-statics">, Group<f_Group>;
 def ftime_report : Flag<"-ftime-report">, Group<f_Group>;
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index cae11a4..aac36bb 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -760,8 +760,9 @@
   void DiagnoseUnusedParameters(ParmVarDecl * const *Begin,
                                 ParmVarDecl * const *End);
 
-  /// \brief Diagnose size of parameters and return value of a Function
-  /// or ObjCMethod.
+  /// \brief Diagnose whether the size of parameters or return value of a
+  /// function or obj-c method definition is pass-by-value and larger than a
+  /// specified threshold.
   void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin,
                                               ParmVarDecl * const *End,
                                               QualType ReturnTy,
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index d9e3760..60d2fe3 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1199,13 +1199,13 @@
     CmdArgs.push_back(A->getValue(Args));
   }
 
-  if (Arg *A = Args.getLastArg(options::OPT_Wargument_larger_than_EQ,
-                               options::OPT_Wargument_larger_than_def)) {
-    CmdArgs.push_back("-Wargument-larger-than");
+  if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ,
+                               options::OPT_Wlarge_by_value_copy_def)) {
+    CmdArgs.push_back("-Wlarge-by-value-copy");
     if (A->getNumValues())
       CmdArgs.push_back(A->getValue(Args));
     else
-      CmdArgs.push_back("64"); // default value for -Wargument-larger-than
+      CmdArgs.push_back("64"); // default value for -Wlarge-by-value-copy.
   }
 
   if (Args.hasArg(options::OPT__relocatable_pch))
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 466dfbd..b1d6adb 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1373,7 +1373,7 @@
   Opts.MathErrno = Args.hasArg(OPT_fmath_errno);
   Opts.InstantiationDepth = Args.getLastArgIntValue(OPT_ftemplate_depth, 1024,
                                                Diags);
-  Opts.ArgumentLargerThan = Args.getLastArgIntValue(OPT_Wargument_larger_than,
+  Opts.NumLargeByValueCopy = Args.getLastArgIntValue(OPT_Wlarge_by_value_copy,
                                                     0, Diags);
   Opts.NeXTRuntime = !Args.hasArg(OPT_fgnu_runtime);
   Opts.ObjCConstantStringClass =
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index dc017d2..d36bd17 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -4869,14 +4869,16 @@
                                                   ParmVarDecl * const *ParamEnd,
                                                   QualType ReturnTy,
                                                   NamedDecl *D) {
-  if (LangOpts.ArgumentLargerThan == 0) // No check.
+  if (LangOpts.NumLargeByValueCopy == 0) // No check.
     return;
 
+  // Warn if the return value is pass-by-value and larger than the specified
+  // threshold.
   if (ReturnTy->isPODType() &&
       Diags.getDiagnosticLevel(diag::warn_return_value_size) !=
           Diagnostic::Ignored) {
     unsigned Size = Context.getTypeSizeInChars(ReturnTy).getQuantity();
-    if (Size > LangOpts.ArgumentLargerThan)
+    if (Size > LangOpts.NumLargeByValueCopy)
       Diag(D->getLocation(), diag::warn_return_value_size)
           << D->getDeclName() << Size;
   }
@@ -4884,12 +4886,14 @@
   if (Diags.getDiagnosticLevel(diag::warn_parameter_size)==Diagnostic::Ignored)
     return;
 
+  // Warn if any parameter is pass-by-value and larger than the specified
+  // threshold.
   for (; Param != ParamEnd; ++Param) {
     QualType T = (*Param)->getType();
     if (!T->isPODType())
       continue;
     unsigned Size = Context.getTypeSizeInChars(T).getQuantity();
-    if (Size > LangOpts.ArgumentLargerThan)
+    if (Size > LangOpts.NumLargeByValueCopy)
       Diag((*Param)->getLocation(), diag::warn_parameter_size)
           << (*Param)->getDeclName() << Size;
   }
diff --git a/test/SemaCXX/warn-argument-larger-than.cpp b/test/SemaCXX/warn-large-by-value-copy.cpp
similarity index 60%
rename from test/SemaCXX/warn-argument-larger-than.cpp
rename to test/SemaCXX/warn-large-by-value-copy.cpp
index 7a80025..39dbd76 100644
--- a/test/SemaCXX/warn-argument-larger-than.cpp
+++ b/test/SemaCXX/warn-large-by-value-copy.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fsyntax-only -Wargument-larger-than=100 %s
+// RUN: %clang_cc1 -verify -fsyntax-only -Wlarge-by-value-copy=100 %s
 
 // rdar://8548050
 namespace rdar8548050 {
@@ -13,8 +13,8 @@
 
 S100 f100(S100 s) { return s; }
 
-S101 f101(S101 s) { return s; } // expected-warning {{return value of 'f101' is 101 bytes}} \
-                                // expected-warning {{size of 's' is 101 bytes}}
+S101 f101(S101 s) { return s; } // expected-warning {{return value of 'f101' is a large (101 bytes) pass-by-value object}} \
+                                // expected-warning {{'s' is a large (101 bytes) pass-by-value argument}}
 
 typedef int Arr[200];
 void farr(Arr a) { }
@@ -32,7 +32,7 @@
 };
 
 template <unsigned size>
-void tf(TS<size> ts) {} // expected-warning {{size of 'ts' is 300 bytes}}
+void tf(TS<size> ts) {} // expected-warning {{ts' is a large (300 bytes) pass-by-value argument}}
 
 void g() {
     TS<300> ts;