[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 21 00:53:46 PST 2024
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/116843 at github.com>
================
@@ -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.
----------------
tbaederr wrote:
Added something like this. In the end I almost didn't use the `Bytes` struct at all though.
https://github.com/llvm/llvm-project/pull/116843
More information about the cfe-commits
mailing list