Skip to content

Commit 45d46ab

Browse files
committed
C_BOOL for oneAPI and NVHPC
1 parent c1eeb95 commit 45d46ab

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

cmake/compilers.cmake

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,23 @@ add_compile_options(-Wall -Wextra
149149
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
150150
add_compile_options(
151151
"$<$<COMPILE_LANGUAGE:Fortran>:-warn>"
152-
"$<$<COMPILE_LANGUAGE:Fortran>:-standard-semantics>"
153152
"$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug,RelWithDebInfo>>:-traceback;-check;-debug>"
154153
$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug>>:-O0>
155154
)
155+
156+
# -fpscomp logicals is required for C_BOOL
157+
if(NOT WIN32)
158+
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-fpscomp;logicals>")
159+
endif()
160+
161+
# -stand f18 is just for warnings, it doesn't change compiler behavior
162+
163+
# DO NOT USE -standard-semantics as it breaks linkage with any other library
164+
# including IntelMPI!
165+
#"$<$<COMPILE_LANGUAGE:Fortran>:-standard-semantics>"
166+
156167
# https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2024-1/standard-semantics.html
168+
169+
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC")
170+
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-Munixlogical>")
157171
endif()

src/bool/logbool.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ logical(c_bool) function logical_not(L) bind(C)
2323
!! nvfortran reference guide:
2424
!! The logical constants .TRUE. and .FALSE. are defined to be the four-byte values -1 and 0 respectively.
2525
!! A logical expression is defined to be .TRUE. if its least significant bit is 1 and .FALSE. otherwise.
26-
! logical_not = .not. L
27-
if(L) then
28-
logical_not = .false._C_BOOL
29-
else
30-
logical_not = .true._C_BOOL
31-
endif
26+
!if(L) then
27+
! logical_not = .false._C_BOOL
28+
!else
29+
! logical_not = .true._C_BOOL
30+
!endif
3231

32+
logical_not = .not. L
3333

3434
print '(/, a, l1, a, l1)', "logical_not(", L, "): ", logical_not
3535

0 commit comments

Comments
 (0)