<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Rafael<div class=""><br class=""></div><div class="">Sorry for a separate (and late) email since I don’t have the email back to March. And sorry for sending it again since I used the wrong email address for the previous and gets rejected by cfe-commit.</div><div class="">I found a problem compiling ObjC recently and I can only trace to the change in this patch.</div><div class="">This patch is indeed a functional change when coming to protocols that are forward declared and implemented in other files (which now generates a warning but not back then).</div><div class="">Originally, the codegen uses a deal with this case by initialize all dependent protocols to ExternalLinkage and change the linkage back when these protocols get processed.</div><div class="">For the external and forward-declared protocols will not get processed and remained ExternalLinkage.</div><div class="">Here is a testcase:</div><div class=""><br class=""></div><div class=""> @interface NSObject @end<br class=""> <br class=""> @protocol p1;<br class=""> <br class=""> @protocol p2 <p1><br class=""> <br class=""> - (void)s1;<br class=""> <br class=""> @end<br class=""> <br class=""> @interface I1 : NSObject <p2><br class=""> <br class=""> - (void)s2;<br class=""> @end<br class=""> <br class=""> @implementation I1<br class=""> <br class=""> - (void)s1 {<br class="">       NSLog(@"s1");<br class=""> }<br class=""> - (void)s2 {<br class="">       NSLog(@"s2");<br class=""> }<br class=""> @end<br class=""> </div><div class="">I am not familiar with ObjC standard so I am not sure if this is 100% legal but this patch causes the compiler fatal error.</div><div class="">Steven</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><pre class="" style="white-space: pre-wrap; background-color: rgb(255, 255, 255);"></pre><blockquote type="cite" class=""><pre class="" style="white-space: pre-wrap; background-color: rgb(255, 255, 255);">Author: rafael
Date: Wed Mar  5 19:10:46 2014
New Revision: 203052

URL: <a href="http://llvm.org/viewvc/llvm-project?rev=203052&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=203052&view=rev</a>
Log:
Construct GlobalValues with the correct linkage instead of using setLinkage.

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=203052&r1=203051&r2=203052&view=diff" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=203052&r1=203051&r2=203052&view=diff</a>
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Mar  5 19:10:46 2014
@@ -2660,8 +2660,8 @@ llvm::Constant *CGObjCMac::GetOrEmitProt
                                                    Values);
 
   if (Entry) {
-    // Already created, fix the linkage and update the initializer.
-    Entry->setLinkage(llvm::GlobalValue::PrivateLinkage);
+    // Already created, update the initializer.
+    assert(Entry->getLinkage() == llvm::GlobalValue::PrivateLinkage);
     Entry->setInitializer(Init);
   } else {
     Entry =
@@ -6242,10 +6242,9 @@ llvm::Constant *CGObjCNonFragileABIMac::
     // reference or not. At module finalization we add the empty
     // contents for protocols which were referenced but never defined.
     Entry =
-      new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABITy, false,
-                               llvm::GlobalValue::ExternalLinkage,
-                               0,
-                               "\01l_OBJC_PROTOCOL_$_" + PD->getName());
+        new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABITy,
+                                 false, llvm::GlobalValue::WeakAnyLinkage, 0,
+                                 "\01l_OBJC_PROTOCOL_$_" + PD->getName());
     Entry->setSection("__DATA,__datacoal_nt,coalesced");
   }
 
@@ -6358,8 +6357,8 @@ llvm::Constant *CGObjCNonFragileABIMac::
                                                    Values);
 
   if (Entry) {
-    // Already created, fix the linkage and update the initializer.
-    Entry->setLinkage(llvm::GlobalValue::WeakAnyLinkage);
+    // Already created, update the initializer.
+    assert(Entry->getLinkage() == llvm::GlobalValue::WeakAnyLinkage);
     Entry->setInitializer(Init);
   } else {
     Entry =</pre></blockquote></div><div class=""><br class=""></div></body></html>