[PATCH] D133522: [clang] Fix Complex x Float conversions so it handles type sugar
Matheus Izvekov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 8 13:51:27 PDT 2022
mizvekov created this revision.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The included test case was broken by D111509 <https://reviews.llvm.org/D111509> since now
those types can have sugar.
Replace dyn_casts and small refactor to preserve sugar by
not stripping it down when type is already Complex.
Signed-off-by: Matheus Izvekov <mizvekov at gmail.com>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133522
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/complex-conversion.cpp
Index: clang/test/SemaCXX/complex-conversion.cpp
===================================================================
--- clang/test/SemaCXX/complex-conversion.cpp
+++ clang/test/SemaCXX/complex-conversion.cpp
@@ -15,4 +15,8 @@
// Conversion to bool doesn't actually discard the imaginary part.
take<bool>(Complex);
+
+ using B = _Complex double;
+ B c;
+ c *= double();
}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -1108,10 +1108,10 @@
bool IsCompAssign) {
// if we have an integer operand, the result is the complex type.
if (!handleIntegerToComplexFloatConversion(S, RHS, LHS, RHSType, LHSType,
- /*skipCast*/false))
+ /*SkipCast=*/false))
return LHSType;
if (!handleIntegerToComplexFloatConversion(S, LHS, RHS, LHSType, RHSType,
- /*skipCast*/IsCompAssign))
+ /*SkipCast=*/IsCompAssign))
return RHSType;
// This handles complex/complex, complex/float, or float/complex.
@@ -1125,20 +1125,17 @@
// when combining a "long double" with a "double _Complex", the
// "double _Complex" is promoted to "long double _Complex".
+ auto *LHSComplexType = LHSType->getAs<ComplexType>();
+ auto *RHSComplexType = RHSType->getAs<ComplexType>();
+
// Compute the rank of the two types, regardless of whether they are complex.
int Order = S.Context.getFloatingTypeOrder(LHSType, RHSType);
-
- auto *LHSComplexType = dyn_cast<ComplexType>(LHSType);
- auto *RHSComplexType = dyn_cast<ComplexType>(RHSType);
- QualType LHSElementType =
- LHSComplexType ? LHSComplexType->getElementType() : LHSType;
- QualType RHSElementType =
- RHSComplexType ? RHSComplexType->getElementType() : RHSType;
-
- QualType ResultType = S.Context.getComplexType(LHSElementType);
if (Order < 0) {
+ QualType RHSElementType =
+ RHSComplexType ? RHSComplexType->getElementType() : RHSType;
+ QualType ResultType =
+ RHSComplexType ? RHSType : S.Context.getComplexType(RHSElementType);
// Promote the precision of the LHS if not an assignment.
- ResultType = S.Context.getComplexType(RHSElementType);
if (!IsCompAssign) {
if (LHSComplexType)
LHS =
@@ -1146,7 +1143,13 @@
else
LHS = S.ImpCastExprToType(LHS.get(), RHSElementType, CK_FloatingCast);
}
- } else if (Order > 0) {
+ return ResultType;
+ }
+ QualType LHSElementType =
+ LHSComplexType ? LHSComplexType->getElementType() : LHSType;
+ QualType ResultType =
+ LHSComplexType ? LHSType : S.Context.getComplexType(LHSElementType);
+ if (Order > 0) {
// Promote the precision of the RHS.
if (RHSComplexType)
RHS = S.ImpCastExprToType(RHS.get(), ResultType, CK_FloatingComplexCast);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133522.458851.patch
Type: text/x-patch
Size: 3018 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220908/6d71ca39/attachment-0001.bin>
More information about the cfe-commits
mailing list