]> granicus.if.org Git - clang/commitdiff
Add __builtin_va_start to the list of builtins, make __builtin_va_list available...
authorAnders Carlsson <andersca@mac.com>
Thu, 11 Oct 2007 01:00:40 +0000 (01:00 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 11 Oct 2007 01:00:40 +0000 (01:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42857 91177308-0d34-0410-b5e6-96231b3b80d8

AST/ASTContext.cpp
AST/Builtins.cpp
Sema/SemaDecl.cpp
include/clang/AST/ASTContext.h
include/clang/AST/Builtins.def

index a6c2bc6680755d4ca303970509883a7af246f84f..56138c3aa169dd889c9b9fe972aa1b3f7cae19f9 100644 (file)
@@ -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;
+}
+
index a227bac480cdd7fafaeed60868c15014c4a59c4b..219f00c47988424c1ef424d150f01de614a9583d 100644 (file)
@@ -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;
index 406a745c29fb2ce59e69adad1884470c9f80d578..a14026519891cd9323bf44e5bc938b21ac56bcd6 100644 (file)
@@ -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);
   
index 43e40015d924712f9b04d39da0d5d636eb666f8f..b554fcf20c642e6bfdfbbf3af5cbde45e32682d0 100644 (file)
@@ -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
   //===--------------------------------------------------------------------===//
index a5e3138c858e5dc10455501c8f4513354f7f699f..3325d385e52ae9ec3ddf077a41eae1c2c1e8e968 100644 (file)
@@ -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