aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-cfg.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@gcc.gnu.org>2017-11-21 18:40:34 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2017-11-21 18:40:34 +0100
commit826eccc6fd8bebfafa3ac02d9755bb2e59f465b7 (patch)
tree39a19feeb4e8a2c41e98c603252802db36730aeb /gcc/tree-cfg.c
parent8fccb0a6b606aacc1bcb3e02b400c5d6455196cc (diff)
downloadgcc-826eccc6fd8bebfafa3ac02d9755bb2e59f465b7.zip
gcc-826eccc6fd8bebfafa3ac02d9755bb2e59f465b7.tar.gz
gcc-826eccc6fd8bebfafa3ac02d9755bb2e59f465b7.tar.bz2
re PR c++/83045 (-Wreturn-type regression in C++)
PR c++/83045 * tree-cfg.c (pass_warn_function_return::execute): Formatting fix. Also warn if seen __builtin_unreachable () call with BUILTINS_LOCATION. Use LOCATION_LOCUS when comparing against UNKNOWN_LOCATION. * c-c++-common/pr61405.c (fn0, fn1): Add return stmts. * c-c++-common/Wlogical-op-2.c (fn): Likewise. * g++.dg/debug/pr53466.C: Add -Wno-return-type to dg-options. * g++.dg/opt/combine.C: Likewise. * g++.dg/ubsan/return-3.C: Likewise. * g++.dg/pr59445.C: Likewise. * g++.dg/pr49847.C: Likewise. * g++.dg/ipa/pr61800.C: Likewise. * g++.dg/ipa/pr63470.C: Likewise. * g++.dg/ipa/pr68672-1.C: Likewise. * g++.dg/pr58438.C: Likewise. * g++.dg/torture/pr59265.C: Likewise. * g++.dg/tree-ssa/ssa-dse-2.C: Likewise. * g++.old-deja/g++.eh/catch13.C: Likewise. * g++.old-deja/g++.eh/crash1.C: Likewise. * g++.dg/tm/pr60004.C: Expect -Wreturn-type warning. * g++.dg/torture/pr55740.C: Likewise. * g++.dg/torture/pr43257.C: Likewise. * g++.dg/torture/pr64280.C: Likewise. * g++.dg/torture/pr54684.C: Likewise. * g++.dg/torture/pr56694.C: Likewise. * g++.dg/torture/pr68470.C: Likewise. * g++.dg/torture/pr60648.C: Likewise. * g++.dg/torture/pr71281.C: Likewise. * g++.dg/torture/pr52772.C: Add -Wno-return-type dg-additional-options. * g++.dg/torture/pr64669.C: Likewise. * g++.dg/torture/pr58369.C: Likewise. * g++.dg/torture/pr33627.C: Likewise. * g++.dg/torture/predcom-1.C: Add #pragma GCC diagnostic ignored "-Wreturn-type". * g++.dg/lto/20090221_0.C: Likewise. * g++.dg/lto/20091026-1_1.C: Likewise. * g++.dg/lto/pr54625-1_1.C: Likewise. * g++.dg/warn/pr83045.C: New test. From-SVN: r255018
Diffstat (limited to 'gcc/tree-cfg.c')
-rw-r--r--gcc/tree-cfg.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 491ac05..bdcb04f 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -9049,7 +9049,8 @@ pass_warn_function_return::execute (function *fun)
if ((gimple_code (last) == GIMPLE_RETURN
|| gimple_call_builtin_p (last, BUILT_IN_RETURN))
&& location == UNKNOWN_LOCATION
- && (location = gimple_location (last)) != UNKNOWN_LOCATION
+ && ((location = LOCATION_LOCUS (gimple_location (last)))
+ != UNKNOWN_LOCATION)
&& !optimize)
break;
/* When optimizing, replace return stmts in noreturn functions
@@ -9075,7 +9076,6 @@ pass_warn_function_return::execute (function *fun)
without returning a value. */
else if (warn_return_type > 0
&& !TREE_NO_WARNING (fun->decl)
- && EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (fun)->preds) > 0
&& !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fun->decl))))
{
FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (fun)->preds)
@@ -9087,13 +9087,43 @@ pass_warn_function_return::execute (function *fun)
&& !gimple_no_warning_p (last))
{
location = gimple_location (last);
- if (location == UNKNOWN_LOCATION)
+ if (LOCATION_LOCUS (location) == UNKNOWN_LOCATION)
location = fun->function_end_locus;
- warning_at (location, OPT_Wreturn_type, "control reaches end of non-void function");
+ warning_at (location, OPT_Wreturn_type,
+ "control reaches end of non-void function");
TREE_NO_WARNING (fun->decl) = 1;
break;
}
}
+ /* The C++ FE turns fallthrough from the end of non-void function
+ into __builtin_unreachable () call with BUILTINS_LOCATION.
+ Recognize those too. */
+ basic_block bb;
+ if (!TREE_NO_WARNING (fun->decl))
+ FOR_EACH_BB_FN (bb, fun)
+ if (EDGE_COUNT (bb->succs) == 0)
+ {
+ gimple *last = last_stmt (bb);
+ if (last
+ && (LOCATION_LOCUS (gimple_location (last))
+ == BUILTINS_LOCATION)
+ && gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE))
+ {
+ gimple_stmt_iterator gsi = gsi_for_stmt (last);
+ gsi_prev_nondebug (&gsi);
+ gimple *prev = gsi_stmt (gsi);
+ if (prev == NULL)
+ location = UNKNOWN_LOCATION;
+ else
+ location = gimple_location (prev);
+ if (LOCATION_LOCUS (location) == UNKNOWN_LOCATION)
+ location = fun->function_end_locus;
+ warning_at (location, OPT_Wreturn_type,
+ "control reaches end of non-void function");
+ TREE_NO_WARNING (fun->decl) = 1;
+ break;
+ }
+ }
}
return 0;
}