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/AST/ASTContext.cpp b/AST/ASTContext.cpp
index 86cf13c..366966f 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -150,6 +150,7 @@
BuiltinVaListType = QualType();
ObjcIdType = QualType();
IdStructType = 0;
+ ObjcConstantStringType = QualType();
}
//===----------------------------------------------------------------------===//
@@ -855,6 +856,13 @@
IdStructType = rec;
}
+void ASTContext::setObjcConstantStringInterface(ObjcInterfaceDecl *Decl) {
+ assert(ObjcConstantStringType.isNull() &&
+ "'NSConstantString' type already set!");
+
+ ObjcConstantStringType = getObjcInterfaceType(Decl);
+}
+
bool ASTContext::builtinTypesAreCompatible(QualType lhs, QualType rhs) {
const BuiltinType *lBuiltin = lhs->getAsBuiltinType();
const BuiltinType *rBuiltin = rhs->getAsBuiltinType();
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);
}
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index e84c423..090cc52 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -40,7 +40,6 @@
llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
llvm::FoldingSet<ObjcQualifiedInterfaceType> ObjcQualifiedInterfaceTypes;
llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo;
- RecordDecl *CFConstantStringTypeDecl;
/// BuiltinVaListType - built-in va list type.
/// This is initially null and set by Sema::LazilyCreateBuiltin when
@@ -50,6 +49,9 @@
/// ObjcIdType - a psuedo built-in typedef type (set by Sema).
QualType ObjcIdType;
const RecordType *IdStructType;
+
+ QualType ObjcConstantStringType;
+ RecordDecl *CFConstantStringTypeDecl;
public:
SourceManager &SourceMgr;
@@ -151,12 +153,19 @@
/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
QualType getPointerDiffType() const;
- // getCFConstantStringType - Return the type used for constant CFStrings.
+ // getCFConstantStringType - Return the type used for constant CFStrings.
+ // CURRENTLY UNUSED (10/15/07). ObjCStringLiteral now uses the hook below.
QualType getCFConstantStringType();
+ // This setter/getter represents the actual ObjC type for an NSConstantString.
+ void setObjcConstantStringInterface(ObjcInterfaceDecl *Decl);
+ QualType getObjcConstantStringInterface() const {
+ return ObjcConstantStringType;
+ }
+
void setObjcIdType(TypedefDecl *Decl);
QualType getObjcIdType() const { return ObjcIdType; }
-
+
void setBuiltinVaListType(QualType T);
QualType getBuiltinVaListType() const { return BuiltinVaListType; }