[cfe-commits] r120890 - in /cfe/trunk: include/clang/AST/ include/clang/Sema/ lib/AST/ lib/Analysis/ lib/Checker/ lib/CodeGen/ lib/Parse/ lib/Sema/ test/CodeGen/ test/CodeGenObjCXX/ test/Rewriter/ test/Sema/ test/SemaCXX/ test/SemaTemplate/
John McCall
rjmccall at apple.com
Fri Dec 3 19:47:34 PST 2010
Author: rjmccall
Date: Fri Dec 3 21:47:34 2010
New Revision: 120890
URL: http://llvm.org/viewvc/llvm-project?rev=120890&view=rev
Log:
Although we currently have explicit lvalue-to-rvalue conversions, they're
not actually frequently used, because ImpCastExprToType only creates a node
if the types differ. So explicitly create an ICE in the lvalue-to-rvalue
conversion code in DefaultFunctionArrayLvalueConversion() as well as several
other new places, and consistently deal with the consequences throughout the
compiler.
In addition, introduce a new cast kind for loading an ObjCProperty l-value,
and make sure we emit those nodes whenever an ObjCProperty l-value appears
that's not on the LHS of an assignment operator.
This breaks a couple of rewriter tests, which I've x-failed until future
development occurs on the rewriter.
Ted Kremenek kindly contributed the analyzer workarounds in this patch.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/OperationKinds.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprClassification.cpp
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/Checker/CheckSecuritySyntaxOnly.cpp
cfe/trunk/lib/Checker/DereferenceChecker.cpp
cfe/trunk/lib/Checker/Environment.cpp
cfe/trunk/lib/Checker/GRExprEngine.cpp
cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/SemaCXXCast.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/CodeGen/volatile-1.c
cfe/trunk/test/CodeGenObjCXX/property-dot-reference.mm
cfe/trunk/test/Rewriter/properties.m
cfe/trunk/test/Rewriter/rewrite-nested-property-in-blocks.mm
cfe/trunk/test/Sema/rdr6094103-unordered-compare-promote.c
cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp
cfe/trunk/test/SemaTemplate/enum-argument.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Dec 3 21:47:34 2010
@@ -39,6 +39,7 @@
class CXXBaseSpecifier;
class CXXOperatorCallExpr;
class CXXMemberCallExpr;
+ class ObjCPropertyRefExpr;
class TemplateArgumentLoc;
class TemplateArgumentListInfo;
@@ -312,6 +313,10 @@
return const_cast<Expr*>(this)->getBitField();
}
+ /// \brief If this expression is an l-value for an Objective C
+ /// property, find the underlying property reference expression.
+ const ObjCPropertyRefExpr *getObjCProperty() const;
+
/// \brief Returns whether this expression refers to a vector element.
bool refersToVectorElement() const;
@@ -456,6 +461,14 @@
const Expr *IgnoreParenImpCasts() const {
return const_cast<Expr*>(this)->IgnoreParenImpCasts();
}
+
+ /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and
+ /// CastExprs that represent lvalue casts, returning their operand.
+ Expr *IgnoreParenLValueCasts();
+
+ const Expr *IgnoreParenLValueCasts() const {
+ return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
+ }
/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
/// value (including ptr->int casts of the same size). Strip off any
@@ -2056,6 +2069,7 @@
case CK_Dependent:
case CK_LValueToRValue:
+ case CK_GetObjCProperty:
case CK_NoOp:
case CK_PointerToBoolean:
case CK_IntegralToBoolean:
Modified: cfe/trunk/include/clang/AST/OperationKinds.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OperationKinds.h?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/OperationKinds.h (original)
+++ cfe/trunk/include/clang/AST/OperationKinds.h Fri Dec 3 21:47:34 2010
@@ -48,6 +48,13 @@
/// an r-value from the operand gl-value. The result of an r-value
/// conversion is always unqualified.
CK_LValueToRValue,
+
+ /// CK_GetObjCProperty - A conversion which calls an Objective-C
+ /// property getter. The operand is an OK_ObjCProperty l-value; the
+ /// result will generally be an r-value, but could be an ordinary
+ /// gl-value if the property reference is to an implicit property
+ /// for a method that returns a reference type.
+ CK_GetObjCProperty,
/// CK_NoOp - A conversion which does not affect the type other than
/// (possibly) adding qualifiers.
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Dec 3 21:47:34 2010
@@ -1579,6 +1579,7 @@
SourceLocation StartLoc,
SourceLocation EndLoc);
void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
+ StmtResult ActOnForEachLValueExpr(Expr *E);
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal,
SourceLocation DotDotDotLoc, Expr *RHSVal,
SourceLocation ColonLoc);
@@ -3984,6 +3985,11 @@
ExprValueKind VK = VK_RValue,
const CXXCastPath *BasePath = 0);
+ /// IgnoredValueConversions - Given that an expression's result is
+ /// syntactically ignored, perform any conversions that are
+ /// required.
+ void IgnoredValueConversions(Expr *&expr);
+
// UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
// functions and arrays to their respective pointers (C99 6.3.2.1).
Expr *UsualUnaryConversions(Expr *&expr);
@@ -4190,7 +4196,8 @@
QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
- void ConvertPropertyAssignment(Expr *LHS, Expr *&RHS, QualType& LHSTy);
+ void ConvertPropertyForRValue(Expr *&E);
+ void ConvertPropertyForLValue(Expr *&LHS, Expr *&RHS, QualType& LHSTy);
QualType CheckConditionalOperands( // C99 6.5.15
Expr *&cond, Expr *&lhs, Expr *&rhs, Expr *&save,
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Dec 3 21:47:34 2010
@@ -824,6 +824,8 @@
return "LValueBitCast";
case CK_LValueToRValue:
return "LValueToRValue";
+ case CK_GetObjCProperty:
+ return "GetObjCProperty";
case CK_NoOp:
return "NoOp";
case CK_BaseToDerived:
@@ -1722,6 +1724,24 @@
}
}
+Expr *Expr::IgnoreParenLValueCasts() {
+ Expr *E = this;
+ while (E) {
+ if (ParenExpr *P = dyn_cast<ParenExpr>(E)) {
+ E = P->getSubExpr();
+ continue;
+ }
+ if (CastExpr *P = dyn_cast<CastExpr>(E)) {
+ if (P->getCastKind() == CK_LValueToRValue) {
+ E = P->getSubExpr();
+ continue;
+ }
+ }
+ break;
+ }
+ return E;
+}
+
Expr *Expr::IgnoreParenImpCasts() {
Expr *E = this;
while (true) {
@@ -2043,12 +2063,34 @@
return isIntegerConstantExpr(Result, Ctx) && Result == 0;
}
+/// \brief If this expression is an l-value for an Objective C
+/// property, find the underlying property reference expression.
+const ObjCPropertyRefExpr *Expr::getObjCProperty() const {
+ const Expr *E = this;
+ while (true) {
+ assert((E->getValueKind() == VK_LValue &&
+ E->getObjectKind() == OK_ObjCProperty) &&
+ "expression is not a property reference");
+ E = E->IgnoreParenCasts();
+ if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
+ if (BO->getOpcode() == BO_Comma) {
+ E = BO->getRHS();
+ continue;
+ }
+ }
+
+ break;
+ }
+
+ return cast<ObjCPropertyRefExpr>(E);
+}
+
FieldDecl *Expr::getBitField() {
Expr *E = this->IgnoreParens();
while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
- if (ICE->getValueKind() != VK_RValue &&
- ICE->getCastKind() == CK_NoOp)
+ if (ICE->getCastKind() == CK_LValueToRValue ||
+ (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp))
E = ICE->getSubExpr()->IgnoreParens();
else
break;
Modified: cfe/trunk/lib/AST/ExprClassification.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprClassification.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprClassification.cpp (original)
+++ cfe/trunk/lib/AST/ExprClassification.cpp Fri Dec 3 21:47:34 2010
@@ -413,8 +413,10 @@
assert(Ctx.getLangOptions().CPlusPlus &&
"This is only relevant for C++.");
// C++ [expr.ass]p1: All [...] return an lvalue referring to the left operand.
+ // Except we override this for writes to ObjC properties.
if (E->isAssignmentOp())
- return Cl::CL_LValue;
+ return (E->getLHS()->getObjectKind() == OK_ObjCProperty
+ ? Cl::CL_PRValue : Cl::CL_LValue);
// C++ [expr.comma]p1: the result is of the same value category as its right
// operand, [...].
@@ -468,9 +470,10 @@
if (Kind == Cl::CL_PRValue) {
// For the sake of better diagnostics, we want to specifically recognize
// use of the GCC cast-as-lvalue extension.
- if (const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(E->IgnoreParens())){
- if (CE->getSubExpr()->Classify(Ctx).isLValue()) {
- Loc = CE->getLParenLoc();
+ if (const ExplicitCastExpr *CE =
+ dyn_cast<ExplicitCastExpr>(E->IgnoreParens())) {
+ if (CE->getSubExpr()->IgnoreParenImpCasts()->isLValue()) {
+ Loc = CE->getExprLoc();
return Cl::CM_LValueCast;
}
}
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Fri Dec 3 21:47:34 2010
@@ -825,6 +825,16 @@
case Stmt::ContinueStmtClass:
return VisitContinueStmt(cast<ContinueStmt>(S));
+
+ case Stmt::CStyleCastExprClass: {
+ CastExpr *castExpr = cast<CastExpr>(S);
+ if (castExpr->getCastKind() == CK_LValueToRValue) {
+ // temporary workaround
+ S = castExpr->getSubExpr();
+ goto tryAgain;
+ }
+ return VisitStmt(S, asc);
+ }
case Stmt::CXXCatchStmtClass:
return VisitCXXCatchStmt(cast<CXXCatchStmt>(S));
@@ -871,8 +881,15 @@
case Stmt::IfStmtClass:
return VisitIfStmt(cast<IfStmt>(S));
- case Stmt::ImplicitCastExprClass:
- return VisitImplicitCastExpr(cast<ImplicitCastExpr>(S), asc);
+ case Stmt::ImplicitCastExprClass: {
+ ImplicitCastExpr *castExpr = cast<ImplicitCastExpr>(S);
+ if (castExpr->getCastKind() == CK_LValueToRValue) {
+ // temporary workaround
+ S = castExpr->getSubExpr();
+ goto tryAgain;
+ }
+ return VisitImplicitCastExpr(castExpr, asc);
+ }
case Stmt::IndirectGotoStmtClass:
return VisitIndirectGotoStmt(cast<IndirectGotoStmt>(S));
Modified: cfe/trunk/lib/Checker/CheckSecuritySyntaxOnly.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/CheckSecuritySyntaxOnly.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/CheckSecuritySyntaxOnly.cpp (original)
+++ cfe/trunk/lib/Checker/CheckSecuritySyntaxOnly.cpp Fri Dec 3 21:47:34 2010
@@ -187,8 +187,10 @@
return;
// Are we comparing variables?
- const DeclRefExpr *drLHS = dyn_cast<DeclRefExpr>(B->getLHS()->IgnoreParens());
- const DeclRefExpr *drRHS = dyn_cast<DeclRefExpr>(B->getRHS()->IgnoreParens());
+ const DeclRefExpr *drLHS =
+ dyn_cast<DeclRefExpr>(B->getLHS()->IgnoreParenLValueCasts());
+ const DeclRefExpr *drRHS =
+ dyn_cast<DeclRefExpr>(B->getRHS()->IgnoreParenLValueCasts());
// Does at least one of the variables have a floating point type?
drLHS = drLHS && drLHS->getType()->isRealFloatingType() ? drLHS : NULL;
Modified: cfe/trunk/lib/Checker/DereferenceChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/DereferenceChecker.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/DereferenceChecker.cpp (original)
+++ cfe/trunk/lib/Checker/DereferenceChecker.cpp Fri Dec 3 21:47:34 2010
@@ -59,6 +59,7 @@
llvm::SmallVectorImpl<SourceRange> &Ranges,
const Expr *Ex,
bool loadedFrom) {
+ Ex = Ex->IgnoreParenLValueCasts();
switch (Ex->getStmtClass()) {
default:
return;
Modified: cfe/trunk/lib/Checker/Environment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/Environment.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/Environment.cpp (original)
+++ cfe/trunk/lib/Checker/Environment.cpp Fri Dec 3 21:47:34 2010
@@ -53,7 +53,8 @@
QualType CT = C->getType();
if (CT->isVoidType())
return UnknownVal();
- if (C->getCastKind() == CK_NoOp) {
+ if (C->getCastKind() == CK_NoOp ||
+ C->getCastKind() == CK_LValueToRValue) { // temporary workaround
E = C->getSubExpr();
continue;
}
Modified: cfe/trunk/lib/Checker/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/GRExprEngine.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Checker/GRExprEngine.cpp Fri Dec 3 21:47:34 2010
@@ -778,6 +778,10 @@
S->getLocStart(),
"Error evaluating statement");
+ // Expressions to ignore.
+ if (const Expr *Ex = dyn_cast<Expr>(S))
+ S = Ex->IgnoreParenLValueCasts();
+
// FIXME: add metadata to the CFG so that we can disable
// this check when we KNOW that there is no block-level subexpression.
// The motivation is that this check requires a hashtable lookup.
@@ -814,7 +818,9 @@
MakeNode(Dst, S, Pred, GetState(Pred));
break;
}
-
+
+ case Stmt::ParenExprClass:
+ llvm_unreachable("ParenExprs already handled.");
// Cases that should never be evaluated simply because they shouldn't
// appear in the CFG.
case Stmt::BreakStmtClass:
@@ -1039,10 +1045,6 @@
break;
}
- case Stmt::ParenExprClass:
- Visit(cast<ParenExpr>(S)->getSubExpr()->IgnoreParens(), Pred, Dst);
- break;
-
case Stmt::ReturnStmtClass:
VisitReturnStmt(cast<ReturnStmt>(S), Pred, Dst);
break;
@@ -1113,8 +1115,8 @@
Ex->getLocStart(),
"Error evaluating statement");
-
- Ex = Ex->IgnoreParens();
+ // Expressions to ignore.
+ Ex = Ex->IgnoreParenLValueCasts();
if (Ex != CurrentStmt && Pred->getLocationContext()->getCFG()->isBlkExpr(Ex)){
Dst.Add(Pred);
@@ -2661,6 +2663,7 @@
}
return;
+ case CK_GetObjCProperty:
case CK_Dependent:
case CK_ArrayToPointerDecay:
case CK_BitCast:
Modified: cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp (original)
+++ cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp Fri Dec 3 21:47:34 2010
@@ -543,7 +543,7 @@
if (VD != RHS_DR->getDecl())
return false;
- return dyn_cast<DeclRefExpr>(RHS->IgnoreParens()) == NULL;
+ return dyn_cast<DeclRefExpr>(RHS->IgnoreParenLValueCasts()) == NULL;
}
// Returns false if a path to this block was not completely analyzed, or true
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Dec 3 21:47:34 2010
@@ -1755,6 +1755,21 @@
case CK_Dependent:
llvm_unreachable("dependent cast kind in IR gen!");
+ case CK_GetObjCProperty: {
+ LValue LV = EmitLValue(E->getSubExpr());
+ assert(LV.isPropertyRef());
+ RValue RV = EmitLoadOfPropertyRefLValue(LV);
+
+ // Property is an aggregate r-value.
+ if (RV.isAggregate()) {
+ return MakeAddrLValue(RV.getAggregateAddr(), E->getType());
+ }
+
+ // Implicit property returns an l-value.
+ assert(RV.isScalar());
+ return MakeAddrLValue(RV.getScalarVal(), E->getSubExpr()->getType());
+ }
+
case CK_NoOp:
if (!E->getSubExpr()->isRValue() || E->getType()->isRecordType()) {
LValue LV = EmitLValue(E->getSubExpr());
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Fri Dec 3 21:47:34 2010
@@ -282,8 +282,16 @@
break;
}
+ case CK_GetObjCProperty: {
+ LValue LV = CGF.EmitLValue(E->getSubExpr());
+ assert(LV.isPropertyRef());
+ RValue RV = CGF.EmitLoadOfPropertyRefLValue(LV, getReturnValueSlot());
+ EmitGCMove(E, RV);
+ break;
+ }
+
+ case CK_LValueToRValue: // hope for downstream optimization
case CK_NoOp:
- case CK_LValueToRValue:
case CK_UserDefinedConversion:
case CK_ConstructorConversion:
assert(CGF.getContext().hasSameUnqualifiedType(E->getSubExpr()->getType(),
@@ -349,9 +357,8 @@
}
void AggExprEmitter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
- RValue RV = CGF.EmitLoadOfPropertyRefLValue(CGF.EmitObjCPropertyRefLValue(E),
- getReturnValueSlot());
- EmitGCMove(E, RV);
+ llvm_unreachable("direct property access not surrounded by "
+ "lvalue-to-rvalue cast");
}
void AggExprEmitter::VisitBinComma(const BinaryOperator *E) {
Modified: cfe/trunk/lib/CodeGen/CGExprComplex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprComplex.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprComplex.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprComplex.cpp Fri Dec 3 21:47:34 2010
@@ -108,6 +108,7 @@
return EmitLoadOfLValue(E);
}
ComplexPairTy VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
+ assert(E->getObjectKind() == OK_Ordinary);
return EmitLoadOfLValue(E);
}
ComplexPairTy VisitObjCMessageExpr(ObjCMessageExpr *E) {
@@ -333,7 +334,21 @@
ComplexPairTy ComplexExprEmitter::EmitCast(CastExpr::CastKind CK, Expr *Op,
QualType DestTy) {
- // FIXME: this should be based off of the CastKind.
+ switch (CK) {
+ case CK_GetObjCProperty: {
+ LValue LV = CGF.EmitLValue(Op);
+ assert(LV.isPropertyRef() && "Unknown LValue type!");
+ return CGF.EmitLoadOfPropertyRefLValue(LV).getComplexVal();
+ }
+
+ case CK_NoOp:
+ case CK_LValueToRValue:
+ return Visit(Op);
+
+ // TODO: do all of these
+ default:
+ break;
+ }
// Two cases here: cast from (complex to complex) and (scalar to complex).
if (Op->getType()->isAnyComplexType())
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Dec 3 21:47:34 2010
@@ -237,6 +237,8 @@
return EmitLoadOfLValue(E);
}
Value *VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
+ assert(E->getObjectKind() == OK_Ordinary &&
+ "reached property reference without lvalue-to-rvalue");
return EmitLoadOfLValue(E);
}
Value *VisitObjCMessageExpr(ObjCMessageExpr *E) {
@@ -1097,9 +1099,18 @@
case CK_ToUnion:
llvm_unreachable("scalar cast to non-scalar value");
break;
+
+ case CK_GetObjCProperty: {
+ assert(CGF.getContext().hasSameUnqualifiedType(E->getType(), DestTy));
+ assert(E->isLValue() && E->getObjectKind() == OK_ObjCProperty &&
+ "CK_GetObjCProperty for non-lvalue or non-ObjCProperty");
+ RValue RV = CGF.EmitLoadOfLValue(CGF.EmitLValue(E), E->getType());
+ return RV.getScalarVal();
+ }
case CK_LValueToRValue:
assert(CGF.getContext().hasSameUnqualifiedType(E->getType(), DestTy));
+ assert(E->isGLValue() && "lvalue-to-rvalue applied to r-value!");
return Visit(const_cast<Expr*>(E));
case CK_IntegralToPointer: {
@@ -1124,11 +1135,8 @@
return Builder.CreatePtrToInt(Src, ConvertType(DestTy));
}
case CK_ToVoid: {
- if (E->Classify(CGF.getContext()).isGLValue()) {
- LValue LV = CGF.EmitLValue(E);
- if (LV.isPropertyRef())
- CGF.EmitLoadOfPropertyRefLValue(LV);
- }
+ if (!E->isRValue())
+ CGF.EmitLValue(E);
else
CGF.EmitAnyExpr(E, AggValueSlot::ignored(), true);
return 0;
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Fri Dec 3 21:47:34 2010
@@ -1032,13 +1032,19 @@
} else {
Value = ParseExpression();
+ ForEach = isTokIdentifier_in();
+
// Turn the expression into a stmt.
- if (!Value.isInvalid())
- FirstPart = Actions.ActOnExprStmt(Actions.MakeFullExpr(Value.get()));
+ if (!Value.isInvalid()) {
+ if (ForEach)
+ FirstPart = Actions.ActOnForEachLValueExpr(Value.get());
+ else
+ FirstPart = Actions.ActOnExprStmt(Actions.MakeFullExpr(Value.get()));
+ }
if (Tok.is(tok::semi)) {
ConsumeToken();
- } else if ((ForEach = isTokIdentifier_in())) {
+ } else if (ForEach) {
ConsumeToken(); // consume 'in'
if (Tok.is(tok::code_completion)) {
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Fri Dec 3 21:47:34 2010
@@ -516,6 +516,7 @@
// a non-lvalue-reference target type does not lead to decay.
// C++ 5.2.9p4: Any expression can be explicitly converted to type "cv void".
if (DestType->isVoidType()) {
+ Self.IgnoredValueConversions(SrcExpr);
Kind = CK_ToVoid;
return;
}
@@ -1371,6 +1372,7 @@
// a non-lvalue-reference target type does not lead to decay.
// C++ 5.2.9p4: Any expression can be explicitly converted to type "cv void".
if (CastTy->isVoidType()) {
+ IgnoredValueConversions(CastExpr);
Kind = CK_ToVoid;
return false;
}
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Dec 3 21:47:34 2010
@@ -2104,8 +2104,8 @@
void Sema::CheckFloatComparison(SourceLocation loc, Expr* lex, Expr *rex) {
bool EmitWarning = true;
- Expr* LeftExprSansParen = lex->IgnoreParens();
- Expr* RightExprSansParen = rex->IgnoreParens();
+ Expr* LeftExprSansParen = lex->IgnoreParenImpCasts();
+ Expr* RightExprSansParen = rex->IgnoreParenImpCasts();
// Special case: check for x == x (which is OK).
// Do not emit warnings for such cases.
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Dec 3 21:47:34 2010
@@ -251,6 +251,24 @@
// A glvalue of a non-function, non-array type T can be
// converted to a prvalue.
if (E->isGLValue()) {
+ QualType T = E->getType();
+ assert(!T.isNull() && "r-value conversion on typeless expression?");
+
+ // Create a load out of an ObjCProperty l-value, if necessary.
+ if (E->getObjectKind() == OK_ObjCProperty) {
+ ConvertPropertyForRValue(E);
+ if (!E->isGLValue())
+ return;
+ }
+
+ // We don't want to throw lvalue-to-rvalue casts on top of
+ // expressions of certain types in C++.
+ if (getLangOptions().CPlusPlus &&
+ (E->getType() == Context.OverloadTy ||
+ T->isDependentType() ||
+ T->isRecordType()))
+ return;
+
// C++ [conv.lval]p1:
// [...] If T is a non-class type, the type of the prvalue is the
// cv-unqualified version of T. Otherwise, the type of the
@@ -259,15 +277,12 @@
// 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.
- QualType T = E->getType();
- assert(!T.isNull() && "r-value conversion on typeless expression?");
-
- if (T.hasQualifiers() && !T->isDependentType() &&
- (!getLangOptions().CPlusPlus || !T->isRecordType()))
+ // type of the lvalue.
+ if (T.hasQualifiers())
T = T.getUnqualifiedType();
-
- ImpCastExprToType(E, T, CK_LValueToRValue);
+
+ E = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue,
+ E, 0, VK_RValue);
}
}
@@ -2649,6 +2664,10 @@
if (V->isTypeDependent())
return S.Context.DependentTy;
+ // _Real and _Imag are only l-values for normal l-values.
+ if (V->getObjectKind() != OK_Ordinary)
+ S.DefaultFunctionArrayLvalueConversion(V);
+
// These operators return the element type of a complex type.
if (const ComplexType *CT = V->getType()->getAs<ComplexType>())
return CT->getElementType();
@@ -3351,6 +3370,11 @@
return ExprError();
}
+ // Perform a property load on the base regardless of whether we
+ // actually need it for the declaration.
+ if (BaseExpr->getObjectKind() == OK_ObjCProperty)
+ ConvertPropertyForRValue(BaseExpr);
+
if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl))
return BuildFieldReferenceExpr(*this, BaseExpr, IsArrow,
SS, FD, FoundDecl, MemberNameInfo);
@@ -3359,7 +3383,7 @@
// We may have found a field within an anonymous union or struct
// (C++ [class.union]).
return BuildAnonymousStructUnionMemberReference(MemberLoc, FD,
- BaseExpr, OpLoc);
+ BaseExpr, OpLoc);
if (VarDecl *Var = dyn_cast<VarDecl>(MemberDecl)) {
MarkDeclarationReferenced(MemberLoc, Var);
@@ -3694,6 +3718,10 @@
// Handle properties on 'id' and qualified "id".
if (!IsArrow && (BaseType->isObjCIdType() ||
BaseType->isObjCQualifiedIdType())) {
+ // This actually uses the base as an r-value.
+ DefaultFunctionArrayLvalueConversion(BaseExpr);
+ assert(Context.hasSameUnqualifiedType(BaseType, BaseExpr->getType()));
+
const ObjCObjectPointerType *QIdTy = BaseType->getAs<ObjCObjectPointerType>();
IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
@@ -3743,9 +3771,12 @@
// pointer to a (potentially qualified) interface type.
if (!IsArrow)
if (const ObjCObjectPointerType *OPT =
- BaseType->getAsObjCInterfacePointerType())
+ BaseType->getAsObjCInterfacePointerType()) {
+ // This actually uses the base as an r-value.
+ DefaultFunctionArrayLvalueConversion(BaseExpr);
return HandleExprPropertyRefExpr(OPT, BaseExpr, MemberName, MemberLoc,
SourceLocation(), QualType(), false);
+ }
// Handle the following exceptional case (*Obj).isa.
if (!IsArrow &&
@@ -4024,8 +4055,8 @@
Param? InitializedEntity::InitializeParameter(Context, Param)
: InitializedEntity::InitializeParameter(Context, ProtoArgType);
ExprResult ArgE = PerformCopyInitialization(Entity,
- SourceLocation(),
- Owned(Arg));
+ SourceLocation(),
+ Owned(Arg));
if (ArgE.isInvalid())
return true;
@@ -4532,16 +4563,19 @@
// We only support r-value casts in C.
VK = VK_RValue;
- DefaultFunctionArrayLvalueConversion(castExpr);
-
// C99 6.5.4p2: the cast type needs to be void or scalar and the expression
// type needs to be scalar.
if (castType->isVoidType()) {
+ // We don't necessarily do lvalue-to-rvalue conversions on this.
+ IgnoredValueConversions(castExpr);
+
// Cast to void allows any expr type.
Kind = CK_ToVoid;
return false;
}
+ DefaultFunctionArrayLvalueConversion(castExpr);
+
if (RequireCompleteType(TyR.getBegin(), castType,
diag::err_typecheck_cast_to_incomplete))
return true;
@@ -5713,7 +5747,7 @@
// FIXME: Currently, we fall through and treat C++ classes like C
// structures.
- }
+ }
// C99 6.5.16.1p1: the left operand is a pointer and the right is
// a null pointer constant.
@@ -6201,8 +6235,8 @@
// obvious cases in the definition of the template anyways. The idea is to
// warn when the typed comparison operator will always evaluate to the same
// result.
- Expr *LHSStripped = lex->IgnoreParens();
- Expr *RHSStripped = rex->IgnoreParens();
+ Expr *LHSStripped = lex->IgnoreParenImpCasts();
+ Expr *RHSStripped = rex->IgnoreParenImpCasts();
if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(LHSStripped)) {
if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(RHSStripped)) {
if (DRL->getDecl() == DRR->getDecl() &&
@@ -6782,7 +6816,8 @@
if (CompoundType.isNull()) {
QualType LHSTy(LHSType);
// Simple assignment "x = y".
- ConvertPropertyAssignment(LHS, RHS, LHSTy);
+ if (LHS->getObjectKind() == OK_ObjCProperty)
+ ConvertPropertyForLValue(LHS, RHS, LHSTy);
ConvTy = CheckSingleAssignmentConstraints(LHSTy, RHS);
// Special case of NSObject attributes on c-style pointer types.
if (ConvTy == IncompatiblePointer &&
@@ -6857,7 +6892,7 @@
}
// C99 6.5.17
-static QualType CheckCommaOperands(Sema &S, Expr *LHS, Expr *&RHS,
+static QualType CheckCommaOperands(Sema &S, Expr *&LHS, Expr *&RHS,
SourceLocation Loc) {
S.DiagnoseUnusedExprResult(LHS);
@@ -6873,11 +6908,12 @@
// C's comma performs lvalue conversion (C99 6.3.2.1) on both its
// operands, but not unary promotions.
// C++'s comma does not do any conversions at all (C++ [expr.comma]p1).
- if (!S.getLangOptions().CPlusPlus) {
- S.DefaultFunctionArrayLvalueConversion(LHS);
- if (!LHS->getType()->isVoidType())
- S.RequireCompleteType(Loc, LHS->getType(), diag::err_incomplete_type);
+ // So we treat the LHS as a ignored value, and in C++ we allow the
+ // containing site to determine what should be done with the RHS.
+ S.IgnoredValueConversions(LHS);
+
+ if (!S.getLangOptions().CPlusPlus) {
S.DefaultFunctionArrayLvalueConversion(RHS);
if (!RHS->getType()->isVoidType())
S.RequireCompleteType(Loc, RHS->getType(), diag::err_incomplete_type);
@@ -6971,21 +7007,47 @@
}
}
-void Sema::ConvertPropertyAssignment(Expr *LHS, Expr *&RHS, QualType& LHSTy) {
- bool copyInit = false;
- if (const ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(LHS)) {
- if (PRE->isImplicitProperty()) {
- // If using property-dot syntax notation for assignment, and there is a
- // setter, RHS expression is being passed to the setter argument. So,
- // type conversion (and comparison) is RHS to setter's argument type.
- if (const ObjCMethodDecl *SetterMD = PRE->getImplicitPropertySetter()) {
- ObjCMethodDecl::param_iterator P = SetterMD->param_begin();
- LHSTy = (*P)->getType();
+void Sema::ConvertPropertyForRValue(Expr *&E) {
+ assert(E->getValueKind() == VK_LValue &&
+ E->getObjectKind() == OK_ObjCProperty);
+ const ObjCPropertyRefExpr *PRE = E->getObjCProperty();
+
+ ExprValueKind VK = VK_RValue;
+ if (PRE->isImplicitProperty()) {
+ QualType Result = PRE->getImplicitPropertyGetter()->getResultType();
+ VK = Expr::getValueKindForType(Result);
+ }
+
+ E = ImplicitCastExpr::Create(Context, E->getType(), CK_GetObjCProperty,
+ E, 0, VK);
+}
+
+void Sema::ConvertPropertyForLValue(Expr *&LHS, Expr *&RHS, QualType &LHSTy) {
+ assert(LHS->getValueKind() == VK_LValue &&
+ LHS->getObjectKind() == OK_ObjCProperty);
+ const ObjCPropertyRefExpr *PRE = LHS->getObjCProperty();
+
+ if (PRE->isImplicitProperty()) {
+ // If using property-dot syntax notation for assignment, and there is a
+ // setter, RHS expression is being passed to the setter argument. So,
+ // type conversion (and comparison) is RHS to setter's argument type.
+ if (const ObjCMethodDecl *SetterMD = PRE->getImplicitPropertySetter()) {
+ ObjCMethodDecl::param_iterator P = SetterMD->param_begin();
+ LHSTy = (*P)->getType();
+
+ // Otherwise, if the getter returns an l-value, just call that.
+ } else {
+ QualType Result = PRE->getImplicitPropertyGetter()->getResultType();
+ ExprValueKind VK = Expr::getValueKindForType(Result);
+ if (VK == VK_LValue) {
+ LHS = ImplicitCastExpr::Create(Context, LHS->getType(),
+ CK_GetObjCProperty, LHS, 0, VK);
+ return;
}
}
- copyInit = (getLangOptions().CPlusPlus && LHSTy->isRecordType());
- }
- if (copyInit) {
+ }
+
+ if (getLangOptions().CPlusPlus && LHSTy->isRecordType()) {
InitializedEntity Entity =
InitializedEntity::InitializeParameter(Context, LHSTy);
Expr *Arg = RHS;
@@ -7318,7 +7380,8 @@
switch (Opc) {
case BO_Assign:
ResultTy = CheckAssignmentOperands(lhs, rhs, OpLoc, QualType());
- if (getLangOptions().CPlusPlus) {
+ if (getLangOptions().CPlusPlus &&
+ lhs->getObjectKind() != OK_ObjCProperty) {
VK = lhs->getValueKind();
OK = lhs->getObjectKind();
}
@@ -7418,7 +7481,7 @@
return Owned(new (Context) BinaryOperator(lhs, rhs, Opc, ResultTy,
VK, OK, OpLoc));
- if (getLangOptions().CPlusPlus) {
+ if (getLangOptions().CPlusPlus && lhs->getObjectKind() != OK_ObjCProperty) {
VK = VK_LValue;
OK = lhs->getObjectKind();
}
@@ -7824,8 +7887,11 @@
LastStmt = Label->getSubStmt();
}
if (Expr *LastExpr = dyn_cast<Expr>(LastStmt)) {
- DefaultFunctionArrayLvalueConversion(LastExpr);
- Ty = LastExpr->getType();
+ // Do function/array conversion on the last expression, but not
+ // lvalue-to-rvalue. However, initialize an unqualified type.
+ DefaultFunctionArrayConversion(LastExpr);
+ Ty = LastExpr->getType().getUnqualifiedType();
+
if (!Ty->isDependentType() && !LastExpr->isTypeDependent()) {
ExprResult Res = PerformCopyInitialization(
InitializedEntity::InitializeResult(LPLoc,
@@ -8971,18 +9037,15 @@
return Diag(E->getLocStart(), diag::err_invalid_use_of_bound_member_func)
<< E->getSourceRange();
- DefaultFunctionArrayLvalueConversion(E);
-
QualType T = E->getType();
- if (getLangOptions().CPlusPlus) {
- if (CheckCXXBooleanCondition(E)) // C++ 6.4p4
- return true;
- } else if (!T->isScalarType()) { // C99 6.8.4.1p1
- Diag(Loc, diag::err_typecheck_statement_requires_scalar)
- << T << E->getSourceRange();
- return true;
- }
+ if (getLangOptions().CPlusPlus)
+ return CheckCXXBooleanCondition(E); // C++ 6.4p4
+
+ DefaultFunctionArrayLvalueConversion(E);
+ if (!T->isScalarType()) // C99 6.8.4.1p1
+ return Diag(Loc, diag::err_typecheck_statement_requires_scalar)
+ << T << E->getSourceRange();
}
return false;
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Dec 3 21:47:34 2010
@@ -1845,10 +1845,21 @@
// Perform the first implicit conversion.
switch (SCS.First) {
case ICK_Identity:
- case ICK_Lvalue_To_Rvalue:
// Nothing to do.
break;
+ case ICK_Lvalue_To_Rvalue:
+ // Should this get its own ICK?
+ if (From->getObjectKind() == OK_ObjCProperty) {
+ ConvertPropertyForRValue(From);
+ if (!From->isRValue()) break;
+ }
+
+ FromType = FromType.getUnqualifiedType();
+ From = ImplicitCastExpr::Create(Context, FromType, CK_LValueToRValue,
+ From, 0, VK_RValue);
+ break;
+
case ICK_Array_To_Pointer:
FromType = Context.getArrayDecayedType(FromType);
ImpCastExprToType(From, FromType, CK_ArrayToPointerDecay);
@@ -2746,14 +2757,14 @@
// The operands have class type. Make a temporary copy.
InitializedEntity Entity = InitializedEntity::InitializeTemporary(LTy);
ExprResult LHSCopy = PerformCopyInitialization(Entity,
- SourceLocation(),
- Owned(LHS));
+ SourceLocation(),
+ Owned(LHS));
if (LHSCopy.isInvalid())
return QualType();
ExprResult RHSCopy = PerformCopyInitialization(Entity,
- SourceLocation(),
- Owned(RHS));
+ SourceLocation(),
+ Owned(RHS));
if (RHSCopy.isInvalid())
return QualType();
@@ -3512,21 +3523,42 @@
return BuildCXXNoexceptExpr(KeyLoc, Operand, RParen);
}
-ExprResult Sema::ActOnFinishFullExpr(Expr *FullExpr) {
- if (!FullExpr) return ExprError();
-
+/// Perform the conversions required for an expression used in a
+/// context that ignores the result.
+void Sema::IgnoredValueConversions(Expr *&E) {
// C99 6.3.2.1:
// [Except in specific positions,] an lvalue that does not have
// array type is converted to the value stored in the
// designated object (and is no longer an lvalue).
- // This rule does not apply in C++; however, in ObjC++, we do want
- // to do lvalue-to-rvalue conversion on top-level ObjCProperty
- // l-values.
- if (!FullExpr->isRValue() &&
- (!getLangOptions().CPlusPlus ||
- FullExpr->getObjectKind() == OK_ObjCProperty))
- DefaultFunctionArrayLvalueConversion(FullExpr);
+ if (E->isRValue()) return;
+
+ // We always want to do this on ObjC property references.
+ if (E->getObjectKind() == OK_ObjCProperty) {
+ ConvertPropertyForRValue(E);
+ if (E->isRValue()) return;
+ }
+
+ // Otherwise, this rule does not apply in C++, at least not for the moment.
+ if (getLangOptions().CPlusPlus) return;
+
+ // GCC seems to also exclude expressions of incomplete enum type.
+ if (const EnumType *T = E->getType()->getAs<EnumType>()) {
+ if (!T->getDecl()->isComplete()) {
+ // FIXME: stupid workaround for a codegen bug!
+ ImpCastExprToType(E, Context.VoidTy, CK_ToVoid);
+ return;
+ }
+ }
+
+ DefaultFunctionArrayLvalueConversion(E);
+ RequireCompleteType(E->getExprLoc(), E->getType(),
+ diag::err_incomplete_type);
+}
+
+ExprResult Sema::ActOnFinishFullExpr(Expr *FullExpr) {
+ if (!FullExpr) return ExprError();
+ IgnoredValueConversions(FullExpr);
CheckImplicitConversions(FullExpr);
return MaybeCreateCXXExprWithTemporaries(FullExpr);
}
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri Dec 3 21:47:34 2010
@@ -284,6 +284,9 @@
}
bool Sema::isSelfExpr(Expr *RExpr) {
+ if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(RExpr))
+ if (ICE->getCastKind() == CK_LValueToRValue)
+ RExpr = ICE->getSubExpr();
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(RExpr))
if (DRE->getDecl()->getIdentifier() == &Context.Idents.get("self"))
return true;
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 3 21:47:34 2010
@@ -3627,12 +3627,18 @@
case SK_ListInitialization:
case SK_CAssignment:
case SK_StringInit:
- case SK_ObjCObjectConversion:
+ case SK_ObjCObjectConversion: {
assert(Args.size() == 1);
- CurInit = ExprResult(Args.get()[0]);
- if (CurInit.isInvalid())
- return ExprError();
+ Expr *CurInitExpr = Args.get()[0];
+ if (!CurInitExpr) return ExprError();
+
+ // Read from a property when initializing something with it.
+ if (CurInitExpr->getObjectKind() == OK_ObjCProperty)
+ S.ConvertPropertyForRValue(CurInitExpr);
+
+ CurInit = ExprResult(CurInitExpr);
break;
+ }
case SK_ConstructorInitialization:
case SK_ZeroInitialization:
@@ -3647,7 +3653,7 @@
if (CurInit.isInvalid())
return ExprError();
- Expr *CurInitExpr = (Expr *)CurInit.get();
+ Expr *CurInitExpr = CurInit.get();
QualType SourceType = CurInitExpr? CurInitExpr->getType() : QualType();
switch (Step->Kind) {
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Dec 3 21:47:34 2010
@@ -92,7 +92,7 @@
if (const CXXExprWithTemporaries *Temps = dyn_cast<CXXExprWithTemporaries>(E))
E = Temps->getSubExpr();
- E = E->IgnoreParens();
+ E = E->IgnoreParenImpCasts();
if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
if (E->getType()->isVoidType())
return;
@@ -952,6 +952,17 @@
RParenLoc));
}
+/// In an Objective C collection iteration statement:
+/// for (x in y)
+/// x can be an arbitrary l-value expression. Bind it up as a
+/// full-expression.
+StmtResult Sema::ActOnForEachLValueExpr(Expr *E) {
+ CheckImplicitConversions(E);
+ ExprResult Result = MaybeCreateCXXExprWithTemporaries(E);
+ if (Result.isInvalid()) return StmtError();
+ return Owned(static_cast<Stmt*>(Result.get()));
+}
+
StmtResult
Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
SourceLocation LParenLoc,
@@ -1228,6 +1239,10 @@
unsigned D = diag::ext_return_has_expr;
if (RetValExp->getType()->isVoidType())
D = diag::ext_return_has_void_expr;
+ else {
+ IgnoredValueConversions(RetValExp);
+ ImpCastExprToType(RetValExp, Context.VoidTy, CK_ToVoid);
+ }
// return (some void expression); is legal in C++.
if (D != diag::ext_return_has_void_expr ||
Modified: cfe/trunk/test/CodeGen/volatile-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/volatile-1.c?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/volatile-1.c (original)
+++ cfe/trunk/test/CodeGen/volatile-1.c Fri Dec 3 21:47:34 2010
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -Wno-unused-value -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -Wno-return-type -Wno-unused-value -emit-llvm %s -o - | FileCheck %s
// CHECK: @i = common global [[INT:i[0-9]+]] 0
volatile int i, j, k;
@@ -301,3 +301,13 @@
printf("s.x is at %p\n", &((s = s1).x));
#endif
}
+
+extern volatile enum X x;
+// CHECK: define void @test1()
+void test1() {
+ // CHECK-NEXT: :
+ // CHECK-NEXT: ret void
+ x;
+ (void) x;
+ return x;
+}
Modified: cfe/trunk/test/CodeGenObjCXX/property-dot-reference.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/property-dot-reference.mm?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/property-dot-reference.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/property-dot-reference.mm Fri Dec 3 21:47:34 2010
@@ -36,3 +36,24 @@
f0([a target]);
}
+ at interface Test2
+ at property (readonly) int myProperty;
+- (int) myProperty;
+- (double) myGetter;
+ at end
+void test2() {
+ Test2 *obj;
+ (void) obj.myProperty;
+ (void) obj.myGetter;
+ static_cast<void>(obj.myProperty);
+ static_cast<void>(obj.myGetter);
+ void(obj.myProperty);
+ void(obj.myGetter);
+}
+// CHECK: define void @_Z5test2v()
+// CHECK: call i32 bitcast
+// CHECK: call double bitcast
+// CHECK: call i32 bitcast
+// CHECK: call double bitcast
+// CHECK: call i32 bitcast
+// CHECK: call double bitcast
Modified: cfe/trunk/test/Rewriter/properties.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/properties.m?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/properties.m (original)
+++ cfe/trunk/test/Rewriter/properties.m Fri Dec 3 21:47:34 2010
@@ -1,5 +1,9 @@
// RUN: %clang_cc1 -rewrite-objc %s -o -
+// Fariborz approved this being xfail'ed during the addition
+// of explicit lvalue-to-rvalue conversions.
+// XFAIL: *
+
@interface Foo {
int i;
int rrrr;
Modified: cfe/trunk/test/Rewriter/rewrite-nested-property-in-blocks.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-nested-property-in-blocks.mm?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-nested-property-in-blocks.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-nested-property-in-blocks.mm Fri Dec 3 21:47:34 2010
@@ -2,6 +2,10 @@
// RUN: %clang_cc1 -fsyntax-only -fms-extensions -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
// radar 8608293
+// Fariborz approved this being xfail'ed during the addition
+// of explicit lvalue-to-rvalue conversions.
+// XFAIL: *
+
void *sel_registerName(const char *);
extern "C" void nowarn(id);
Modified: cfe/trunk/test/Sema/rdr6094103-unordered-compare-promote.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/rdr6094103-unordered-compare-promote.c?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/test/Sema/rdr6094103-unordered-compare-promote.c (original)
+++ cfe/trunk/test/Sema/rdr6094103-unordered-compare-promote.c Fri Dec 3 21:47:34 2010
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -ast-dump %s 2>&1 | grep ImplicitCastExpr | count 2
+// RUN: %clang_cc1 -ast-dump %s 2>&1 | grep ImplicitCastExpr | count 4
int foo (double x, long double y) {
// There needs to be an implicit cast on x here.
Modified: cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp (original)
+++ cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp Fri Dec 3 21:47:34 2010
@@ -7,8 +7,8 @@
// Expressions.
T(a)->m = 7;
- int(a)++; // expected-error {{expression is not assignable}}
- __extension__ int(a)++; // expected-error {{expression is not assignable}}
+ int(a)++; // expected-error {{assignment to cast is illegal}}
+ __extension__ int(a)++; // expected-error {{assignment to cast is illegal}}
__typeof(int)(a,5)<<a; // expected-error {{excess elements in scalar initializer}}
void(a), ++a;
if (int(a)+1) {}
Modified: cfe/trunk/test/SemaTemplate/enum-argument.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/enum-argument.cpp?rev=120890&r1=120889&r2=120890&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/enum-argument.cpp (original)
+++ cfe/trunk/test/SemaTemplate/enum-argument.cpp Fri Dec 3 21:47:34 2010
@@ -30,7 +30,7 @@
unsigned long long bitfield : e0;
void f(int j) {
- bitfield + j;
+ bitfield + j; // expected-warning {{expression result unused}}
}
};
}
More information about the cfe-commits
mailing list