[cfe-commits] r144520 - in /cfe/trunk: include/clang/AST/ASTMutationListener.h include/clang/Serialization/ASTWriter.h lib/Sema/SemaObjCProperty.cpp lib/Serialization/ASTWriter.cpp test/PCH/chain-categories2.m

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Nov 13 20:52:29 PST 2011


Author: akirtzidis
Date: Sun Nov 13 22:52:29 2011
New Revision: 144520

URL: http://llvm.org/viewvc/llvm-project?rev=144520&view=rev
Log:
[PCH] Do not crash if a class extension in a chained PCH introduces/redeclares a property.

Modified:
    cfe/trunk/include/clang/AST/ASTMutationListener.h
    cfe/trunk/include/clang/Serialization/ASTWriter.h
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp
    cfe/trunk/test/PCH/chain-categories2.m

Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTMutationListener.h?rev=144520&r1=144519&r2=144520&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTMutationListener.h (original)
+++ cfe/trunk/include/clang/AST/ASTMutationListener.h Sun Nov 13 22:52:29 2011
@@ -25,6 +25,7 @@
   class ObjCCategoryDecl;
   class ObjCInterfaceDecl;
   class ObjCContainerDecl;
+  class ObjCPropertyDecl;
 
 /// \brief An abstract interface that should be implemented by listeners
 /// that want to be notified when an AST entity gets modified after its
@@ -65,6 +66,18 @@
   /// \brief A objc interface or protocol forward reference was completed.
   virtual void CompletedObjCForwardRef(const ObjCContainerDecl *D) {}
 
+  /// \brief A objc class extension redeclared or introduced a property.
+  ///
+  /// \param Prop the property in the class extension
+  ///
+  /// \param OrigProp the property from the original interface that was declared
+  /// or null if the property was introduced.
+  ///
+  /// \param ClassExt the class extension.
+  virtual void AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop,
+                                            const ObjCPropertyDecl *OrigProp,
+                                            const ObjCCategoryDecl *ClassExt) {}
+
   /// \brief The attributes list of a declaration was updated.
   virtual void UpdatedAttributeList(const Decl *D) {}
 };

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=144520&r1=144519&r2=144520&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Sun Nov 13 22:52:29 2011
@@ -661,6 +661,9 @@
   virtual void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
                                             const ObjCInterfaceDecl *IFD);
   virtual void CompletedObjCForwardRef(const ObjCContainerDecl *D);
+  virtual void AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop,
+                                            const ObjCPropertyDecl *OrigProp,
+                                            const ObjCCategoryDecl *ClassExt);
   virtual void UpdatedAttributeList(const Decl *D);
 };
 

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=144520&r1=144519&r2=144520&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Sun Nov 13 22:52:29 2011
@@ -17,6 +17,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/ASTMutationListener.h"
 #include "llvm/ADT/DenseSet.h"
 
 using namespace clang;
@@ -271,6 +272,8 @@
     // Make sure setter/getters are declared here.
     ProcessPropertyDecl(PDecl, CCPrimary, /* redeclaredProperty = */ 0,
                         /* lexicalDC = */ CDecl);
+    if (ASTMutationListener *L = Context.getASTMutationListener())
+      L->AddedObjCPropertyInClassExtension(PDecl, /*OrigProp=*/0, CDecl);
     return PDecl;
   }
   if (PIDecl->getType().getCanonicalType() 
@@ -343,6 +346,8 @@
   *isOverridingProperty = true;
   // Make sure setter decl is synthesized, and added to primary class's list.
   ProcessPropertyDecl(PIDecl, CCPrimary, PDecl, CDecl);
+  if (ASTMutationListener *L = Context.getASTMutationListener())
+    L->AddedObjCPropertyInClassExtension(PDecl, PIDecl, CDecl);
   return 0;
 }
 

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=144520&r1=144519&r2=144520&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Sun Nov 13 22:52:29 2011
@@ -4130,6 +4130,20 @@
   RewriteDecl(D);
 }
 
+void ASTWriter::AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop,
+                                          const ObjCPropertyDecl *OrigProp,
+                                          const ObjCCategoryDecl *ClassExt) {
+  const ObjCInterfaceDecl *D = ClassExt->getClassInterface();
+  if (!D)
+    return;
+
+  assert(!WritingAST && "Already writing the AST!");
+  if (!D->isFromASTFile())
+    return; // Declaration not imported from PCH.
+
+  RewriteDecl(D);
+}
+
 void ASTWriter::UpdatedAttributeList(const Decl *D) {
   assert(!WritingAST && "Already writing the AST!");
   if (!D->isFromASTFile())

Modified: cfe/trunk/test/PCH/chain-categories2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-categories2.m?rev=144520&r1=144519&r2=144520&view=diff
==============================================================================
--- cfe/trunk/test/PCH/chain-categories2.m (original)
+++ cfe/trunk/test/PCH/chain-categories2.m Sun Nov 13 22:52:29 2011
@@ -13,6 +13,10 @@
 
 @class I;
 
+ at interface I2
+ at property (readonly) id prop1;
+ at end
+
 //===----------------------------------------------------------------------===//
 #elif !defined(HEADER2)
 #define HEADER2
@@ -32,6 +36,11 @@
 @interface I(Cat2)
 @end
 
+ at interface I2()
+ at property (readwrite,assign) id prop1;
+ at property (copy) id prop2;
+ at end
+
 //===----------------------------------------------------------------------===//
 #else
 //===----------------------------------------------------------------------===//
@@ -40,5 +49,9 @@
   [i meth]; // expected-warning {{not found}}
 }
 
+ at implementation I2
+ at synthesize prop1, prop2;
+ at end
+
 //===----------------------------------------------------------------------===//
 #endif





More information about the cfe-commits mailing list