r229402 - Fix crash when clang tries to build NSNumber literal after forward declaration
Alex Denisov
1101.debian at gmail.com
Mon Feb 16 08:17:06 PST 2015
Author: alexdenisov
Date: Mon Feb 16 10:17:05 2015
New Revision: 229402
URL: http://llvm.org/viewvc/llvm-project?rev=229402&view=rev
Log:
Fix crash when clang tries to build NSNumber literal after forward declaration
Bug report: http://llvm.org/bugs/show_bug.cgi?id=22561
Clang tries to create ObjCBoxedExpression of type 'NSNumber'
when 'NSNumber' has only forward declaration, this cause a crash later,
when 'Sema' refers to a nil QualType of the whole expression.
Please, refer to the bug report for the better explanation.
Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=229402&r1=229401&r2=229402&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Feb 16 10:17:05 2015
@@ -218,7 +218,9 @@ static ObjCMethodDecl *getNSNumberFactor
S.Diag(Loc, diag::err_undeclared_nsnumber);
return nullptr;
}
-
+ }
+
+ if (S.NSNumberPointer.isNull()) {
// generate the pointer to NSNumber type.
QualType NSNumberObject = CX.getObjCInterfaceType(S.NSNumberDecl);
S.NSNumberPointer = CX.getObjCObjectPointerType(NSNumberObject);
Modified: cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m?rev=229402&r1=229401&r2=229402&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m (original)
+++ cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m Mon Feb 16 10:17:05 2015
@@ -9,6 +9,24 @@ typedef unsigned int NSUInteger;
typedef int NSInteger;
#endif
+void checkNSNumberUnavailableDiagnostic() {
+ id num = @1000; // expected-error {{NSNumber must be available to use Objective-C literals}}
+
+ int x = 1000;
+ id num1 = @(x); // expected-error {{NSNumber must be available to use Objective-C literals}}\
+ // expected-error {{illegal type 'int' used in a boxed expression}}
+}
+
+ at class NSNumber;
+
+void checkNSNumberFDDiagnostic() {
+ id num = @1000; // expected-error {{NSNumber must be available to use Objective-C literals}}
+
+ int x = 1000;
+ id num1 = @(x); // expected-error {{declaration of 'numberWithInt:' is missing in NSNumber class}}\
+ // expected-error {{illegal type 'int' used in a boxed expression}}
+}
+
@interface NSObject
+ (NSObject*)nsobject;
@end
More information about the cfe-commits
mailing list