diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-04-25 23:46:54 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-04-25 23:46:54 +0000 |
commit | ab2784f2c16e53e725f0bb54c78c90a12ae79adb (patch) | |
tree | 1429cd8c5b058ee3ac861345febe1d19288c691d /clang/lib | |
parent | 0dedefe4f2c42c1d6185e203b3a3420ba8ead431 (diff) | |
download | bcm5719-llvm-ab2784f2c16e53e725f0bb54c78c90a12ae79adb.tar.gz bcm5719-llvm-ab2784f2c16e53e725f0bb54c78c90a12ae79adb.zip |
Fix for PR4074: allow subscripting non-lvalue arrays in C90 mode.
I wasn't originally going to use this approach, but cases like
test/Sema/expr-comma.c make things difficult.
llvm-svn: 70096
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 873dd53f12c..e789e542893 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1621,13 +1621,11 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, } else if (const PointerType *PTy = LHSTy->getAsPointerType()) { BaseExpr = LHSExp; IndexExpr = RHSExp; - // FIXME: need to deal with const... ResultType = PTy->getPointeeType(); } else if (const PointerType *PTy = RHSTy->getAsPointerType()) { // Handle the uncommon case of "123[Ptr]". BaseExpr = RHSExp; IndexExpr = LHSExp; - // FIXME: need to deal with const... ResultType = PTy->getPointeeType(); } else if (const VectorType *VTy = LHSTy->getAsVectorType()) { BaseExpr = LHSExp; // vectors: V[123] @@ -1635,6 +1633,30 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, // FIXME: need to deal with const... ResultType = VTy->getElementType(); + } else if (LHSTy->isArrayType()) { + // If we see an array that wasn't promoted by + // DefaultFunctionArrayConversion, it must be an array that + // wasn't promoted because of the C90 rule that doesn't + // allow promoting non-lvalue arrays. Warn, then + // force the promotion here. + Diag(LHSExp->getLocStart(), diag::ext_subscript_non_lvalue) << + LHSExp->getSourceRange(); + ImpCastExprToType(LHSExp, Context.getArrayDecayedType(LHSTy)); + LHSTy = LHSExp->getType(); + + BaseExpr = LHSExp; + IndexExpr = RHSExp; + ResultType = LHSTy->getAsPointerType()->getPointeeType(); + } else if (RHSTy->isArrayType()) { + // Same as previous, except for 123[f().a] case + Diag(RHSExp->getLocStart(), diag::ext_subscript_non_lvalue) << + RHSExp->getSourceRange(); + ImpCastExprToType(RHSExp, Context.getArrayDecayedType(RHSTy)); + RHSTy = RHSExp->getType(); + + BaseExpr = RHSExp; + IndexExpr = LHSExp; + ResultType = RHSTy->getAsPointerType()->getPointeeType(); } else { return ExprError(Diag(LLoc, diag::err_typecheck_subscript_value) << LHSExp->getSourceRange() << RHSExp->getSourceRange()); |