Skip to content

[flang] Put ISO_Fortran_binding.h where it can be easily used #68756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions flang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ if (NOT(FLANG_DEFAULT_RTLIB STREQUAL ""))
"Default runtime library to use (empty for platform default)" FORCE)
endif()



set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")

if (NOT PACKAGE_VERSION)
set(PACKAGE_VERSION ${LLVM_VERSION_MAJOR})
endif()

if (NOT DEFINED FLANG_VERSION_MAJOR)
set(FLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
Expand Down Expand Up @@ -490,3 +490,17 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
PATTERN "*.inc"
)
endif()

# Put ISO_Fortran_binding.h into the include files of the build area now
# so that we can run tests before installing
include(GetClangResourceDir)
get_clang_resource_dir(HEADER_BINARY_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include)
configure_file(
${FLANG_SOURCE_DIR}/include/flang/ISO_Fortran_binding.h
${HEADER_BINARY_DIR}/ISO_Fortran_binding.h)

# And also install it into the install area
get_clang_resource_dir(HEADER_INSTALL_DIR PREFIX ${CMAKE_INSTALL_PREFIX} SUBDIR include)
install(
FILES ${CMAKE_INSTALL_PREFIX}/include/flang/ISO_Fortran_binding.h
DESTINATION ${HEADER_INSTALL_DIR})
60 changes: 60 additions & 0 deletions flang/test/Examples/ctofortran.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
! UNSUPPORTED: system-windows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add something like REQUIRES: clang

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Kiran. Will do.

! REQUIRES: clang
! RUN: split-file %s %t
! RUN: %clang -c %t/cfile.c
! RUN: %flang -flang-experimental-hlfir cfile.o %t/src.f90 -o %t/ctofortran
! RUN: %t/ctofortran | FileCheck %s

!--- src.f90
subroutine foo(a) bind(c)
integer :: a(:)
if (lbound(a, 1) .ne. 1) then
print *, 'FAIL expected 1 for lbound but got ',lbound(a, 1)
stop 1
endif

if (ubound(a, 1) .ne. 10) then
print *, 'FAIL expected 10 for ubound but got ',ubound(a, 1)
stop 1
endif

do i = lbound(a,1),ubound(a,1)
!print *, a(i)
if (a(i) .ne. i) then
print *, 'FAIL expected', i, ' for index ',i, ' but got ',a(i)
stop 1
endif
enddo
print *, 'PASS'
end subroutine foo

! CHECK: PASS
!--- cfile.c
#include <stdio.h>
#include <stdlib.h>
#include <ISO_Fortran_binding.h>

void foo(CFI_cdesc_t*);

int a[10];

int main() {
int i, res;
static CFI_CDESC_T(1) r1;
CFI_cdesc_t *desc = (CFI_cdesc_t*)&r1;
CFI_index_t extent[1] = {10};

for(i=0; i<10; ++i) {
a[i] = i+1;
}

res = CFI_establish(desc, (void*)a, CFI_attribute_other, CFI_type_int32_t,
sizeof(int), 1, extent);
if (res != 0) {
printf("FAIL CFI_establish returned %d instead of 0.\n",res);
exit(1);
}

foo(desc);
return 0;
}
1 change: 1 addition & 0 deletions flang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
# For each occurrence of a flang tool name, replace it with the full path to
# the build directory holding that tool.
tools = [
ToolSubst("%clang", command=FindTool("clang"), unresolved="fatal"),
ToolSubst("%flang", command=FindTool("flang-new"), unresolved="fatal"),
ToolSubst(
"%flang_fc1",
Expand Down