[clang] [clang][Headers] add endian.h (PR #186032)
Hubert Tong via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 12 07:26:52 PDT 2026
================
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -triple powerpc64-unknown -fsyntax-only -verify -xc++ -ffreestanding %s
+// RUN: %clang_cc1 -triple ppc64le-unknown -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -triple ppc64le-unknown -fsyntax-only -verify -xc++ -ffreestanding %s
+// expected-no-diagnostics
+
+#include <endian.h>
+
+
+#if BYTE_ORDER == BIG_ENDIAN
+
+_Static_assert(htobe16(0xBEEF) == 0xBEEF, "");
+_Static_assert(htobe32(0xDEADBEEF) == 0xDEADBEEF, "");
+_Static_assert(htobe64(0xDEADBEEFDEADBEEF) == 0xDEADBEEFDEADBEEF, "");
+_Static_assert(htole16(0xBEEF) == 0xEFBE, "");
+_Static_assert(htole32(0xDEADBEEF) == 0xEFBEADDE, "");
+_Static_assert(htole64(0xDEADBEEFDEADBEEF) == 0xEFBEADDEEFBEADDE, "");
----------------
hubert-reinterpretcast wrote:
Might be more reasonable to go with something where the first and second half are distinct, e.g., `DEADBEEFBAADF00D`.
https://github.com/llvm/llvm-project/pull/186032
More information about the cfe-commits
mailing list