diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -295,6 +295,14 @@ add_definitions(-DFLANG_REPOSITORY_STRING="${FLANG_REPOSITORY_STRING}") endif() +include(TestBigEndian) +test_big_endian(IS_BIGENDIAN) +if (IS_BIGENDIAN) + add_compile_definitions(FLANG_BIG_ENDIAN=1) +else () + add_compile_definitions(FLANG_LITTLE_ENDIAN=1) +endif () + # Configure Flang's Version.inc file. configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/flang/Version.inc.in diff --git a/flang/include/flang/Evaluate/common.h b/flang/include/flang/Evaluate/common.h --- a/flang/include/flang/Evaluate/common.h +++ b/flang/include/flang/Evaluate/common.h @@ -133,9 +133,9 @@ static constexpr Rounding defaultRounding; -#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#if FLANG_BIG_ENDIAN constexpr bool isHostLittleEndian{false}; -#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#elif FLANG_LITTLE_ENDIAN constexpr bool isHostLittleEndian{true}; #else #error host endianness is not known diff --git a/flang/runtime/environment.h b/flang/runtime/environment.h --- a/flang/runtime/environment.h +++ b/flang/runtime/environment.h @@ -14,9 +14,9 @@ namespace Fortran::runtime { -#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#if FLANG_BIG_ENDIAN constexpr bool isHostLittleEndian{false}; -#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#elif FLANG_LITTLE_ENDIAN constexpr bool isHostLittleEndian{true}; #else #error host endianness is not known