|
| 1 | +! UNSUPPORTED: system-windows |
| 2 | +! RUN: split-file %s %t |
| 3 | +! RUN: chmod +x %t/runtest.sh |
| 4 | +! RUN: %t/runtest.sh %t %flang $t/ffile.f90 $t/cfile.c |
| 5 | + |
| 6 | +!--- ffile.f90 |
| 7 | +subroutine foo(a) bind(c) |
| 8 | + integer :: a(:) |
| 9 | + if (lbound(a, 1) .ne. 1) then |
| 10 | + print *, 'FAIL expected 1 for lbound but got ',lbound(a, 1) |
| 11 | + stop 1 |
| 12 | + endif |
| 13 | + |
| 14 | + if (ubound(a, 1) .ne. 10) then |
| 15 | + print *, 'FAIL expected 10 for ubound but got ',ubound(a, 1) |
| 16 | + stop 1 |
| 17 | + endif |
| 18 | + |
| 19 | + do i = lbound(a,1),ubound(a,1) |
| 20 | + !print *, a(i) |
| 21 | + if (a(i) .ne. i) then |
| 22 | + print *, 'FAIL expected', i, ' for index ',i, ' but got ',a(i) |
| 23 | + stop 1 |
| 24 | + endif |
| 25 | + enddo |
| 26 | + print *, 'PASS' |
| 27 | +end subroutine foo |
| 28 | + |
| 29 | +! CHECK: PASS |
| 30 | +!--- cfile.c |
| 31 | +#include <stdio.h> |
| 32 | +#include <stdlib.h> |
| 33 | +#include <ISO_Fortran_binding.h> |
| 34 | + |
| 35 | +void foo(CFI_cdesc_t*); |
| 36 | + |
| 37 | +int a[10]; |
| 38 | + |
| 39 | +int main() { |
| 40 | + int i, res; |
| 41 | + static CFI_CDESC_T(1) r1; |
| 42 | + CFI_cdesc_t *desc = (CFI_cdesc_t*)&r1; |
| 43 | + CFI_index_t extent[1] = {10}; |
| 44 | + |
| 45 | + for(i=0; i<10; ++i) { |
| 46 | + a[i] = i+1; |
| 47 | + } |
| 48 | + |
| 49 | + res = CFI_establish(desc, (void*)a, CFI_attribute_other, CFI_type_int32_t, |
| 50 | + sizeof(int), 1, extent); |
| 51 | + if (res != 0) { |
| 52 | + printf("FAIL CFI_establish returned %d instead of 0.\n",res); |
| 53 | + exit(1); |
| 54 | + } |
| 55 | + |
| 56 | + foo(desc); |
| 57 | + return 0; |
| 58 | +} |
| 59 | +!--- runtest.sh |
| 60 | +#!/bin/bash |
| 61 | +export BINDIR=`dirname $2` |
| 62 | +export CCOMP=$BINDIR/clang |
| 63 | +if [ -x $CCOMP ] |
| 64 | +then |
| 65 | + export LIBDIR=$BINDIR/../lib |
| 66 | + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBDIR |
| 67 | + $CCOMP -c $1/$4 -o $1/cfile.o |
| 68 | + $2 $1/$3 $1/cfile.o -o $1/ctofortran |
| 69 | + $1/ctofortran # should print "PASS" |
| 70 | +else |
| 71 | + # No clang compiler, just pass by default |
| 72 | + echo "PASS" |
| 73 | +fi |
0 commit comments