]> granicus.if.org Git - clang/commitdiff
"this patch adds code generation hooks for Objective-C constant strings. It also...
authorChris Lattner <sabre@nondot.org>
Sat, 21 Jun 2008 21:44:18 +0000 (21:44 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 21 Jun 2008 21:44:18 +0000 (21:44 +0000)
Patch by David Chisnall!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52599 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp
lib/CodeGen/CGObjCGNU.cpp
lib/Sema/SemaExprObjC.cpp
test/Parser/objc-foreach-error-1.m
test/Sema/missing-string-interface.m [deleted file]
test/Sema/objc-property-8.m

index cae1f4bb248689c34daecf93a8d1b57d010e3b1b..fe11a5fb0ac9eed6a9b4ddb8825eecabcc5b1faa 100644 (file)
@@ -59,6 +59,10 @@ public:
   llvm::Constant *VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
     return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue());
   }
+  llvm::Constant *VisitObjCStringLiteral(const ObjCStringLiteral *E) {
+    return CGM.getObjCRuntime()->GenerateConstantString(
+        E->getString()->getStrData(), E->getString()->getByteLength());
+  }
   
   llvm::Constant *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
     return Visit(E->getInitializer());
index e545fc12eefbdc30ab0f8ce307d8419d4d8a3425..f2cfdcab82fb5359598065e5913c9a9baa872241 100644 (file)
@@ -302,9 +302,10 @@ llvm::Constant *CGObjCGNU::MakeGlobal(const llvm::ArrayType *Ty,
 //constant strings.
 llvm::Constant *CGObjCGNU::GenerateConstantString(const char *String, const
     size_t length) {
+  std::string Str(String, String +length);
   std::vector<llvm::Constant*> Ivars;
   Ivars.push_back(NULLPtr);
-  Ivars.push_back(MakeConstantString(String));
+  Ivars.push_back(MakeConstantString(Str));
   Ivars.push_back(llvm::ConstantInt::get(IntTy, length));
   llvm::Constant *ObjCStr = MakeGlobal(
     llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, IntTy, NULL),
index 920457e00c6af4fd2b507b80a52f8c327114f08f..1aed69ec2c5674099f4c6c09d05e1e6628079777 100644 (file)
@@ -54,13 +54,17 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
     IdentifierInfo *NSIdent = &Context.Idents.get("NSConstantString");
     Decl *IFace = LookupDecl(NSIdent, Decl::IDNS_Ordinary, TUScope);
     ObjCInterfaceDecl *strIFace = dyn_cast_or_null<ObjCInterfaceDecl>(IFace);
-    if (!strIFace)
-      return Diag(S->getLocStart(), diag::err_undef_interface,
-                  NSIdent->getName());
-    Context.setObjCConstantStringInterface(strIFace);
+    if (strIFace)
+      Context.setObjCConstantStringInterface(strIFace);
   }
   QualType t = Context.getObjCConstantStringInterface();
-  t = Context.getPointerType(t);
+  // If there is no NSConstantString interface defined then treat constant
+  // strings as untyped objects and let the runtime figure it out later.
+  if (t == QualType()) {
+    t = Context.getObjCIdType();
+  } else {
+    t = Context.getPointerType(t);
+  }
   return new ObjCStringLiteral(S, t, AtLoc);
 }
 
@@ -298,9 +302,9 @@ Sema::ExprResult Sema::ActOnInstanceMessage(
     else {
       ObjCInterfaceType *OCIReceiver =dyn_cast<ObjCInterfaceType>(receiverType);
       if (OCIReceiver == 0) {
-        Diag(lbrac, diag::error_bad_receiver_type,
-             RExpr->getType().getAsString());
-        return true;
+          Diag(lbrac, diag::error_bad_receiver_type,
+               RExpr->getType().getAsString());
+          return true;
       }
       ClassDecl = OCIReceiver->getDecl();
       // FIXME: consider using InstanceMethodPool, since it will be faster
index 693f12e2ffe9053e1827537e7da4f0226a30740f..76251abf33fcdaa10057d89d7b6fc4dea50640ce 100644 (file)
@@ -17,8 +17,7 @@ int LOOP();
 @implementation MyList (BasicTest)  // expected-error {{cannot find interface declaration for 'MyList'}}
 - (void)compilerTestAgainst {
 MyList * el;  // expected-error {{use of undeclared identifier 'MyList'}}
-     for (el in @"foo")    // expected-error {{use of undeclared identifier 'el'}} \
-                          // expected-error {{cannot find interface declaration for 'NSConstantString'}}
+     for (el in @"foo")    // expected-error {{use of undeclared identifier 'el'}}
          { LOOP(); }
 }
 @end
diff --git a/test/Sema/missing-string-interface.m b/test/Sema/missing-string-interface.m
deleted file mode 100644 (file)
index f96fb4c..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// RUN: clang %s -verify -fsyntax-only
-
-@class NSString;
-
-// GCC considers this an error, so clang will...
-NSString *s = @"123"; // expected-error: {{cannot find interface declaration for 'NSConstantString'}}
-
index a081f39ec4f9ddb45ceb32bb7ca0df68a7aa3f8f..8ca0afc1ed434e26676756ea7d164b52405e8b5d 100644 (file)
@@ -68,7 +68,7 @@ extern NSString *PBXWindowDidChangeFirstResponderNotification;
 @synthesize query = _query;
 - (void) _clearQuery
 {
-  [self.query removeObserver: self forKeyPath: @"matches"]; // expected-error{{cannot find interface declaration for 'NSConstantString'}}
+  [self.query removeObserver: self forKeyPath: @"matches"];
 }
 @end