Skip to content

Commit bca8f16

Browse files
author
Damian Rouson
authored
Merge pull request #544 from sourceryinstitute/IFB-dot-h
Fix memory allocation bugs that cause downstream failures ISO_Fortran_binding_tests.h
2 parents 0dafd67 + a544143 commit bca8f16

File tree

4 files changed

+101
-83
lines changed

4 files changed

+101
-83
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,10 @@ endif()
440440
#----------------
441441
# Setup MPI flags
442442
#----------------
443-
set(CMAKE_C_COMPILE_FLAGS ${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS})
444-
set(CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS})
445-
set(CMAKE_Fortran_COMPILE_FLAGS ${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS})
446-
set(CMAKE_Fortran_LINK_FLAGS ${CMAKE_Fortran_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
443+
set(CMAKE_C_COMPILE_FLAGS "${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS}")
444+
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS}")
445+
set(CMAKE_Fortran_COMPILE_FLAGS "${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS}")
446+
set(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS}")
447447
include_directories(BEFORE ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH})
448448

449449
#---------------------------------------------------

src/iso-fortran-binding/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
add_library(ISO_Fortran_binding SHARED ISO_Fortran_binding.c)
22
add_library(ISO_Fortran_binding_static STATIC ISO_Fortran_binding.c)
33

4-
set_target_properties(ISO_Fortran_binding_static PROPERTIES OUTPUT_NAME cISO_Fortran_binding)
4+
set_target_properties(ISO_Fortran_binding_static PROPERTIES OUTPUT_NAME ISO_Fortran_binding)
55

66
set(CFI_SO_VERSION 0)
77
if(gfortran_compiler)

src/mpi/CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
if (NOT MPI_C_FOUND)
22
find_package(MPI REQUIRED)
33

4-
set(CMAKE_C_COMPILE_FLAGS ${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS})
5-
set(CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS})
6-
set(CMAKE_Fortran_COMPILE_FLAGS ${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS})
7-
set(CMAKE_Fortran_LINK_FLAGS ${CMAKE_Fortran_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
4+
set(CMAKE_C_COMPILE_FLAGS "${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS}")
5+
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS}")
6+
set(CMAKE_Fortran_COMPILE_FLAGS "${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS}")
7+
set(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS}")
88
include_directories(BEFORE ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH})
99
endif()
1010

@@ -81,19 +81,19 @@ set(NEEDED_SYMBOLS MPIX_ERR_PROC_FAILED;MPIX_ERR_REVOKED;MPIX_Comm_failure_ack;M
8181

8282
set(old_cmake_required_includes "${CMAKE_REQUIRED_INCLUDES}")
8383
if(CMAKE_REQUIRED_INCLUDES)
84-
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${MPI_C_INCLUDE_PATH})
84+
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${MPI_C_INCLUDE_PATH})
8585
else()
8686
set(CMAKE_REQUIRED_INCLUDES ${MPI_C_INCLUDE_PATH})
8787
endif()
8888
set(old_cmake_required_flags "${CMAKE_REQUIRED_FLAGS}")
8989
if(CMAKE_REQUIRED_FLAGS)
90-
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS};${MPI_C_COMPILE_FLAGS};${MPI_C_LINK_FLAGS})
90+
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${MPI_C_COMPILE_FLAGS} ${MPI_C_LINK_FLAGS})
9191
else()
92-
set(CMAKE_REQUIRED_FLAGS ${MPI_C_COMPILE_FLAGS};${MPI_C_LINK_FLAGS})
92+
set(CMAKE_REQUIRED_FLAGS ${MPI_C_COMPILE_FLAGS} ${MPI_C_LINK_FLAGS})
9393
endif()
9494
set(old_cmake_required_libraries "${CMAKE_REQUIRED_LIBRARIES}")
9595
if(CMAKE_REQUIRED_LIBRARIES)
96-
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES};${MPI_C_LIBRARIES})
96+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${MPI_C_LIBRARIES})
9797
else()
9898
set(CMAKE_REQUIRED_LIBRARIES ${MPI_C_LIBRARIES})
9999
endif()
@@ -134,7 +134,7 @@ endif()
134134
#---------------------------------------------------
135135
set(old_cmake_required_includes "${CMAKE_REQUIRED_INCLUDES}")
136136
if(CMAKE_REQUIRED_INCLUDES)
137-
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${MPI_C_INCLUDE_PATH})
137+
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${MPI_C_INCLUDE_PATH})
138138
else()
139139
set(CMAKE_REQUIRED_INCLUDES ${MPI_C_INCLUDE_PATH})
140140
endif()

src/tests/unit/iso-fortran-binding/ISO_Fortran_binding_tests.c

Lines changed: 87 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,14 @@ int main (void)
414414
ind = CFI_establish ((CFI_cdesc_t *) &test6, NULL, attribute, type[i],
415415
elem_len, rank, extents);
416416
ind = CFI_allocate ((CFI_cdesc_t *) &test6, lower, upper, base_type_size);
417-
ind = CFI_deallocate ((CFI_cdesc_t *) &test6);
418-
if (ind != CFI_INVALID_ATTRIBUTE && test6.base_addr != NULL)
417+
if (ind == CFI_SUCCESS)
419418
{
420-
printf ("CFI_deallocate: failed to deallocate memory.\n");
421-
return 1;
419+
ind = CFI_deallocate ((CFI_cdesc_t *) &test6);
420+
if (ind != CFI_INVALID_ATTRIBUTE && test6.base_addr != NULL)
421+
{
422+
printf ("CFI_deallocate: failed to deallocate memory.\n");
423+
return 1;
424+
}
422425
}
423426
}
424427

@@ -459,6 +462,10 @@ int main (void)
459462
elem_len, rank, extents);
460463
tmp_ind = CFI_allocate ((CFI_cdesc_t *) &test7, lower, upper,
461464
base_type_size);
465+
if (tmp_ind != CFI_SUCCESS)
466+
{
467+
goto next_attribute4;
468+
}
462469
ind = CFI_is_contiguous ((CFI_cdesc_t *) &test7);
463470
if (ind != CFI_INVALID_RANK && rank == 0 &&
464471
tmp_ind != CFI_INVALID_ATTRIBUTE)
@@ -474,6 +481,7 @@ int main (void)
474481
return 1;
475482
}
476483
}
484+
next_attribute4:;
477485
}
478486

479487
/* Test CFI_address. */
@@ -875,7 +883,7 @@ int main (void)
875883
CFI_attribute_other, type[i], elem_len, rank,
876884
NULL);
877885
ind = CFI_allocate ((CFI_cdesc_t *) &source, lower, upper, elem_len);
878-
if (ind == CFI_ERROR_MEM_ALLOCATION)
886+
if (ind != CFI_SUCCESS)
879887
{
880888
goto next_type2;
881889
}
@@ -1036,44 +1044,48 @@ int main (void)
10361044
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
10371045
type[3], elem_len, rank, NULL);
10381046
ind = CFI_allocate ((CFI_cdesc_t *) &source, lower, upper, elem_len);
1039-
for (int r = 0; r < rank; r++)
1040-
{
1041-
lower[r] = rank - r - 3;
1042-
strides[r] = r + 1;
1043-
upper[r] = lower[r] + extents[r] - 3;
1044-
}
1045-
ind = CFI_section ((CFI_cdesc_t *) &section, NULL, lower, upper, strides);
1046-
if (ind != CFI_INVALID_DESCRIPTOR)
1047-
{
1048-
printf ("CFI_section: failed to detect that source is NULL.\n");
1049-
return 1;
1050-
}
1051-
ind = CFI_section (NULL, (CFI_cdesc_t *) &source, lower, upper, strides);
1052-
if (ind != CFI_INVALID_DESCRIPTOR)
1047+
if (ind == CFI_SUCCESS)
10531048
{
1054-
printf ("CFI_section: failed to detect that section is NULL.\n");
1055-
return 1;
1056-
}
1057-
ind =
1058-
CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_allocatable,
1059-
type[3], elem_len, rank, NULL);
1060-
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1061-
upper, strides);
1062-
if (ind != CFI_INVALID_ATTRIBUTE)
1063-
{
1064-
printf ("CFI_section: failed to detect invalid attribute.\n");
1065-
return 1;
1066-
}
1067-
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
1068-
type[3], elem_len, rank, NULL);
1069-
ind = CFI_deallocate ((CFI_cdesc_t *) &source);
1070-
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1071-
upper, strides);
1072-
if (ind != CFI_ERROR_BASE_ADDR_NULL)
1073-
{
1074-
printf ("CFI_section: failed to detect that the base address is NULL.\n");
1075-
return 1;
1049+
for (int r = 0; r < rank; r++)
1050+
{
1051+
lower[r] = rank - r - 3;
1052+
strides[r] = r + 1;
1053+
upper[r] = lower[r] + extents[r] - 3;
1054+
}
1055+
ind = CFI_section ((CFI_cdesc_t *) &section, NULL, lower, upper, strides);
1056+
if (ind != CFI_INVALID_DESCRIPTOR)
1057+
{
1058+
printf ("CFI_section: failed to detect that source is NULL.\n");
1059+
return 1;
1060+
}
1061+
ind = CFI_section (NULL, (CFI_cdesc_t *) &source, lower, upper, strides);
1062+
if (ind != CFI_INVALID_DESCRIPTOR)
1063+
{
1064+
printf ("CFI_section: failed to detect that section is NULL.\n");
1065+
return 1;
1066+
}
1067+
ind =
1068+
CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_allocatable,
1069+
type[3], elem_len, rank, NULL);
1070+
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1071+
upper, strides);
1072+
if (ind != CFI_INVALID_ATTRIBUTE)
1073+
{
1074+
printf ("CFI_section: failed to detect invalid attribute.\n");
1075+
return 1;
1076+
}
1077+
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
1078+
type[3], elem_len, rank, NULL);
1079+
ind = CFI_deallocate ((CFI_cdesc_t *) &source);
1080+
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1081+
upper, strides);
1082+
if (ind != CFI_ERROR_BASE_ADDR_NULL)
1083+
{
1084+
printf ("CFI_section: failed to detect that the base address is NULL.\n");
1085+
return 1;
1086+
}
10761087
}
1088+
10771089
CFI_CDESC_T (0) section2, source2;
10781090
ind = CFI_establish ((CFI_cdesc_t *) &source2, &ind, CFI_attribute_other,
10791091
type[3], 0, 0, NULL);
@@ -1086,33 +1098,37 @@ int main (void)
10861098
printf ("CFI_section: failed to detect invalid rank.\n");
10871099
return 1;
10881100
}
1101+
10891102
ind = CFI_establish ((CFI_cdesc_t *) &source, NULL, CFI_attribute_allocatable,
10901103
type[3], 0, rank, extents);
10911104
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
10921105
type[6], 0, rank, NULL);
10931106
ind = CFI_allocate ((CFI_cdesc_t *) &source, lower, upper, elem_len);
1094-
for (int r = 0; r < rank; r++)
1095-
{
1096-
lower[r] = rank - r - 3;
1097-
strides[r] = r + 1;
1098-
upper[r] = lower[r] + extents[r] - 3;
1099-
}
1100-
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1101-
upper, strides);
1102-
if (ind != CFI_INVALID_ELEM_LEN)
1107+
if (ind == CFI_SUCCESS)
11031108
{
1104-
printf ("CFI_section: failed to detect incompatible element lengths "
1105-
"between source and section.\n");
1106-
return 1;
1107-
}
1108-
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
1109-
CFI_type_long, 0, rank, NULL);
1110-
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1111-
upper, strides);
1112-
if (ind != CFI_INVALID_TYPE)
1113-
{
1114-
printf ("CFI_section: failed to detect invalid type.\n");
1115-
return 1;
1109+
for (int r = 0; r < rank; r++)
1110+
{
1111+
lower[r] = rank - r - 3;
1112+
strides[r] = r + 1;
1113+
upper[r] = lower[r] + extents[r] - 3;
1114+
}
1115+
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1116+
upper, strides);
1117+
if (ind != CFI_INVALID_ELEM_LEN)
1118+
{
1119+
printf ("CFI_section: failed to detect incompatible element lengths "
1120+
"between source and section.\n");
1121+
return 1;
1122+
}
1123+
ind = CFI_establish ((CFI_cdesc_t *) &section, NULL, CFI_attribute_other,
1124+
CFI_type_long, 0, rank, NULL);
1125+
ind = CFI_section ((CFI_cdesc_t *) &section, (CFI_cdesc_t *) &source, lower,
1126+
upper, strides);
1127+
if (ind != CFI_INVALID_TYPE)
1128+
{
1129+
printf ("CFI_section: failed to detect invalid type.\n");
1130+
return 1;
1131+
}
11161132
}
11171133

11181134
for (int i = 1; i < CFI_MAX_RANK; i++)
@@ -1151,7 +1167,7 @@ int main (void)
11511167
CFI_establish ((CFI_cdesc_t *) &source, NULL,
11521168
CFI_attribute_allocatable, type[3], 0, rank, extents);
11531169
ind = CFI_allocate ((CFI_cdesc_t *) &source, lower, upper, elem_len);
1154-
if (ind == CFI_ERROR_MEM_ALLOCATION)
1170+
if (ind != CFI_SUCCESS)
11551171
{
11561172
continue;
11571173
}
@@ -1252,13 +1268,15 @@ int main (void)
12521268
ind = CFI_establish ((CFI_cdesc_t *) &section3, NULL, CFI_attribute_other,
12531269
type[3], 0, rank, NULL);
12541270
ind = CFI_allocate ((CFI_cdesc_t *) &source3, lower, upper, elem_len);
1255-
1256-
ind = CFI_section ((CFI_cdesc_t *) &section3, (CFI_cdesc_t *) &source3, upper,
1257-
lower, strides);
1258-
if (ind != CFI_SUCCESS && ind != CFI_INVALID_STRIDE)
1271+
if (ind == CFI_SUCCESS)
12591272
{
1260-
printf ("CFI_section: failed to detect invalid stride.\n");
1261-
return 1;
1273+
ind = CFI_section ((CFI_cdesc_t *) &section3, (CFI_cdesc_t *) &source3,
1274+
upper, lower, strides);
1275+
if (ind != CFI_SUCCESS && ind != CFI_INVALID_STRIDE)
1276+
{
1277+
printf ("CFI_section: failed to detect invalid stride.\n");
1278+
return 1;
1279+
}
12621280
}
12631281

12641282
/* CFI_select_part */

0 commit comments

Comments
 (0)