[cfe-commits] r149074 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaType.cpp test/SemaObjC/arc-decls.m

John McCall rjmccall at apple.com
Thu Jan 26 12:04:03 PST 2012


Author: rjmccall
Date: Thu Jan 26 14:04:03 2012
New Revision: 149074

URL: http://llvm.org/viewvc/llvm-project?rev=149074&view=rev
Log:
Don't suppress access-control or invalid-type diagnostics from a
declarator just because we were able to build an invalid decl
for it.  The invalid-type diagnostics, in particular, are still useful
to know, and may indicate something about why the decl is invalid.

Also, recover from an illegal pointer/reference-to-unqualified-retainable
type using __strong instead of __autoreleasing;  in general, a random
object is much more likely to be __strong, so this avoids unnecessary
cascading errors in the most common case.

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaObjC/arc-decls.m

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=149074&r1=149073&r2=149074&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Jan 26 14:04:03 2012
@@ -4033,7 +4033,7 @@
 
   // We only want to actually emit delayed diagnostics when we
   // successfully parsed a decl.
-  if (decl && !decl->isInvalidDecl()) {
+  if (decl) {
     // We emit all the active diagnostics, not just those starting
     // from the saved state.  The idea is this:  we get one push for a
     // decl spec and another for each declarator;  in a decl group like:
@@ -4048,7 +4048,9 @@
 
       switch (diag.Kind) {
       case DelayedDiagnostic::Deprecation:
-        S.HandleDelayedDeprecationCheck(diag, decl);
+        // Don't bother giving deprecation diagnostics if the decl is invalid.
+        if (!decl->isInvalidDecl())
+          S.HandleDelayedDeprecationCheck(diag, decl);
         break;
 
       case DelayedDiagnostic::Access:

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=149074&r1=149073&r2=149074&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Jan 26 14:04:03 2012
@@ -1062,7 +1062,9 @@
   } else if (S.ExprEvalContexts.back().Context == Sema::Unevaluated) {
     return type;
 
-  // If that failed, give an error and recover using __autoreleasing.
+  // If that failed, give an error and recover using __strong.  __strong
+  // is the option most likely to prevent spurious second-order diagnostics,
+  // like when binding a reference to a field.
   } else {
     // These types can show up in private ivars in system headers, so
     // we need this to not be an error in those cases.  Instead we
@@ -1074,7 +1076,7 @@
     } else {
       S.Diag(loc, diag::err_arc_indirect_no_ownership) << type << isReference;
     }
-    implicitLifetime = Qualifiers::OCL_Autoreleasing;
+    implicitLifetime = Qualifiers::OCL_Strong;
   }
   assert(implicitLifetime && "didn't infer any lifetime!");
 

Modified: cfe/trunk/test/SemaObjC/arc-decls.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-decls.m?rev=149074&r1=149073&r2=149074&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-decls.m (original)
+++ cfe/trunk/test/SemaObjC/arc-decls.m Thu Jan 26 14:04:03 2012
@@ -86,3 +86,14 @@
 - (id)not_ret:(id) b __attribute((ns_returns_retained)); // expected-error {{overriding method has mismatched ns_returns_retained attributes}}
 - (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained));
 @end
+
+// Test that we give a good diagnostic here that mentions the missing
+// ownership qualifier.  We don't want this to get suppressed because
+// of an invalid conversion.
+void test7(void) {
+  id x;
+  id *px = &x; // expected-error {{pointer to non-const type 'id' with no explicit ownership}}
+
+  I *y;
+  J **py = &y; // expected-error {{pointer to non-const type 'J *' with no explicit ownership}} expected-warning {{incompatible pointer types initializing}}
+}





More information about the cfe-commits mailing list