Author: Yingwei Zheng Date: 2023-10-23T21:40:04+08:00 New Revision: 48508c13500908079ae605ad4bd6be075e46f5fb
URL: https://github.com/llvm/llvm-project/commit/48508c13500908079ae605ad4bd6be075e46f5fb DIFF: https://github.com/llvm/llvm-project/commit/48508c13500908079ae605ad4bd6be075e46f5fb.diff LOG: [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. Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/AST/APValue.cpp clang/test/Sema/complex-imag.c Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1315eaffcd4850e..c292e012c4548d9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp index ef424215182280b..d08c2936b56dd45 100644 --- a/clang/lib/AST/APValue.cpp +++ b/clang/lib/AST/APValue.cpp @@ -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() << ']'; diff --git a/clang/test/Sema/complex-imag.c b/clang/test/Sema/complex-imag.c index 69121271f4b7876..8014addf4d3a40c 100644 --- a/clang/test/Sema/complex-imag.c +++ b/clang/test/Sema/complex-imag.c @@ -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); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits