Skip to content

Commit 48508c1

Browse files
authored
[Clang] Handle real and imaginary parts of complex lvalue in APValue::printPretty (#69252)
This patch handles formatting of real and imaginary parts of complex lvalue. Fixes #69218.
1 parent d95d1c3 commit 48508c1

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ Bug Fixes in This Version
474474
- Clang now accepts anonymous members initialized with designated initializers
475475
inside templates.
476476
Fixes (`#65143 <https://github.com/llvm/llvm-project/issues/65143>`_)
477+
- Fix crash in formatting the real/imaginary part of a complex lvalue.
478+
Fixes (`#69218 <https://github.com/llvm/llvm-project/issues/69218>`_)
477479

478480
Bug Fixes to Compiler Builtins
479481
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/APValue.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,10 @@ void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
841841
Out << *VD;
842842
ElemTy = VD->getType();
843843
}
844+
} else if (ElemTy->isAnyComplexType()) {
845+
// The lvalue refers to a complex type
846+
Out << (Path[I].getAsArrayIndex() == 0 ? ".real" : ".imag");
847+
ElemTy = ElemTy->castAs<ComplexType>()->getElementType();
844848
} else {
845849
// The lvalue must refer to an array.
846850
Out << '[' << Path[I].getAsArrayIndex() << ']';

clang/test/Sema/complex-imag.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ void f4(void) {
2727
double *c = &__real a;
2828
double *d = &__imag a;
2929
}
30+
31+
// PR69218
32+
int f5(void) {
33+
float _Complex a;
34+
return (0 < &__real__ a) && (0 < &__imag__ a);
35+
}

0 commit comments

Comments
 (0)