[cfe-commits] r119594 - in /cfe/trunk: 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-argument-larger-than.cpp test/SemaCXX/warn-large-by-value-copy.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Nov 17 16:20:36 PST 2010
Author: akirtzidis
Date: Wed Nov 17 18:20:36 2010
New Revision: 119594
URL: http://llvm.org/viewvc/llvm-project?rev=119594&view=rev
Log:
-Rename -Wargument-larger-than -> -Wlarge-by-value-copy
-Improve the diagnostic message
-Add some comments
Suggestions by Chris.
Added:
cfe/trunk/test/SemaCXX/warn-large-by-value-copy.cpp
- copied, changed from r119585, cfe/trunk/test/SemaCXX/warn-argument-larger-than.cpp
Removed:
cfe/trunk/test/SemaCXX/warn-argument-larger-than.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=119594&r1=119593&r2=119594&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Nov 17 18:20:36 2010
@@ -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.
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=119594&r1=119593&r2=119594&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Nov 17 18:20:36 2010
@@ -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">,
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=119594&r1=119593&r2=119594&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Wed Nov 17 18:20:36 2010
@@ -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;
Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=119594&r1=119593&r2=119594&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Wed Nov 17 18:20:36 2010
@@ -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">,
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=119594&r1=119593&r2=119594&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Nov 17 18:20:36 2010
@@ -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>;
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=119594&r1=119593&r2=119594&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Nov 17 18:20:36 2010
@@ -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,
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=119594&r1=119593&r2=119594&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Nov 17 18:20:36 2010
@@ -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))
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=119594&r1=119593&r2=119594&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Nov 17 18:20:36 2010
@@ -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 =
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=119594&r1=119593&r2=119594&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Nov 17 18:20:36 2010
@@ -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;
}
Removed: cfe/trunk/test/SemaCXX/warn-argument-larger-than.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-argument-larger-than.cpp?rev=119593&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-argument-larger-than.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-argument-larger-than.cpp (removed)
@@ -1,42 +0,0 @@
-// RUN: %clang_cc1 -verify -fsyntax-only -Wargument-larger-than=100 %s
-
-// rdar://8548050
-namespace rdar8548050 {
-
-struct S100 {
- char x[100];
-};
-
-struct S101 {
- char x[101];
-};
-
-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}}
-
-typedef int Arr[200];
-void farr(Arr a) { }
-
-struct NonPOD {
- char x[200];
- virtual void m();
-};
-
-NonPOD fNonPOD(NonPOD s) { return s; }
-
-template <unsigned size>
-struct TS {
- char x[size];
-};
-
-template <unsigned size>
-void tf(TS<size> ts) {} // expected-warning {{size of 'ts' is 300 bytes}}
-
-void g() {
- TS<300> ts;
- tf<300>(ts); // expected-note {{instantiation}}
-}
-
-}
Copied: cfe/trunk/test/SemaCXX/warn-large-by-value-copy.cpp (from r119585, cfe/trunk/test/SemaCXX/warn-argument-larger-than.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-large-by-value-copy.cpp?p2=cfe/trunk/test/SemaCXX/warn-large-by-value-copy.cpp&p1=cfe/trunk/test/SemaCXX/warn-argument-larger-than.cpp&r1=119585&r2=119594&rev=119594&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-argument-larger-than.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-large-by-value-copy.cpp Wed Nov 17 18:20:36 2010
@@ -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;
More information about the cfe-commits
mailing list