Skip to content

Commit 13f8f7e

Browse files
committed
skip bounds test with GCC < 12
known GCC bug
1 parent 226108d commit 13f8f7e

4 files changed

Lines changed: 86 additions & 108 deletions

File tree

src/bounds/bounds.c

Lines changed: 0 additions & 103 deletions
This file was deleted.

src/bounds/bounds.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <iostream>
2+
#include <ISO_Fortran_binding.h>
3+
4+
#include "bounds.h"
5+
6+
// ==================== 1D Version ====================
7+
bool c_bounder(CFI_cdesc_t* a,
8+
CFI_index_t fortran_lower,
9+
CFI_index_t fortran_upper)
10+
{
11+
std::cout << "=== C++: c_bounder (1D) called ===\n";
12+
13+
if (a == nullptr) {
14+
std::cerr << "ERROR: nullptr descriptor\n";
15+
return false;
16+
}
17+
18+
if (a->rank != 1) {
19+
std::cerr << "ERROR: Expected rank 1, got " << a->rank << "\n";
20+
return false;
21+
}
22+
23+
const CFI_dim_t& dim = a->dim[0];
24+
const CFI_index_t c_lower = dim.lower_bound;
25+
const CFI_index_t extent = dim.extent;
26+
const CFI_index_t c_upper = c_lower + extent - 1;
27+
28+
std::cout << "C Descriptor: lower=" << c_lower << ", upper=" << c_upper << ", extent=" << extent << "\n";
29+
std::cout << "Fortran Array: lower=" << fortran_lower << ", upper=" << fortran_upper << "\n";
30+
31+
if (c_lower != 0) {
32+
std::cerr << "WARNING: C lower bound is not 0 (got " << c_lower << ")\n";
33+
}
34+
35+
if (extent != (fortran_upper - fortran_lower + 1)) {
36+
std::cerr << "ERROR: Extent mismatch! Expected " << (fortran_upper - fortran_lower + 1) << ", got " << extent << "\n";
37+
return false;
38+
}
39+
40+
std::cout << "✓ Extent check PASSED\n";
41+
42+
return true;
43+
}
44+
45+
// ==================== 2D Version ====================
46+
bool c_bounder_2d(CFI_cdesc_t* a,
47+
CFI_index_t fl1, CFI_index_t fu1,
48+
CFI_index_t fl2, CFI_index_t fu2)
49+
{
50+
std::cout << "=== C++: c_bounder_2d called ===\n";
51+
52+
if (a == nullptr || a->rank != 2) {
53+
std::cerr << "ERROR: Expected rank 2\n";
54+
return false;
55+
}
56+
57+
// Check dimensions
58+
const CFI_index_t extent1 = a->dim[0].extent;
59+
const CFI_index_t extent2 = a->dim[1].extent;
60+
61+
if (extent1 != (fu1 - fl1 + 1)) {
62+
std::cerr << "ERROR: Dim1 extent mismatch\n";
63+
return false;
64+
}
65+
66+
if (extent2 != (fu2 - fl2 + 1)) {
67+
std::cerr << "ERROR: Dim2 extent mismatch\n";
68+
return false;
69+
}
70+
71+
std::cout << "✓ 2D Extent check PASSED: [" << fl1 << ":" << fu1 << ", " << fl2 << ":" << fu2 << "]\n";
72+
73+
return true;
74+
}

src/bounds/bounds.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#if defined(__STDC_VERSION__) && __STDC_VERSION__ < 202311L
2-
#include <stdbool.h>
3-
#endif
1+
#include <ISO_Fortran_binding.h>
42

3+
extern "C" {
54
bool c_bounder(CFI_cdesc_t*, CFI_index_t, CFI_index_t);
65
bool c_bounder_2d(CFI_cdesc_t*, CFI_index_t, CFI_index_t, CFI_index_t, CFI_index_t);
6+
}

test/bounds/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ if(NOT HAVE_ISO_FORTRAN_BINDING_H)
44
return()
55
endif()
66

7-
add_executable(bounds_fortran bounds.f90 ${PROJECT_SOURCE_DIR}/src/bounds/bounds.c)
8-
target_include_directories(bounds_fortran INTERFACE ${PROJECT_SOURCE_DIR}/src/bounds)
7+
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND
8+
CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 12)
9+
message(STATUS "GNU Fortran < 12 has known bugs in non-default array bounds. Skipping bounds tests.")
10+
return()
11+
endif()
12+
13+
add_executable(bounds_fortran bounds.f90 ${PROJECT_SOURCE_DIR}/src/bounds/bounds.cpp)
14+
target_include_directories(bounds_fortran PRIVATE ${PROJECT_SOURCE_DIR}/src/bounds)
15+
916
add_test(NAME BoundsFortran COMMAND bounds_fortran)

0 commit comments

Comments
 (0)