Sundry missing lvalue-to-rvalue conversions. Also leave a TODO for the vital

future task of performing contextual conversion to size_t in a VLA size
expression. :)

llvm-svn: 121836
This commit is contained in:
John McCall 2010-12-15 04:42:30 +00:00
parent 3f8688b614
commit 15317a2f5b
3 changed files with 19 additions and 7 deletions

View File

@ -3450,6 +3450,7 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr,
// Perform default conversions. // Perform default conversions.
DefaultFunctionArrayConversion(BaseExpr); DefaultFunctionArrayConversion(BaseExpr);
if (IsArrow) DefaultLvalueConversion(BaseExpr);
QualType BaseType = BaseExpr->getType(); QualType BaseType = BaseExpr->getType();
assert(!BaseType->isDependentType()); assert(!BaseType->isDependentType());
@ -3795,8 +3796,9 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr,
// Handle 'field access' to vectors, such as 'V.xx'. // Handle 'field access' to vectors, such as 'V.xx'.
if (BaseType->isExtVectorType()) { if (BaseType->isExtVectorType()) {
// FIXME: this expr should store IsArrow.
IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
ExprValueKind VK = BaseExpr->getValueKind(); ExprValueKind VK = (IsArrow ? VK_LValue : BaseExpr->getValueKind());
QualType ret = CheckExtVectorComponent(*this, BaseType, VK, OpLoc, QualType ret = CheckExtVectorComponent(*this, BaseType, VK, OpLoc,
Member, MemberLoc); Member, MemberLoc);
if (ret.isNull()) if (ret.isNull())
@ -3826,12 +3828,12 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr,
/// this is an ugly hack around the fact that ObjC @implementations /// this is an ugly hack around the fact that ObjC @implementations
/// aren't properly put in the context chain /// aren't properly put in the context chain
ExprResult Sema::ActOnMemberAccessExpr(Scope *S, Expr *Base, ExprResult Sema::ActOnMemberAccessExpr(Scope *S, Expr *Base,
SourceLocation OpLoc, SourceLocation OpLoc,
tok::TokenKind OpKind, tok::TokenKind OpKind,
CXXScopeSpec &SS, CXXScopeSpec &SS,
UnqualifiedId &Id, UnqualifiedId &Id,
Decl *ObjCImpDecl, Decl *ObjCImpDecl,
bool HasTrailingLParen) { bool HasTrailingLParen) {
if (SS.isSet() && SS.isInvalid()) if (SS.isSet() && SS.isInvalid())
return ExprError(); return ExprError();

View File

@ -1597,6 +1597,8 @@ Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
StmtResult Sema::BuildObjCAtThrowStmt(SourceLocation AtLoc, StmtResult Sema::BuildObjCAtThrowStmt(SourceLocation AtLoc,
Expr *Throw) { Expr *Throw) {
if (Throw) { if (Throw) {
DefaultLvalueConversion(Throw);
QualType ThrowType = Throw->getType(); QualType ThrowType = Throw->getType();
// Make sure the expression type is an ObjC pointer or "void *". // Make sure the expression type is an ObjC pointer or "void *".
if (!ThrowType->isDependentType() && if (!ThrowType->isDependentType() &&
@ -1632,6 +1634,8 @@ Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SyncExpr,
Stmt *SyncBody) { Stmt *SyncBody) {
getCurFunction()->setHasBranchProtectedScope(); getCurFunction()->setHasBranchProtectedScope();
DefaultLvalueConversion(SyncExpr);
// Make sure the expression type is an ObjC pointer or "void *". // Make sure the expression type is an ObjC pointer or "void *".
if (!SyncExpr->getType()->isDependentType() && if (!SyncExpr->getType()->isDependentType() &&
!SyncExpr->getType()->isObjCObjectPointerType()) { !SyncExpr->getType()->isObjCObjectPointerType()) {

View File

@ -680,7 +680,13 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
return QualType(); return QualType();
} }
// Do lvalue-to-rvalue conversions on the array size expression.
if (ArraySize && !ArraySize->isRValue())
DefaultLvalueConversion(ArraySize);
// C99 6.7.5.2p1: The size expression shall have integer type. // C99 6.7.5.2p1: The size expression shall have integer type.
// TODO: in theory, if we were insane, we could allow contextual
// conversions to integer type here.
if (ArraySize && !ArraySize->isTypeDependent() && if (ArraySize && !ArraySize->isTypeDependent() &&
!ArraySize->getType()->isIntegralOrUnscopedEnumerationType()) { !ArraySize->getType()->isIntegralOrUnscopedEnumerationType()) {
Diag(ArraySize->getLocStart(), diag::err_array_size_non_int) Diag(ArraySize->getLocStart(), diag::err_array_size_non_int)