diff options
author | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2008-08-13 17:57:47 +0000 |
---|---|---|
committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2008-08-13 17:57:47 +0000 |
commit | 4003301d719865df5b0f445ab4d80339d86572d7 (patch) | |
tree | d1fe225e6b0637a6333ddd4ed28cd99d4d43c234 | |
parent | 6cd7942d77ea3017ce217daf9621fadc35fe8f8f (diff) | |
download | gcc-4003301d719865df5b0f445ab4d80339d86572d7.zip gcc-4003301d719865df5b0f445ab4d80339d86572d7.tar.gz gcc-4003301d719865df5b0f445ab4d80339d86572d7.tar.bz2 |
re PR c/30551 (-pedantic does not include -Wmain, but -pedantic-errors does make -Wmain cause error messages)
2008-08-13 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 30551
* doc/invoke.texi (Wmain): Update.
* c-decl.c (start_decl): warn_main is only 0 or 1.
(start_function): Likewise. Fix formatting.
(finish_function): Delete redundant warning.
* c.opt (Wmain): Add Var(warn_main) and Init(-1).
* c-opts (c_common_handle_option): -Wall only has effect if
warn_main is uninitialized. OPT_Wmain is automatically
handled. -pedantic also enables Wmain.
(c_common_post_options): Handle all logic for Wmain here.
* c-common.c (warn_main): Delete.
(check_main_parameter_types): Make pedwarns conditional on
OPT_Wmain.
* c-common.h (warn_main): Delete.
cp/
* decl.c (grokfndecl): Call check_main_parameters_type only if
-Wmain.
testsuite/
* gcc.dg/pr30551.c: New.
* gcc.dg/pr30551-2.c: New.
* gcc.dg/pr30551-3.c: New.
* gcc.dg/pr30551-4.c: New.
* gcc.dg/pr30551-5.c: New.
* gcc.dg/pr30551-6.c: New.
* gcc.dg/tree-ssa/reassoc-3.c: Don't compile with -pedantic-errors.
* g++.dg/warn/pr30551.C: New.
* g++.dg/warn/pr30551-2.C: New.
From-SVN: r139063
-rw-r--r-- | gcc/ChangeLog | 17 | ||||
-rw-r--r-- | gcc/c-common.c | 17 | ||||
-rw-r--r-- | gcc/c-common.h | 5 | ||||
-rw-r--r-- | gcc/c-decl.c | 43 | ||||
-rw-r--r-- | gcc/c-opts.c | 30 | ||||
-rw-r--r-- | gcc/c.opt | 2 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/decl.c | 3 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 9 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/pr30551-2.C | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/pr30551.C | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr30551-2.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr30551-3.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr30551-4.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr30551-5.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr30551-6.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr30551.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/reassoc-3.c | 1 |
19 files changed, 140 insertions, 62 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d74b64a..767f3b3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,20 @@ +2008-08-13 Manuel Lopez-Ibanez <manu@gcc.gnu.org> + + PR 30551 + * doc/invoke.texi (Wmain): Update. + * c-decl.c (start_decl): warn_main is only 0 or 1. + (start_function): Likewise. Fix formatting. + (finish_function): Delete redundant warning. + * c.opt (Wmain): Add Var(warn_main) and Init(-1). + * c-opts (c_common_handle_option): -Wall only has effect if + warn_main is uninitialized. OPT_Wmain is automatically + handled. -pedantic also enables Wmain. + (c_common_post_options): Handle all logic for Wmain here. + * c-common.c (warn_main): Delete. + (check_main_parameter_types): Make pedwarns conditional on + OPT_Wmain. + * c-common.h (warn_main): Delete. + 2008-08-13 H.J. Lu <hongjiu.lu@intel.com> PR middle-end/36701 diff --git a/gcc/c-common.c b/gcc/c-common.c index 9302182..8bac9cb 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -342,10 +342,6 @@ int flag_isoc99; int flag_hosted = 1; -/* Warn if main is suspicious. */ - -int warn_main; - /* ObjC language option variables. */ @@ -1363,7 +1359,8 @@ check_main_parameter_types (tree decl) { case 1: if (TYPE_MAIN_VARIANT (type) != integer_type_node) - pedwarn (0, "first argument of %q+D should be %<int%>", decl); + pedwarn (OPT_Wmain, "first argument of %q+D should be %<int%>", + decl); break; case 2: @@ -1371,8 +1368,8 @@ check_main_parameter_types (tree decl) || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) != char_type_node)) - pedwarn (0, "second argument of %q+D should be %<char **%>", - decl); + pedwarn (OPT_Wmain, "second argument of %q+D should be %<char **%>", + decl); break; case 3: @@ -1380,8 +1377,8 @@ check_main_parameter_types (tree decl) || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) != char_type_node)) - pedwarn (0, "third argument of %q+D should probably be " - "%<char **%>", decl); + pedwarn (OPT_Wmain, "third argument of %q+D should probably be " + "%<char **%>", decl); break; } } @@ -1390,7 +1387,7 @@ check_main_parameter_types (tree decl) argument because it's only mentioned in an appendix of the standard. */ if (argct > 0 && (argct < 2 || argct > 3)) - pedwarn (0, "%q+D takes only zero or two arguments", decl); + pedwarn (OPT_Wmain, "%q+D takes only zero or two arguments", decl); } /* True if pointers to distinct types T1 and T2 can be converted to diff --git a/gcc/c-common.h b/gcc/c-common.h index 0f2a359..b0abe3e 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -498,11 +498,6 @@ extern int flag_isoc99; extern int flag_hosted; -/* Warn if main is suspicious. */ - -extern int warn_main; - - /* ObjC language option variables. */ diff --git a/gcc/c-decl.c b/gcc/c-decl.c index e55e809..7be2ca4 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -3153,8 +3153,7 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs, if (!decl) return 0; - if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL - && MAIN_NAME_P (DECL_NAME (decl))) + if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))) warning (OPT_Wmain, "%q+D is usually a function", decl); if (initialized) @@ -6207,13 +6206,13 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, maybe_apply_pragma_weak (decl1); /* Warn for unlikely, improbable, or stupid declarations of `main'. */ - if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1))) + if (warn_main && MAIN_NAME_P (DECL_NAME (decl1))) { if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) != integer_type_node) pedwarn (OPT_Wmain, "return type of %q+D is not %<int%>", decl1); - check_main_parameter_types(decl1); + check_main_parameter_types (decl1); if (!TREE_PUBLIC (decl1)) pedwarn (OPT_Wmain, "%q+D is normally a non-static function", decl1); @@ -6672,30 +6671,18 @@ finish_function (void) if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node) DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; - if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted) - { - if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) - != integer_type_node) - { - /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned. - If warn_main is -1 (-Wno-main) we don't want to be warned. */ - if (!warn_main) - pedwarn (0, "return type of %q+D is not %<int%>", fndecl); - } - else - { - if (flag_isoc99) - { - tree stmt = c_finish_return (integer_zero_node); - /* Hack. We don't want the middle-end to warn that this return - is unreachable, so we mark its location as special. Using - UNKNOWN_LOCATION has the problem that it gets clobbered in - annotate_one_with_locus. A cleaner solution might be to - ensure ! should_carry_locus_p (stmt), but that needs a flag. - */ - SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION); - } - } + if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted + && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) + == integer_type_node && flag_isoc99) + { + tree stmt = c_finish_return (integer_zero_node); + /* Hack. We don't want the middle-end to warn that this return + is unreachable, so we mark its location as special. Using + UNKNOWN_LOCATION has the problem that it gets clobbered in + annotate_one_with_locus. A cleaner solution might be to + ensure ! should_carry_locus_p (stmt), but that needs a flag. + */ + SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION); } /* Tie off the statement tree for this function. */ diff --git a/gcc/c-opts.c b/gcc/c-opts.c index 83e2ed1..300bf14 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -404,9 +404,12 @@ c_common_handle_option (size_t scode, const char *arg, int value) warn_uninitialized = (value ? 2 : 0); if (!c_dialect_cxx ()) - /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding - can turn it off only if it's not explicit. */ - warn_main = value * 2; + { + /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding + can turn it off only if it's not explicit. */ + if (warn_main == -1) + warn_main = (value ? 2 : 0); + } else { /* C++-specific warnings. */ @@ -467,13 +470,6 @@ c_common_handle_option (size_t scode, const char *arg, int value) cpp_opts->warn_invalid_pch = value; break; - case OPT_Wmain: - if (value) - warn_main = 1; - else - warn_main = -1; - break; - case OPT_Wmissing_include_dirs: cpp_opts->warn_missing_include_dirs = value; break; @@ -615,9 +611,6 @@ c_common_handle_option (size_t scode, const char *arg, int value) case OPT_fhosted: flag_hosted = value; flag_no_builtin = !value; - /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */ - if (!value && warn_main == 2) - warn_main = 0; break; case OPT_fshort_double: @@ -907,6 +900,8 @@ c_common_handle_option (size_t scode, const char *arg, int value) warn_pointer_sign = 1; if (warn_overlength_strings == -1) warn_overlength_strings = 1; + if (warn_main == -1) + warn_main = 2; break; case OPT_print_objc_runtime_info: @@ -1071,6 +1066,15 @@ c_common_post_options (const char **pfilename) if (warn_overlength_strings == -1 || c_dialect_cxx ()) warn_overlength_strings = 0; + /* Wmain is enabled by default in C++ but not in C. */ + /* Wmain is disabled by default for -ffreestanding (!flag_hosted), + even if -Wall was given (warn_main will be 2 if set by -Wall, 1 + if set by -Wmain). */ + if (warn_main == -1) + warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0; + else if (warn_main == 2) + warn_main = flag_hosted ? 1 : 0; + /* In C, -Wconversion enables -Wsign-conversion (unless disabled through -Wno-sign-conversion). While in C++, -Wsign-conversion needs to be requested explicitly. */ @@ -281,7 +281,7 @@ C ObjC C++ ObjC++ Var(warn_long_long) Init(1) Warning Do not warn about using \"long long\" when -pedantic Wmain -C ObjC C++ ObjC++ Warning +C ObjC C++ ObjC++ Var(warn_main) Init(-1) Warning Warn about suspicious declarations of \"main\" Wmissing-braces diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 00b3613..e34fb22 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2008-08-13 Manuel Lopez-Ibanez <manu@gcc.gnu.org> + + PR 30551 + * decl.c (grokfndecl): Call check_main_parameters_type only if + -Wmain. + 2008-08-12 Paolo Carlini <paolo.carlini@oracle.com> PR c++/37087 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 6910562..3cd2511 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6692,7 +6692,8 @@ grokfndecl (tree ctype, newtype = build_function_type (integer_type_node, oldtypeargs); TREE_TYPE (decl) = newtype; } - check_main_parameter_types (decl); + if (warn_main) + check_main_parameter_types (decl); } if (ctype != NULL_TREE diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 906c6a6..56a0bda 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2940,10 +2940,11 @@ This warning is also enabled by @option{-Wextra}. @item -Wmain @opindex Wmain @opindex Wno-main -Warn if the type of @samp{main} is suspicious. @samp{main} should be a -function with external linkage, returning int, taking either zero -arguments, two, or three arguments of appropriate types. -This warning is enabled by @option{-Wall}. +Warn if the type of @samp{main} is suspicious. @samp{main} should be +a function with external linkage, returning int, taking either zero +arguments, two, or three arguments of appropriate types. This warning +is enabled by default in C++ and is enabled by either @option{-Wall} +or @option{-pedantic}. @item -Wmissing-braces @opindex Wmissing-braces diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 951f82e..1f1890a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2008-08-13 Manuel Lopez-Ibanez <manu@gcc.gnu.org> + + PR 30551 + * gcc.dg/pr30551.c: New. + * gcc.dg/pr30551-2.c: New. + * gcc.dg/pr30551-3.c: New. + * gcc.dg/pr30551-4.c: New. + * gcc.dg/pr30551-5.c: New. + * gcc.dg/pr30551-6.c: New. + * gcc.dg/tree-ssa/reassoc-3.c: Don't compile with -pedantic-errors. + * g++.dg/warn/pr30551.C: New. + * g++.dg/warn/pr30551-2.C: New. + 2008-08-13 Richard Guenther <rguenther@suse.de> * gcc.dg/tree-ssa/ssa-ccp-21.c: New testcase. diff --git a/gcc/testsuite/g++.dg/warn/pr30551-2.C b/gcc/testsuite/g++.dg/warn/pr30551-2.C new file mode 100644 index 0000000..7a4b136 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr30551-2.C @@ -0,0 +1,6 @@ +// PR 30551 -Wmain is enabled by -pedantic/-pedantic-errors. +// { dg-do compile } +// { dg-options "-pedantic-errors" } + +int main(char a) {} /* { dg-error "error: first argument of .*main.* should be .int." } */ +/* { dg-error "error: .*main.* takes only zero or two arguments" "" { target *-*-* } 5 } */ diff --git a/gcc/testsuite/g++.dg/warn/pr30551.C b/gcc/testsuite/g++.dg/warn/pr30551.C new file mode 100644 index 0000000..ed92487 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr30551.C @@ -0,0 +1,6 @@ +// PR 30551 -Wmain is enabled by default. +// { dg-do compile } +// { dg-options "" } + +int main(char a) {} /* { dg-warning "warning: first argument of .*main.* should be .int." } */ +/* { dg-warning "warning: .*main.* takes only zero or two arguments" "" { target *-*-* } 5 } */ diff --git a/gcc/testsuite/gcc.dg/pr30551-2.c b/gcc/testsuite/gcc.dg/pr30551-2.c new file mode 100644 index 0000000..fdd5df6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr30551-2.c @@ -0,0 +1,8 @@ +/* PR 30551 -Wmain is not enabled by default. */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +void main(char a) {} /* { dg-bogus "first argument of .main. should be .int." } */ +/* { dg-bogus ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */ +/* { dg-bogus "return type of .main. is not .int." "" { target *-*-* } 5 } */ + diff --git a/gcc/testsuite/gcc.dg/pr30551-3.c b/gcc/testsuite/gcc.dg/pr30551-3.c new file mode 100644 index 0000000..120d45b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr30551-3.c @@ -0,0 +1,7 @@ +/* PR 30551 -Wmain is enabled by -pedantic-errors. */ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors" } */ + +void main(char a) {} /* { dg-error "first argument of .main. should be .int." } */ +/* { dg-error ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */ +/* { dg-error "return type of .main. is not .int." "" { target *-*-* } 5 } */ diff --git a/gcc/testsuite/gcc.dg/pr30551-4.c b/gcc/testsuite/gcc.dg/pr30551-4.c new file mode 100644 index 0000000..4803dba --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr30551-4.c @@ -0,0 +1,8 @@ +/* PR 30551 -Wmain is enabled by -pedantic-errors and can be disabled. */ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors -Wno-main" } */ + +void main(char a) {} /* { dg-bogus "first argument of .main. should be .int." } */ +/* { dg-bogus ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */ +/* { dg-bogus "return type of .main. is not .int." "" { target *-*-* } 5 } */ + diff --git a/gcc/testsuite/gcc.dg/pr30551-5.c b/gcc/testsuite/gcc.dg/pr30551-5.c new file mode 100644 index 0000000..060ed01 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr30551-5.c @@ -0,0 +1,7 @@ +/* PR 30551 -Wmain is enabled by -pedantic and can be disabled. */ +/* { dg-do compile } */ +/* { dg-options "-pedantic -Wno-main" } */ + +void main(char a) {} /* { dg-bogus "first argument of .main. should be .int." } */ +/* { dg-bogus ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */ +/* { dg-bogus "return type of .main. is not .int." "" { target *-*-* } 5 } */ diff --git a/gcc/testsuite/gcc.dg/pr30551-6.c b/gcc/testsuite/gcc.dg/pr30551-6.c new file mode 100644 index 0000000..9c33cd1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr30551-6.c @@ -0,0 +1,7 @@ +/* PR 30551 -Wmain is enabled by -pedantic. */ +/* { dg-do compile } */ +/* { dg-options "-pedantic" } */ + +void main(char a) {} /* { dg-warning "first argument of .main. should be .int." } */ +/* { dg-warning ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */ +/* { dg-warning "return type of .main. is not .int." "" { target *-*-* } 5 } */ diff --git a/gcc/testsuite/gcc.dg/pr30551.c b/gcc/testsuite/gcc.dg/pr30551.c new file mode 100644 index 0000000..d6fdd8f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr30551.c @@ -0,0 +1,7 @@ +/* PR 30551 -Wmain is enabled by -Wall. */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +void main(char a) {} /* { dg-warning "first argument of .main. should be .int." } */ +/* { dg-warning ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */ +/* { dg-warning "return type of .main. is not .int." "" { target *-*-* } 5 } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-3.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-3.c index 6103c40..178e6a4 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-3.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-3.c @@ -1,3 +1,4 @@ +/* { dg-options "" } */ int main(int a, int b, int c, int d) { int e = (a & ~b) & (~c & d); |