This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, RFC] Introduce -fsanitize=use-after-scope (v2)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Martin Liška <mliska at suse dot cz>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 1 Nov 2016 16:12:19 +0100
- Subject: Re: [PATCH, RFC] Introduce -fsanitize=use-after-scope (v2)
- Authentication-results: sourceware.org; auth=none
- References: <20160512104156.GY28550@tucnak.redhat.com> <57348F45.5020700@suse.cz> <20160818133609.GN14857@tucnak.redhat.com> <98f408c5-7e1e-6fd8-e589-34f8de2f4455@suse.cz> <20161007111347.GF7282@tucnak.redhat.com> <bcad9f73-a54c-bc50-2bcc-a6f0f8c9e9c4@suse.cz> <20161021142617.GG7282@tucnak.redhat.com> <3a109250-0440-7438-8e1f-7e5c6d8b6580@suse.cz> <20161027172358.GN3541@tucnak.redhat.com> <606cd948-6cba-02a4-f114-35900ab53203@suse.cz>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Nov 01, 2016 at 03:53:46PM +0100, Martin Liška wrote:
> @@ -1504,7 +1505,7 @@ non_rewritable_lvalue_p (tree lhs)
>
> static void
> maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
> - bitmap suitable_for_renaming)
> + bitmap suitable_for_renaming, bitmap marked_nonaddressable)
> {
> /* Global Variables, result decls cannot be changed. */
> if (is_global_var (var)
> @@ -1522,6 +1523,7 @@ maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
> || !bitmap_bit_p (not_reg_needs, DECL_UID (var))))
> {
> TREE_ADDRESSABLE (var) = 0;
> + bitmap_set_bit (marked_nonaddressable, DECL_UID (var));
Why do you need the marked_nonaddressable bitmap?
> if (is_gimple_reg (var))
> bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
> if (dump_file)
> @@ -1550,20 +1552,43 @@ maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
> }
> }
>
> -/* Compute TREE_ADDRESSABLE and DECL_GIMPLE_REG_P for local variables. */
> +/* Return true when STMT is ASAN mark where second argument is an address
> + of a local variable. */
>
> -void
> -execute_update_addresses_taken (void)
> +static bool
> +is_asan_mark_p (gimple *stmt)
> +{
> + if (!gimple_call_internal_p (stmt, IFN_ASAN_MARK))
> + return false;
> +
> + tree addr = get_base_address (gimple_call_arg (stmt, 1));
> + if (TREE_CODE (addr) == ADDR_EXPR
> + && TREE_CODE (TREE_OPERAND (addr, 0)) == VAR_DECL)
Just check here if dropping TREE_ADDRESSABLE from the VAR (use VAR_P btw)
would turn it into is_gimple_reg), and don't return true if not.
> + return true;
> +
> + return false;
> +}
> +
> +/* Compute TREE_ADDRESSABLE and DECL_GIMPLE_REG_P for local variables.
> + If SANITIZE_ASAN_MARK is set to true, sanitize also ASAN_MARK built-ins. */
> +
> +
> +static void
> +execute_update_addresses_taken (bool sanitize_asan_mark = false)
I wonder if the sanitize_asan_mark wouldn't better be some PROP_* property
set during the asan pass and kept on until end of compilation of that
function. That means even if a var only addressable because of ASAN_MARK is
discovered after this pass we'd still be able to rewrite it into SSA.
Jakub