[clang] [Clang] Handle real and imaginary parts of complex lvalue in `APValue::printPretty` (PR #69252)
Yingwei Zheng via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 23 05:31:18 PDT 2023
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/69252
>From 6e34e74e8e8046aaa086869e8a8aecb781dd3b3b Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 17 Oct 2023 05:17:17 +0800
Subject: [PATCH 1/3] [Clang] Add pre-commit tests for PR69218. NFC.
---
clang/test/CodeGen/complex.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/clang/test/CodeGen/complex.c b/clang/test/CodeGen/complex.c
index 6233529a18f8b8d..b50d607d00c0167 100644
--- a/clang/test/CodeGen/complex.c
+++ b/clang/test/CodeGen/complex.c
@@ -113,3 +113,8 @@ void t92(void) {
(0 ? (_Complex double) 2.0f : 2.0f);
}
+// PR69218
+int t10(void) {
+ float _Complex a;
+ return (0 < &__real__ a) && (0 < &__imag__ a);
+}
>From 07a9bd8da0602bedc7603752a3af26f89d3e9a2b Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 17 Oct 2023 05:19:11 +0800
Subject: [PATCH 2/3] [Clang] Handle real and imaginary part of complex lvalue
in `APValue::printPretty`
---
clang/lib/AST/APValue.cpp | 4 ++++
1 file changed, 4 insertions(+)
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() << ']';
>From b6ad30530cba4aaa94002691b97208abdb24533e Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Mon, 23 Oct 2023 20:20:40 +0800
Subject: [PATCH 3/3] fixup! [Clang] Handle real and imaginary part of complex
lvalue in `APValue::printPretty`
Add release notes.
Move the test from CodeGen to Sema.
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/test/CodeGen/complex.c | 5 -----
clang/test/Sema/complex-imag.c | 6 ++++++
3 files changed, 8 insertions(+), 5 deletions(-)
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/test/CodeGen/complex.c b/clang/test/CodeGen/complex.c
index b50d607d00c0167..6233529a18f8b8d 100644
--- a/clang/test/CodeGen/complex.c
+++ b/clang/test/CodeGen/complex.c
@@ -113,8 +113,3 @@ void t92(void) {
(0 ? (_Complex double) 2.0f : 2.0f);
}
-// PR69218
-int t10(void) {
- float _Complex a;
- return (0 < &__real__ a) && (0 < &__imag__ a);
-}
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);
+}
More information about the cfe-commits
mailing list