http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55501

--- Comment #12 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-11-28 
14:54:33 UTC ---
(In reply to comment #10)
>   integer :: i(-1:1) = 0
>   print *, lbound(merge(i,i,.true.))

> Without the patch, this prints:
>            1
> And with the patch:
>           -1

Makes perfectly sense: For "lbound(array,dim)": "If ARRAY is a whole array and
either ARRAY is an assumed-size array of rank DIM or dimension DIM of ARRAY has
nonzero extent, LBOUND (ARRAY, DIM) has a value equal to the lower bound for
subscript DIM of ARRAY. Otherwise the result value is 1."
With "whole array  array component or array name without further qualication
(6.5.2)"

Thus "lbound(i)" is a whole-array, "lbound(i(:))" or "lbound(merge(i,i,.true))"
is not.

I think the simplest it to replace "lbound (merge(i,i,.true.)" by "lbound( (i)
)" [e->expr_type = EXPR_OP && e->value.op.op == INTRINSIC_PARENTHESES].
Possibly only if expr_type == EXPR_VARIABLE as otherwise the
INTRINSIC_PARENTHESES will hamper further optimization (unless
-fno-protect-parens).

Reply via email to