Change the type of ObjCStringLiteral from "struct __builtin_CFString *" to "NSConstantString *".

This makes the typecheck much happier. Without this change, the type checker would have to special case "struct __builtin_CFString *". This change does assume the interface for NSConstantString is declared in the translation unit.

I left ASTContext::getCFConstantStringType() around for now (with a comment that says it is currently unused).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43021 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index c7d74e9..29a3b66 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -1890,10 +1890,18 @@
   if (CheckBuiltinCFStringArgument(S))
     return true;
   
-  QualType t = Context.getCFConstantStringType();
-  t = t.getQualifiedType(QualType::Const);
+  if (Context.getObjcConstantStringInterface().isNull()) {
+    // Initialize the constant string interface lazily. This assumes
+    // the NSConstantString interface is seen in this translation unit.
+    IdentifierInfo *NSIdent = &Context.Idents.get("NSConstantString");
+    ScopedDecl *IFace = LookupScopedDecl(NSIdent, Decl::IDNS_Ordinary, 
+                                         SourceLocation(), TUScope);
+    ObjcInterfaceDecl *stringInterface = cast<ObjcInterfaceDecl>(IFace);
+    assert(stringInterface && "missing '@interface NSConstantString'");
+    Context.setObjcConstantStringInterface(stringInterface);
+  }
+  QualType t = Context.getObjcConstantStringInterface();
   t = Context.getPointerType(t);
-
   return new ObjCStringLiteral(S, t);
 }