]> granicus.if.org Git - clang/commitdiff
Add an internal CreateRecordDecl that will create a CXXRecordDecl when compiling...
authorAnders Carlsson <andersca@mac.com>
Sat, 14 Nov 2009 21:45:58 +0000 (21:45 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 14 Nov 2009 21:45:58 +0000 (21:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88816 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
test/SemaCXX/builtins.cpp [new file with mode: 0644]

index 7aa3418b165902fe431bee00428ad7400ae5ca4f..9850ad6f53a67ba20a17f47339febd0f30a4369b 100644 (file)
@@ -2740,12 +2740,22 @@ int ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) {
   return 1;
 }
 
+static RecordDecl *
+CreateRecordDecl(ASTContext &Ctx, RecordDecl::TagKind TK, DeclContext *DC,
+                 SourceLocation L, IdentifierInfo *Id) {
+  if (Ctx.getLangOptions().CPlusPlus)
+    return CXXRecordDecl::Create(Ctx, TK, DC, L, Id);
+  else
+    return RecordDecl::Create(Ctx, TK, DC, L, Id);
+}
+                                    
 // getCFConstantStringType - Return the type used for constant CFStrings.
 QualType ASTContext::getCFConstantStringType() {
   if (!CFConstantStringTypeDecl) {
     CFConstantStringTypeDecl =
-      RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
-                         &Idents.get("NSConstantString"));
+      CreateRecordDecl(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
+                       &Idents.get("NSConstantString"));
+
     QualType FieldTypes[4];
 
     // const int *isa;
@@ -2782,8 +2792,8 @@ void ASTContext::setCFConstantStringType(QualType T) {
 QualType ASTContext::getObjCFastEnumerationStateType() {
   if (!ObjCFastEnumerationStateTypeDecl) {
     ObjCFastEnumerationStateTypeDecl =
-      RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
-                         &Idents.get("__objcFastEnumerationState"));
+      CreateRecordDecl(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
+                       &Idents.get("__objcFastEnumerationState"));
 
     QualType FieldTypes[] = {
       UnsignedLongTy,
@@ -2815,8 +2825,8 @@ QualType ASTContext::getBlockDescriptorType() {
 
   RecordDecl *T;
   // FIXME: Needs the FlagAppleBlock bit.
-  T = RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
-                         &Idents.get("__block_descriptor"));
+  T = CreateRecordDecl(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
+                       &Idents.get("__block_descriptor"));
   
   QualType FieldTypes[] = {
     UnsignedLongTy,
@@ -2858,8 +2868,8 @@ QualType ASTContext::getBlockDescriptorExtendedType() {
 
   RecordDecl *T;
   // FIXME: Needs the FlagAppleBlock bit.
-  T = RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
-                         &Idents.get("__block_descriptor_withcopydispose"));
+  T = CreateRecordDecl(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
+                       &Idents.get("__block_descriptor_withcopydispose"));
   
   QualType FieldTypes[] = {
     UnsignedLongTy,
@@ -2928,8 +2938,8 @@ QualType ASTContext::BuildByRefType(const char *DeclName, QualType Ty) {
   llvm::raw_svector_ostream(Name) << "__Block_byref_" <<
                                   ++UniqueBlockByRefTypeID << '_' << DeclName;
   RecordDecl *T;
-  T = RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
-                         &Idents.get(Name.str()));
+  T = CreateRecordDecl(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
+                       &Idents.get(Name.str()));
   T->startDefinition();
   QualType Int32Ty = IntTy;
   assert(getIntWidth(IntTy) == 32 && "non-32bit int not supported");
@@ -2978,8 +2988,8 @@ QualType ASTContext::getBlockParmType(
   llvm::raw_svector_ostream(Name) << "__block_literal_"
                                   << ++UniqueBlockParmTypeID;
   RecordDecl *T;
-  T = RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
-                         &Idents.get(Name.str()));
+  T = CreateRecordDecl(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
+                       &Idents.get(Name.str()));
   QualType FieldTypes[] = {
     getPointerType(VoidPtrTy),
     IntTy,
diff --git a/test/SemaCXX/builtins.cpp b/test/SemaCXX/builtins.cpp
new file mode 100644 (file)
index 0000000..9e9d152
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: clang-cc %s -fsyntax-only -verify
+typedef const struct __CFString * CFStringRef;
+#define CFSTR __builtin___CFStringMakeConstantString
+
+void f() {
+  (void)CFStringRef(CFSTR("Hello"));
+}
\ No newline at end of file