<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Aug 24, 2018, at 7:28 PM, Manoj Gupta <<a href="mailto:manojgupta@google.com" class="">manojgupta@google.com</a>> wrote:</div><div class=""><div dir="ltr" class=""><div class="">Thanks everyone,</div><div class=""><br class=""></div><div class="">I have a simple patch to fix the crash but what I don't know if the patch makes sense. </div><div class=""> 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 class="">that "__CFConstantStringClassReference" should be an unsized array if declared by user code?</div></div></div></blockquote><div><br class=""></div>The type of __CFConstantStringClassReference in user code shouldn't matter. User code is under no obligation to make it match anything.</div><div><br class=""></div><div>IRGen should just leave the declaration alone if it already exists.</div><div><br class=""></div><div>John.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">--- a/clang/lib/CodeGen/CodeGenModule.cpp</div><div class="">+++ b/clang/lib/CodeGen/CodeGenModule.cpp</div><div class="">@@ -4068,8 +4068,13 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {</div><div class=""> if (!CFConstantStringClassRef) {</div><div class=""> llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy);</div><div class=""> Ty = llvm::ArrayType::get(Ty, 0); </div><div class="">- llvm::GlobalValue *GV = cast<llvm::GlobalValue>(</div><div class="">- CreateRuntimeVariable(Ty, "__CFConstantStringClassReference"));</div><div class="">+ const std::string CFStringRef = "__CFConstantStringClassReference";</div><div class="">+ llvm::GlobalValue *GV = GetGlobalValue(CFStringRef);</div><div class="">+ if (!GV)</div><div class="">+ GV = cast<llvm::GlobalValue>(</div><div class="">+ CreateRuntimeVariable(Ty, CFStringRef)); // Ty is [0 x intTy ] when created by clang.</div><div class="">+ else</div><div class="">+ Ty = GV->getValueType(); // Ok to use the user defined type? Ty = [12 x i32] for this case.</div><div class=""> </div><div class=""> if (getTriple().isOSBinFormatCOFF()) {</div><div class=""> IdentifierInfo &II = getContext().Idents.get(GV->getName());</div><div class=""><br class=""></div><div class="">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 class="">e.g. Clang will still crash if the code following Ty does not match the expected type (array of int). </div><div class=""><br class=""></div><div class="">Is it enough to check if the user defined type is of [ N x intTy] type. </div><div class="">In this particular case, I see the type as a sizedarray even though no size was provided by user code:</div><div class=""> _CFConstantStringClassReference = global [12 x i32] zeroinitializer </div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Manoj</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, Aug 24, 2018 at 4:22 PM John McCall <<a href="mailto:rjmccall@apple.com" class="">rjmccall@apple.com</a>> wrote:<br class=""></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" class=""><div class=""><blockquote type="cite" class=""><div class="">On Aug 24, 2018, at 5:17 PM, Richard Smith via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="m_4680501780240283875Apple-interchange-newline"><div class=""><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" class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, 21 Aug 2018 at 17:09, Manoj Gupta via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a>> wrote:<br class=""></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" class="">Hi,<div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Crash location:</div><div class=""><div class=""><a href="https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CodeGenModule.cpp#L4058" target="_blank" class="">https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CodeGenModule.cpp#L4058</a></div><div class=""><br class=""></div><div class=""><div class=""> <span class="m_4680501780240283875Apple-converted-space"> </span>// If we don't already have it, get __CFConstantStringClassReference.</div><div class=""> <span class="m_4680501780240283875Apple-converted-space"> </span>if (!CFConstantStringClassRef) {</div><div class=""> <span class="m_4680501780240283875Apple-converted-space"> </span>llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy);</div><div class=""> <span class="m_4680501780240283875Apple-converted-space"> </span>Ty = llvm::ArrayType::get(Ty, 0);</div><div class=""> <span class="m_4680501780240283875Apple-converted-space"> </span>llvm::GlobalValue *GV = cast<llvm::GlobalValue>(</div><div class=""> <span class="m_4680501780240283875Apple-converted-space"> </span>CreateRuntimeVariable(Ty, "__CFConstantStringClassReference")); // Crashes here</div></div></div><div class=""><br class=""></div><div class="">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" class="">https://github.com/nevali/opencflite/blob/03999700cf3b79975ae2f2e5f4100ea7096acb3a/CFInternal.h#L364</a><span class="m_4680501780240283875Apple-converted-space"> </span>:</div><div class=""><br class=""></div><div class="">extern int __CFConstantStringClassReference[];</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></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 class=""><br class=""></div><div class="">John.</div><div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><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" class=""><div class="gmail_quote"><div class=""> </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" class=""><div class="">If so, appreciate any advice on how to fix the offending code. </div><div class=""><br class=""></div><div class="">Or is this a bug in clang?<br class=""></div><div class=""><br class=""></div><div class="">For reference, r327993 (<a href="https://reviews.llvm.org/rL327993" target="_blank" class="">https://reviews.llvm.org/rL327993</a>) introduced this code.</div><div class=""><div class=""><br class=""></div><div class="">Author: Rafael Espindola <<a href="mailto:rafael.espindola@gmail.com" target="_blank" class="">rafael.espindola@gmail.com</a>><br class=""></div><div class="">AuthorDate: Tue Mar 20 15:48:00 2018 +0000</div><div class=""><br class=""></div><div class=""> <span class="m_4680501780240283875Apple-converted-space"> </span>Set dso_local for CFConstantStringClassReference.</div><div class=""> </div><div class=""> <span class="m_4680501780240283875Apple-converted-space"> </span>This one cannot use setGVProperties since it has special logic for</div><div class=""> <span class="m_4680501780240283875Apple-converted-space"> </span>when it is dllimport or not.</div></div><div class=""><div class=""> <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" class="">https://llvm.org/svn/llvm-project/cfe/trunk@</a><b class="">327993</b><span class="m_4680501780240283875Apple-converted-space"> </span>91177308-0d34-0410-b5e6-96231b3b80d8</div></div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Manoj</div></div>_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class=""></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" class="">_______________________________________________</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" class=""><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" class="">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" class=""><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" class="">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" class=""><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" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a></div></blockquote></div><br class=""></div></blockquote></div>
</div></blockquote></div><br class=""></body></html>