diff options
| -rw-r--r-- | clang/AST/ASTContext.cpp | 8 | ||||
| -rw-r--r-- | clang/AST/Builtins.cpp | 3 | ||||
| -rw-r--r-- | clang/Sema/SemaDecl.cpp | 11 | ||||
| -rw-r--r-- | clang/include/clang/AST/ASTContext.h | 8 | ||||
| -rw-r--r-- | clang/include/clang/AST/Builtins.def | 2 |
5 files changed, 31 insertions, 1 deletions
diff --git a/clang/AST/ASTContext.cpp b/clang/AST/ASTContext.cpp index a6c2bc66807..56138c3aa16 100644 --- a/clang/AST/ASTContext.cpp +++ b/clang/AST/ASTContext.cpp @@ -830,3 +830,11 @@ QualType ASTContext::getCFConstantStringType() { return getTagDeclType(CFConstantStringTypeDecl); } + +void ASTContext::setBuiltinVaListType(QualType T) +{ + assert(BuiltinVaListType.isNull() && "__builtin_va_list type already set!"); + + BuiltinVaListType = T; +} + diff --git a/clang/AST/Builtins.cpp b/clang/AST/Builtins.cpp index a227bac480c..219f00c4798 100644 --- a/clang/AST/Builtins.cpp +++ b/clang/AST/Builtins.cpp @@ -133,6 +133,9 @@ static QualType DecodeTypeFromStr(const char *&Str, ASTContext &Context) { case 'F': Type = Context.getCFConstantStringType(); break; + case 'V': + Type = Context.getBuiltinVaListType(); + break; } Done = false; diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp index 406a745c29f..a1402651989 100644 --- a/clang/Sema/SemaDecl.cpp +++ b/clang/Sema/SemaDecl.cpp @@ -137,7 +137,16 @@ ScopedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid, Scope *S) { Builtin::ID BID = (Builtin::ID)bid; - QualType R = Context.BuiltinInfo.GetBuiltinType(BID, Context); + if (BID == Builtin::BI__builtin_va_start && + Context.getBuiltinVaListType().isNull()) { + IdentifierInfo *VaIdent = &Context.Idents.get("__builtin_va_list"); + ScopedDecl *VaDecl = LookupScopedDecl(VaIdent, Decl::IDNS_Ordinary, + SourceLocation(), TUScope); + TypedefDecl *VaTypedef = cast<TypedefDecl>(VaDecl); + Context.setBuiltinVaListType(Context.getTypedefType(VaTypedef)); + } + + QualType R = Context.BuiltinInfo.GetBuiltinType(BID, Context); FunctionDecl *New = new FunctionDecl(SourceLocation(), II, R, FunctionDecl::Extern, false, 0); diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 43e40015d92..b554fcf20c6 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -41,6 +41,11 @@ class ASTContext { 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 + /// a builtin that takes a valist is encountered. + QualType BuiltinVaListType; public: SourceManager &SourceMgr; @@ -145,6 +150,9 @@ public: // getCFConstantStringType - Return the type used for constant CFStrings. QualType getCFConstantStringType(); + void setBuiltinVaListType(QualType T); + QualType getBuiltinVaListType() const { return BuiltinVaListType; } + //===--------------------------------------------------------------------===// // Type Sizing and Analysis //===--------------------------------------------------------------------===// diff --git a/clang/include/clang/AST/Builtins.def b/clang/include/clang/AST/Builtins.def index a5e3138c858..3325d385e52 100644 --- a/clang/include/clang/AST/Builtins.def +++ b/clang/include/clang/AST/Builtins.def @@ -30,6 +30,7 @@ // f -> float // d -> double // F -> constant CFString +// V -> __builtin_va_list // . -> "...". This may only occur at the end of the function list. // // Types maybe prefixed with the following modifiers: @@ -58,5 +59,6 @@ BUILTIN(__builtin_fabsl, "LdLd", "ncF") BUILTIN(__builtin_constant_p, "UsUs", "nc") BUILTIN(__builtin_classify_type, "i.", "nc") BUILTIN(__builtin___CFStringMakeConstantString, "FC*cC*", "nc") +BUILTIN(__builtin_va_start, "vV.", "nc") #undef BUILTIN |

