Skip to content

Commit c9e403d

Browse files
committed
[clang][Interp] Fix zero-init of float and pointer arrays
Our Zero opcode only exists for integer types. Use visitZeroInitializer() here as well so it works for floats and pointers. Differential Revision: https://reviews.llvm.org/D149059
1 parent e042efd commit c9e403d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ bool ByteCodeExprGen<Emitter>::visitArrayInitializer(const Expr *Initializer) {
12911291
// since we memset our Block*s to 0 and so we have the desired value
12921292
// without this.
12931293
for (size_t I = 0; I != NumElems; ++I) {
1294-
if (!this->emitZero(*ElemT, Initializer))
1294+
if (!this->visitZeroInitializer(CAT->getElementType(), Initializer))
12951295
return false;
12961296
if (!this->emitInitElem(*ElemT, I, Initializer))
12971297
return false;

clang/test/AST/Interp/arrays.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,19 @@ namespace IncDec {
334334
// ref-error {{not an integral constant expression}} \
335335
// ref-note {{in call to}}
336336
};
337+
338+
namespace ZeroInit {
339+
struct A {
340+
int *p[2];
341+
};
342+
constexpr A a = {};
343+
static_assert(a.p[0] == nullptr, "");
344+
static_assert(a.p[1] == nullptr, "");
345+
346+
struct B {
347+
double f[2];
348+
};
349+
constexpr B b = {};
350+
static_assert(b.f[0] == 0.0, "");
351+
static_assert(b.f[1] == 0.0, "");
352+
}

0 commit comments

Comments
 (0)