Debian Codegraph @

flang/test/Driver/ctofortran.f90

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