[cfe-commits] r52599 - in /cfe/trunk: 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 test/Sema/objc-property-8.m

Chris Lattner sabre at nondot.org
Sat Jun 21 14:44:18 PDT 2008


Author: lattner
Date: Sat Jun 21 16:44:18 2008
New Revision: 52599

URL: http://llvm.org/viewvc/llvm-project?rev=52599&view=rev
Log:
"this patch adds code generation hooks for Objective-C constant strings.  It also modifies Sema so that Objective-C constant strings are treated as untyped objects if the interface for the constant string class can not be found.  This is consistent with Apple GCC.  I thought it was consistent with GNU GCC, since this was causing failures when trying to compile GNUstep with (GNU) GCC, but it appears that this is not the case when attempting to produce a simple test case to demonstrate it.  Possibly there is a way of making the error go away, but I haven't found out what it is yet."

Patch by David Chisnall!


Removed:
    cfe/trunk/test/Sema/missing-string-interface.m
Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/Parser/objc-foreach-error-1.m
    cfe/trunk/test/Sema/objc-property-8.m

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=52599&r1=52598&r2=52599&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sat Jun 21 16:44:18 2008
@@ -59,6 +59,10 @@
   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());

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=52599&r1=52598&r2=52599&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Sat Jun 21 16:44:18 2008
@@ -302,9 +302,10 @@
 //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),

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=52599&r1=52598&r2=52599&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sat Jun 21 16:44:18 2008
@@ -54,13 +54,17 @@
     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 @@
     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

Modified: cfe/trunk/test/Parser/objc-foreach-error-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-foreach-error-1.m?rev=52599&r1=52598&r2=52599&view=diff

==============================================================================
--- cfe/trunk/test/Parser/objc-foreach-error-1.m (original)
+++ cfe/trunk/test/Parser/objc-foreach-error-1.m Sat Jun 21 16:44:18 2008
@@ -17,8 +17,7 @@
 @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

Removed: cfe/trunk/test/Sema/missing-string-interface.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/missing-string-interface.m?rev=52598&view=auto

==============================================================================
--- cfe/trunk/test/Sema/missing-string-interface.m (original)
+++ cfe/trunk/test/Sema/missing-string-interface.m (removed)
@@ -1,7 +0,0 @@
-// RUN: clang %s -verify -fsyntax-only
-
- at class NSString;
-
-// GCC considers this an error, so clang will...
-NSString *s = @"123"; // expected-error: {{cannot find interface declaration for 'NSConstantString'}}
-

Modified: cfe/trunk/test/Sema/objc-property-8.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-property-8.m?rev=52599&r1=52598&r2=52599&view=diff

==============================================================================
--- cfe/trunk/test/Sema/objc-property-8.m (original)
+++ cfe/trunk/test/Sema/objc-property-8.m Sat Jun 21 16:44:18 2008
@@ -68,7 +68,7 @@
 @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
 





More information about the cfe-commits mailing list