aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-12-01 04:43:34 +0000
committerJohn McCall <rjmccall@apple.com>2010-12-01 04:43:34 +0000
commit0ae287a498b8cec2086fe6b7e753cbb3df63e74a (patch)
tree22c868a442c3e824b29d555680ef1f86e13b5ee3 /lib/Sema/SemaExpr.cpp
parentbb3f9952842f4efa663303b0fd1e23a04a0ad082 (diff)
Restore the lvalue-to-rvalue conversion patch with a minimal fix.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120555 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp87
1 files changed, 50 insertions, 37 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 08941505d5..c115061164 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -246,22 +246,28 @@ void Sema::DefaultFunctionArrayConversion(Expr *&E) {
void Sema::DefaultFunctionArrayLvalueConversion(Expr *&E) {
DefaultFunctionArrayConversion(E);
-
- QualType Ty = E->getType();
- assert(!Ty.isNull() && "DefaultFunctionArrayLvalueConversion - missing type");
- if (!Ty->isDependentType() && Ty.hasQualifiers() &&
- (!getLangOptions().CPlusPlus || !Ty->isRecordType()) &&
- E->isLValue()) {
+
+ // C++ [conv.lval]p1:
+ // A glvalue of a non-function, non-array type T can be
+ // converted to a prvalue.
+ if (E->isGLValue()) {
// C++ [conv.lval]p1:
- // [...] If T is a non-class type, the type of the rvalue is the
+ // [...] If T is a non-class type, the type of the prvalue is the
// cv-unqualified version of T. Otherwise, the type of the
- // rvalue is T
+ // rvalue is T.
//
// C99 6.3.2.1p2:
// If the lvalue has qualified type, the value has the unqualified
// version of the type of the lvalue; otherwise, the value has the
// type of the lvalue.
- ImpCastExprToType(E, Ty.getUnqualifiedType(), CK_NoOp);
+ QualType T = E->getType();
+ assert(!T.isNull() && "r-value conversion on typeless expression?");
+
+ if (T.hasQualifiers() && !T->isDependentType() &&
+ (!getLangOptions().CPlusPlus || !T->isRecordType()))
+ T = T.getUnqualifiedType();
+
+ ImpCastExprToType(E, T, CK_LValueToRValue);
}
}
@@ -271,36 +277,43 @@ void Sema::DefaultFunctionArrayLvalueConversion(Expr *&E) {
/// sometimes surpressed. For example, the array->pointer conversion doesn't
/// apply if the array is an argument to the sizeof or address (&) operators.
/// In these instances, this routine should *not* be called.
-Expr *Sema::UsualUnaryConversions(Expr *&Expr) {
- QualType Ty = Expr->getType();
+Expr *Sema::UsualUnaryConversions(Expr *&E) {
+ // First, convert to an r-value.
+ DefaultFunctionArrayLvalueConversion(E);
+
+ QualType Ty = E->getType();
assert(!Ty.isNull() && "UsualUnaryConversions - missing type");
+
+ // Try to perform integral promotions if the object has a theoretically
+ // promotable type.
+ if (Ty->isIntegralOrUnscopedEnumerationType()) {
+ // C99 6.3.1.1p2:
+ //
+ // The following may be used in an expression wherever an int or
+ // unsigned int may be used:
+ // - an object or expression with an integer type whose integer
+ // conversion rank is less than or equal to the rank of int
+ // and unsigned int.
+ // - A bit-field of type _Bool, int, signed int, or unsigned int.
+ //
+ // If an int can represent all values of the original type, the
+ // value is converted to an int; otherwise, it is converted to an
+ // unsigned int. These are called the integer promotions. All
+ // other types are unchanged by the integer promotions.
+
+ QualType PTy = Context.isPromotableBitField(E);
+ if (!PTy.isNull()) {
+ ImpCastExprToType(E, PTy, CK_IntegralCast);
+ return E;
+ }
+ if (Ty->isPromotableIntegerType()) {
+ QualType PT = Context.getPromotedIntegerType(Ty);
+ ImpCastExprToType(E, PT, CK_IntegralCast);
+ return E;
+ }
+ }
- // C99 6.3.1.1p2:
- //
- // The following may be used in an expression wherever an int or
- // unsigned int may be used:
- // - an object or expression with an integer type whose integer
- // conversion rank is less than or equal to the rank of int
- // and unsigned int.
- // - A bit-field of type _Bool, int, signed int, or unsigned int.
- //
- // If an int can represent all values of the original type, the
- // value is converted to an int; otherwise, it is converted to an
- // unsigned int. These are called the integer promotions. All
- // other types are unchanged by the integer promotions.
- QualType PTy = Context.isPromotableBitField(Expr);
- if (!PTy.isNull()) {
- ImpCastExprToType(Expr, PTy, CK_IntegralCast);
- return Expr;
- }
- if (Ty->isPromotableIntegerType()) {
- QualType PT = Context.getPromotedIntegerType(Ty);
- ImpCastExprToType(Expr, PT, CK_IntegralCast);
- return Expr;
- }
-
- DefaultFunctionArrayLvalueConversion(Expr);
- return Expr;
+ return E;
}
/// DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that