This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hello, On 13/11/2013 17:42, Sylvestre Ledru wrote: > Hello, > > I would like to propose the activation by default of -Wreturn-type. > So, here is an update on this subject. Feedbacks are more than welcome (my first gcc patch). === return-type-by-default-and-missing-return.diff === implements 1) -Wreturn-type enabled by default 2) Introduce back the option -Wmissing-return (enabled by -Wall) to manage cases like the one from Jonathan Wakely int f(int c) { if (c) return 0; function_that_never_returns(); } $ gcc -Wmissing-return -c foo.c foo.c: In function ÂfÂ: foo.c:7:1: warning: control reaches end of non-void function [-Wmissing-return] } ^ I will split this patch before submitting it. === return-type-by-default-and-missing-return-test-suite.diff.gz === Update the testsuite (for now, 715 files modified, more to come). As you can imagine, it was a great fun ... ;) Basically, there were several cases: 1) Add return 0; (or return true;) to make sure that the function returns something 2) Add -Wno-return-type to dg-options / dg-lto-options when it is too hard to construct the type to return 3) explicit declaration of the function like: -t() +void t() 4) idem with main -main() { +int main() { === What next? === There are some other tests to fix. There are also the fortran tests to fix. Many of them (about 95) are failing because of -Wreturn-type Before finishing everything and sending to gcc patches, I would like to know if I am on the right track and/or if I am missing things. Thanks Sylvestre
Index: gcc/c-family/c.opt =================================================================== --- gcc/c-family/c.opt (révision 205009) +++ gcc/c-family/c.opt (copie de travail) @@ -665,9 +665,13 @@ Warn about returning a pointer/reference to a local or temporary variable. Wreturn-type -C ObjC C++ ObjC++ Var(warn_return_type) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) +C ObjC C++ ObjC++ Var(warn_return_type) Init(1) Warning Warn whenever a function's return type defaults to \"int\" (C), or about inconsistent return types (C++) +Wmissing-return +C ObjC C++ ObjC++ Var(warn_missing_return) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) +Warn whenever control may reach end of non-void function + Wselector ObjC ObjC++ Var(warn_selector) Warning Warn if a selector has multiple methods Index: gcc/fortran/options.c =================================================================== --- gcc/fortran/options.c (révision 205009) +++ gcc/fortran/options.c (copie de travail) @@ -717,6 +717,10 @@ warn_return_type = value; break; + case OPT_Wmissing_return: + warn_missing_return = value; + break; + case OPT_Wsurprising: gfc_option.warn_surprising = value; break; Index: gcc/tree-cfg.c =================================================================== --- gcc/tree-cfg.c (révision 205009) +++ gcc/tree-cfg.c (copie de travail) @@ -8067,7 +8067,7 @@ /* If we see "return;" in some basic block, then we do reach the end without returning a value. */ - else if (warn_return_type + else if (warn_missing_return && !TREE_NO_WARNING (cfun->decl) && EDGE_COUNT (EXIT_BLOCK_PTR->preds) > 0 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (cfun->decl)))) @@ -8082,7 +8082,7 @@ location = gimple_location (last); if (location == UNKNOWN_LOCATION) location = cfun->function_end_locus; - warning_at (location, OPT_Wreturn_type, "control reaches end of non-void function"); + warning_at (location, OPT_Wmissing_return, "control reaches end of non-void function"); TREE_NO_WARNING (cfun->decl) = 1; break; }
Attachment:
return-type-by-default-and-missing-return-test-suite.diff.gz
Description: application/gzip
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |