[clang] [clang][bytecode] Move bases and virtual bases in moveRecord (PR #127627)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 18 05:05:08 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
The fixme comment turned out to be true.
---
Full diff: https://github.com/llvm/llvm-project/pull/127627.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Descriptor.cpp (+24-2)
- (modified) clang/test/AST/ByteCode/records.cpp (+19)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp b/clang/lib/AST/ByteCode/Descriptor.cpp
index 319d1690c1cd0..026f3d96f9a46 100644
--- a/clang/lib/AST/ByteCode/Descriptor.cpp
+++ b/clang/lib/AST/ByteCode/Descriptor.cpp
@@ -237,8 +237,7 @@ static void moveRecord(Block *B, std::byte *Src, std::byte *Dst,
assert(D);
assert(D->ElemRecord);
- // FIXME: There might be cases where we need to move over the (v)bases as
- // well.
+ // FIXME: Code duplication.
for (const auto &F : D->ElemRecord->fields()) {
auto FieldOffset = F.Offset;
const auto *SrcDesc =
@@ -250,6 +249,29 @@ static void moveRecord(Block *B, std::byte *Src, std::byte *Dst,
if (auto Fn = F.Desc->MoveFn)
Fn(B, Src + FieldOffset, Dst + FieldOffset, F.Desc);
}
+
+ for (const auto &Base : D->ElemRecord->bases()) {
+ auto BaseOffset = Base.Offset;
+ const auto *SrcDesc =
+ reinterpret_cast<const InlineDescriptor *>(Src + BaseOffset) - 1;
+ auto *DestDesc = reinterpret_cast<InlineDescriptor *>(Dst + BaseOffset) - 1;
+ std::memcpy(DestDesc, SrcDesc, sizeof(InlineDescriptor));
+
+ if (auto Fn = Base.Desc->MoveFn)
+ Fn(B, Src + BaseOffset, Dst + BaseOffset, Base.Desc);
+ }
+
+ for (const auto &VBase : D->ElemRecord->virtual_bases()) {
+ auto VBaseOffset = VBase.Offset;
+ const auto *SrcDesc =
+ reinterpret_cast<const InlineDescriptor *>(Src + VBaseOffset) - 1;
+ auto *DestDesc =
+ reinterpret_cast<InlineDescriptor *>(Dst + VBaseOffset) - 1;
+ std::memcpy(DestDesc, SrcDesc, sizeof(InlineDescriptor));
+
+ if (auto Fn = VBase.Desc->MoveFn)
+ Fn(B, Src + VBaseOffset, Dst + VBaseOffset, VBase.Desc);
+ }
}
static BlockCtorFn getCtorPrim(PrimType Type) {
diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp
index 9470e7d8e3dcb..a515f69d6903d 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1699,3 +1699,22 @@ namespace IgnoredMemberExpr {
};
static_assert(B{}.foo() == 0, "");
}
+
+#if __cplusplus >= 202002L
+namespace DeadUpcast {
+ struct A {};
+ struct B : A{};
+ constexpr bool foo() {
+
+ B *pb;
+ {
+ B b;
+ pb = &b;
+ }
+ A *pa = pb;
+
+ return true;
+ }
+ static_assert(foo(), "");
+}
+#endif
``````````
</details>
https://github.com/llvm/llvm-project/pull/127627
More information about the cfe-commits
mailing list