Skip to content

[Clang] Handle real and imaginary parts of complex lvalue in APValue::printPretty #69252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ Bug Fixes in This Version
- Clang now accepts anonymous members initialized with designated initializers
inside templates.
Fixes (`#65143 <https://github.com/llvm/llvm-project/issues/65143>`_)
- Fix crash in formatting the real/imaginary part of a complex lvalue.
Fixes (`#69218 <https://github.com/llvm/llvm-project/issues/69218>`_)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/APValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,10 @@ void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
Out << *VD;
ElemTy = VD->getType();
}
} else if (ElemTy->isAnyComplexType()) {
// The lvalue refers to a complex type
Out << (Path[I].getAsArrayIndex() == 0 ? ".real" : ".imag");
ElemTy = ElemTy->castAs<ComplexType>()->getElementType();
} else {
// The lvalue must refer to an array.
Out << '[' << Path[I].getAsArrayIndex() << ']';
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Sema/complex-imag.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ void f4(void) {
double *c = &__real a;
double *d = &__imag a;
}

// PR69218
int f5(void) {
float _Complex a;
return (0 < &__real__ a) && (0 < &__imag__ a);
}