On Tue, Apr 16, 2024 at 04:00:59PM +0200, Richard Biener wrote: > Currently we expand POINTER_DIFF_EXPR using subv_optab when -ftrapv > (but -fsanitize=undefined does nothing). That's not consistent > with the behavior of POINTER_PLUS_EXPR which never uses addv_optab > with -ftrapv. Both are because of the way we select whether to use > the trapping or the non-trapping optab - we look at the result type > of the expression and check > > trapv = INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_TRAPS (type); > > the bugreport correctly complains that -ftrapv affects pointer > subtraction (there's no -ftrapv-pointer). Now that we have > POINTER_DIFF_EXPR we can honor that appropriately. > > The patch moves both POINTER_DIFF_EXPR and POINTER_PLUS_EXPR > handling so they will never consider trapping (or saturating) > optabs. > > Bootstrapped and tested on x86_64-unknown-linux-gnu. > > OK for stage1? > > Thanks, > Richard. > > PR middle-end/13421 > * optabs-tree.cc (optab_for_tree_code): Do not consider > {add,sub}v or {us,ss}{add,sub} optabs for POINTER_DIFF_EXPR > or POINTER_PLUS_EXPR.
LGTM. Jakub