@@ -7237,6 +7237,7 @@ class APValueToBufferConverter {
72377237
72387238 case APValue::ComplexInt:
72397239 case APValue::ComplexFloat:
7240+ return visitComplex(Val, Ty, Offset);
72407241 case APValue::FixedPoint:
72417242 // FIXME: We should support these.
72427243
@@ -7323,6 +7324,31 @@ class APValueToBufferConverter {
73237324 return true;
73247325 }
73257326
7327+ bool visitComplex(const APValue &Val, QualType Ty, CharUnits Offset) {
7328+ const ComplexType *ComplexTy = Ty->castAs<ComplexType>();
7329+ QualType EltTy = ComplexTy->getElementType();
7330+ CharUnits EltSizeChars = Info.Ctx.getTypeSizeInChars(EltTy);
7331+ bool IsInt = Val.isComplexInt();
7332+
7333+ if (IsInt) {
7334+ if (!visitInt(Val.getComplexIntReal(), EltTy,
7335+ Offset + (0 * EltSizeChars)))
7336+ return false;
7337+ if (!visitInt(Val.getComplexIntImag(), EltTy,
7338+ Offset + (1 * EltSizeChars)))
7339+ return false;
7340+ } else {
7341+ if (!visitFloat(Val.getComplexFloatReal(), EltTy,
7342+ Offset + (0 * EltSizeChars)))
7343+ return false;
7344+ if (!visitFloat(Val.getComplexFloatImag(), EltTy,
7345+ Offset + (1 * EltSizeChars)))
7346+ return false;
7347+ }
7348+
7349+ return true;
7350+ }
7351+
73267352 bool visitVector(const APValue &Val, QualType Ty, CharUnits Offset) {
73277353 const VectorType *VTy = Ty->castAs<VectorType>();
73287354 QualType EltTy = VTy->getElementType();
@@ -7595,6 +7621,23 @@ class BufferToAPValueConverter {
75957621 return ArrayValue;
75967622 }
75977623
7624+ std::optional<APValue> visit(const ComplexType *Ty, CharUnits Offset) {
7625+ QualType ElementType = Ty->getElementType();
7626+ CharUnits ElementWidth = Info.Ctx.getTypeSizeInChars(ElementType);
7627+ bool IsInt = ElementType->isIntegerType();
7628+
7629+ std::optional<APValue> Values[2];
7630+ for (unsigned I = 0; I != 2; ++I) {
7631+ Values[I] = visitType(Ty->getElementType(), Offset + I * ElementWidth);
7632+ if (!Values[I])
7633+ return std::nullopt;
7634+ }
7635+
7636+ if (IsInt)
7637+ return APValue(Values[0]->getInt(), Values[1]->getInt());
7638+ return APValue(Values[0]->getFloat(), Values[1]->getFloat());
7639+ }
7640+
75987641 std::optional<APValue> visit(const VectorType *VTy, CharUnits Offset) {
75997642 QualType EltTy = VTy->getElementType();
76007643 unsigned NElts = VTy->getNumElements();
0 commit comments