[PATCH] D111509: [clang] use getCommonSugar in an assortment of places
David Rector via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 13 07:55:54 PDT 2022
davrec added a comment.
The lines you changed (clang/lib/Sema/SemaExpr.cpp:1091-1150) look good (IIUC you just change cast to cast_as and dyn_cast to getAs, and reorganize for clarity). I suggested some renaming and a few more comments to further clarify.
================
Comment at: clang/lib/Sema/SemaExpr.cpp:1113-1114
+// "double _Complex" is promoted to "long double _Complex".
+static QualType handleComplexFloatConversion(Sema &S, ExprResult &LHS,
+ QualType LHSType, QualType RHSType,
+ bool PromotePrecision) {
----------------
Rename params for clarity, e.g.
LHS->Longer
LHSType->LongerType
RHSType->ShorterType
================
Comment at: clang/lib/Sema/SemaExpr.cpp:1143
return RHSType;
int Order = S.Context.getFloatingTypeOrder(LHSType, RHSType);
----------------
```
// Compute the rank of the two types, regardless of whether they are complex.
```
================
Comment at: clang/lib/Sema/SemaExpr.cpp:1145
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) {
- // Promote the precision of the LHS if not an assignment.
- ResultType = S.Context.getComplexType(RHSElementType);
- if (!IsCompAssign) {
- if (LHSComplexType)
- LHS =
- S.ImpCastExprToType(LHS.get(), ResultType, CK_FloatingComplexCast);
- else
- LHS = S.ImpCastExprToType(LHS.get(), RHSElementType, CK_FloatingCast);
- }
- } else if (Order > 0) {
- // Promote the precision of the RHS.
- if (RHSComplexType)
- RHS = S.ImpCastExprToType(RHS.get(), ResultType, CK_FloatingComplexCast);
- else
- RHS = S.ImpCastExprToType(RHS.get(), LHSElementType, CK_FloatingCast);
- }
- return ResultType;
+ if (Order < 0)
+ return handleComplexFloatConversion(S, LHS, LHSType, RHSType,
----------------
```
// Promote the precision of the LHS if not an assignment.
```
================
Comment at: clang/lib/Sema/SemaExpr.cpp:1147
+ return handleComplexFloatConversion(S, LHS, LHSType, RHSType,
+ /*PromotePrecision=*/!IsCompAssign);
+ return handleComplexFloatConversion(S, RHS, RHSType, LHSType,
----------------
```
// Promote the precision of the RHS unless it is already the same as the LHS.
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111509/new/
https://reviews.llvm.org/D111509
More information about the cfe-commits
mailing list