]> granicus.if.org Git - clang/commitdiff
Fix undefined behavior: don't call ObjCInterfaceDecl::isArcWeakrefUnavailable
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 23 Aug 2012 04:53:18 +0000 (04:53 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 23 Aug 2012 04:53:18 +0000 (04:53 +0000)
on a null pointer. (This function happens to work for a null 'this' pointer, so
no test.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162427 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp

index 3e72c2d06f9ab4dd4e984732060fe9761bee7d84..94ddc239cdf85290350939c3948cb315762ce8fc 100644 (file)
@@ -3611,11 +3611,12 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
     while (const PointerType *ptr = T->getAs<PointerType>())
       T = ptr->getPointeeType();
     if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) {
-      ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl();
-      if (Class->isArcWeakrefUnavailable()) {
-          S.Diag(AttrLoc, diag::err_arc_unsupported_weak_class);
-          S.Diag(ObjT->getInterfaceDecl()->getLocation(),
-                 diag::note_class_declared);
+      if (ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl()) {
+        if (Class->isArcWeakrefUnavailable()) {
+            S.Diag(AttrLoc, diag::err_arc_unsupported_weak_class);
+            S.Diag(ObjT->getInterfaceDecl()->getLocation(),
+                   diag::note_class_declared);
+        }
       }
     }
   }