@@ -750,16 +750,6 @@ ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
750
750
return new CastExpr (castType, castExpr, LParenLoc);
751
751
}
752
752
753
- // promoteExprToType - a helper function to ensure we create exactly one
754
- // ImplicitCastExpr.
755
- static void promoteExprToType (Expr *&expr, QualType type) {
756
- if (ImplicitCastExpr *impCast = dyn_cast<ImplicitCastExpr>(expr))
757
- impCast->setType (type);
758
- else
759
- expr = new ImplicitCastExpr (type, expr);
760
- return ;
761
- }
762
-
763
753
// / Note that lex is not null here, even if this is the gnu "x ?: y" extension.
764
754
// / In that case, lex = cond.
765
755
inline QualType Sema::CheckConditionalOperands ( // C99 6.5.15
@@ -804,11 +794,11 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
804
794
// C99 6.5.15p6 - "if one operand is a null pointer constant, the result has
805
795
// the type of the other operand."
806
796
if (lexT->isPointerType () && rex->isNullPointerConstant (Context)) {
807
- promoteExprToType (rex, lexT); // promote the null to a pointer.
797
+ ImpCastExprToType (rex, lexT); // promote the null to a pointer.
808
798
return lexT;
809
799
}
810
800
if (rexT->isPointerType () && lex->isNullPointerConstant (Context)) {
811
- promoteExprToType (lex, rexT); // promote the null to a pointer.
801
+ ImpCastExprToType (lex, rexT); // promote the null to a pointer.
812
802
return rexT;
813
803
}
814
804
// Handle the case where both operands are pointers before we handle null
@@ -882,9 +872,9 @@ void Sema::DefaultArgumentPromotion(Expr *&Expr) {
882
872
assert (!Ty.isNull () && " DefaultArgumentPromotion - missing type" );
883
873
884
874
if (Ty->isPromotableIntegerType ()) // C99 6.3.1.1p2
885
- promoteExprToType (Expr, Context.IntTy );
875
+ ImpCastExprToType (Expr, Context.IntTy );
886
876
if (Ty == Context.FloatTy )
887
- promoteExprToType (Expr, Context.DoubleTy );
877
+ ImpCastExprToType (Expr, Context.DoubleTy );
888
878
}
889
879
890
880
// / DefaultFunctionArrayConversion (C99 6.3.2.1p3, C99 6.3.2.1p4).
@@ -893,13 +883,13 @@ void Sema::DefaultFunctionArrayConversion(Expr *&e) {
893
883
assert (!t.isNull () && " DefaultFunctionArrayConversion - missing type" );
894
884
895
885
if (const ReferenceType *ref = t->getAsReferenceType ()) {
896
- promoteExprToType (e, ref->getReferenceeType ()); // C++ [expr]
886
+ ImpCastExprToType (e, ref->getReferenceeType ()); // C++ [expr]
897
887
t = e->getType ();
898
888
}
899
889
if (t->isFunctionType ())
900
- promoteExprToType (e, Context.getPointerType (t));
890
+ ImpCastExprToType (e, Context.getPointerType (t));
901
891
else if (const ArrayType *ary = t->getAsArrayType ())
902
- promoteExprToType (e, Context.getPointerType (ary->getElementType ()));
892
+ ImpCastExprToType (e, Context.getPointerType (ary->getElementType ()));
903
893
}
904
894
905
895
// / UsualUnaryConversion - Performs various conversions that are common to most
@@ -912,11 +902,11 @@ Expr *Sema::UsualUnaryConversions(Expr *&Expr) {
912
902
assert (!Ty.isNull () && " UsualUnaryConversions - missing type" );
913
903
914
904
if (const ReferenceType *Ref = Ty->getAsReferenceType ()) {
915
- promoteExprToType (Expr, Ref->getReferenceeType ()); // C++ [expr]
905
+ ImpCastExprToType (Expr, Ref->getReferenceeType ()); // C++ [expr]
916
906
Ty = Expr->getType ();
917
907
}
918
908
if (Ty->isPromotableIntegerType ()) // C99 6.3.1.1p2
919
- promoteExprToType (Expr, Context.IntTy );
909
+ ImpCastExprToType (Expr, Context.IntTy );
920
910
else
921
911
DefaultFunctionArrayConversion (Expr);
922
912
@@ -955,12 +945,12 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
955
945
// if we have an integer operand, the result is the complex type.
956
946
if (rhs->isIntegerType () || rhs->isComplexIntegerType ()) {
957
947
// convert the rhs to the lhs complex type.
958
- if (!isCompAssign) promoteExprToType (rhsExpr, lhs);
948
+ if (!isCompAssign) ImpCastExprToType (rhsExpr, lhs);
959
949
return lhs;
960
950
}
961
951
if (lhs->isIntegerType () || lhs->isComplexIntegerType ()) {
962
952
// convert the lhs to the rhs complex type.
963
- if (!isCompAssign) promoteExprToType (lhsExpr, rhs);
953
+ if (!isCompAssign) ImpCastExprToType (lhsExpr, rhs);
964
954
return rhs;
965
955
}
966
956
// This handles complex/complex, complex/float, or float/complex.
@@ -978,23 +968,23 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
978
968
if (result > 0 ) { // The left side is bigger, convert rhs.
979
969
rhs = Context.getFloatingTypeOfSizeWithinDomain (lhs, rhs);
980
970
if (!isCompAssign)
981
- promoteExprToType (rhsExpr, rhs);
971
+ ImpCastExprToType (rhsExpr, rhs);
982
972
} else if (result < 0 ) { // The right side is bigger, convert lhs.
983
973
lhs = Context.getFloatingTypeOfSizeWithinDomain (rhs, lhs);
984
974
if (!isCompAssign)
985
- promoteExprToType (lhsExpr, lhs);
975
+ ImpCastExprToType (lhsExpr, lhs);
986
976
}
987
977
// At this point, lhs and rhs have the same rank/size. Now, make sure the
988
978
// domains match. This is a requirement for our implementation, C99
989
979
// does not require this promotion.
990
980
if (lhs != rhs) { // Domains don't match, we have complex/float mix.
991
981
if (lhs->isRealFloatingType ()) { // handle "double, _Complex double".
992
982
if (!isCompAssign)
993
- promoteExprToType (lhsExpr, rhs);
983
+ ImpCastExprToType (lhsExpr, rhs);
994
984
return rhs;
995
985
} else { // handle "_Complex double, double".
996
986
if (!isCompAssign)
997
- promoteExprToType (rhsExpr, lhs);
987
+ ImpCastExprToType (rhsExpr, lhs);
998
988
return lhs;
999
989
}
1000
990
}
@@ -1005,24 +995,24 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
1005
995
// if we have an integer operand, the result is the real floating type.
1006
996
if (rhs->isIntegerType () || rhs->isComplexIntegerType ()) {
1007
997
// convert rhs to the lhs floating point type.
1008
- if (!isCompAssign) promoteExprToType (rhsExpr, lhs);
998
+ if (!isCompAssign) ImpCastExprToType (rhsExpr, lhs);
1009
999
return lhs;
1010
1000
}
1011
1001
if (lhs->isIntegerType () || lhs->isComplexIntegerType ()) {
1012
1002
// convert lhs to the rhs floating point type.
1013
- if (!isCompAssign) promoteExprToType (lhsExpr, rhs);
1003
+ if (!isCompAssign) ImpCastExprToType (lhsExpr, rhs);
1014
1004
return rhs;
1015
1005
}
1016
1006
// We have two real floating types, float/complex combos were handled above.
1017
1007
// Convert the smaller operand to the bigger result.
1018
1008
int result = Context.compareFloatingType (lhs, rhs);
1019
1009
1020
1010
if (result > 0 ) { // convert the rhs
1021
- if (!isCompAssign) promoteExprToType (rhsExpr, lhs);
1011
+ if (!isCompAssign) ImpCastExprToType (rhsExpr, lhs);
1022
1012
return lhs;
1023
1013
}
1024
1014
if (result < 0 ) { // convert the lhs
1025
- if (!isCompAssign) promoteExprToType (lhsExpr, rhs); // convert the lhs
1015
+ if (!isCompAssign) ImpCastExprToType (lhsExpr, rhs); // convert the lhs
1026
1016
return rhs;
1027
1017
}
1028
1018
assert (0 && " Sema::UsualArithmeticConversions(): illegal float comparison" );
@@ -1034,28 +1024,30 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
1034
1024
1035
1025
if (lhsComplexInt && rhsComplexInt) {
1036
1026
if (Context.maxIntegerType (lhsComplexInt->getElementType (),
1037
- rhsComplexInt->getElementType ()) == lhs) {
1038
- if (!isCompAssign) promoteExprToType (rhsExpr, lhs); // convert the rhs
1039
- return lhs;
1027
+ rhsComplexInt->getElementType ()) == lhs) {
1028
+ // convert the rhs
1029
+ if (!isCompAssign) ImpCastExprToType (rhsExpr, lhs);
1030
+ return lhs;
1040
1031
}
1041
- if (!isCompAssign) promoteExprToType (lhsExpr, rhs); // convert the lhs
1032
+ if (!isCompAssign)
1033
+ ImpCastExprToType (lhsExpr, rhs); // convert the lhs
1042
1034
return rhs;
1043
1035
} else if (lhsComplexInt && rhs->isIntegerType ()) {
1044
1036
// convert the rhs to the lhs complex type.
1045
- if (!isCompAssign) promoteExprToType (rhsExpr, lhs);
1037
+ if (!isCompAssign) ImpCastExprToType (rhsExpr, lhs);
1046
1038
return lhs;
1047
1039
} else if (rhsComplexInt && lhs->isIntegerType ()) {
1048
1040
// convert the lhs to the rhs complex type.
1049
- if (!isCompAssign) promoteExprToType (lhsExpr, rhs);
1041
+ if (!isCompAssign) ImpCastExprToType (lhsExpr, rhs);
1050
1042
return rhs;
1051
1043
}
1052
1044
}
1053
1045
// Finally, we have two differing integer types.
1054
1046
if (Context.maxIntegerType (lhs, rhs) == lhs) { // convert the rhs
1055
- if (!isCompAssign) promoteExprToType (rhsExpr, lhs);
1047
+ if (!isCompAssign) ImpCastExprToType (rhsExpr, lhs);
1056
1048
return lhs;
1057
1049
}
1058
- if (!isCompAssign) promoteExprToType (lhsExpr, rhs); // convert the lhs
1050
+ if (!isCompAssign) ImpCastExprToType (lhsExpr, rhs); // convert the lhs
1059
1051
return rhs;
1060
1052
}
1061
1053
@@ -1212,7 +1204,7 @@ Sema::CheckSingleAssignmentConstraints(QualType lhsType, Expr *&rExpr) {
1212
1204
// a null pointer constant.
1213
1205
if ((lhsType->isPointerType () || lhsType->isObjCQualifiedIdType ())
1214
1206
&& rExpr->isNullPointerConstant (Context)) {
1215
- promoteExprToType (rExpr, lhsType);
1207
+ ImpCastExprToType (rExpr, lhsType);
1216
1208
return Compatible;
1217
1209
}
1218
1210
// This check seems unnatural, however it is necessary to ensure the proper
@@ -1231,7 +1223,7 @@ Sema::CheckSingleAssignmentConstraints(QualType lhsType, Expr *&rExpr) {
1231
1223
// C99 6.5.16.1p2: The value of the right operand is converted to the
1232
1224
// type of the assignment expression.
1233
1225
if (rExpr->getType () != lhsType)
1234
- promoteExprToType (rExpr, lhsType);
1226
+ ImpCastExprToType (rExpr, lhsType);
1235
1227
return result;
1236
1228
}
1237
1229
@@ -1260,7 +1252,7 @@ inline QualType Sema::CheckVectorOperands(SourceLocation loc, Expr *&lex,
1260
1252
if (const OCUVectorType *V = lhsType->getAsOCUVectorType ()) {
1261
1253
if (V->getElementType ().getCanonicalType ().getTypePtr ()
1262
1254
== rhsType.getCanonicalType ().getTypePtr ()) {
1263
- promoteExprToType (rex, lhsType);
1255
+ ImpCastExprToType (rex, lhsType);
1264
1256
return lhsType;
1265
1257
}
1266
1258
}
@@ -1270,7 +1262,7 @@ inline QualType Sema::CheckVectorOperands(SourceLocation loc, Expr *&lex,
1270
1262
if (const OCUVectorType *V = rhsType->getAsOCUVectorType ()) {
1271
1263
if (V->getElementType ().getCanonicalType ().getTypePtr ()
1272
1264
== lhsType.getCanonicalType ().getTypePtr ()) {
1273
- promoteExprToType (lex, rhsType);
1265
+ ImpCastExprToType (lex, rhsType);
1274
1266
return rhsType;
1275
1267
}
1276
1268
}
@@ -1463,28 +1455,28 @@ inline QualType Sema::CheckCompareOperands( // C99 6.5.8
1463
1455
lType.getAsString (), rType.getAsString (),
1464
1456
lex->getSourceRange (), rex->getSourceRange ());
1465
1457
}
1466
- promoteExprToType (rex, lType); // promote the pointer to pointer
1458
+ ImpCastExprToType (rex, lType); // promote the pointer to pointer
1467
1459
return Context.IntTy ;
1468
1460
}
1469
1461
if ((lType->isObjCQualifiedIdType () || rType->isObjCQualifiedIdType ())
1470
1462
&& Context.ObjCQualifiedIdTypesAreCompatible (lType, rType, true )) {
1471
- promoteExprToType (rex, lType);
1463
+ ImpCastExprToType (rex, lType);
1472
1464
return Context.IntTy ;
1473
1465
}
1474
1466
if (lType->isPointerType () && rType->isIntegerType ()) {
1475
1467
if (!RHSIsNull)
1476
1468
Diag (loc, diag::ext_typecheck_comparison_of_pointer_integer,
1477
1469
lType.getAsString (), rType.getAsString (),
1478
1470
lex->getSourceRange (), rex->getSourceRange ());
1479
- promoteExprToType (rex, lType); // promote the integer to pointer
1471
+ ImpCastExprToType (rex, lType); // promote the integer to pointer
1480
1472
return Context.IntTy ;
1481
1473
}
1482
1474
if (lType->isIntegerType () && rType->isPointerType ()) {
1483
1475
if (!LHSIsNull)
1484
1476
Diag (loc, diag::ext_typecheck_comparison_of_pointer_integer,
1485
1477
lType.getAsString (), rType.getAsString (),
1486
1478
lex->getSourceRange (), rex->getSourceRange ());
1487
- promoteExprToType (lex, rType); // promote the integer to pointer
1479
+ ImpCastExprToType (lex, rType); // promote the integer to pointer
1488
1480
return Context.IntTy ;
1489
1481
}
1490
1482
return InvalidOperands (loc, lex, rex);
0 commit comments