[cfe-commits] r128324 - in /cfe/trunk: lib/Sema/SemaType.cpp test/SemaObjC/weak-attr-ivar.m

John McCall rjmccall at apple.com
Fri Mar 25 18:39:56 PDT 2011


Author: rjmccall
Date: Fri Mar 25 20:39:56 2011
New Revision: 128324

URL: http://llvm.org/viewvc/llvm-project?rev=128324&view=rev
Log:
Properly move attributes to the decl spec when applying them there.


Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaObjC/weak-attr-ivar.m

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=128324&r1=128323&r2=128324&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Mar 25 20:39:56 2011
@@ -138,6 +138,9 @@
     /// Whether there are non-trivial modifications to the decl spec.
     bool trivial;
 
+    /// Whether we saved the attributes in the decl spec.
+    bool hasSavedAttrs;
+
     /// The original set of attributes on the DeclSpec.
     llvm::SmallVector<AttributeList*, 2> savedAttrs;
 
@@ -149,7 +152,7 @@
     TypeProcessingState(Sema &sema, Declarator &declarator)
       : sema(sema), declarator(declarator),
         chunkIndex(declarator.getNumTypeObjects()),
-        trivial(true) {}
+        trivial(true), hasSavedAttrs(false) {}
 
     Sema &getSema() const {
       return sema;
@@ -178,13 +181,14 @@
     /// Save the current set of attributes on the DeclSpec.
     void saveDeclSpecAttrs() {
       // Don't try to save them multiple times.
-      if (!savedAttrs.empty()) return;
+      if (hasSavedAttrs) return;
 
       DeclSpec &spec = getMutableDeclSpec();
       for (AttributeList *attr = spec.getAttributes().getList(); attr;
              attr = attr->getNext())
         savedAttrs.push_back(attr);
       trivial &= savedAttrs.empty();
+      hasSavedAttrs = true;
     }
 
     /// Record that we had nowhere to put the given type attribute.
@@ -214,7 +218,13 @@
     }
 
     void restoreDeclSpecAttrs() {
-      assert(!savedAttrs.empty());
+      assert(hasSavedAttrs);
+
+      if (savedAttrs.empty()) {
+        getMutableDeclSpec().getAttributes().set(0);
+        return;
+      }
+
       getMutableDeclSpec().getAttributes().set(savedAttrs[0]);
       for (unsigned i = 0, e = savedAttrs.size() - 1; i != e; ++i)
         savedAttrs[i]->setNext(savedAttrs[i+1]);
@@ -360,8 +370,15 @@
   // That might actually be the decl spec if we weren't blocked by
   // anything in the declarator.
   if (considerDeclSpec) {
-    if (handleObjCPointerTypeAttr(state, attr, declSpecType))
+    if (handleObjCPointerTypeAttr(state, attr, declSpecType)) {
+      // Splice the attribute into the decl spec.  Prevents the
+      // attribute from being applied multiple times and gives
+      // the source-location-filler something to work with.
+      state.saveDeclSpecAttrs();
+      moveAttrFromListToList(attr, declarator.getAttrListRef(),
+               declarator.getMutableDeclSpec().getAttributes().getListRef());
       return;
+    }
   }
 
   // Otherwise, if we found an appropriate chunk, splice the attribute

Modified: cfe/trunk/test/SemaObjC/weak-attr-ivar.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/weak-attr-ivar.m?rev=128324&r1=128323&r2=128324&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/weak-attr-ivar.m (original)
+++ cfe/trunk/test/SemaObjC/weak-attr-ivar.m Fri Mar 25 20:39:56 2011
@@ -72,3 +72,13 @@
 }
 @end
 
+// rdar://problem/9123040
+ at interface Test1 {
+ at public
+  id ivar __attribute__((objc_gc(weak)));
+}
+ at property (assign) id prop __attribute((objc_gc(weak)));
+ at end
+void test1(Test1 *t) {
+  id *(__attribute__((objc_gc(strong))) x) = &t->ivar; // expected-warning {{initializing '__strong id *' with an expression of type '__weak id *' discards qualifiers}}
+}





More information about the cfe-commits mailing list