<div dir="ltr"><div>Thanks everyone,</div><div><br></div><div>I have a simple patch to fix the crash but what I don't know if the patch makes sense. </div><div> I also have no idea what is an _acceptable_ type for "__CFConstantStringClassReference" when declared in user code. Should this be checked somewhere earlier</div><div>that  "__CFConstantStringClassReference" should be an unsized array if declared by user code?</div><div><br></div><div>--- a/clang/lib/CodeGen/CodeGenModule.cpp</div><div>+++ b/clang/lib/CodeGen/CodeGenModule.cpp</div><div>@@ -4068,8 +4068,13 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {</div><div>   if (!CFConstantStringClassRef) {</div><div>     llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy);</div><div>     Ty = llvm::ArrayType::get(Ty, 0); </div><div>-    llvm::GlobalValue *GV = cast<llvm::GlobalValue>(</div><div>-        CreateRuntimeVariable(Ty, "__CFConstantStringClassReference"));</div><div>+    const std::string CFStringRef = "__CFConstantStringClassReference";</div><div>+    llvm::GlobalValue *GV =  GetGlobalValue(CFStringRef);</div><div>+    if (!GV)</div><div>+      GV = cast<llvm::GlobalValue>(</div><div>+          CreateRuntimeVariable(Ty, CFStringRef)); //  Ty is [0 x intTy ] when created by clang.</div><div>+    else</div><div>+      Ty = GV->getValueType();  // Ok to use the user defined type? Ty = [12 x i32] for this case.</div><div> </div><div>     if (getTriple().isOSBinFormatCOFF()) {</div><div>       IdentifierInfo &II = getContext().Idents.get(GV->getName());</div><div><br></div><div>Is it ok to just use the type of user declared variable.  I believe, this is still error prone since it may not match the expected type by the following code or future consumers of this Variable (Linker?). </div><div>e.g. Clang will still crash if the  code following Ty does not match the expected type (array of int). </div><div><br></div><div>Is it enough to check  if the user defined type is of [ N x intTy]  type. </div><div>In this particular case, I see the type as a sizedarray even though no size was provided by user code:</div><div>  _CFConstantStringClassReference = global [12 x i32] zeroinitializer  </div><div><br></div><div>Thanks,</div><div>Manoj</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 24, 2018 at 4:22 PM John McCall <<a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><blockquote type="cite"><div>On Aug 24, 2018, at 5:17 PM, Richard Smith via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="m_4680501780240283875Apple-interchange-newline"><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div class="gmail_quote"><div dir="ltr">On Tue, 21 Aug 2018 at 17:09, Manoj Gupta via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I am looking for some help regarding a clang crash  when building opencflite. The root cause of the crash is because clang tries to create a GlobalValue "__CFConstantStringClassReference"  but a variable of same name is also present in the source file.</div><div><br></div><div>Crash location:</div><div><div><a href="https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CodeGenModule.cpp#L4058" target="_blank">https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CodeGenModule.cpp#L4058</a></div><div><br></div><div><div> <span class="m_4680501780240283875Apple-converted-space"> </span>// If we don't already have it, get __CFConstantStringClassReference.</div><div> <span class="m_4680501780240283875Apple-converted-space"> </span>if (!CFConstantStringClassRef) {</div><div>   <span class="m_4680501780240283875Apple-converted-space"> </span>llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy);</div><div>   <span class="m_4680501780240283875Apple-converted-space"> </span>Ty = llvm::ArrayType::get(Ty, 0);</div><div>   <span class="m_4680501780240283875Apple-converted-space"> </span>llvm::GlobalValue *GV = cast<llvm::GlobalValue>(</div><div>       <span class="m_4680501780240283875Apple-converted-space"> </span>CreateRuntimeVariable(Ty, "__CFConstantStringClassReference")); // Crashes here</div></div></div><div><br></div><div>Opencflite also declares __CFConstantStringClassReference as a variable,<span class="m_4680501780240283875Apple-converted-space"> </span><a href="https://github.com/nevali/opencflite/blob/03999700cf3b79975ae2f2e5f4100ea7096acb3a/CFInternal.h#L364" target="_blank">https://github.com/nevali/opencflite/blob/03999700cf3b79975ae2f2e5f4100ea7096acb3a/CFInternal.h#L364</a><span class="m_4680501780240283875Apple-converted-space"> </span>:</div><div><br></div><div>extern int __CFConstantStringClassReference[];</div><div><br></div><div>I do not know the semantics of the name __CFConstantStringClassReference. Is this a reserved name and should opencflite not be declaring this variable ?</div></div></blockquote><div><br></div><div>Yes, this is a reserved identifier and should generally not be declared by user code. (In this case, though, it looks like the code is attempting to find the variable introduced by Clang, and maybe we want to allow that?) In any case, Clang shouldn't crash :)</div></div></div></div></blockquote><div><br></div>Well, it's supposed to be an external reference to a symbol defined in the Objective-C library.  In this case, I think opencflite is acting as the Objective-C library that defines that symbol, so it's not illegitimate.  I don't know what's different about Apple's library that it doesn't have this problem — maybe it just doesn't have any CF string literals in the equivalent to this file.</div><div><br></div><div>John.</div><div><br></div><div><br><blockquote type="cite"><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>If so, appreciate any advice on how to fix the offending code. </div><div><br></div><div>Or is this a  bug in clang?<br></div><div><br></div><div>For reference, r327993 (<a href="https://reviews.llvm.org/rL327993" target="_blank">https://reviews.llvm.org/rL327993</a>)  introduced this code.</div><div><div><br></div><div>Author:     Rafael Espindola <<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>><br></div><div>AuthorDate: Tue Mar 20 15:48:00 2018 +0000</div><div><br></div><div>   <span class="m_4680501780240283875Apple-converted-space"> </span>Set dso_local for CFConstantStringClassReference.</div><div>    </div><div>   <span class="m_4680501780240283875Apple-converted-space"> </span>This one cannot use setGVProperties since it has special logic for</div><div>   <span class="m_4680501780240283875Apple-converted-space"> </span>when it is dllimport or not.</div></div><div><div>   <span class="m_4680501780240283875Apple-converted-space"> </span>git-svn-id:<span class="m_4680501780240283875Apple-converted-space"> </span><a href="https://llvm.org/svn/llvm-project/cfe/trunk@" target="_blank">https://llvm.org/svn/llvm-project/cfe/trunk@</a><b>327993</b><span class="m_4680501780240283875Apple-converted-space"> </span>91177308-0d34-0410-b5e6-96231b3b80d8</div></div><div><br></div><div>Thanks,</div><div>Manoj</div></div>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br></blockquote></div></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline!important">cfe-dev mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><a href="mailto:cfe-dev@lists.llvm.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">cfe-dev@lists.llvm.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a></div></blockquote></div><br></div></blockquote></div>