[cfe-commits] r151296 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/Sema/SemaExprObjC.cpp test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m test/PCH/objc_exprs.m test/SemaObjC/NSString-type.m test/SemaObjCXX/NSString-type.mm
Fariborz Jahanian
fjahanian at apple.com
Thu Feb 23 14:51:36 PST 2012
Author: fjahanian
Date: Thu Feb 23 16:51:36 2012
New Revision: 151296
URL: http://llvm.org/viewvc/llvm-project?rev=151296&view=rev
Log:
objective-c++: Type of an objc string literal is NSString, not 'id'.
// rdar://10907410
Added:
cfe/trunk/test/SemaObjC/NSString-type.m
cfe/trunk/test/SemaObjCXX/NSString-type.mm
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
cfe/trunk/test/PCH/objc_exprs.m
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=151296&r1=151295&r2=151296&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Feb 23 16:51:36 2012
@@ -218,6 +218,8 @@
QualType ObjCConstantStringType;
mutable RecordDecl *CFConstantStringTypeDecl;
+
+ QualType ObjCNSStringType;
/// \brief The typedef declaration for the Objective-C "instancetype" type.
TypedefDecl *ObjCInstanceTypeDecl;
@@ -944,6 +946,14 @@
return ObjCConstantStringType;
}
+ QualType getObjCNSStringType() const {
+ return ObjCNSStringType;
+ }
+
+ void setObjCNSStringType(QualType T) {
+ ObjCNSStringType = T;
+ }
+
/// \brief Retrieve the type that 'id' has been defined to, which may be
/// different from the built-in 'id' if 'id' has been typedef'd.
QualType getObjCIdRedefinitionType() const {
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=151296&r1=151295&r2=151296&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Feb 23 16:51:36 2012
@@ -113,9 +113,21 @@
Ty = Context.getObjCConstantStringInterface();
Ty = Context.getObjCObjectPointerType(Ty);
} else {
- // If there is no NSString interface defined then treat constant
- // strings as untyped objects and let the runtime figure it out later.
- Ty = Context.getObjCIdType();
+ // If there is no NSString interface defined, implicitly declare
+ // a @class NSString; and use that instead. This is to make sure
+ // type of an NSString literal is represented correctly, instead of
+ // being an 'id' type.
+ Ty = Context.getObjCNSStringType();
+ if (Ty.isNull()) {
+ ObjCInterfaceDecl *NSStringIDecl =
+ ObjCInterfaceDecl::Create (Context,
+ Context.getTranslationUnitDecl(),
+ SourceLocation(), NSIdent,
+ 0, SourceLocation());
+ Ty = Context.getObjCInterfaceType(NSStringIDecl);
+ Context.setObjCNSStringType(Ty);
+ }
+ Ty = Context.getObjCObjectPointerType(Ty);
}
}
Modified: cfe/trunk/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m?rev=151296&r1=151295&r2=151296&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m (original)
+++ cfe/trunk/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m Thu Feb 23 16:51:36 2012
@@ -48,7 +48,7 @@
}
void createFoo5() {
- MyClass *obj = @"";
+ MyClass *obj = (id)@"";
double d = [obj doubleM]; // no-warning
}
Modified: cfe/trunk/test/PCH/objc_exprs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/objc_exprs.m?rev=151296&r1=151295&r2=151296&view=diff
==============================================================================
--- cfe/trunk/test/PCH/objc_exprs.m (original)
+++ cfe/trunk/test/PCH/objc_exprs.m Thu Feb 23 16:51:36 2012
@@ -6,7 +6,7 @@
// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -verify %s
// Expressions
-int *A1 = (objc_string)0; // expected-warning {{aka 'id'}}
+int *A1 = (objc_string)0; // expected-warning {{aka 'NSString *'}}
char A2 = (objc_encode){}; // expected-error {{not a compile-time constant}} \
expected-warning {{char [2]}}
Added: cfe/trunk/test/SemaObjC/NSString-type.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/NSString-type.m?rev=151296&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/NSString-type.m (added)
+++ cfe/trunk/test/SemaObjC/NSString-type.m Thu Feb 23 16:51:36 2012
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -fsyntax-only -verify %s
+// rdar://10907410
+
+void test(id pid, Class pclass) {
+ void (^block)(void) = @"help"; // expected-error {{initializing 'void (^)(void)' with an expression of incompatible type 'NSString *'}}
+ void (^block1)(void) = pid;
+ void (^block2)(void) = @"help"; // expected-error {{initializing 'void (^)(void)' with an expression of incompatible type 'NSString *'}}
+ void (^block3)(void) = @"help"; // expected-error {{initializing 'void (^)(void)' with an expression of incompatible type 'NSString *'}}
+}
+
Added: cfe/trunk/test/SemaObjCXX/NSString-type.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/NSString-type.mm?rev=151296&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/NSString-type.mm (added)
+++ cfe/trunk/test/SemaObjCXX/NSString-type.mm Thu Feb 23 16:51:36 2012
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fblocks -fsyntax-only -verify %s
+// rdar://10907410
+
+void test(id pid, Class pclass) {
+ void (^block)(void) = @"help"; // expected-error {{cannot initialize a variable of type 'void (^)()' with an rvalue of type 'NSString *'}}
+ void (^block1)(void) = pid;
+ void (^block2)(void) = @"help"; // expected-error {{cannot initialize a variable of type 'void (^)()' with an rvalue of type 'NSString *'}}
+ void (^block3)(void) = @"help"; // expected-error {{cannot initialize a variable of type 'void (^)()' with an rvalue of type 'NSString *'}}
+}
+
More information about the cfe-commits
mailing list