Skip to content

Commit d5c8af4

Browse files
authored
[clang][bytecode] Consider start index when copying composite array (llvm#121461)
... elements.
1 parent a3744f0 commit d5c8af4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static bool enumerateData(const Pointer &P, const Context &Ctx, Bits Offset,
110110
if (FieldDesc->isCompositeArray()) {
111111
QualType ElemType = FieldDesc->getElemQualType();
112112
Bits ElemSize = Bits(Ctx.getASTContext().getTypeSize(ElemType));
113-
for (unsigned I = 0; I != FieldDesc->getNumElems(); ++I) {
113+
for (unsigned I = P.getIndex(); I != FieldDesc->getNumElems(); ++I) {
114114
enumerateData(P.atIndex(I).narrow(), Ctx, Offset, BitsToRead, F);
115115
Offset += ElemSize;
116116
if (Offset >= BitsToRead)

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,16 @@ namespace BuiltinMemcpy {
12531253
static_assert(test_memmove(2, 0, 12) == 4234); // both-error {{constant}} \
12541254
// both-note {{in call}}
12551255
#endif
1256+
1257+
struct Trivial { char k; short s; constexpr bool ok() { return k == 3 && s == 4; } };
1258+
constexpr bool test_trivial() {
1259+
Trivial arr[3] = {{1, 2}, {3, 4}, {5, 6}};
1260+
__builtin_memcpy(arr, arr+1, sizeof(Trivial));
1261+
__builtin_memmove(arr+1, arr, 2 * sizeof(Trivial));
1262+
1263+
return arr[0].ok() && arr[1].ok() && arr[2].ok();
1264+
}
1265+
static_assert(test_trivial());
12561266
}
12571267

12581268
namespace Memcmp {

0 commit comments

Comments
 (0)