[cfe-commits] r69670 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmt.cpp test/Parser/objc-try-catch-1.m test/SemaObjC/synchronized.m test/SemaObjC/try-catch.m

Chris Lattner sabre at nondot.org
Mon Apr 20 23:11:25 PDT 2009


Author: lattner
Date: Tue Apr 21 01:11:25 2009
New Revision: 69670

URL: http://llvm.org/viewvc/llvm-project?rev=69670&view=rev
Log:
implement semantic analysis for @synchronized, fixing a crash on invalid
rdar://6810940 - @synchronized has no sema checks

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Parser/objc-try-catch-1.m
    cfe/trunk/test/SemaObjC/synchronized.m
    cfe/trunk/test/SemaObjC/try-catch.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=69670&r1=69669&r2=69670&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 21 01:11:25 2009
@@ -1079,7 +1079,9 @@
   "casting it to 'id'">;
 def err_bad_receiver_type : Error<"bad receiver type %0">;
 def error_objc_throw_expects_object : Error<
-  "invalid %0 argument (expected an ObjC object type)">;
+  "@throw requires an Objective-C object type (%0 invalid)">;
+def error_objc_synchronized_expects_object : Error<
+  "@synchronized requires an Objective-C object type (%0 invalid)">;
 def error_rethrow_used_outside_catch : Error<
   "@throw (rethrow) used outside of a @catch block">;
 def err_attribute_multiple_objc_gc : Error<

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Apr 21 01:11:25 2009
@@ -1092,6 +1092,15 @@
                                   StmtArg SynchBody) {
   CurFunctionNeedsScopeChecking = true;
 
+  // Make sure the expression type is an ObjC pointer or "void *".
+  Expr *SyncExpr = static_cast<Expr*>(SynchExpr.get());
+  if (!Context.isObjCObjectPointerType(SyncExpr->getType())) {
+    const PointerType *PT = SyncExpr->getType()->getAsPointerType();
+    if (!PT || !PT->getPointeeType()->isVoidType())
+      return StmtError(Diag(AtLoc, diag::error_objc_synchronized_expects_object)
+                       << SyncExpr->getType() << SyncExpr->getSourceRange());
+  }
+  
   return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc,
                      static_cast<Stmt*>(SynchExpr.release()),
                      static_cast<Stmt*>(SynchBody.release())));

Modified: cfe/trunk/test/Parser/objc-try-catch-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-try-catch-1.m?rev=69670&r1=69669&r2=69670&view=diff

==============================================================================
--- cfe/trunk/test/Parser/objc-try-catch-1.m (original)
+++ cfe/trunk/test/Parser/objc-try-catch-1.m Tue Apr 21 01:11:25 2009
@@ -27,7 +27,10 @@
       return proc();
     }
     @catch (Frob* ex) {
-      @throw 1,2; // expected-error {{invalid 'int' argument (expected an ObjC object type)}}
+      @throw 1,2; // expected-error {{@throw requires an Objective-C object type ('int' invalid)}}
+    }
+    @catch (float x) {  // expected-error {{@catch parameter is not a pointer to an interface type}}
+      
     }
     @catch(...) {
       @throw (4,3,proc());

Modified: cfe/trunk/test/SemaObjC/synchronized.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/synchronized.m?rev=69670&r1=69669&r2=69670&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/synchronized.m (original)
+++ cfe/trunk/test/SemaObjC/synchronized.m Tue Apr 21 01:11:25 2009
@@ -1,75 +1,23 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-typedef signed char BOOL;
-typedef unsigned int NSUInteger;
-typedef struct _NSZone NSZone;
- at class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
 
- at protocol NSObject
-- (BOOL)isEqual:(id)object;
- at end
-
- at protocol NSCopying
-- (id)copyWithZone:(NSZone *)zone;
- at end
-
- at protocol NSMutableCopying
-- (id)mutableCopyWithZone:(NSZone *)zone;
- at end
-
- at protocol NSCoding
-- (void)encodeWithCoder:(NSCoder *)aCoder;
- at end
-
- at interface NSObject <NSObject> {} @end
-
-typedef float CGFloat;
-typedef struct { int a; } NSFastEnumerationState;
-
- at protocol NSFastEnumeration 
-- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
- at end
-
-typedef unsigned short unichar;
-
- at interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
-- (NSUInteger)length;
- at end
-
- at interface NSSimpleCString : NSString {} @end
-
- at interface NSConstantString : NSSimpleCString @end
-
-extern void *_NSConstantStringClassReference;
-
- at interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
-- (NSUInteger)count;
- at end
-
- at interface NSMutableDictionary : NSDictionary
-- (void)removeObjectForKey:(id)aKey;
- at end
-
- at class NSArray, NSSet, NSHashTable;
-
- at protocol PBXTrackableTask <NSObject>
-- (float) taskPercentComplete;
-- taskIdentifier;
- at end
-
- at interface PBXTrackableTaskManager : NSObject {
-  NSMutableDictionary *_trackableTasks;
-}
- at end
-
-NSString *XCExecutableDebugTaskIdentifier = @"XCExecutableDebugTaskIdentifier";
+ at class PBXTrackableTaskManager;
 
 @implementation PBXTrackableTaskManager
 - (id) init {}
-- (void) unregisterTask:(id <PBXTrackableTask>) task {
+- (void) unregisterTask:(id) task {
   @synchronized (self) {
-  id taskID = [task taskIdentifier];
-  id task = [_trackableTasks objectForKey:taskID]; // expected-warning{{method '-objectForKey:' not found (return type defaults to 'id')}}
+  id taskID = [task taskIdentifier];  // expected-warning {{method '-taskIdentifier' not found (return type defaults to 'id')}}
   }
 }
 @end
 
+
+struct x { int a; } b;
+
+void test1() {
+  @synchronized (b) {  // expected-error {{@synchronized requires an Objective-C object type ('struct x' invalid)}}
+  }
+
+  @synchronized (42) {  // expected-error {{@synchronized requires an Objective-C object type ('int' invalid)}}
+  }
+}

Modified: cfe/trunk/test/SemaObjC/try-catch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/try-catch.m?rev=69670&r1=69669&r2=69670&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/try-catch.m (original)
+++ cfe/trunk/test/SemaObjC/try-catch.m Tue Apr 21 01:11:25 2009
@@ -40,8 +40,8 @@
 int foo() {
   struct s { int a, b; } agg, *pagg;
 
-  @throw 42; // expected-error {{invalid 'int' argument (expected an ObjC object type)}}
-  @throw agg; // expected-error {{invalid 'struct s' argument (expected an ObjC object type)}}
-  @throw pagg; // expected-error {{invalid 'struct s *' argument (expected an ObjC object type)}}
+  @throw 42; // expected-error {{@throw requires an Objective-C object type ('int' invalid))}}
+  @throw agg; // expected-error {{@throw requires an Objective-C object type ('struct s' invalid)}}
+  @throw pagg; // expected-error {{@throw requires an Objective-C object type ('struct s *' invalid)}}
   @throw; // expected-error {{@throw (rethrow) used outside of a @catch block}}
 }





More information about the cfe-commits mailing list