Skip to content

Commit 80737d2

Browse files
committed
[clang][Interp][NFC] Pass PrimType to visitZeroInitializer()
This fixes an old FIXME comment. Almost all callers already classify() the type anyway, so just pass the result of that to visitZeroInitializer().
1 parent 0ad92c0 commit 80737d2

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ template <class Emitter>
493493
bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
494494
QualType QT = E->getType();
495495

496-
if (classify(QT))
497-
return this->visitZeroInitializer(QT, E);
496+
if (std::optional<PrimType> T = classify(QT))
497+
return this->visitZeroInitializer(*T, QT, E);
498498

499499
if (QT->isRecordType())
500500
return false;
@@ -510,7 +510,7 @@ bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueIni
510510
// since we memset our Block*s to 0 and so we have the desired value
511511
// without this.
512512
for (size_t I = 0; I != NumElems; ++I) {
513-
if (!this->visitZeroInitializer(CAT->getElementType(), E))
513+
if (!this->visitZeroInitializer(*ElemT, CAT->getElementType(), E))
514514
return false;
515515
if (!this->emitInitElem(*ElemT, I, E))
516516
return false;
@@ -620,7 +620,7 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
620620
if (std::optional<PrimType> T = classify(E->getType())) {
621621
assert(!DiscardResult);
622622
if (E->getNumInits() == 0)
623-
return this->visitZeroInitializer(E->getType(), E);
623+
return this->visitZeroInitializer(*T, E->getType(), E);
624624
assert(E->getNumInits() == 1);
625625
return this->delegate(E->inits()[0]);
626626
}
@@ -1560,7 +1560,8 @@ bool ByteCodeExprGen<Emitter>::VisitOffsetOfExpr(const OffsetOfExpr *E) {
15601560
template <class Emitter>
15611561
bool ByteCodeExprGen<Emitter>::VisitCXXScalarValueInitExpr(
15621562
const CXXScalarValueInitExpr *E) {
1563-
return this->visitZeroInitializer(E->getType(), E);
1563+
return this->visitZeroInitializer(classifyPrim(E->getType()), E->getType(),
1564+
E);
15641565
}
15651566

15661567
template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
@@ -1648,12 +1649,8 @@ bool ByteCodeExprGen<Emitter>::visitBool(const Expr *E) {
16481649
}
16491650

16501651
template <class Emitter>
1651-
bool ByteCodeExprGen<Emitter>::visitZeroInitializer(QualType QT,
1652+
bool ByteCodeExprGen<Emitter>::visitZeroInitializer(PrimType T, QualType QT,
16521653
const Expr *E) {
1653-
// FIXME: We need the QualType to get the float semantics, but that means we
1654-
// classify it over and over again in array situations.
1655-
PrimType T = classifyPrim(QT);
1656-
16571654
switch (T) {
16581655
case PT_Bool:
16591656
return this->emitZeroBool(E);
@@ -1699,7 +1696,7 @@ bool ByteCodeExprGen<Emitter>::visitZeroRecordInitializer(const Record *R,
16991696
if (D->isPrimitive()) {
17001697
QualType QT = D->getType();
17011698
PrimType T = classifyPrim(D->getType());
1702-
if (!this->visitZeroInitializer(QT, E))
1699+
if (!this->visitZeroInitializer(T, QT, E))
17031700
return false;
17041701
if (!this->emitInitField(T, Field.Offset, E))
17051702
return false;
@@ -1716,7 +1713,7 @@ bool ByteCodeExprGen<Emitter>::visitZeroRecordInitializer(const Record *R,
17161713
QualType ET = D->getElemQualType();
17171714
PrimType T = classifyPrim(ET);
17181715
for (uint32_t I = 0, N = D->getNumElems(); I != N; ++I) {
1719-
if (!this->visitZeroInitializer(ET, E))
1716+
if (!this->visitZeroInitializer(T, ET, E))
17201717
return false;
17211718
if (!this->emitInitElem(T, I, E))
17221719
return false;

clang/lib/AST/Interp/ByteCodeExprGen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
222222
friend class SourceLocScope<Emitter>;
223223

224224
/// Emits a zero initializer.
225-
bool visitZeroInitializer(QualType QT, const Expr *E);
225+
bool visitZeroInitializer(PrimType T, QualType QT, const Expr *E);
226226
bool visitZeroRecordInitializer(const Record *R, const Expr *E);
227227

228228
enum class DerefKind {

0 commit comments

Comments
 (0)