From 2fb20ba2e4f3f036716fc7cfe5d4c5c713297874 Mon Sep 17 00:00:00 2001 From: marxin Date: Mon, 6 Nov 2017 09:02:15 +0000 Subject: Instrument function exit with __builtin_unreachable in C++ 2017-11-06 Martin Liska PR middle-end/82404 * c-opts.c (c_common_post_options): Set -Wreturn-type for C++ FE. * c.opt: Set default value of warn_return_type. 2017-11-06 Martin Liska PR middle-end/82404 * constexpr.c (cxx_eval_builtin_function_call): Handle __builtin_unreachable call. (get_function_named_in_call): Declare function earlier. (constexpr_fn_retval): Skip __builtin_unreachable. * cp-gimplify.c (cp_ubsan_maybe_instrument_return): Rename to ... (cp_maybe_instrument_return): ... this. (cp_genericize): Call the function unconditionally. 2017-11-06 Martin Liska PR middle-end/82404 * options.c (gfc_post_options): Set default value of -Wreturn-type to false. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254437 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/cp-gimplify.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'gcc/cp/cp-gimplify.c') diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 262485a5c1f..014c1ee7231 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1556,10 +1556,11 @@ cp_genericize_tree (tree* t_p, bool handle_invisiref_parm_p) /* If a function that should end with a return in non-void function doesn't obviously end with return, add ubsan - instrumentation code to verify it at runtime. */ + instrumentation code to verify it at runtime. If -fsanitize=return + is not enabled, instrument __builtin_unreachable. */ static void -cp_ubsan_maybe_instrument_return (tree fndecl) +cp_maybe_instrument_return (tree fndecl) { if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl))) || DECL_CONSTRUCTOR_P (fndecl) @@ -1600,7 +1601,16 @@ cp_ubsan_maybe_instrument_return (tree fndecl) tree *p = &DECL_SAVED_TREE (fndecl); if (TREE_CODE (*p) == BIND_EXPR) p = &BIND_EXPR_BODY (*p); - t = ubsan_instrument_return (DECL_SOURCE_LOCATION (fndecl)); + + location_t loc = DECL_SOURCE_LOCATION (fndecl); + if (sanitize_flags_p (SANITIZE_RETURN, fndecl)) + t = ubsan_instrument_return (loc); + else + { + tree fndecl = builtin_decl_explicit (BUILT_IN_UNREACHABLE); + t = build_call_expr_loc (BUILTINS_LOCATION, fndecl, 0); + } + append_to_statement_list (t, p); } @@ -1674,9 +1684,7 @@ cp_genericize (tree fndecl) walk_tree's hash functionality. */ cp_genericize_tree (&DECL_SAVED_TREE (fndecl), true); - if (sanitize_flags_p (SANITIZE_RETURN) - && current_function_decl != NULL_TREE) - cp_ubsan_maybe_instrument_return (fndecl); + cp_maybe_instrument_return (fndecl); /* Do everything else. */ c_genericize (fndecl); -- cgit v1.2.1 From c06d7bdd817f3eb7647a8ea14cb006b6534644d8 Mon Sep 17 00:00:00 2001 From: jakub Date: Tue, 7 Nov 2017 20:51:05 +0000 Subject: PR c++/82835 * cp-gimplify.c (cxx_omp_clause_apply_fn): For methods pass i - 1 to convert_default_arg instead of i. * testsuite/libgomp.c++/pr82835.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254511 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/cp-gimplify.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'gcc/cp/cp-gimplify.c') diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 014c1ee7231..7c7c0409af8 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1717,6 +1717,7 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2) if (arg2) defparm = TREE_CHAIN (defparm); + bool is_method = TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE; if (TREE_CODE (TREE_TYPE (arg1)) == ARRAY_TYPE) { tree inner_type = TREE_TYPE (arg1); @@ -1765,8 +1766,8 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2) for (parm = defparm; parm && parm != void_list_node; parm = TREE_CHAIN (parm), i++) argarray[i] = convert_default_arg (TREE_VALUE (parm), - TREE_PURPOSE (parm), fn, i, - tf_warning_or_error); + TREE_PURPOSE (parm), fn, + i - is_method, tf_warning_or_error); t = build_call_a (fn, i, argarray); t = fold_convert (void_type_node, t); t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); @@ -1798,8 +1799,8 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2) for (parm = defparm; parm && parm != void_list_node; parm = TREE_CHAIN (parm), i++) argarray[i] = convert_default_arg (TREE_VALUE (parm), - TREE_PURPOSE (parm), - fn, i, tf_warning_or_error); + TREE_PURPOSE (parm), fn, + i - is_method, tf_warning_or_error); t = build_call_a (fn, i, argarray); t = fold_convert (void_type_node, t); return fold_build_cleanup_point_expr (TREE_TYPE (t), t); -- cgit v1.2.1