aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-03-22 23:00:19 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-03-22 23:00:19 +0000
commit7fa3faa4176915b068301be677c983cc5cc80cad (patch)
tree4a72fbc66a987ecf2ee67bcd02e807b9f6b79884
parente88b229b48a92b157d51761a2919368bf8c539bf (diff)
downloadllvm-7fa3faa4176915b068301be677c983cc5cc80cad.zip
llvm-7fa3faa4176915b068301be677c983cc5cc80cad.tar.gz
llvm-7fa3faa4176915b068301be677c983cc5cc80cad.tar.bz2
Fix code to mark block variables as const to actually work. Fix
isObjCObjectPointerType to work with qualified types. Adjust test for changes. If the SemaExpr changes are wrong or break existing code, feel free to delete the "ExprTy.addConst();" line and revert my changes to test/Sema/block-literal.c. llvm-svn: 67489
-rw-r--r--clang/lib/AST/ASTContext.cpp3
-rw-r--r--clang/lib/Sema/SemaExpr.cpp9
-rw-r--r--clang/test/Sema/block-literal.c4
3 files changed, 8 insertions, 8 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index c5441dd..c656d96 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2469,7 +2469,8 @@ bool ASTContext::isObjCObjectPointerType(QualType Ty) const {
// Check to see if this is 'id' or 'Class', both of which are typedefs for
// pointer types. This looks for the typedef specifically, not for the
// underlying type.
- if (Ty == getObjCIdType() || Ty == getObjCClassType())
+ if (Ty.getUnqualifiedType() == getObjCIdType() ||
+ Ty.getUnqualifiedType() == getObjCClassType())
return true;
// If this a pointer to an interface (e.g. NSString*), it is ok.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 079ff74..3220a9e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -932,15 +932,14 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
// Blocks that have these can't be constant.
CurBlock->hasBlockDeclRefExprs = true;
+ QualType ExprTy = VD->getType().getNonReferenceType();
// The BlocksAttr indicates the variable is bound by-reference.
if (VD->getAttr<BlocksAttr>())
- return Owned(new (Context) BlockDeclRefExpr(VD,
- VD->getType().getNonReferenceType(), Loc, true));
+ return Owned(new (Context) BlockDeclRefExpr(VD, ExprTy, Loc, true));
// Variable will be bound by-copy, make it const within the closure.
- VD->getType().addConst();
- return Owned(new (Context) BlockDeclRefExpr(VD,
- VD->getType().getNonReferenceType(), Loc, false));
+ ExprTy.addConst();
+ return Owned(new (Context) BlockDeclRefExpr(VD, ExprTy, Loc, false));
}
// If this reference is not in a block or if the referenced variable is
// within the block, create a normal DeclRefExpr.
diff --git a/clang/test/Sema/block-literal.c b/clang/test/Sema/block-literal.c
index 7f64c03..290cef1 100644
--- a/clang/test/Sema/block-literal.c
+++ b/clang/test/Sema/block-literal.c
@@ -39,7 +39,7 @@ void test2() {
}
foo:
- takeclosure(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}}
+ takeclosure(^{ x = 4; }); // expected-error {{read-only variable is not assignable}}
__block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}}
takeclosure(^{ y = 8; });
}
@@ -56,7 +56,7 @@ void test4() {
void myfunc(int (^block)(int)) {}
-void myfunc3(int *x);
+void myfunc3(const int *x);
void test5() {
int a;