Author: Timm Baeder Date: 2026-06-01T12:07:39+02:00 New Revision: 044b63d5771802d1baaa6e877e76e0c562aa0724
URL: https://github.com/llvm/llvm-project/commit/044b63d5771802d1baaa6e877e76e0c562aa0724 DIFF: https://github.com/llvm/llvm-project/commit/044b63d5771802d1baaa6e877e76e0c562aa0724.diff LOG: [clang][bytecode][NFC] Avoid some code duplication for `ScalarValueInitExpr` (#200755) Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 322c1f827223b..732a9e227430c 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -3831,7 +3831,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) @@ -3840,34 +3840,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)) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
