]> granicus.if.org Git - clang/commitdiff
Introduce ObjCRuntime::hasWeakClassImport() and use it in the appropriate
authorJohn McCall <rjmccall@apple.com>
Wed, 20 Jun 2012 21:58:02 +0000 (21:58 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 20 Jun 2012 21:58:02 +0000 (21:58 +0000)
places.  I've turned this off for the GNU runtimes --- I don't know if
they support weak class import, but it's easy enough for them to opt in.

Also tweak a comment per review by Jordan.

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

include/clang/Basic/ObjCRuntime.h
lib/AST/DeclBase.cpp
lib/Basic/ObjCRuntime.cpp
lib/Lex/PPMacroExpansion.cpp

index b87632ff6adc80f6a25a6130885e8d782adea667..a1024c4a585ecc35d4df659dc115a63e3b28a391 100644 (file)
@@ -160,6 +160,18 @@ public:
     llvm_unreachable("bad kind");
   }
 
+  /// Does this runtime support weakly importing classes?
+  bool hasWeakClassImport() const {
+    switch (getKind()) {
+    case MacOSX: return true;
+    case iOS: return true;
+    case FragileMacOSX: return false;
+    case FragileGNU: return false;
+    case GNU: return false;
+    }
+    llvm_unreachable("bad kind");
+  }
+
   /// Try to parse an Objective-C runtime specification from the given string.
   ///
   /// Return true on error.
index 7d7209370049c88a27fbe99d777ebba47c27d684..574f779b86c9d3ca7986cc70fa79140f0f02c400 100644 (file)
@@ -430,7 +430,7 @@ bool Decl::canBeWeakImported(bool &IsDefinition) const {
 
   // Objective-C classes, if this is the non-fragile runtime.
   } else if (isa<ObjCInterfaceDecl>(this) &&
-             getASTContext().getLangOpts().ObjCRuntime.isNonFragile()) {
+             getASTContext().getLangOpts().ObjCRuntime.hasWeakClassImport()) {
     return true;
 
   // Nothing else.
index d92adbcb4612d425fc07344c5246127510f1ee45..d66da0706f36c0d9ca9e660daf34eb4c8c7f2221 100644 (file)
@@ -43,8 +43,9 @@ bool ObjCRuntime::tryParse(StringRef input) {
   // Look for the last dash.
   std::size_t dash = input.rfind('-');
 
-  // We permit (1) dashes in the runtime name and (2) the version to
-  // be omitted, so ignore dashes that aren't followed by a digit.
+  // We permit dashes in the runtime name, and we also permit the
+  // version to be omitted, so if we see a dash not followed by a
+  // digit then we need to ignore it.
   if (dash != StringRef::npos && dash + 1 != input.size() &&
       (input[dash+1] < '0' || input[dash+1] > '9')) {
     dash = StringRef::npos;
index 826fa03621c4b0fd9b7e35a2c9ce1e889835224a..a5337867b1b3dffa78b00cb18b90c6fe2b25fb5f 100644 (file)
@@ -644,7 +644,7 @@ static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) {
            .Case("objc_instancetype", LangOpts.ObjC2)
            .Case("objc_modules", LangOpts.ObjC2 && LangOpts.Modules)
            .Case("objc_nonfragile_abi", LangOpts.ObjCRuntime.isNonFragile())
-           .Case("objc_weak_class", LangOpts.ObjCRuntime.isNonFragile())
+           .Case("objc_weak_class", LangOpts.ObjCRuntime.hasWeakClassImport())
            .Case("ownership_holds", true)
            .Case("ownership_returns", true)
            .Case("ownership_takes", true)