diff mbox

Speed-up use-after-scope (re-writing to SSA) (version 2)

Message ID 20170120143429.GA13630@x4
State New
Headers show

Commit Message

Markus Trippelsdorf Jan. 20, 2017, 2:34 p.m. UTC
On 2017.01.20 at 15:27 +0100, Jakub Jelinek wrote:
> On Fri, Jan 20, 2017 at 03:08:21PM +0100, Martin Liška wrote:
> > Unfortunately this way would not work as clobber marks content of the memory as uninitialize
> > is different behavior that just marking a memory can be used (and maybe already contains a value).
> > 
> > This shows the problem:
> > 
> > #include <string.h>
> > 
> > char cc;
> > char ptr[] = "sparta2";
> > 
> > void get(char **x)
> > {
> >   *x = ptr;
> > }
> >   
> > int main()
> > {
> >   char *here = &cc;
> > 
> >   for (;;)
> >     {
> >     next_line:
> > 	if (here == NULL)
> > 	  __builtin_abort();
> > 	get (&here);
> > 	if (strcmp (here, "sparta") == 0)
> > 	    goto next_line;
> > 	else if (strcmp (here, "sparta2") == 0)
> > 	  break;
> >     }
> > }
> > 
> > With the patch, DSE would optimize out '*here = &cc;' and thus aborts. The problem is definitely
> > related to goto magic, where we are more defensive in placement of ASAN_MARK(UNPOISON,...).
> > Hope your optimization is still valid for situations w/o artificial ASAN_MARK(UNPOISON,...) placed due
> > to goto magic.
> > 
> > Do we still want to do it now, or postponing to GCC 8 would be better option?
> 
> I'd still like to resolve it for GCC 7 if at all possible, I think otherwise
> -fsanitize=address is by default unnecessarily slower (so it is a regression
> anyway).

Another possibility would be to disable use-after-scope for gcc-7 (like
LLVM) and re-enable it for gcc-8.
diff mbox

Patch

diff --git a/gcc/opts.c b/gcc/opts.c
index 5f573a16ff15..2664b54133e4 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -993,7 +993,7 @@  finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
      enabled.  */
   if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS)
       && !opts_set->x_flag_sanitize_address_use_after_scope)
-    opts->x_flag_sanitize_address_use_after_scope = true;
+    opts->x_flag_sanitize_address_use_after_scope = false;

   /* Force -fstack-reuse=none in case -fsanitize-address-use-after-scope
      is enabled.  */