<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Well, it was there.</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Let’s consider we have this code:</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="margin: 0px;"><div id="bloop_customfont" style="margin: 0px;">@class NSNumber;</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">void checkNSNumberFDDiagnostic() {</div><div id="bloop_customfont" style="margin: 0px;">    id num = @1000;</div><div id="bloop_customfont" style="margin: 0px;">}</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">@interface NSNumber</div><div id="bloop_customfont" style="margin: 0px;">+ (NSNumber *)numberWithInt:(int)value;</div><div id="bloop_customfont" style="margin: 0px;">@end</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">int main() {</div><div id="bloop_customfont" style="margin: 0px;">    id num = @1000;</div><div id="bloop_customfont" style="margin: 0px;">}</div><div style="color: rgb(0, 0, 0); font-family: Helvetica, Arial; font-size: 13px;"><br></div></div><div id="bloop_customfont" style="margin: 0px;">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="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">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="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">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="margin: 0px;">I’d appreciate any suggestions how to improve this code.</div> <div id="bloop_sign_1424114853921054976" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>AlexDenisov</div><div style="font-family:helvetica,arial;font-size:13px">Software Engineer, <a href="https://github.com/AlexDenisov">https://github.com/AlexDenisov</a></div></div> <br><p style="color:#000;">On 16 Feb 2015 at 20:26:56, jahanian (<a href="mailto:fjahanian@apple.com">fjahanian@apple.com</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div></div><div>



<title></title>


<br class="">
<div>
<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: <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: <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: <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><br class=""></div>
Creation of NSNumberPointer should go inside <span style="font-family: Menlo; font-size: 11px;" class="">if
(!S.NSNumberDecl) </span></div>
<div><font face="Menlo" class=""><span style="font-size: 11px;" class="">which is right before this
code. </span></font></div>
<div><font face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div>
<div><font face="Menlo" class=""><span style="font-size: 11px;" class="">- Fariborz</span></font></div>
<div><font face="Menlo" class=""><span style="font-size: 11px;" class=""><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: <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="">
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits<br class=""></div>
</blockquote>
</div>
<br class="">


</div></div></span></blockquote></body></html>