On 11/04/2016 10:32 AM, Jakub Jelinek wrote: > Hi! > > On Fri, Nov 04, 2016 at 10:17:31AM +0100, Martin Liška wrote: >> diff --git a/gcc/gimplify.c b/gcc/gimplify.c >> index 813777d..86ce793 100644 >> --- a/gcc/gimplify.c >> +++ b/gcc/gimplify.c >> @@ -1678,7 +1678,9 @@ warn_switch_unreachable_r (gimple_stmt_iterator >> *gsi_p, bool *handled_ops_p, >> worse location info. */ >> if (gimple_try_eval (stmt) == NULL) >> { >> - wi->info = stmt; >> + gimple_stmt_iterator *it = XNEW (gimple_stmt_iterator); >> + memcpy (it, gsi_p, sizeof (gimple_stmt_iterator)); > > That would be cleaner as *it = *gsi_p;
I know that it's kind of ugly, but as the gimple stmt is not yet added to a BB, using gsi_for_stmt ICEs: /tmp/use-after-scope-switch.c:12:5: internal compiler error: Segmentation fault switch (argc) ^~~~~~ 0xe16a14 crash_signal ../../gcc/toplev.c:338 0xadf890 bb_seq_addr ../../gcc/gimple.h:1658 0xae01dd gsi_start_bb ../../gcc/gimple-iterator.h:129 0xae111f gsi_for_stmt(gimple*) ../../gcc/gimple-iterator.c:617 > That set, I fail to see > 1) the need to use a gsi pointer in wi->info compared to stmt itself, > you can gsi_for_stmt cheaply at any time > 2) why is anything done about this in warn_switch_unreachable_r > - the problem isn't related to this warning IMHO. Even > switch (x) > { > case 1: > int x; > x = 6; > ptr = &x; > break; > case 2: > ptr = &x; > *ptr = 7; > break; > } > has the same issue and there is no switch unreachable code there, but you > still want for -fsanitize-use-after-scope pretend it is actually: You're right, that's not handled. I'm wondering whether it's always profitable because when you do not reach the case 1, you're not doing a poisoning operation? Martin > x_tmp = x; > { > int x; > switch (x_tmp) > { > case 1: > x = 6; > ptr = &x; > break; > case 2: > ptr = &x; > *ptr = 7; > break; > } > } > and put ASAN_MARK unpoisoning before GIMPLE_SWITCH. > > Jakub >