https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101758

--- Comment #15 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #14)
> This is wrong.  tree_expr_nonzero_p is an optimization which relies on lack
> of UB in the program, in many cases the non-zero property is determined by
> assuming a program doesn't have UB and if so, this has some range or some
> constant bits etc.
> While ubsan is meant to check for invalid programs.  So, it has to try hard
> to avoid relying on lack of UB as much as possible because it is meant to
> diagnose UB.
> So, sure, if it can prove something must be non-NULL regardless of whether
> the program is valid or not, it can avoid the check.  But if the check does
> or could rely on lack of UB, we need to avoid it.  So using e.g. VRP info is
> no-way, etc.

Except that is what happens right now even without aby change. As sanopt
expands it into that and then cfgcleanup calls match on the condition (a != 0B)
and there is a match pattern for that which then calls tree_expr_nonzero_p. So
if it is wrong here, it is wrong even without my patch.
I just exposing what is done currently earlier.
So maybe unsan should expand it with hiding the address then. The alignment
check i did is exactly the same in sanopt too. 
It depends on assume values from vrp and the assume alignment builtin which is
why I started down this path in the first place. We dont instrument the builtin
assume alignment (maybe we should).

Reply via email to