diff options
author | Anders Carlsson <andersca@mac.com> | 2009-11-14 21:45:58 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-11-14 21:45:58 +0000 |
commit | 79cbc7dd2aacd85a28f469b5dc73c4ea296e7072 (patch) | |
tree | f5fa73943d57d2336487318c66c28baa8c68460a | |
parent | a8a1e3da7cc741ab36be18041fafbebdc9be826b (diff) |
Add an internal CreateRecordDecl that will create a CXXRecordDecl when compiling C++ and a RecordDecl otherwise.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88816 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/AST/ASTContext.cpp | 34 | ||||
-rw-r--r-- | test/SemaCXX/builtins.cpp | 7 |
2 files changed, 29 insertions, 12 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 7aa3418b16..9850ad6f53 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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 index 0000000000..9e9d1522f4 --- /dev/null +++ b/test/SemaCXX/builtins.cpp @@ -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 |