[PATCH][RFC] Instrument function exit with __builtin_unreachable in C++.
Jakub Jelinek
jakub@redhat.com
Thu Oct 12 09:36:00 GMT 2017
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
More information about the Gcc-patches
mailing list