Skip to content

Commit bcedb36

Browse files
authored
[clang][bytecode] Support composite arrays in memcpy op (#132775)
See the attached test case.
1 parent 1e2ad67 commit bcedb36

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,6 +2769,18 @@ static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
27692769
return true;
27702770
}
27712771

2772+
if (DestDesc->isCompositeArray()) {
2773+
assert(SrcDesc->isCompositeArray());
2774+
assert(SrcDesc->getNumElems() == DestDesc->getNumElems());
2775+
for (unsigned I = 0, N = DestDesc->getNumElems(); I != N; ++I) {
2776+
const Pointer &SrcElem = Src.atIndex(I).narrow();
2777+
Pointer DestElem = Dest.atIndex(I).narrow();
2778+
if (!copyComposite(S, OpPC, SrcElem, DestElem, Activate))
2779+
return false;
2780+
}
2781+
return true;
2782+
}
2783+
27722784
if (DestDesc->isRecord())
27732785
return copyRecord(S, OpPC, Src, Dest, Activate);
27742786
return Invalid(S, OpPC);

clang/test/AST/ByteCode/c.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ const struct StrA sc = *sb;
203203
_Static_assert(sc.a == 12, ""); // pedantic-ref-warning {{GNU extension}} \
204204
// pedantic-expected-warning {{GNU extension}}
205205

206+
struct ComplexS {
207+
int a;
208+
float b;
209+
struct StrA sa[2];
210+
};
211+
const struct ComplexS CS = {12, 23.0f, {{1}, {2}}};
212+
const struct ComplexS CS2 = CS;
213+
_Static_assert(CS2.sa[0].a == 1, ""); // pedantic-ref-warning {{GNU extension}} \
214+
// pedantic-expected-warning {{GNU extension}}
215+
206216
_Static_assert(((void*)0 + 1) != (void*)0, ""); // pedantic-expected-warning {{arithmetic on a pointer to void is a GNU extension}} \
207217
// pedantic-expected-warning {{not an integer constant expression}} \
208218
// pedantic-expected-note {{cannot perform pointer arithmetic on null pointer}} \

0 commit comments

Comments
 (0)