From: Steve Naroff Date: Tue, 6 May 2008 18:26:51 +0000 (+0000) Subject: Fix clang ObjC Rewriter: Protocol structure defined twice... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fbfe82527dadb09c95609a742744d75a2322850c;p=clang Fix clang ObjC Rewriter: Protocol structure defined twice when two interfaces use it in same file git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50767 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp index 8cf98a1643..66f98a41c5 100644 --- a/Driver/RewriteObjC.cpp +++ b/Driver/RewriteObjC.cpp @@ -50,6 +50,7 @@ namespace { llvm::SmallVector ClassImplementation; llvm::SmallVector CategoryImplementation; llvm::SmallPtrSet ObjCSynthesizedStructs; + llvm::SmallPtrSet ObjCSynthesizedProtocols; llvm::SmallPtrSet ObjCForwardDecls; llvm::DenseMap MethodInternalNames; llvm::SmallVector Stmts; @@ -2299,7 +2300,7 @@ void RewriteObjC::SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl, } // Mark this struct as having been generated. if (!ObjCSynthesizedStructs.insert(CDecl)) - assert(false && "struct already synthesize- SynthesizeObjCInternalStruct"); + assert(false && "struct already synthesize- SynthesizeObjCInternalStruct"); } // RewriteObjCMethodsMetaData - Rewrite methods metadata for instance or @@ -2399,6 +2400,10 @@ void RewriteObjC::RewriteObjCProtocolsMetaData(ObjCProtocolDecl **Protocols, objc_protocol_methods = true; } + // Do not synthesize the protocol more than once. + if (ObjCSynthesizedProtocols.count(PDecl)) + continue; + if (PDecl->instmeth_begin() != PDecl->instmeth_end()) { unsigned NumMethods = PDecl->getNumInstanceMethods(); /* struct _objc_protocol_method_list { @@ -2467,6 +2472,7 @@ void RewriteObjC::RewriteObjCProtocolsMetaData(ObjCProtocolDecl **Protocols, } Result += "\t }\n};\n"; } + // Output: /* struct _objc_protocol { // Objective-C 1.0 extensions @@ -2511,6 +2517,10 @@ void RewriteObjC::RewriteObjCProtocolsMetaData(ObjCProtocolDecl **Protocols, else Result += "0\n"; Result += "};\n"; + + // Mark this protocol as having been generated. + if (!ObjCSynthesizedProtocols.insert(PDecl)) + assert(false && "protocol already synthesized"); } // Output the top lovel protocol meta-data for the class. /* struct _objc_protocol_list {