@@ -7237,6 +7237,7 @@ class APValueToBufferConverter {
7237
7237
7238
7238
case APValue::ComplexInt:
7239
7239
case APValue::ComplexFloat:
7240
+ return visitComplex(Val, Ty, Offset);
7240
7241
case APValue::FixedPoint:
7241
7242
// FIXME: We should support these.
7242
7243
@@ -7323,6 +7324,31 @@ class APValueToBufferConverter {
7323
7324
return true;
7324
7325
}
7325
7326
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
+
7326
7352
bool visitVector(const APValue &Val, QualType Ty, CharUnits Offset) {
7327
7353
const VectorType *VTy = Ty->castAs<VectorType>();
7328
7354
QualType EltTy = VTy->getElementType();
@@ -7595,6 +7621,23 @@ class BufferToAPValueConverter {
7595
7621
return ArrayValue;
7596
7622
}
7597
7623
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
+
7598
7641
std::optional<APValue> visit(const VectorType *VTy, CharUnits Offset) {
7599
7642
QualType EltTy = VTy->getElementType();
7600
7643
unsigned NElts = VTy->getNumElements();
0 commit comments