[clang] [clang][bytecode][NFC] Avoid some code duplication for `ScalarValueInitExpr` (PR #200755)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 1 02:00:11 PDT 2026
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/200755
>From dccaf391ff39b8aaf6c5129e55b0e5ace674866d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 1 Jun 2026 10:48:53 +0200
Subject: [PATCH] test
---
clang/lib/AST/ByteCode/Compiler.cpp | 37 ++++++++++-------------------
1 file changed, 12 insertions(+), 25 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 774a853950837..a2f05faee5a64 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -3829,7 +3829,7 @@ bool Compiler<Emitter>::VisitCXXScalarValueInitExpr(
if (OptPrimType T = classify(Ty))
return this->visitZeroInitializer(*T, Ty, E);
- if (const auto *CT = Ty->getAs<ComplexType>()) {
+ if (Ty->isAnyComplexType() || Ty->isVectorType()) {
if (!Initializing) {
UnsignedOrNone LocalIndex = allocateLocal(E);
if (!LocalIndex)
@@ -3838,34 +3838,21 @@ bool Compiler<Emitter>::VisitCXXScalarValueInitExpr(
return false;
}
- // Initialize both fields to 0.
- QualType ElemQT = CT->getElementType();
- PrimType ElemT = classifyPrim(ElemQT);
-
- for (unsigned I = 0; I != 2; ++I) {
- if (!this->visitZeroInitializer(ElemT, ElemQT, E))
- return false;
- if (!this->emitInitElem(ElemT, I, E))
- return false;
- }
- return true;
- }
-
- if (const auto *VT = Ty->getAs<VectorType>()) {
- // FIXME: Code duplication with the _Complex case above.
- if (!Initializing) {
- UnsignedOrNone LocalIndex = allocateLocal(E);
- if (!LocalIndex)
- return false;
- if (!this->emitGetPtrLocal(*LocalIndex, E))
- return false;
+ QualType ElemQT;
+ unsigned NumElems;
+ if (const auto *CT = Ty->getAs<ComplexType>()) {
+ NumElems = 2;
+ ElemQT = CT->getElementType();
+ } else {
+ const auto *VT = Ty->castAs<VectorType>();
+ NumElems = VT->getNumElements();
+ ElemQT = VT->getElementType();
}
- // Initialize all fields to 0.
- QualType ElemQT = VT->getElementType();
PrimType ElemT = classifyPrim(ElemQT);
- for (unsigned I = 0, N = VT->getNumElements(); I != N; ++I) {
+ // Initialize all fields to 0.
+ for (unsigned I = 0, N = NumElems; I != N; ++I) {
if (!this->visitZeroInitializer(ElemT, ElemQT, E))
return false;
if (!this->emitInitElem(ElemT, I, E))
More information about the cfe-commits
mailing list