]> granicus.if.org Git - clang/commitdiff
-Rename -Wargument-larger-than -> -Wlarge-by-value-copy
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 18 Nov 2010 00:20:36 +0000 (00:20 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 18 Nov 2010 00:20:36 +0000 (00:20 +0000)
-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

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Basic/LangOptions.h
include/clang/Driver/CC1Options.td
include/clang/Driver/Options.td
include/clang/Sema/Sema.h
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-large-by-value-copy.cpp [moved from test/SemaCXX/warn-argument-larger-than.cpp with 60% similarity]

index 1010e84490bb7422d6a2db61679e41a3943efae4..711380fa39b7005264cb514169aade45140fd8f2 100644 (file)
@@ -158,7 +158,7 @@ def VLA : DiagGroup<"vla">;
 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.
 
index f2cd0ce01c5f21be8e8941b1418691b6019bd732..198f0e16395977510ee438eb3bcacbee7c5db8e3 100644 (file)
@@ -113,10 +113,12 @@ def warn_unused_member_function : Warning<"unused member function %0">,
 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">,
index 558d6dc416f6fe76da358e7f8e3a26b3760aa171..2fef7bad469f631a51887392cd65636f68b0e5b5 100644 (file)
@@ -122,7 +122,7 @@ private:
 
 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 @@ public:
 
     InstantiationDepth = 1024;
 
-    ArgumentLargerThan = 0;
+    NumLargeByValueCopy = 0;
 
     Optimize = 0;
     OptimizeSize = 0;
index 78f79c1eb17ba7a0198d44684ab3c501e42e26fa..87a7680454928917e36ba32e0ae4ce36d3d06a77 100644 (file)
@@ -500,11 +500,11 @@ def fvisibility_inlines_hidden : Flag<"-fvisibility-inlines-hidden">,
   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">,
index 51c366564b500667c1e1d9c503a5da9657c2e41c..0198f3468e7357016be2f623fd1da55585c4c458 100644 (file)
@@ -401,8 +401,8 @@ def ferror_limit_EQ : Joined<"-ferror-limit=">, Group<f_Group>;
 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>;
index cae11a4a2050fab19a73a7ef908e5a9705ba8dc4..aac36bb155815908d86c771ef94a9e7be1388402 100644 (file)
@@ -760,8 +760,9 @@ public:
   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,
index d9e3760a8d87084f81977900ca95bfbd177d0a52..60d2fe37925cb6162bff7fa38bf7cc51d057648c 100644 (file)
@@ -1199,13 +1199,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     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))
index 466dfbd9af4118c70233f0aa8fef55ba457c1acb..b1d6adb94badfee8fc7dadc80ecf26cda10a6372 100644 (file)
@@ -1373,7 +1373,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   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 =
index dc017d2ba55256eb4b13fbe6ae9549ce5e134550..d36bd178e89a6cc7aab2a7883a6d98312a3dd88d 100644 (file)
@@ -4869,14 +4869,16 @@ void Sema::DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Param,
                                                   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 @@ void Sema::DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Param,
   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;
   }
similarity index 60%
rename from test/SemaCXX/warn-argument-larger-than.cpp
rename to test/SemaCXX/warn-large-by-value-copy.cpp
index 7a8002530b013211dccc3737299c007c4ffd558e..39dbd7697d26bbfec264d3304f43a61d18c76718 100644 (file)
@@ -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 @@ struct S101 {
 
 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 @@ struct TS {
 };
 
 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;