71 lines · plain
1! UNSUPPORTED: system-windows2! UNSUPPORTED: offload-cuda3 4! RUN: split-file %s %t5! RUN: %clang %isysroot -I"%include/flang" -c %t/cfile.c -o %t/cfile.o6! RUN: %flang %isysroot -L"%libdir" %t/ffile.f90 %t/cfile.o -o %t/ctofortran7! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%libdir" %t/ctofortran | FileCheck %s8 9!--- ffile.f9010program fmain11 interface12 subroutine csub() bind(c)13 end subroutine14 end interface15 16 call csub()17end program fmain18 19subroutine foo(a) bind(c)20 integer :: a(:)21 if (lbound(a, 1) .ne. 1) then22 print *, 'FAIL expected 1 for lbound but got ',lbound(a, 1)23 stop 124 endif25 26 if (ubound(a, 1) .ne. 10) then27 print *, 'FAIL expected 10 for ubound but got ',ubound(a, 1)28 stop 129 endif30 31 do i = lbound(a,1),ubound(a,1)32 !print *, a(i)33 if (a(i) .ne. i) then34 print *, 'FAIL expected', i, ' for index ',i, ' but got ',a(i)35 stop 136 endif37 enddo38 print *, 'PASS'39end subroutine foo40 41! CHECK: PASS42!--- cfile.c43#include <stdio.h>44#include <stdlib.h>45#include <ISO_Fortran_binding.h>46 47void foo(CFI_cdesc_t*);48 49int a[10];50 51void csub() {52 int i, res;53 static CFI_CDESC_T(1) r1;54 CFI_cdesc_t *desc = (CFI_cdesc_t*)&r1;55 CFI_index_t extent[1] = {10};56 57 for(i=0; i<10; ++i) {58 a[i] = i+1;59 }60 61 res = CFI_establish(desc, (void*)a, CFI_attribute_other, CFI_type_int32_t,62 sizeof(int), 1, extent);63 if (res != 0) {64 printf("FAIL CFI_establish returned %d instead of 0.\n",res);65 exit(1);66 }67 68 foo(desc);69 return;70}71