[PATCH] D109108: [flang] Use CMake to determine endianness.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 29 10:00:50 PDT 2021


Meinersbur added a comment.

In D109108#3029584 <https://reviews.llvm.org/D109108#3029584>, @tschuett wrote:

> This does not solve your problem?
> https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/Endian.h

This uses a manually-maintained list of compilers and with their endianness

name=llvm/Support/SwapByteOrder.h
  #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||            \
      defined(__Fuchsia__) || defined(__EMSCRIPTEN__)
  #include <endian.h>
  #elif defined(_AIX)
  #include <sys/machine.h>
  #elif defined(__sun)
  /* Solaris provides _BIG_ENDIAN/_LITTLE_ENDIAN selector in sys/types.h */
  #include <sys/types.h>
  #define BIG_ENDIAN 4321
  #define LITTLE_ENDIAN 1234
  #if defined(_BIG_ENDIAN)
  #define BYTE_ORDER BIG_ENDIAN
  #else
  #define BYTE_ORDER LITTLE_ENDIAN
  #endif
  #elif defined(__MVS__)
  #define BIG_ENDIAN 4321
  #define LITTLE_ENDIAN 1234
  #define BYTE_ORDER BIG_ENDIAN
  #else
  #if !defined(BYTE_ORDER) && !defined(_WIN32)
  #include <machine/endian.h>
  #endif
  #endif

I personally find asking cmake the cleaner solution (it does introspection anyway, and endianness must be consistent with the rest of build environment), but I guess the LLVM community will be committed to maintain that list with all supported compilers and would ensure consistency with the rest of LLVM, I could use that if others prefer it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109108/new/

https://reviews.llvm.org/D109108



More information about the llvm-commits mailing list