<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="">You are right. It is more code to move this into where check is made for <span style="font-family: Menlo; font-size: 11px;" class="">!S.</span><span style="color: rgb(79, 129, 135); font-family: Menlo; font-size: 11px;" class="">NSNumberDecl as </span><span style="font-family: Helvetica, Arial; font-size: 13px;" class="">NSNumberPointer</span><div class=""><font face="Helvetica, Arial" size="2" class="">need be initialized in couple of places. Your patch is fine.</font></div><div class=""><font face="Helvetica, Arial" size="2" class="">- Fariborz</font></div><div class=""><font face="Helvetica, Arial" size="2" class=""><br class=""></font><div class=""><div><blockquote type="cite" class=""><div class="">On Feb 16, 2015, at 11:38 AM, AlexDenisov <<a href="mailto:1101.debian@gmail.com" class="">1101.debian@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">Well, it was there.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">Let’s consider we have this code:</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class="">@class NSNumber;</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">void checkNSNumberFDDiagnostic() {</div><div id="bloop_customfont" style="margin: 0px;" class="">    id num = @1000;</div><div id="bloop_customfont" style="margin: 0px;" class="">}</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">@interface NSNumber</div><div id="bloop_customfont" style="margin: 0px;" class="">+ (NSNumber *)numberWithInt:(int)value;</div><div id="bloop_customfont" style="margin: 0px;" class="">@end</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">int main() {</div><div id="bloop_customfont" style="margin: 0px;" class="">    id num = @1000;</div><div id="bloop_customfont" style="margin: 0px;" class="">}</div><div style="font-family: Helvetica, Arial; font-size: 13px;" class=""><br class=""></div></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">Parser finds first @1000 and tries to create literal expression, S.NSNumberDecl is nil in this case, so it created NSNumberDecl from forward declaration _and_ it fills NSNumberPointer with NULL type and then fails with error, because class NSNumber is not defined.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">Then, is finds second @1000 and tries to create literal, NSNumber is defined now and has numberWithInt method, everything is fine and seems legit. Then it finally attempts to create literal and passes there NULL type (NSNumberPointer), which is cause the crash.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">Maybe I used a wrong place to solve the problem, but it’s the only place that I’ve found.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">I’d appreciate any suggestions how to improve this code.</div><div id="bloop_sign_1424114853921054976" class="bloop_sign" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="font-family: helvetica, arial; font-size: 13px;" class="">-- <br class="">AlexDenisov</div><div style="font-family: helvetica, arial; font-size: 13px;" class="">Software Engineer, <a href="https://github.com/AlexDenisov" class="">https://github.com/AlexDenisov</a></div></div><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><p style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">On 16 Feb 2015 at 20:26:56, jahanian (<a href="mailto:fjahanian@apple.com" class="">fjahanian@apple.com</a>) wrote:</p><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 16, 2015, at 8:17 AM, Alex Denisov <<a href="mailto:1101.debian@gmail.com" class="">1101.debian@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Author: alexdenisov<br class="">Date: Mon Feb 16 10:17:05 2015<br class="">New Revision: 229402<br class=""><br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=229402&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=229402&view=rev</a><br class="">Log:<br class="">Fix crash when clang tries to build NSNumber literal after forward declaration<br class=""><br class="">Bug report:<span class="Apple-converted-space"> </span><a href="http://llvm.org/bugs/show_bug.cgi?id=22561" class="">http://llvm.org/bugs/show_bug.cgi?id=22561</a><br class=""><br class="">Clang tries to create ObjCBoxedExpression of type 'NSNumber'<br class="">when 'NSNumber' has only forward declaration, this cause a crash later,<br class="">when 'Sema' refers to a nil QualType of the whole expression.<br class="">Please, refer to the bug report for the better explanation.<br class=""><br class=""><br class="">Modified:<br class="">   cfe/trunk/lib/Sema/SemaExprObjC.cpp<br class="">   cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m<br class=""><br class="">Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=229402&r1=229401&r2=229402&view=diff" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=229402&r1=229401&r2=229402&view=diff</a><br class="">==============================================================================<br class="">--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)<br class="">+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Feb 16 10:17:05 2015<br class="">@@ -218,7 +218,9 @@ static ObjCMethodDecl *getNSNumberFactor<br class="">      S.Diag(Loc, diag::err_undeclared_nsnumber);<br class="">      return nullptr;<br class="">    }<br class="">-    <br class="">+  }<br class="">+<br class="">+  if (S.NSNumberPointer.isNull()) {<br class=""></div></blockquote><div class=""><br class=""></div>Creation of NSNumberPointer should go inside <span class="" style="font-family: Menlo; font-size: 11px;">if (!S.NSNumberDecl) </span></div><div class=""><font face="Menlo" class=""><span class="" style="font-size: 11px;">which is right before this code. </span></font></div><div class=""><font face="Menlo" class=""><span class="" style="font-size: 11px;"><br class=""></span></font></div><div class=""><font face="Menlo" class=""><span class="" style="font-size: 11px;">- Fariborz</span></font></div><div class=""><font face="Menlo" class=""><span class="" style="font-size: 11px;"><br class=""></span></font><blockquote type="cite" class=""><div class="">    // generate the pointer to NSNumber type.<br class="">    QualType NSNumberObject = CX.getObjCInterfaceType(S.NSNumberDecl);<br class="">    S.NSNumberPointer = CX.getObjCObjectPointerType(NSNumberObject);<br class=""><br class="">Modified: cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m?rev=229402&r1=229401&r2=229402&view=diff" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m?rev=229402&r1=229401&r2=229402&view=diff</a><br class="">==============================================================================<br class="">--- cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m (original)<br class="">+++ cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m Mon Feb 16 10:17:05 2015<br class="">@@ -9,6 +9,24 @@ typedef unsigned int NSUInteger;<br class="">typedef int NSInteger;<br class="">#endif<br class=""><br class="">+void checkNSNumberUnavailableDiagnostic() {<br class="">+  id num = @1000; // expected-error {{NSNumber must be available to use Objective-C literals}}<br class="">+<br class="">+  int x = 1000;<br class="">+  id num1 = @(x); // expected-error {{NSNumber must be available to use Objective-C literals}}\<br class="">+                  // expected-error {{illegal type 'int' used in a boxed expression}}<br class="">+}<br class="">+<br class="">+@class NSNumber;<br class="">+<br class="">+void checkNSNumberFDDiagnostic() {<br class="">+  id num = @1000; // expected-error {{NSNumber must be available to use Objective-C literals}}<br class="">+<br class="">+  int x = 1000;<br class="">+  id num1 = @(x); // expected-error {{declaration of 'numberWithInt:' is missing in NSNumber class}}\<br class="">+                  // expected-error {{illegal type 'int' used in a boxed expression}}<br class="">+}<br class="">+<br class="">@interface NSObject<br class="">+ (NSObject*)nsobject;<br class="">@end<br class=""><br class=""><br class="">_______________________________________________<br class="">cfe-commits mailing list<br class=""><a href="mailto:cfe-commits@cs.uiuc.edu" class="">cfe-commits@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" class="">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a></div></blockquote></div></div></div></span></blockquote></div></blockquote></div><br class=""></div></div></body></html>