URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gfortran.dg/] [elemental_optional_args_3.f90] - Rev 694
Compare with Previous | Blame | View Log
! { dg-do run }!! PR fortran/50981! The program used to dereference a NULL pointer when trying to access! a pointer dummy argument to be passed to an elemental subprocedure.!! Original testcase from Andriy Kostyuk <kostyuk@fias.uni-frankfurt.de>PROGRAM testIMPLICIT NONEREAL(KIND=8), DIMENSION(2) :: aa, rrINTEGER, TARGET :: cINTEGER, POINTER :: baa(1)=10.aa(2)=11.b=>cb=1! WRITE(*,*) 'Both f1 and ff work if the optional parameter is present:'rr=f1(aa,b)! WRITE(*,*) ' rr(1)=', rr(1), ' rr(2)=', rr(2)IF (ANY(rr /= (/ 110, 132 /))) CALL ABORTrr=0rr=ff(aa,b)! WRITE(*,*) ' rr(1)=', rr(1), ' rr(2)=', rr(2)IF (ANY(rr /= (/ 110, 132 /))) CALL ABORTb => NULL()! WRITE(*,*) 'But only f1 works if the optional parameter is absent:'rr=0rr=f1(aa, b)! WRITE(*,*) ' rr(1)=', rr(1), ' rr(2)=', rr(2)IF (ANY(rr /= (/ 110, 132 /))) CALL ABORTrr = 0rr=ff(aa, b)! WRITE(*,*) ' rr(1)=', rr(1), ' rr(2)=', rr(2)IF (ANY(rr /= (/ 110, 132 /))) CALL ABORTCONTAINSFUNCTION ff(a,b)IMPLICIT NONEREAL(KIND=8), INTENT(IN) :: a(:)REAL(KIND=8), DIMENSION(SIZE(a)) :: ffINTEGER, INTENT(IN), POINTER :: bREAL(KIND=8), DIMENSION(2, SIZE(a)) :: acac(1,:)=aac(2,:)=a**2ff=SUM(gg(ac,b), dim=1)END FUNCTION ffFUNCTION f1(a,b)IMPLICIT NONEREAL(KIND=8), INTENT(IN) :: a(:)REAL(KIND=8), DIMENSION(SIZE(a)) :: f1INTEGER, INTENT(IN), POINTER :: bREAL(KIND=8), DIMENSION(2, SIZE(a)) :: acac(1,:)=aac(2,:)=a**2f1=gg(ac(1,:),b)+gg(ac(2,:),b) ! This is the same as in ff, but without using the elemental feature of ggEND FUNCTION f1ELEMENTAL REAL(KIND=8) FUNCTION gg(a,b)IMPLICIT NONEREAL(KIND=8), INTENT(IN) :: aINTEGER, INTENT(IN), OPTIONAL :: bINTEGER ::b1IF(PRESENT(b)) THENb1=bELSEb1=1ENDIFgg=a**b1END FUNCTION ggEND PROGRAM test
