[clang] 4a8b43b - [clang][Interp][NFC] Factor array element init into its own function
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 20 04:01:08 PST 2023
Author: Timm Bäder
Date: 2023-11-20T13:00:57+01:00
New Revision: 4a8b43ba3bd5427dd98a7a93d1b1ed25051c31e8
URL: https://github.com/llvm/llvm-project/commit/4a8b43ba3bd5427dd98a7a93d1b1ed25051c31e8
DIFF: https://github.com/llvm/llvm-project/commit/4a8b43ba3bd5427dd98a7a93d1b1ed25051c31e8.diff
LOG: [clang][Interp][NFC] Factor array element init into its own function
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a1f45f5e3658d26..5dc1f9dfb10ff32 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -614,6 +614,29 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
return true;
}
+/// Pointer to the array(not the element!) must be on the stack when calling
+/// this.
+template <class Emitter>
+bool ByteCodeExprGen<Emitter>::visitArrayElemInit(unsigned ElemIndex,
+ const Expr *Init) {
+ if (std::optional<PrimType> T = classify(Init->getType())) {
+ // Visit the primitive element like normal.
+ if (!this->visit(Init))
+ return false;
+ return this->emitInitElem(*T, ElemIndex, Init);
+ }
+
+ // Advance the pointer currently on the stack to the given
+ // dimension.
+ if (!this->emitConstUint32(ElemIndex, Init))
+ return false;
+ if (!this->emitArrayElemPtrUint32(Init))
+ return false;
+ if (!this->visitInitializer(Init))
+ return false;
+ return this->emitPopPtr(Init);
+}
+
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
// Handle discarding first.
@@ -642,25 +665,8 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
// FIXME: Array fillers.
unsigned ElementIndex = 0;
for (const Expr *Init : E->inits()) {
- if (std::optional<PrimType> T = classify(Init->getType())) {
- // Visit the primitive element like normal.
- if (!this->visit(Init))
- return false;
- if (!this->emitInitElem(*T, ElementIndex, Init))
- return false;
- } else {
- // Advance the pointer currently on the stack to the given
- // dimension.
- if (!this->emitConstUint32(ElementIndex, Init))
- return false;
- if (!this->emitArrayElemPtrUint32(Init))
- return false;
- if (!this->visitInitializer(Init))
- return false;
- if (!this->emitPopPtr(Init))
- return false;
- }
-
+ if (!this->visitArrayElemInit(ElementIndex, Init))
+ return false;
++ElementIndex;
}
return true;
@@ -831,7 +837,6 @@ bool ByteCodeExprGen<Emitter>::VisitArrayInitLoopExpr(
const Expr *SubExpr = E->getSubExpr();
const Expr *CommonExpr = E->getCommonExpr();
size_t Size = E->getArraySize().getZExtValue();
- std::optional<PrimType> ElemT = classify(SubExpr->getType());
// If the common expression is an opaque expression, we visit it
// here once so we have its value cached.
@@ -848,22 +853,8 @@ bool ByteCodeExprGen<Emitter>::VisitArrayInitLoopExpr(
ArrayIndexScope<Emitter> IndexScope(this, I);
BlockScope<Emitter> BS(this);
- if (ElemT) {
- if (!this->visit(SubExpr))
- return false;
- if (!this->emitInitElem(*ElemT, I, E))
- return false;
- } else {
- // Get to our array element and recurse into visitInitializer()
- if (!this->emitConstUint64(I, SubExpr))
- return false;
- if (!this->emitArrayElemPtrUint64(SubExpr))
- return false;
- if (!visitInitializer(SubExpr))
- return false;
- if (!this->emitPopPtr(E))
- return false;
- }
+ if (!this->visitArrayElemInit(I, SubExpr))
+ return false;
}
return true;
}
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 602cee45f381df5..bc1d5d11a115135 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -209,6 +209,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
}
bool visitInitList(ArrayRef<const Expr *> Inits, const Expr *E);
+ bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init);
/// Creates a local primitive value.
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst,
More information about the cfe-commits
mailing list