[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 20 07:35:20 PST 2024
================
@@ -0,0 +1,66 @@
+//===--------------------- BitcastBuffer.h ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+#define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+
+#include <cassert>
+#include <cstddef>
+#include <memory>
+
+namespace clang {
+namespace interp {
+
+enum class Endian { Little, Big };
+
+/// Returns the value of the bit in the given sequence of bytes.
+static inline bool bitof(const std::byte *B, unsigned BitIndex) {
+ return (B[BitIndex / 8] & (std::byte{1} << (BitIndex % 8))) != std::byte{0};
+}
+
+/// Returns whether \p N is a full byte offset or size.
+static inline bool fullByte(unsigned N) { return N % 8 == 0; }
+
+/// Track what bits have been initialized to known values and which ones
+/// have indeterminate value.
+/// All offsets are in bits.
----------------
Sirraide wrote:
> There's a small part of me that wonders if we should use a different type for representing bits. e.g., instead of using `size_t` to mean byte offset and bit offset depending on context,
I second that because I at least confuse those two all the time, to the point where all my compiler projects have a `Size` struct that requires you to always be explicit as to whether you’re passing in / want to have bits or bytes.
https://github.com/llvm/llvm-project/pull/116843
More information about the cfe-commits
mailing list