diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-11-23 16:04:03 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-11-23 16:04:03 +0000 |
commit | 6cb25bec2e76666e0630ddc7a4e756cc5ef10e55 (patch) | |
tree | 756c94d3f1786802105c930a7ed81bf4e39c9a8d /gcc | |
parent | cd624b70542f340a0ff543967f975c03967df3dd (diff) | |
download | gcc-6cb25bec2e76666e0630ddc7a4e756cc5ef10e55.tar.gz |
PR c++/54046
* Makefile.in (gimple-low.o): Depend on langhooks.h.
* gimple-low.c: Include langhooks.c.
(block_may_fallthru): Handle TARGET_EXPR and ERROR_MARK,
by default call lang_hooks.block_may_fallthru.
* langhooks.h (struct lang_hooks): Add block_may_fallthru
langhook.
* langhooks-def.h (LANG_HOOKS_BLOCK_MAY_FALLTHRU): Define.
(LANG_HOOKS_INITIALIZER): Use it.
* cp-objcp-common.h (LANG_HOOKS_BLOCK_MAY_FALLTHRU): Redefine.
* cp-objcp-common.c (cxx_block_may_fallthru): New function.
* cp-tree.h (cxx_block_may_fallthru): New prototype.
* g++.dg/warn/Wreturn-type-8.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@193762 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 12 | ||||
-rw-r--r-- | gcc/Makefile.in | 2 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/cp-objcp-common.c | 19 | ||||
-rw-r--r-- | gcc/cp/cp-objcp-common.h | 2 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 1 | ||||
-rw-r--r-- | gcc/gimple-low.c | 9 | ||||
-rw-r--r-- | gcc/langhooks-def.h | 2 | ||||
-rw-r--r-- | gcc/langhooks.h | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wreturn-type-8.C | 90 |
11 files changed, 150 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 46760a06e4a..ee7531ce40d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2012-11-23 Jakub Jelinek <jakub@redhat.com> + + PR c++/54046 + * Makefile.in (gimple-low.o): Depend on langhooks.h. + * gimple-low.c: Include langhooks.c. + (block_may_fallthru): Handle TARGET_EXPR and ERROR_MARK, + by default call lang_hooks.block_may_fallthru. + * langhooks.h (struct lang_hooks): Add block_may_fallthru + langhook. + * langhooks-def.h (LANG_HOOKS_BLOCK_MAY_FALLTHRU): Define. + (LANG_HOOKS_INITIALIZER): Use it. + 2012-11-23 Jan Hubicka <jh@suse.cz> * i386-c.c (ix86_target_macros_internal): Update handling of core diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 7ac7b2594a2..44f1e085866 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2527,7 +2527,7 @@ gimple-low.o : gimple-low.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) \ $(DIAGNOSTIC_CORE_H) $(GIMPLE_H) $(TREE_INLINE_H) langhooks.h \ $(LANGHOOKS_DEF_H) $(TREE_FLOW_H) $(TM_H) coretypes.h \ $(EXCEPT_H) $(FLAGS_H) $(RTL_H) $(FUNCTION_H) $(TREE_PASS_H) \ - $(HASHTAB_H) $(DIAGNOSTIC_CORE_H) tree-iterator.h + $(HASHTAB_H) $(DIAGNOSTIC_CORE_H) tree-iterator.h langhooks.h omp-low.o : omp-low.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ $(RTL_H) $(GIMPLE_H) $(TREE_INLINE_H) langhooks.h $(DIAGNOSTIC_CORE_H) \ $(TREE_FLOW_H) $(FLAGS_H) $(EXPR_H) $(DIAGNOSTIC_CORE_H) \ diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 47734c58d43..95fb0bff864 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2012-11-23 Jakub Jelinek <jakub@redhat.com> + + PR c++/54046 + * cp-objcp-common.h (LANG_HOOKS_BLOCK_MAY_FALLTHRU): Redefine. + * cp-objcp-common.c (cxx_block_may_fallthru): New function. + * cp-tree.h (cxx_block_may_fallthru): New prototype. + 2012-11-23 Markus Trippelsdorf <markus@trippelsdorf.de> PR c++/55418 diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index 9b7d361939c..20dd3395037 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -227,6 +227,25 @@ init_shadowed_var_for_decl (void) tree_decl_map_eq, 0); } +/* Return true if stmt can fall thru. Used by block_may_fallthru + default case. */ + +bool +cxx_block_may_fallthru (const_tree stmt) +{ + switch (TREE_CODE (stmt)) + { + case EXPR_STMT: + return block_may_fallthru (EXPR_STMT_EXPR (stmt)); + + case THROW_EXPR: + return false; + + default: + return true; + } +} + void cp_common_init_ts (void) { diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h index 06cc796050b..4cfc59c40d2 100644 --- a/gcc/cp/cp-objcp-common.h +++ b/gcc/cp/cp-objcp-common.h @@ -94,6 +94,8 @@ extern void cp_common_init_ts (void); #define LANG_HOOKS_TYPE_HASH_EQ cxx_type_hash_eq #undef LANG_HOOKS_MISSING_NORETURN_OK_P #define LANG_HOOKS_MISSING_NORETURN_OK_P cp_missing_noreturn_ok_p +#undef LANG_HOOKS_BLOCK_MAY_FALLTHRU +#define LANG_HOOKS_BLOCK_MAY_FALLTHRU cxx_block_may_fallthru /* Attribute hooks. */ #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 8592125e4cf..85c8e7c702c 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6019,6 +6019,7 @@ extern bool cp_var_mod_type_p (tree, tree); extern void cxx_initialize_diagnostics (diagnostic_context *); extern int cxx_types_compatible_p (tree, tree); extern void init_shadowed_var_for_decl (void); +extern bool cxx_block_may_fallthru (const_tree); /* in cp-gimplify.c */ extern int cp_gimplify_expr (tree *, gimple_seq *, diff --git a/gcc/gimple-low.c b/gcc/gimple-low.c index e26d91ef4b4..282dba187c3 100644 --- a/gcc/gimple-low.c +++ b/gcc/gimple-low.c @@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "function.h" #include "diagnostic-core.h" #include "tree-pass.h" +#include "langhooks.h" /* The differences between High GIMPLE and Low GIMPLE are the following: @@ -739,8 +740,14 @@ block_may_fallthru (const_tree block) case CLEANUP_POINT_EXPR: return block_may_fallthru (TREE_OPERAND (stmt, 0)); - default: + case TARGET_EXPR: + return block_may_fallthru (TREE_OPERAND (stmt, 1)); + + case ERROR_MARK: return true; + + default: + return lang_hooks.block_may_fallthru (stmt); } } diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h index d8f479f3f5d..75793f62325 100644 --- a/gcc/langhooks-def.h +++ b/gcc/langhooks-def.h @@ -115,6 +115,7 @@ extern void lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *, #define LANG_HOOKS_EH_PERSONALITY lhd_gcc_personality #define LANG_HOOKS_EH_RUNTIME_TYPE lhd_pass_through_t #define LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS NULL +#define LANG_HOOKS_BLOCK_MAY_FALLTHRU hook_bool_const_tree_true #define LANG_HOOKS_EH_USE_CXA_END_CLEANUP false #define LANG_HOOKS_DEEP_UNSHARING false @@ -300,6 +301,7 @@ extern void lhd_end_section (void); LANG_HOOKS_EH_PERSONALITY, \ LANG_HOOKS_EH_RUNTIME_TYPE, \ LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS, \ + LANG_HOOKS_BLOCK_MAY_FALLTHRU, \ LANG_HOOKS_EH_USE_CXA_END_CLEANUP, \ LANG_HOOKS_DEEP_UNSHARING \ } diff --git a/gcc/langhooks.h b/gcc/langhooks.h index a9190672920..8481ba46d6c 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -1,6 +1,6 @@ /* The lang_hooks data structure. Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, - 2011 Free Software Foundation, Inc. + 2011, 2012 Free Software Foundation, Inc. This file is part of GCC. @@ -456,6 +456,10 @@ struct lang_hooks FUNCTION_DECL for `std::terminate'. */ tree (*eh_protect_cleanup_actions) (void); + /* Return true if a stmt can fallthru. Used by block_may_fallthru + to possibly handle language trees. */ + bool (*block_may_fallthru) (const_tree); + /* True if this language uses __cxa_end_cleanup when the ARM EABI is enabled. */ bool eh_use_cxa_end_cleanup; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ee90eeb74bd..a42b0013393 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2012-11-23 Jakub Jelinek <jakub@redhat.com> + PR c++/54046 + * g++.dg/warn/Wreturn-type-8.C: New test. + PR middle-end/55430 * gcc.dg/pr55430.c: New test. diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-8.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-8.C new file mode 100644 index 00000000000..346cab47649 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-8.C @@ -0,0 +1,90 @@ +// PR c++/54046 +// { dg-do compile } +// { dg-options "-O0 -Wall" } + +void foo (void) __attribute__((noreturn)); + +struct A +{ + ~A () {} +}; + +bool +check1 (int x) +{ + A z; + switch (x) + { + case 0: + return false; + default: + throw "X"; + break; + } +} + +bool +check2 (int x) +{ + A z; + switch (x) + { + case 0: + return false; + default: + foo (); + break; + } +} + +bool +check3 (int x) +{ + switch (x) + { + case 0: + return false; + default: + throw "X"; + break; + } +} + +bool +check4 (int x) +{ + switch (x) + { + case 0: + return false; + default: + foo (); + break; + } +} + +bool +check5 (int x) +{ + A z; + switch (x) + { + case 0: + return false; + default: + throw "X"; + } +} + +bool +check6 (int x) +{ + A z; + switch (x) + { + case 0: + return false; + default: + foo (); + } +} |