[cfe-commits] r46830 - in /cfe/trunk: AST/StmtSerialization.cpp Driver/RewriteTest.cpp Sema/SemaExpr.cpp include/clang/AST/Expr.h test/Sema/assign.c
Eli Friedman
eli.friedman at gmail.com
Wed Feb 6 14:48:17 PST 2008
Author: efriedma
Date: Wed Feb 6 16:48:16 2008
New Revision: 46830
URL: http://llvm.org/viewvc/llvm-project?rev=46830&view=rev
Log:
Make sure to propagate qualifiers through the member operator.
Modified:
cfe/trunk/AST/StmtSerialization.cpp
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/test/Sema/assign.c
Modified: cfe/trunk/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtSerialization.cpp?rev=46830&r1=46829&r2=46830&view=diff
==============================================================================
--- cfe/trunk/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/AST/StmtSerialization.cpp Wed Feb 6 16:48:16 2008
@@ -686,6 +686,7 @@
S.EmitPtr(MemberDecl);
S.EmitBool(IsArrow);
S.EmitOwnedPtr(Base);
+ S.Emit(getType());
}
MemberExpr* MemberExpr::CreateImpl(Deserializer& D) {
@@ -693,8 +694,9 @@
FieldDecl* MemberDecl = cast<FieldDecl>(D.ReadPtr<Decl>());
bool IsArrow = D.ReadBool();
Expr* base = D.ReadOwnedPtr<Expr>();
+ QualType T = QualType::ReadVal(D);
- return new MemberExpr(base,IsArrow,MemberDecl,L);
+ return new MemberExpr(base,IsArrow,MemberDecl,L,T);
}
void NullStmt::EmitImpl(Serializer& S) const {
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=46830&r1=46829&r2=46830&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Wed Feb 6 16:48:16 2008
@@ -746,7 +746,7 @@
ObjCIvarDecl *D = IV->getDecl();
if (IV->isFreeIvar()) {
Expr *Replacement = new MemberExpr(IV->getBase(), true, D,
- IV->getLocation());
+ IV->getLocation(), D->getType());
ReplaceStmt(IV, Replacement);
delete IV;
return Replacement;
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=46830&r1=46829&r2=46830&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Wed Feb 6 16:48:16 2008
@@ -532,7 +532,15 @@
if (!MemberDecl)
return Diag(OpLoc, diag::err_typecheck_no_member, Member.getName(),
SourceRange(MemberLoc));
- return new MemberExpr(BaseExpr, OpKind==tok::arrow, MemberDecl, MemberLoc);
+
+ // Figure out the type of the member; see C99 6.5.2.3p3
+ QualType MemberType = MemberDecl->getType();
+ unsigned combinedQualifiers =
+ MemberType.getQualifiers() | BaseType.getQualifiers();
+ MemberType = MemberType.getQualifiedType(combinedQualifiers);
+
+ return new MemberExpr(BaseExpr, OpKind==tok::arrow, MemberDecl,
+ MemberLoc, MemberType);
} else if (BaseType->isOCUVectorType() && OpKind == tok::period) {
// Component access limited to variables (reject vec4.rg.g).
if (!isa<DeclRefExpr>(BaseExpr))
@@ -2050,8 +2058,9 @@
// FIXME: C++: Verify that MemberDecl isn't a static field.
// FIXME: Verify that MemberDecl isn't a bitfield.
-
- Res = new MemberExpr(Res, false, MemberDecl, OC.LocEnd);
+ // MemberDecl->getType() doesn't get the right qualifiers, but it doesn't
+ // matter here.
+ Res = new MemberExpr(Res, false, MemberDecl, OC.LocEnd, MemberDecl->getType());
}
return new UnaryOperator(Res, UnaryOperator::OffsetOf, Context.getSizeType(),
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=46830&r1=46829&r2=46830&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Feb 6 16:48:16 2008
@@ -650,10 +650,11 @@
SourceLocation MemberLoc;
bool IsArrow; // True if this is "X->F", false if this is "X.F".
public:
- MemberExpr(Expr *base, bool isarrow, FieldDecl *memberdecl, SourceLocation l)
- : Expr(MemberExprClass, memberdecl->getType()),
+ MemberExpr(Expr *base, bool isarrow, FieldDecl *memberdecl, SourceLocation l,
+ QualType ty)
+ : Expr(MemberExprClass, ty),
Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
-
+
Expr *getBase() const { return Base; }
FieldDecl *getMemberDecl() const { return MemberDecl; }
bool isArrow() const { return IsArrow; }
Modified: cfe/trunk/test/Sema/assign.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/assign.c?rev=46830&r1=46829&r2=46830&view=diff
==============================================================================
--- cfe/trunk/test/Sema/assign.c (original)
+++ cfe/trunk/test/Sema/assign.c Wed Feb 6 16:48:16 2008
@@ -2,4 +2,6 @@
void *test1(void) { return 0; }
-
+void test2 (const struct {int a;} *x) {
+ x->a = 10; // expected-error {{read-only variable is not assignable}}
+}
More information about the cfe-commits
mailing list