This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][RFC] Instrument function exit with __builtin_unreachable in C++.
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Martin Liška <mliska at suse dot cz>
- Cc: Jason Merrill <jason at redhat dot com>, gcc-patches List <gcc-patches at gcc dot gnu dot org>, Jonathan Wakely <jwakely at redhat dot com>
- Date: Thu, 12 Oct 2017 10:48:34 +0200
- Subject: Re: [PATCH][RFC] Instrument function exit with __builtin_unreachable in C++.
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jakub at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AB4EE7AEB7
- References: <31ddd79e-1152-9dd9-663b-acd8d1bcd4ab@suse.cz> <CADzB+2=fe6aDbFM3W3_=xog_VZh2iV1jR6dyBHEuu25-ttn5uw@mail.gmail.com> <a5543eb7-6774-a58a-38e7-33d3edf23fa2@suse.cz> <CADzB+2koi_th-P6S6=91NeA41LJoqPNk9GVWZP9Oq5PdQd6FtQ@mail.gmail.com> <a20e5418-a0af-d235-721b-9869c50f963a@suse.cz>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Oct 12, 2017 at 10:40:42AM +0200, Martin Liška wrote:
> --- a/gcc/cp/constexpr.c
> +++ b/gcc/cp/constexpr.c
> @@ -1175,7 +1175,12 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun,
> {
> new_call = build_call_array_loc (EXPR_LOCATION (t), TREE_TYPE (t),
> CALL_EXPR_FN (t), nargs, args);
> - error ("%q+E is not a constant expression", new_call);
> +
> + /* Do not allow__builtin_unreachable in constexpr function. */
> + if (DECL_FUNCTION_CODE (fun) == BUILT_IN_UNREACHABLE)
As I said earlier, I think it would be better to differentiate between
explicit __builtin_unreachable and the implicitly added one from the patch.
So this could be done as
if (DECL_FUNCTION_CODE (fun) == BUILT_IN_UNREACHABLE
&& EXPR_LOCATION (t) == BUILTINS_LOCATION)
> + location_t loc = DECL_SOURCE_LOCATION (fndecl);
> + if (sanitize_flags_p (SANITIZE_RETURN, fndecl))
> + t = ubsan_instrument_return (loc);
> + else
> + t = build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_UNREACHABLE),
and here use BUILTINS_LOCATION instead of loc.
The code might be more readable by doing:
{
tree fndecl = builtin_decl_explicit (BUILT_IN_UNREACHABLE);
t = build_call_expr_loc (BUILTINS_LOCATION, fndecl, 0);
}
> + 0);
> +
Jakub