aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/Expr.h7
-rw-r--r--lib/AST/Expr.cpp11
-rw-r--r--lib/Sema/SemaExpr.cpp11
-rw-r--r--test/Sema/exprs.c3
4 files changed, 24 insertions, 8 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 2102126eb6..ba26ef3e90 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -152,6 +152,10 @@ public:
/// and if it is a structure or union, does not have any member (including,
/// recursively, any member or element of all contained aggregates or unions)
/// with a const-qualified type.
+ ///
+ /// \param Loc [in] [out] - A source location which *may* be filled
+ /// in with the location of the expression making this a
+ /// non-modifiable lvalue, if specified.
enum isModifiableLvalueResult {
MLV_Valid,
MLV_NotObjectType,
@@ -167,7 +171,8 @@ public:
MLV_NoSetterProperty,
MLV_MemberFunction
};
- isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx) const;
+ isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
+ SourceLocation *Loc = 0) const;
bool isBitField();
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 973e662b25..dd346176bf 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -756,7 +756,8 @@ Expr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const {
/// if it is a structure or union, does not have any member (including,
/// recursively, any member or element of all contained aggregates or unions)
/// with a const-qualified type.
-Expr::isModifiableLvalueResult Expr::isModifiableLvalue(ASTContext &Ctx) const {
+Expr::isModifiableLvalueResult
+Expr::isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc) const {
isLvalueResult lvalResult = isLvalue(Ctx);
switch (lvalResult) {
@@ -775,9 +776,13 @@ Expr::isModifiableLvalueResult Expr::isModifiableLvalue(ASTContext &Ctx) const {
// lvalue, then this is probably a use of the old-school "cast as lvalue"
// GCC extension. We don't support it, but we want to produce good
// diagnostics when it happens so that the user knows why.
- if (const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(IgnoreParens()))
- if (CE->getSubExpr()->isLvalue(Ctx) == LV_Valid)
+ if (const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(IgnoreParens())) {
+ if (CE->getSubExpr()->isLvalue(Ctx) == LV_Valid) {
+ if (Loc)
+ *Loc = CE->getLParenLoc();
return MLV_LValueCast;
+ }
+ }
return MLV_InvalidExpression;
case LV_MemberFunction: return MLV_MemberFunction;
}
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 0dc3b87d52..a5999cc890 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -3725,7 +3725,9 @@ static bool IsReadonlyProperty(Expr *E, Sema &S)
/// CheckForModifiableLvalue - Verify that E is a modifiable lvalue. If not,
/// emit an error and return true. If so, return false.
static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) {
- Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(S.Context);
+ SourceLocation OrigLoc = Loc;
+ Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(S.Context,
+ &Loc);
if (IsLV == Expr::MLV_Valid && IsReadonlyProperty(E, S))
IsLV = Expr::MLV_ReadonlyProperty;
if (IsLV == Expr::MLV_Valid)
@@ -3769,10 +3771,13 @@ static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) {
break;
}
+ SourceRange Assign;
+ if (Loc != OrigLoc)
+ Assign = SourceRange(OrigLoc, OrigLoc);
if (NeedType)
- S.Diag(Loc, Diag) << E->getType() << E->getSourceRange();
+ S.Diag(Loc, Diag) << E->getType() << E->getSourceRange() << Assign;
else
- S.Diag(Loc, Diag) << E->getSourceRange();
+ S.Diag(Loc, Diag) << E->getSourceRange() << Assign;
return true;
}
diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c
index 617eaa086c..d92141ce1d 100644
--- a/test/Sema/exprs.c
+++ b/test/Sema/exprs.c
@@ -34,7 +34,8 @@ void test4() {
// rdar://6319320
void test5(int *X, float *P) {
(float*)X = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
- ((float*)X) = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
+#define FOO ((float*) X)
+ FOO = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
}
void test6() {