[cfe-commits] r67489 - in /cfe/trunk: lib/AST/ASTContext.cpp lib/Sema/SemaExpr.cpp test/Sema/block-literal.c

Eli Friedman eli.friedman at gmail.com
Sun Mar 22 16:00:19 PDT 2009


Author: efriedma
Date: Sun Mar 22 18:00:19 2009
New Revision: 67489

URL: http://llvm.org/viewvc/llvm-project?rev=67489&view=rev
Log:
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.


Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/block-literal.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=67489&r1=67488&r2=67489&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Mar 22 18:00:19 2009
@@ -2469,7 +2469,8 @@
   // 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.

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=67489&r1=67488&r2=67489&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Mar 22 18:00:19 2009
@@ -932,15 +932,14 @@
     // 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.

Modified: cfe/trunk/test/Sema/block-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-literal.c?rev=67489&r1=67488&r2=67489&view=diff

==============================================================================
--- cfe/trunk/test/Sema/block-literal.c (original)
+++ cfe/trunk/test/Sema/block-literal.c Sun Mar 22 18:00:19 2009
@@ -39,7 +39,7 @@
 	}
 
 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 myfunc(int (^block)(int)) {}
 
-void myfunc3(int *x);
+void myfunc3(const int *x);
 
 void test5() {
     int a;





More information about the cfe-commits mailing list