>
> If I manually add a __builtin_unreachable () to the above case
> I see the *(int *)0 = 0; store DSEd. Maybe we should avoid
> removing stores that might trap here? POSIX wise such a trap
> could be a way to jump out of the path leading to unreachable ()
> via siglongjmp ...
I am not sure how much POSIX actually promises here.
I don't think we are supposed to keep such undefined behaviours in
original order. We compile:
int test (int *a, int *b, int c)
{
int res = *a;
return res + *b / c;
}
to:
test:
.LFB0:
.cfi_startproc
movl (%rsi), %eax
movl %edx, %ecx
cltd
idivl %ecx
addl (%rdi), %eax
ret
So we read *b before *a. Passing a==NULL, b non-null and c==0 and
using signal sigsev to recover the program before division by 0 will not
work with optimization.
Reaching unreachable is always undefined behaviour so I think we are
safe to reorder it with a load.
Honza
>
> Thanks,
> Richard.