Skip to content

[flang][NFC] Use LLVM's endianness enum #86516

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 3 additions & 4 deletions flang/include/flang/Common/uint128.h
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
#endif

#include "leading-zero-bit-count.h"
#include "llvm/ADT/bit.h"
#include <cstdint>
#include <type_traits>

@@ -261,12 +262,10 @@ template <bool IS_SIGNED = false> class Int128 {
}
}
static constexpr std::uint64_t topBit{std::uint64_t{1} << 63};
#if FLANG_LITTLE_ENDIAN
std::uint64_t low_{0}, high_{0};
#elif FLANG_BIG_ENDIAN
#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
std::uint64_t high_{0}, low_{0};
#else
#error host endianness is not known
std::uint64_t low_{0}, high_{0};
Copy link
Contributor

Choose a reason for hiding this comment

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

You're just defaulting to little-endianness here if BYTE_ORDER is undefined. This can be worse than the current situation.

#endif
};

10 changes: 3 additions & 7 deletions flang/include/flang/Evaluate/common.h
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
#include "flang/Common/restorer.h"
#include "flang/Parser/char-block.h"
#include "flang/Parser/message.h"
#include "llvm/ADT/bit.h"
#include <cinttypes>
#include <map>
#include <set>
@@ -142,13 +143,8 @@ template <typename A> struct ValueWithRealFlags {
RealFlags flags{};
};

#if FLANG_BIG_ENDIAN
constexpr bool isHostLittleEndian{false};
#elif FLANG_LITTLE_ENDIAN
constexpr bool isHostLittleEndian{true};
#else
#error host endianness is not known
#endif
constexpr bool isHostLittleEndian =
Copy link
Contributor

Choose a reason for hiding this comment

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

This initialization should use braces and does not need parentheses.

(llvm::endianness::native == llvm::endianness::little);

// HostUnsignedInt<BITS> finds the smallest native unsigned integer type
// whose size is >= BITS.
11 changes: 4 additions & 7 deletions flang/runtime/environment.h
Original file line number Diff line number Diff line change
@@ -12,19 +12,16 @@
#include "flang/Common/optional.h"
#include "flang/Decimal/decimal.h"

#include "llvm/ADT/bit.h"

struct EnvironmentDefaultList;

namespace Fortran::runtime {

class Terminator;

#if FLANG_BIG_ENDIAN
constexpr bool isHostLittleEndian{false};
#elif FLANG_LITTLE_ENDIAN
constexpr bool isHostLittleEndian{true};
#else
#error host endianness is not known
#endif
constexpr bool isHostLittleEndian =
(llvm::endianness::native == llvm::endianness::little);

// External unformatted I/O data conversions
enum class Convert { Unknown, Native, LittleEndian, BigEndian, Swap };