[PATCH] D144943: [clang][Interp] Implement bitcasts (WIP)

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 27 23:22:10 PST 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafi.ahmad.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This implements bitcasts by traversing the pointer fields at interpretation-time, copying them into a buffer and then either creating a new primitive value from the buffer, or traversing the destination pointer and reading the field values from that buffer.

This is a bit non-idiomatic to the new interpreter since we do so much work at interpretation time instead of doing it at compile-time.
I can imagine ways to change this, but it would require bytecode instructions that are rather awkward, I think. So this is my attempt at
doing it this way instead.

It's also missing all the eligibility checks for bitcasts of course.
I have also not tested this on a big-endian host, which I definitely need to do (is the bit rotation needed if the host is BE //and// the target is BE?).

I'll try to leave a few comments in the diff.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144943

Files:
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Descriptor.h
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/builtin-bit-cast.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144943.501037.patch
Type: text/x-patch
Size: 23051 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230228/7032f994/attachment-0001.bin>


More information about the cfe-commits mailing list