[cfe-commits] r158592 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/Basic/TargetInfo.h include/clang/Serialization/ASTBitCodes.h lib/AST/ASTContext.cpp lib/Basic/Targets.cpp lib/Frontend/InitPreprocessor.cpp lib/Sema/Sema.cpp lib/

NAKAMURA Takumi geek4civic at gmail.com
Fri Jun 15 23:08:39 PDT 2012


Meador,

I have tweaked unittest in r158595. -fms-extensions still provides another decl.

...Takumi

2012/6/16 Meador Inge <meadori at codesourcery.com>:
> Author: meadori
> Date: Fri Jun 15 22:34:49 2012
> New Revision: 158592
>
> URL: http://llvm.org/viewvc/llvm-project?rev=158592&view=rev
> Log:
> Explicitly build __builtin_va_list.
>
> The target specific __builtin_va_list types are now explicitly built instead
> of injecting strings into the preprocessor input.
>
> Modified:
>    cfe/trunk/include/clang/AST/ASTContext.h
>    cfe/trunk/include/clang/Basic/TargetInfo.h
>    cfe/trunk/include/clang/Serialization/ASTBitCodes.h
>    cfe/trunk/lib/AST/ASTContext.cpp
>    cfe/trunk/lib/Basic/Targets.cpp
>    cfe/trunk/lib/Frontend/InitPreprocessor.cpp
>    cfe/trunk/lib/Sema/Sema.cpp
>    cfe/trunk/lib/Sema/SemaDecl.cpp
>    cfe/trunk/lib/Serialization/ASTReader.cpp
>    cfe/trunk/lib/Serialization/ASTWriter.cpp
>    cfe/trunk/test/PCH/chain-trivial.c
>    cfe/trunk/unittests/Tooling/ToolingTest.cpp
>
> Modified: cfe/trunk/include/clang/AST/ASTContext.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
> +++ cfe/trunk/include/clang/AST/ASTContext.h Fri Jun 15 22:34:49 2012
> @@ -198,10 +198,9 @@
>   /// \brief The typedef for the __uint128_t type.
>   mutable TypedefDecl *UInt128Decl;
>
> -  /// 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;
> +  /// \brief The typedef for the target specific predefined
> +  /// __builtin_va_list type.
> +  mutable TypedefDecl *BuiltinVaListDecl;
>
>   /// \brief The typedef for the predefined 'id' type.
>   mutable TypedefDecl *ObjCIdDecl;
> @@ -1153,8 +1152,14 @@
>     return getObjCInterfaceType(getObjCProtocolDecl());
>   }
>
> -  void setBuiltinVaListType(QualType T);
> -  QualType getBuiltinVaListType() const { return BuiltinVaListType; }
> +  /// \brief Retrieve the C type declaration corresponding to the predefined
> +  /// __builtin_va_list type.
> +  TypedefDecl *getBuiltinVaListDecl() const;
> +
> +  /// \brief Retrieve the type of the __builtin_va_list type.
> +  QualType getBuiltinVaListType() const {
> +    return getTypeDeclType(getBuiltinVaListDecl());
> +  }
>
>   /// getCVRQualifiedType - Returns a type with additional const,
>   /// volatile, or restrict qualifiers.
>
> Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
> +++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Jun 15 22:34:49 2012
> @@ -128,6 +128,29 @@
>     LongDouble
>   };
>
> +  /// BuiltinVaListKind - The different kinds of __builtin_va_list types
> +  /// defined by the target implementation.
> +  enum BuiltinVaListKind {
> +    /// typedef char* __builtin_va_list;
> +    CharPtrBuiltinVaList = 0,
> +
> +    /// typedef void* __builtin_va_list;
> +    VoidPtrBuiltinVaList,
> +
> +    /// __builtin_va_list as defined by the PNaCl ABI:
> +    /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
> +    PNaClABIBuiltinVaList,
> +
> +    /// __builtin_va_list as defined by the Power ABI:
> +    /// https://www.power.org
> +    ///        /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
> +    PowerABIBuiltinVaList,
> +
> +    /// __builtin_va_list as defined by the x86-64 ABI:
> +    /// http://www.x86-64.org/documentation/abi.pdf
> +    X86_64ABIBuiltinVaList
> +  };
> +
>  protected:
>   IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType,
>           WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType;
> @@ -379,9 +402,9 @@
>   /// idea to avoid optimizing based on that undef behavior.
>   virtual bool isCLZForZeroUndef() const { return true; }
>
> -  /// getVAListDeclaration - Return the declaration to use for
> -  /// __builtin_va_list, which is target-specific.
> -  virtual const char *getVAListDeclaration() const = 0;
> +  /// getBuiltinVaListKind - Returns the kind of __builtin_va_list
> +  /// type that should be used with this target.
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
>
>   /// isValidClobber - Returns whether the passed in string is
>   /// a valid clobber in an inline asm statement. This is used by
>
> Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
> +++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Fri Jun 15 22:34:49 2012
> @@ -738,28 +738,26 @@
>     /// The constants in this enumeration are indices into the
>     /// SPECIAL_TYPES record.
>     enum SpecialTypeIDs {
> -      /// \brief __builtin_va_list
> -      SPECIAL_TYPE_BUILTIN_VA_LIST             = 0,
>       /// \brief CFConstantString type
> -      SPECIAL_TYPE_CF_CONSTANT_STRING          = 1,
> +      SPECIAL_TYPE_CF_CONSTANT_STRING          = 0,
>       /// \brief C FILE typedef type
> -      SPECIAL_TYPE_FILE                        = 2,
> +      SPECIAL_TYPE_FILE                        = 1,
>       /// \brief C jmp_buf typedef type
> -      SPECIAL_TYPE_JMP_BUF                     = 3,
> +      SPECIAL_TYPE_JMP_BUF                     = 2,
>       /// \brief C sigjmp_buf typedef type
> -      SPECIAL_TYPE_SIGJMP_BUF                  = 4,
> +      SPECIAL_TYPE_SIGJMP_BUF                  = 3,
>       /// \brief Objective-C "id" redefinition type
> -      SPECIAL_TYPE_OBJC_ID_REDEFINITION        = 5,
> +      SPECIAL_TYPE_OBJC_ID_REDEFINITION        = 4,
>       /// \brief Objective-C "Class" redefinition type
> -      SPECIAL_TYPE_OBJC_CLASS_REDEFINITION     = 6,
> +      SPECIAL_TYPE_OBJC_CLASS_REDEFINITION     = 5,
>       /// \brief Objective-C "SEL" redefinition type
> -      SPECIAL_TYPE_OBJC_SEL_REDEFINITION       = 7,
> +      SPECIAL_TYPE_OBJC_SEL_REDEFINITION       = 6,
>       /// \brief C ucontext_t typedef type
> -      SPECIAL_TYPE_UCONTEXT_T                  = 8
> +      SPECIAL_TYPE_UCONTEXT_T                  = 7
>     };
>
>     /// \brief The number of special type IDs.
> -    const unsigned NumSpecialTypeIDs = 9;
> +    const unsigned NumSpecialTypeIDs = 8;
>
>     /// \brief Predefined declaration IDs.
>     ///
> @@ -793,14 +791,17 @@
>       PREDEF_DECL_UNSIGNED_INT_128_ID = 7,
>
>       /// \brief The internal 'instancetype' typedef.
> -      PREDEF_DECL_OBJC_INSTANCETYPE_ID = 8
> +      PREDEF_DECL_OBJC_INSTANCETYPE_ID = 8,
> +
> +      /// \brief The internal '__builtin_va_list' typedef.
> +      PREDEF_DECL_BUILTIN_VA_LIST_ID = 9
>     };
>
>     /// \brief The number of declaration IDs that are predefined.
>     ///
>     /// For more information about predefined declarations, see the
>     /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
> -    const unsigned int NUM_PREDEF_DECL_IDS = 9;
> +    const unsigned int NUM_PREDEF_DECL_IDS = 10;
>
>     /// \brief Record codes for each kind of declaration.
>     ///
>
> Modified: cfe/trunk/lib/AST/ASTContext.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTContext.cpp (original)
> +++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jun 15 22:34:49 2012
> @@ -229,6 +229,7 @@
>     SubstTemplateTemplateParmPacks(this_()),
>     GlobalNestedNameSpecifier(0),
>     Int128Decl(0), UInt128Decl(0),
> +    BuiltinVaListDecl(0),
>     ObjCIdDecl(0), ObjCSelDecl(0), ObjCClassDecl(0), ObjCProtocolClassDecl(0),
>     CFConstantStringTypeDecl(0), ObjCInstanceTypeDecl(0),
>     FILEDecl(0),
> @@ -478,8 +479,6 @@
>   DoubleComplexTy     = getComplexType(DoubleTy);
>   LongDoubleComplexTy = getComplexType(LongDoubleTy);
>
> -  BuiltinVaListType = QualType();
> -
>   // Builtin types for 'id', 'Class', and 'SEL'.
>   InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId);
>   InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass);
> @@ -4870,12 +4869,6 @@
>     S += 'V';
>  }
>
> -void ASTContext::setBuiltinVaListType(QualType T) {
> -  assert(BuiltinVaListType.isNull() && "__builtin_va_list type already set!");
> -
> -  BuiltinVaListType = T;
> -}
> -
>  TypedefDecl *ASTContext::getObjCIdDecl() const {
>   if (!ObjCIdDecl) {
>     QualType T = getObjCObjectType(ObjCBuiltinIdTy, 0, 0);
> @@ -4929,6 +4922,230 @@
>   return ObjCProtocolClassDecl;
>  }
>
> +//===----------------------------------------------------------------------===//
> +// __builtin_va_list Construction Functions
> +//===----------------------------------------------------------------------===//
> +
> +static TypedefDecl *CreateCharPtrBuiltinVaListDecl(const ASTContext *Context) {
> +  // typedef char* __builtin_va_list;
> +  QualType CharPtrType = Context->getPointerType(Context->CharTy);
> +  TypeSourceInfo *TInfo
> +    = Context->getTrivialTypeSourceInfo(CharPtrType);
> +
> +  TypedefDecl *VaListTypeDecl
> +    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
> +                          Context->getTranslationUnitDecl(),
> +                          SourceLocation(), SourceLocation(),
> +                          &Context->Idents.get("__builtin_va_list"),
> +                          TInfo);
> +  return VaListTypeDecl;
> +}
> +
> +static TypedefDecl *CreateVoidPtrBuiltinVaListDecl(const ASTContext *Context) {
> +  // typedef void* __builtin_va_list;
> +  QualType VoidPtrType = Context->getPointerType(Context->VoidTy);
> +  TypeSourceInfo *TInfo
> +    = Context->getTrivialTypeSourceInfo(VoidPtrType);
> +
> +  TypedefDecl *VaListTypeDecl
> +    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
> +                          Context->getTranslationUnitDecl(),
> +                          SourceLocation(), SourceLocation(),
> +                          &Context->Idents.get("__builtin_va_list"),
> +                          TInfo);
> +  return VaListTypeDecl;
> +}
> +
> +static TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) {
> +  // typedef struct __va_list_tag {
> +  RecordDecl *VaListTagDecl;
> +
> +  VaListTagDecl = CreateRecordDecl(*Context, TTK_Struct,
> +                                   Context->getTranslationUnitDecl(),
> +                                   &Context->Idents.get("__va_list_tag"));
> +  VaListTagDecl->startDefinition();
> +
> +  const size_t NumFields = 5;
> +  QualType FieldTypes[NumFields];
> +  const char *FieldNames[NumFields];
> +
> +  //   unsigned char gpr;
> +  FieldTypes[0] = Context->UnsignedCharTy;
> +  FieldNames[0] = "gpr";
> +
> +  //   unsigned char fpr;
> +  FieldTypes[1] = Context->UnsignedCharTy;
> +  FieldNames[1] = "fpr";
> +
> +  //   unsigned short reserved;
> +  FieldTypes[2] = Context->UnsignedShortTy;
> +  FieldNames[2] = "reserved";
> +
> +  //   void* overflow_arg_area;
> +  FieldTypes[3] = Context->getPointerType(Context->VoidTy);
> +  FieldNames[3] = "overflow_arg_area";
> +
> +  //   void* reg_save_area;
> +  FieldTypes[4] = Context->getPointerType(Context->VoidTy);
> +  FieldNames[4] = "reg_save_area";
> +
> +  // Create fields
> +  for (unsigned i = 0; i < NumFields; ++i) {
> +    FieldDecl *Field = FieldDecl::Create(*Context, VaListTagDecl,
> +                                         SourceLocation(),
> +                                         SourceLocation(),
> +                                         &Context->Idents.get(FieldNames[i]),
> +                                         FieldTypes[i], /*TInfo=*/0,
> +                                         /*BitWidth=*/0,
> +                                         /*Mutable=*/false,
> +                                         ICIS_NoInit);
> +    Field->setAccess(AS_public);
> +    VaListTagDecl->addDecl(Field);
> +  }
> +  VaListTagDecl->completeDefinition();
> +  QualType VaListTagType = Context->getRecordType(VaListTagDecl);
> +
> +  // } __va_list_tag;
> +  TypedefDecl *VaListTagTypedefDecl
> +    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
> +                          Context->getTranslationUnitDecl(),
> +                          SourceLocation(), SourceLocation(),
> +                          &Context->Idents.get("__va_list_tag"),
> +                          Context->getTrivialTypeSourceInfo(VaListTagType));
> +  QualType VaListTagTypedefType =
> +    Context->getTypedefType(VaListTagTypedefDecl);
> +
> +  // typedef __va_list_tag __builtin_va_list[1];
> +  llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1);
> +  QualType VaListTagArrayType
> +    = Context->getConstantArrayType(VaListTagTypedefType,
> +                                    Size, ArrayType::Normal, 0);
> +  TypeSourceInfo *TInfo
> +    = Context->getTrivialTypeSourceInfo(VaListTagArrayType);
> +  TypedefDecl *VaListTypedefDecl
> +    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
> +                          Context->getTranslationUnitDecl(),
> +                          SourceLocation(), SourceLocation(),
> +                          &Context->Idents.get("__builtin_va_list"),
> +                          TInfo);
> +
> +  return VaListTypedefDecl;
> +}
> +
> +static TypedefDecl *
> +CreateX86_64ABIBuiltinVaListDecl(const ASTContext *Context) {
> +  // typedef struct __va_list_tag {
> +  RecordDecl *VaListTagDecl;
> +  VaListTagDecl = CreateRecordDecl(*Context, TTK_Struct,
> +                                   Context->getTranslationUnitDecl(),
> +                                   &Context->Idents.get("__va_list_tag"));
> +  VaListTagDecl->startDefinition();
> +
> +  const size_t NumFields = 4;
> +  QualType FieldTypes[NumFields];
> +  const char *FieldNames[NumFields];
> +
> +  //   unsigned gp_offset;
> +  FieldTypes[0] = Context->UnsignedIntTy;
> +  FieldNames[0] = "gp_offset";
> +
> +  //   unsigned fp_offset;
> +  FieldTypes[1] = Context->UnsignedIntTy;
> +  FieldNames[1] = "fp_offset";
> +
> +  //   void* overflow_arg_area;
> +  FieldTypes[2] = Context->getPointerType(Context->VoidTy);
> +  FieldNames[2] = "overflow_arg_area";
> +
> +  //   void* reg_save_area;
> +  FieldTypes[3] = Context->getPointerType(Context->VoidTy);
> +  FieldNames[3] = "reg_save_area";
> +
> +  // Create fields
> +  for (unsigned i = 0; i < NumFields; ++i) {
> +    FieldDecl *Field = FieldDecl::Create(const_cast<ASTContext &>(*Context),
> +                                         VaListTagDecl,
> +                                         SourceLocation(),
> +                                         SourceLocation(),
> +                                         &Context->Idents.get(FieldNames[i]),
> +                                         FieldTypes[i], /*TInfo=*/0,
> +                                         /*BitWidth=*/0,
> +                                         /*Mutable=*/false,
> +                                         ICIS_NoInit);
> +    Field->setAccess(AS_public);
> +    VaListTagDecl->addDecl(Field);
> +  }
> +  VaListTagDecl->completeDefinition();
> +  QualType VaListTagType = Context->getRecordType(VaListTagDecl);
> +
> +  // } __va_list_tag;
> +  TypedefDecl *VaListTagTypedefDecl
> +    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
> +                          Context->getTranslationUnitDecl(),
> +                          SourceLocation(), SourceLocation(),
> +                          &Context->Idents.get("__va_list_tag"),
> +                          Context->getTrivialTypeSourceInfo(VaListTagType));
> +  QualType VaListTagTypedefType =
> +    Context->getTypedefType(VaListTagTypedefDecl);
> +
> +  // typedef __va_list_tag __builtin_va_list[1];
> +  llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1);
> +  QualType VaListTagArrayType
> +    = Context->getConstantArrayType(VaListTagTypedefType,
> +                                      Size, ArrayType::Normal,0);
> +  TypeSourceInfo *TInfo
> +    = Context->getTrivialTypeSourceInfo(VaListTagArrayType);
> +  TypedefDecl *VaListTypedefDecl
> +    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
> +                          Context->getTranslationUnitDecl(),
> +                          SourceLocation(), SourceLocation(),
> +                          &Context->Idents.get("__builtin_va_list"),
> +                          TInfo);
> +
> +  return VaListTypedefDecl;
> +}
> +
> +static TypedefDecl *CreatePNaClABIBuiltinVaListDecl(const ASTContext *Context) {
> +  // typedef int __builtin_va_list[4];
> +  llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 4);
> +  QualType IntArrayType
> +    = Context->getConstantArrayType(Context->IntTy,
> +                                   Size, ArrayType::Normal, 0);
> +  TypedefDecl *VaListTypedefDecl
> +    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
> +                          Context->getTranslationUnitDecl(),
> +                          SourceLocation(), SourceLocation(),
> +                          &Context->Idents.get("__builtin_va_list"),
> +                          Context->getTrivialTypeSourceInfo(IntArrayType));
> +
> +  return VaListTypedefDecl;
> +}
> +
> +static TypedefDecl *CreateVaListDecl(const ASTContext *Context,
> +                                     TargetInfo::BuiltinVaListKind Kind) {
> +  switch (Kind) {
> +  case TargetInfo::CharPtrBuiltinVaList:
> +    return CreateCharPtrBuiltinVaListDecl(Context);
> +  case TargetInfo::VoidPtrBuiltinVaList:
> +    return CreateVoidPtrBuiltinVaListDecl(Context);
> +  case TargetInfo::PowerABIBuiltinVaList:
> +    return CreatePowerABIBuiltinVaListDecl(Context);
> +  case TargetInfo::X86_64ABIBuiltinVaList:
> +    return CreateX86_64ABIBuiltinVaListDecl(Context);
> +  case TargetInfo::PNaClABIBuiltinVaList:
> +    return CreatePNaClABIBuiltinVaListDecl(Context);
> +  }
> +
> +  llvm_unreachable("Unhandled __builtin_va_list type kind");
> +}
> +
> +TypedefDecl *ASTContext::getBuiltinVaListDecl() const {
> +  if (!BuiltinVaListDecl)
> +    BuiltinVaListDecl = CreateVaListDecl(this, Target->getBuiltinVaListKind());
> +
> +  return BuiltinVaListDecl;
> +}
> +
>  void ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) {
>   assert(ObjCConstantStringType.isNull() &&
>          "'NSConstantString' type already set!");
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Fri Jun 15 22:34:49 2012
> @@ -929,15 +929,9 @@
>     }
>   }
>
> -  virtual const char *getVAListDeclaration() const {
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
>     // This is the ELF definition, and is overridden by the Darwin sub-target
> -    return "typedef struct __va_list_tag {"
> -           "  unsigned char gpr;"
> -           "  unsigned char fpr;"
> -           "  unsigned short reserved;"
> -           "  void* overflow_arg_area;"
> -           "  void* reg_save_area;"
> -           "} __builtin_va_list[1];";
> +    return TargetInfo::PowerABIBuiltinVaList;
>   }
>  };
>  } // end anonymous namespace.
> @@ -958,8 +952,8 @@
>       LongDoubleFormat = &llvm::APFloat::IEEEdouble;
>     }
>   }
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef char* __builtin_va_list;";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::CharPtrBuiltinVaList;
>   }
>  };
>  } // end anonymous namespace.
> @@ -978,8 +972,8 @@
>     DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
>                         "i64:32:64-f32:32:32-f64:64:64-v128:128:128-n32";
>   }
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef char* __builtin_va_list;";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::CharPtrBuiltinVaList;
>   }
>  };
>
> @@ -1047,9 +1041,9 @@
>       // FIXME: Is this really right?
>       return "";
>     }
> -    virtual const char *getVAListDeclaration() const {
> +    virtual BuiltinVaListKind getBuiltinVaListKind() const {
>       // FIXME: implement
> -      return "typedef char* __builtin_va_list;";
> +      return TargetInfo::CharPtrBuiltinVaList;
>     }
>     virtual bool setCPU(const std::string &Name) {
>       return Name == "sm_10" || Name == "sm_13" || Name == "sm_20";
> @@ -1138,8 +1132,8 @@
>     return Feature == "mblaze";
>   }
>
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef char* __builtin_va_list;";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::CharPtrBuiltinVaList;
>   }
>   virtual const char *getTargetPrefix() const {
>     return "mblaze";
> @@ -2344,8 +2338,8 @@
>     // MaxAtomicInlineWidth. (cmpxchg8b is an i586 instruction.)
>     MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
>   }
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef char* __builtin_va_list;";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::CharPtrBuiltinVaList;
>   }
>
>   int getEHDataRegisterNumber(unsigned RegNo) const {
> @@ -2604,14 +2598,8 @@
>     MaxAtomicPromoteWidth = 128;
>     MaxAtomicInlineWidth = 64;
>   }
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef struct __va_list_tag {"
> -           "  unsigned gp_offset;"
> -           "  unsigned fp_offset;"
> -           "  void* overflow_arg_area;"
> -           "  void* reg_save_area;"
> -           "} __va_list_tag;"
> -           "typedef __va_list_tag __builtin_va_list[1];";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::X86_64ABIBuiltinVaList;
>   }
>
>   int getEHDataRegisterNumber(unsigned RegNo) const {
> @@ -2645,8 +2633,8 @@
>     WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder);
>     Builder.defineMacro("_WIN64");
>   }
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef char* __builtin_va_list;";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::CharPtrBuiltinVaList;
>   }
>  };
>  } // end anonymous namespace
> @@ -2977,8 +2965,8 @@
>     NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin;
>   }
>   virtual bool isCLZForZeroUndef() const { return false; }
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef void* __builtin_va_list;";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::VoidPtrBuiltinVaList;
>   }
>   virtual void getGCCRegNames(const char * const *&Names,
>                               unsigned &NumNames) const;
> @@ -3158,8 +3146,8 @@
>     return Feature == "hexagon";
>   }
>
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef char* __builtin_va_list;";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::CharPtrBuiltinVaList;
>   }
>   virtual void getGCCRegNames(const char * const *&Names,
>                               unsigned &NumNames) const;
> @@ -3325,8 +3313,8 @@
>                                  unsigned &NumRecords) const {
>     // FIXME: Implement!
>   }
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef void* __builtin_va_list;";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::VoidPtrBuiltinVaList;
>   }
>   virtual void getGCCRegNames(const char * const *&Names,
>                               unsigned &NumNames) const;
> @@ -3469,9 +3457,9 @@
>       // FIXME: Is this really right?
>       return "";
>     }
> -    virtual const char *getVAListDeclaration() const {
> +    virtual BuiltinVaListKind getBuiltinVaListKind() const {
>       // FIXME: implement
> -      return "typedef char* __builtin_va_list;";
> +      return TargetInfo::CharPtrBuiltinVaList;
>    }
>   };
>
> @@ -3553,8 +3541,8 @@
>     virtual const char *getClobbers() const {
>       return "";
>     }
> -    virtual const char *getVAListDeclaration() const {
> -      return "typedef void* __builtin_va_list;";
> +    virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +      return TargetInfo::VoidPtrBuiltinVaList;
>     }
>     virtual void getGCCRegNames(const char * const *&Names,
>                                 unsigned &NumNames) const {}
> @@ -3623,8 +3611,8 @@
>   virtual bool hasFeature(StringRef Feature) const {
>     return Feature == "mips";
>   }
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef void* __builtin_va_list;";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::VoidPtrBuiltinVaList;
>   }
>   virtual void getGCCRegNames(const char * const *&Names,
>                               unsigned &NumNames) const {
> @@ -3997,8 +3985,8 @@
>   virtual void getTargetBuiltins(const Builtin::Info *&Records,
>                                  unsigned &NumRecords) const {
>   }
> -  virtual const char *getVAListDeclaration() const {
> -    return "typedef int __builtin_va_list[4];";
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::PNaClABIBuiltinVaList;
>   }
>   virtual void getGCCRegNames(const char * const *&Names,
>                               unsigned &NumNames) const;
>
> Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
> +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Fri Jun 15 22:34:49 2012
> @@ -519,9 +519,6 @@
>   if (TI.getLongLongWidth() > TI.getLongWidth())
>     DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Builder);
>
> -  // Add __builtin_va_list typedef.
> -  Builder.append(TI.getVAListDeclaration());
> -
>   if (const char *Prefix = TI.getUserLabelPrefix())
>     Builder.defineMacro("__USER_LABEL_PREFIX__", Prefix);
>
>
> Modified: cfe/trunk/lib/Sema/Sema.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/Sema.cpp (original)
> +++ cfe/trunk/lib/Sema/Sema.cpp Fri Jun 15 22:34:49 2012
> @@ -180,6 +180,10 @@
>     if (IdResolver.begin(Protocol) == IdResolver.end())
>       PushOnScopeChains(Context.getObjCProtocolDecl(), TUScope);
>   }
> +
> +  DeclarationName BuiltinVaList = &Context.Idents.get("__builtin_va_list");
> +  if (IdResolver.begin(BuiltinVaList) == IdResolver.end())
> +    PushOnScopeChains(Context.getBuiltinVaListDecl(), TUScope);
>  }
>
>  Sema::~Sema() {
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jun 15 22:34:49 2012
> @@ -3930,8 +3930,6 @@
>         Context.setsigjmp_bufDecl(NewTD);
>       else if (II->isStr("ucontext_t"))
>         Context.setucontext_tDecl(NewTD);
> -      else if (II->isStr("__builtin_va_list"))
> -        Context.setBuiltinVaListType(Context.getTypedefType(NewTD));
>     }
>
>   return NewTD;
>
> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Jun 15 22:34:49 2012
> @@ -2851,11 +2851,6 @@
>
>   // Load the special types.
>   if (SpecialTypes.size() >= NumSpecialTypeIDs) {
> -    if (Context.getBuiltinVaListType().isNull()) {
> -      Context.setBuiltinVaListType(
> -        GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST]));
> -    }
> -
>     if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
>       if (!Context.CFConstantStringTypeDecl)
>         Context.setCFConstantStringType(GetType(String));
> @@ -4646,6 +4641,9 @@
>
>     case PREDEF_DECL_OBJC_INSTANCETYPE_ID:
>       return Context.getObjCInstanceTypeDecl();
> +
> +    case PREDEF_DECL_BUILTIN_VA_LIST_ID:
> +      return Context.getBuiltinVaListDecl();
>     }
>   }
>
>
> Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Jun 15 22:34:49 2012
> @@ -3212,7 +3212,9 @@
>     DeclIDs[Context.UInt128Decl] = PREDEF_DECL_UNSIGNED_INT_128_ID;
>   if (Context.ObjCInstanceTypeDecl)
>     DeclIDs[Context.ObjCInstanceTypeDecl] = PREDEF_DECL_OBJC_INSTANCETYPE_ID;
> -
> +  if (Context.BuiltinVaListDecl)
> +    DeclIDs[Context.getBuiltinVaListDecl()] = PREDEF_DECL_BUILTIN_VA_LIST_ID;
> +
>   if (!Chain) {
>     // Make sure that we emit IdentifierInfos (and any attached
>     // declarations) for builtins. We don't need to do this when we're
> @@ -3384,7 +3386,6 @@
>
>   // Form the record of special types.
>   RecordData SpecialTypes;
> -  AddTypeRef(Context.getBuiltinVaListType(), SpecialTypes);
>   AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
>   AddTypeRef(Context.getFILEType(), SpecialTypes);
>   AddTypeRef(Context.getjmp_bufType(), SpecialTypes);
>
> Modified: cfe/trunk/test/PCH/chain-trivial.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-trivial.c?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/test/PCH/chain-trivial.c (original)
> +++ cfe/trunk/test/PCH/chain-trivial.c Fri Jun 15 22:34:49 2012
> @@ -1,4 +1,2 @@
>  // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t1 %S/Inputs/chain-trivial1.h
>  // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t2 -include-pch %t1 %S/Inputs/chain-trivial2.h
> -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-print -include-pch %t2 %s | FileCheck %s
> -// CHECK: struct __va_list_tag {
>
> Modified: cfe/trunk/unittests/Tooling/ToolingTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/ToolingTest.cpp?rev=158592&r1=158591&r2=158592&view=diff
> ==============================================================================
> --- cfe/trunk/unittests/Tooling/ToolingTest.cpp (original)
> +++ cfe/trunk/unittests/Tooling/ToolingTest.cpp Fri Jun 15 22:34:49 2012
> @@ -53,11 +53,11 @@
>  };
>  } // end namespace
>
> -TEST(runToolOnCode, FindsTopLevelDeclOnEmptyCode) {
> +TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) {
>   bool FoundTopLevelDecl = false;
>   EXPECT_TRUE(runToolOnCode(
>       new TestAction(new FindTopLevelDeclConsumer(&FoundTopLevelDecl)), ""));
> -  EXPECT_TRUE(FoundTopLevelDecl);
> +  EXPECT_FALSE(FoundTopLevelDecl);
>  }
>
>  namespace {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list