zcov: / lib/Sema/SemaType.cpp


Files: 1 Branches Taken: 84.1% 662 / 787
Generated: 2010-02-10 01:31 Branches Executed: 98.5% 775 / 787
Line Coverage: 93.0% 789 / 848


Programs: 2 Runs 3018


       1                 : //===--- SemaType.cpp - Semantic Analysis for Types -----------------------===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : //  This file implements type-related semantic analysis.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #include "Sema.h"
      15                 : #include "clang/AST/ASTContext.h"
      16                 : #include "clang/AST/CXXInheritance.h"
      17                 : #include "clang/AST/DeclObjC.h"
      18                 : #include "clang/AST/DeclTemplate.h"
      19                 : #include "clang/AST/TypeLoc.h"
      20                 : #include "clang/AST/TypeLocVisitor.h"
      21                 : #include "clang/AST/Expr.h"
      22                 : #include "clang/Basic/PartialDiagnostic.h"
      23                 : #include "clang/Parse/DeclSpec.h"
      24                 : #include "llvm/ADT/SmallPtrSet.h"
      25                 : #include "llvm/Support/ErrorHandling.h"
      26                 : using namespace clang;
      27                 : 
      28                 : /// \brief Perform adjustment on the parameter type of a function.
      29                 : ///
      30                 : /// This routine adjusts the given parameter type @p T to the actual
      31                 : /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8],
      32                 : /// C++ [dcl.fct]p3). The adjusted parameter type is returned.
      33            31725: QualType Sema::adjustParameterType(QualType T) {
      34                 :   // C99 6.7.5.3p7:
      35                 :   //   A declaration of a parameter as "array of type" shall be
      36                 :   //   adjusted to "qualified pointer to type", where the type
      37                 :   //   qualifiers (if any) are those specified within the [ and ] of
      38                 :   //   the array type derivation.
                      206: branch 2 taken
                    31519: branch 3 taken
      39            31725:   if (T->isArrayType())
      40              206:     return Context.getArrayDecayedType(T);
      41                 :   
      42                 :   // C99 6.7.5.3p8:
      43                 :   //   A declaration of a parameter as "function returning type"
      44                 :   //   shall be adjusted to "pointer to function returning type", as
      45                 :   //   in 6.3.2.1.
                       29: branch 2 taken
                    31490: branch 3 taken
      46            31519:   if (T->isFunctionType())
      47               29:     return Context.getPointerType(T);
      48                 : 
      49            31490:   return T;
      50                 : }
      51                 : 
      52                 : 
      53                 : 
      54                 : /// isOmittedBlockReturnType - Return true if this declarator is missing a
      55                 : /// return type because this is a omitted return type on a block literal. 
      56              291: static bool isOmittedBlockReturnType(const Declarator &D) {
                      245: branch 1 taken
                       46: branch 2 taken
                        0: branch 5 not taken
                      245: branch 6 taken
                       46: branch 7 taken
                      245: branch 8 taken
      57              291:   if (D.getContext() != Declarator::BlockLiteralContext ||
      58                 :       D.getDeclSpec().hasTypeSpecifier())
      59               46:     return false;
      60                 :   
                        2: branch 1 taken
                      243: branch 2 taken
      61              245:   if (D.getNumTypeObjects() == 0)
      62                2:     return true;   // ^{ ... }
      63                 :   
                      243: branch 1 taken
                        0: branch 2 not taken
                      243: branch 4 taken
                        0: branch 5 not taken
                      243: branch 6 taken
                        0: branch 7 not taken
      64              243:   if (D.getNumTypeObjects() == 1 &&
      65                 :       D.getTypeObject(0).Kind == DeclaratorChunk::Function)
      66              243:     return true;   // ^(int X, float Y) { ... }
      67                 :   
      68                0:   return false;
      69                 : }
      70                 : 
      71                 : typedef std::pair<const AttributeList*,QualType> DelayedAttribute;
      72                 : typedef llvm::SmallVectorImpl<DelayedAttribute> DelayedAttributeSet;
      73                 : 
      74                 : static void ProcessTypeAttributeList(Sema &S, QualType &Type,
      75                 :                                      const AttributeList *Attrs,
      76                 :                                      DelayedAttributeSet &DelayedFnAttrs);
      77                 : static bool ProcessFnAttr(Sema &S, QualType &Type, const AttributeList &Attr);
      78                 : 
      79                 : static void ProcessDelayedFnAttrs(Sema &S, QualType &Type,
      80            79481:                                   DelayedAttributeSet &Attrs) {
                       29: branch 1 taken
                    79481: branch 2 taken
      81           158991:   for (DelayedAttributeSet::iterator I = Attrs.begin(),
      82            79481:          E = Attrs.end(); I != E; ++I)
                        2: branch 1 taken
                       27: branch 2 taken
      83               29:     if (ProcessFnAttr(S, Type, *I->first))
      84                 :       S.Diag(I->first->getLoc(), diag::warn_function_attribute_wrong_type)
      85                2:         << I->first->getName() << I->second;
      86            79481:   Attrs.clear();
      87            79481: }
      88                 : 
      89            98509: static void DiagnoseDelayedFnAttrs(Sema &S, DelayedAttributeSet &Attrs) {
                        1: branch 1 taken
                    98509: branch 2 taken
      90           197019:   for (DelayedAttributeSet::iterator I = Attrs.begin(),
      91            98509:          E = Attrs.end(); I != E; ++I) {
      92                 :     S.Diag(I->first->getLoc(), diag::warn_function_attribute_wrong_type)
      93                1:       << I->first->getName() << I->second;
      94                 :   }
      95            98509:   Attrs.clear();
      96            98509: }
      97                 : 
      98                 : /// \brief Convert the specified declspec to the appropriate type
      99                 : /// object.
     100                 : /// \param D  the declarator containing the declaration specifier.
     101                 : /// \returns The type described by the declaration specifiers.  This function
     102                 : /// never returns null.
     103                 : static QualType ConvertDeclSpecToType(Sema &TheSema,
     104                 :                                       Declarator &TheDeclarator,
     105            63684:                                       DelayedAttributeSet &Delayed) {
     106                 :   // FIXME: Should move the logic from DeclSpec::Finish to here for validity
     107                 :   // checking.
     108            63684:   const DeclSpec &DS = TheDeclarator.getDeclSpec();
     109            63684:   SourceLocation DeclLoc = TheDeclarator.getIdentifierLoc();
                     1232: branch 1 taken
                    62452: branch 2 taken
     110            63684:   if (DeclLoc.isInvalid())
     111             1232:     DeclLoc = DS.getSourceRange().getBegin();
     112                 :   
     113            63684:   ASTContext &Context = TheSema.Context;
     114                 : 
     115            63684:   QualType Result;
                    11689: branch 1 taken
                     5446: branch 2 taken
                       20: branch 3 taken
                        2: branch 4 taken
                        2: branch 5 taken
                      294: branch 6 taken
                    18783: branch 7 taken
                     1711: branch 8 taken
                      993: branch 9 taken
                      372: branch 10 taken
                        1: branch 11 taken
                     2880: branch 12 taken
                    21125: branch 13 taken
                       17: branch 14 taken
                      245: branch 15 taken
                       16: branch 16 taken
                       10: branch 17 taken
                       78: branch 18 taken
                        0: branch 19 not taken
     116            63684:   switch (DS.getTypeSpecType()) {
     117                 :   case DeclSpec::TST_void:
     118            11689:     Result = Context.VoidTy;
     119            11689:     break;
     120                 :   case DeclSpec::TST_char:
                     4835: branch 1 taken
                      611: branch 2 taken
     121             5446:     if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified)
     122             4835:       Result = Context.CharTy;
                      266: branch 1 taken
                      345: branch 2 taken
     123              611:     else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed)
     124              266:       Result = Context.SignedCharTy;
     125                 :     else {
     126                 :       assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned &&
                      345: branch 1 taken
                        0: branch 2 not taken
     127              345:              "Unknown TSS value");
     128              345:       Result = Context.UnsignedCharTy;
     129                 :     }
     130             5446:     break;
     131                 :   case DeclSpec::TST_wchar:
                       18: branch 1 taken
                        2: branch 2 taken
     132               20:     if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified)
     133               18:       Result = Context.WCharTy;
                        1: branch 1 taken
                        1: branch 2 taken
     134                2:     else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed) {
     135                 :       TheSema.Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec)
     136                1:         << DS.getSpecifierName(DS.getTypeSpecType());
     137                1:       Result = Context.getSignedWCharType();
     138                 :     } else {
     139                 :       assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned &&
                        1: branch 1 taken
                        0: branch 2 not taken
     140                1:         "Unknown TSS value");
     141                 :       TheSema.Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec)
     142                1:         << DS.getSpecifierName(DS.getTypeSpecType());
     143                1:       Result = Context.getUnsignedWCharType();
     144                 :     }
     145               20:     break;
     146                 :   case DeclSpec::TST_char16:
     147                 :       assert(DS.getTypeSpecSign() == DeclSpec::TSS_unspecified &&
                        2: branch 1 taken
                        0: branch 2 not taken
     148                2:         "Unknown TSS value");
     149                2:       Result = Context.Char16Ty;
     150                2:     break;
     151                 :   case DeclSpec::TST_char32:
     152                 :       assert(DS.getTypeSpecSign() == DeclSpec::TSS_unspecified &&
                        2: branch 1 taken
                        0: branch 2 not taken
     153                2:         "Unknown TSS value");
     154                2:       Result = Context.Char32Ty;
     155                2:     break;
     156                 :   case DeclSpec::TST_unspecified:
     157                 :     // "<proto1,proto2>" is an objc qualified ID with a missing id.
                        3: branch 1 taken
                      291: branch 2 taken
     158              294:     if (DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers()) {
     159                 :       Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy,
     160                 :                                                 (ObjCProtocolDecl**)PQ,
     161                3:                                                 DS.getNumProtocolQualifiers());
     162                3:       break;
     163                 :     }
     164                 :     
     165                 :     // If this is a missing declspec in a block literal return context, then it
     166                 :     // is inferred from the return statements inside the block.
                      245: branch 1 taken
                       46: branch 2 taken
     167              291:     if (isOmittedBlockReturnType(TheDeclarator)) {
     168              245:       Result = Context.DependentTy;
     169              245:       break;
     170                 :     }
     171                 : 
     172                 :     // Unspecified typespec defaults to int in C90.  However, the C90 grammar
     173                 :     // [C90 6.5] only allows a decl-spec if there was *some* type-specifier,
     174                 :     // type-qualifier, or storage-class-specifier.  If not, emit an extwarn.
     175                 :     // Note that the one exception to this is function definitions, which are
     176                 :     // allowed to be completely missing a declspec.  This is handled in the
     177                 :     // parser already though by it pretending to have seen an 'int' in this
     178                 :     // case.
                        4: branch 1 taken
                       42: branch 2 taken
     179               46:     if (TheSema.getLangOptions().ImplicitInt) {
     180                 :       // In C89 mode, we only warn if there is a completely missing declspec
     181                 :       // when one is not allowed.
                        3: branch 1 taken
                        1: branch 2 taken
     182                4:       if (DS.isEmpty()) {
     183                 :         TheSema.Diag(DeclLoc, diag::ext_missing_declspec)
     184                 :           << DS.getSourceRange()
     185                 :         << CodeModificationHint::CreateInsertion(DS.getSourceRange().getBegin(),
     186                3:                                                  "int");
     187                 :       }
                       30: branch 1 taken
                       12: branch 2 taken
     188               42:     } else if (!DS.hasTypeSpecifier()) {
     189                 :       // C99 and C++ require a type specifier.  For example, C99 6.7.2p2 says:
     190                 :       // "At least one type specifier shall be given in the declaration
     191                 :       // specifiers in each declaration, and in the specifier-qualifier list in
     192                 :       // each struct declaration and type name."
     193                 :       // FIXME: Does Microsoft really have the implicit int extension in C++?
                        6: branch 1 taken
                       24: branch 2 taken
                        6: branch 4 taken
                        0: branch 5 not taken
                        6: branch 6 taken
                       24: branch 7 taken
     194               30:       if (TheSema.getLangOptions().CPlusPlus &&
     195                 :           !TheSema.getLangOptions().Microsoft) {
     196                 :         TheSema.Diag(DeclLoc, diag::err_missing_type_specifier)
     197                6:           << DS.getSourceRange();
     198                 : 
     199                 :         // When this occurs in C++ code, often something is very broken with the
     200                 :         // value being declared, poison it as invalid so we don't get chains of
     201                 :         // errors.
     202                6:         TheDeclarator.setInvalidType(true);
     203                 :       } else {
     204                 :         TheSema.Diag(DeclLoc, diag::ext_missing_type_specifier)
     205               24:           << DS.getSourceRange();
     206                 :       }
     207                 :     }
     208                 : 
     209                 :     // FALL THROUGH.
     210                 :   case DeclSpec::TST_int: {
                    16469: branch 1 taken
                     2360: branch 2 taken
     211            18829:     if (DS.getTypeSpecSign() != DeclSpec::TSS_unsigned) {
                    14989: branch 1 taken
                      458: branch 2 taken
                      663: branch 3 taken
                      359: branch 4 taken
                        0: branch 5 not taken
     212            16469:       switch (DS.getTypeSpecWidth()) {
     213            14989:       case DeclSpec::TSW_unspecified: Result = Context.IntTy; break;
     214              458:       case DeclSpec::TSW_short:       Result = Context.ShortTy; break;
     215              663:       case DeclSpec::TSW_long:        Result = Context.LongTy; break;
     216                 :       case DeclSpec::TSW_longlong:
     217              359:         Result = Context.LongLongTy;
     218                 :           
     219                 :         // long long is a C99 feature.
                       58: branch 1 taken
                      301: branch 2 taken
                       54: branch 4 taken
                        4: branch 5 taken
                       54: branch 6 taken
                      305: branch 7 taken
     220              359:         if (!TheSema.getLangOptions().C99 &&
     221                 :             !TheSema.getLangOptions().CPlusPlus0x)
     222               54:           TheSema.Diag(DS.getTypeSpecWidthLoc(), diag::ext_longlong);
     223                 :         break;
     224                 :       }
     225                 :     } else {
                     1603: branch 1 taken
                      299: branch 2 taken
                      296: branch 3 taken
                      162: branch 4 taken
                        0: branch 5 not taken
     226             2360:       switch (DS.getTypeSpecWidth()) {
     227             1603:       case DeclSpec::TSW_unspecified: Result = Context.UnsignedIntTy; break;
     228              299:       case DeclSpec::TSW_short:       Result = Context.UnsignedShortTy; break;
     229              296:       case DeclSpec::TSW_long:        Result = Context.UnsignedLongTy; break;
     230                 :       case DeclSpec::TSW_longlong:
     231              162:         Result = Context.UnsignedLongLongTy;
     232                 :           
     233                 :         // long long is a C99 feature.
                       42: branch 1 taken
                      120: branch 2 taken
                       37: branch 4 taken
                        5: branch 5 taken
                       37: branch 6 taken
                      125: branch 7 taken
     234              162:         if (!TheSema.getLangOptions().C99 &&
     235                 :             !TheSema.getLangOptions().CPlusPlus0x)
     236               37:           TheSema.Diag(DS.getTypeSpecWidthLoc(), diag::ext_longlong);
     237                 :         break;
     238                 :       }
     239                 :     }
     240            18829:     break;
     241                 :   }
     242             1711:   case DeclSpec::TST_float: Result = Context.FloatTy; break;
     243                 :   case DeclSpec::TST_double:
                      114: branch 1 taken
                      879: branch 2 taken
     244              993:     if (DS.getTypeSpecWidth() == DeclSpec::TSW_long)
     245              114:       Result = Context.LongDoubleTy;
     246                 :     else
     247              879:       Result = Context.DoubleTy;
     248              993:     break;
     249              372:   case DeclSpec::TST_bool: Result = Context.BoolTy; break; // _Bool or bool
     250                 :   case DeclSpec::TST_decimal32:    // _Decimal32
     251                 :   case DeclSpec::TST_decimal64:    // _Decimal64
     252                 :   case DeclSpec::TST_decimal128:   // _Decimal128
     253                1:     TheSema.Diag(DS.getTypeSpecTypeLoc(), diag::err_decimal_unsupported);
     254                1:     Result = Context.IntTy;
     255                1:     TheDeclarator.setInvalidType(true);
     256                1:     break;
     257                 :   case DeclSpec::TST_class:
     258                 :   case DeclSpec::TST_enum:
     259                 :   case DeclSpec::TST_union:
     260                 :   case DeclSpec::TST_struct: {
     261                 :     TypeDecl *D 
     262             2880:       = dyn_cast_or_null<TypeDecl>(static_cast<Decl *>(DS.getTypeRep()));
                        3: branch 0 taken
                     2877: branch 1 taken
     263             2880:     if (!D) {
     264                 :       // This can happen in C++ with ambiguous lookups.
     265                3:       Result = Context.IntTy;
     266                3:       TheDeclarator.setInvalidType(true);
     267                3:       break;
     268                 :     }
     269                 : 
     270                 :     // If the type is deprecated or unavailable, diagnose it.
     271             2877:     TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc());
     272                 :     
     273                 :     assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 &&
                     2877: branch 1 taken
                        0: branch 2 not taken
                     2877: branch 4 taken
                        0: branch 5 not taken
                     2877: branch 7 taken
                        0: branch 8 not taken
     274             2877:            DS.getTypeSpecSign() == 0 && "No qualifiers on tag names!");
     275                 :     
     276                 :     // TypeQuals handled by caller.
     277             2877:     Result = Context.getTypeDeclType(D);
     278                 : 
     279                 :     // In C++, make an ElaboratedType.
                      458: branch 1 taken
                     2419: branch 2 taken
     280             2877:     if (TheSema.getLangOptions().CPlusPlus) {
     281                 :       TagDecl::TagKind Tag
     282              458:         = TagDecl::getTagKindForTypeSpec(DS.getTypeSpecType());
     283              458:       Result = Context.getElaboratedType(Result, Tag);
     284                 :     }
     285                 : 
                       17: branch 1 taken
                     2860: branch 2 taken
     286             2877:     if (D->isInvalidDecl())
     287               17:       TheDeclarator.setInvalidType(true);
     288             2877:     break;
     289                 :   }
     290                 :   case DeclSpec::TST_typename: {
     291                 :     assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 &&
     292                 :            DS.getTypeSpecSign() == 0 &&
                    21125: branch 1 taken
                        0: branch 2 not taken
                    21125: branch 4 taken
                        0: branch 5 not taken
                    21125: branch 7 taken
                        0: branch 8 not taken
     293            21125:            "Can't handle qualifiers on typedef names yet!");
     294            21125:     Result = TheSema.GetTypeFromParser(DS.getTypeRep());
     295                 : 
                      330: branch 1 taken
                    20795: branch 2 taken
     296            21125:     if (DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers()) {
                      105: branch 0 taken
                      225: branch 1 taken
     297              330:       if (const ObjCInterfaceType *
     298              330:             Interface = Result->getAs<ObjCInterfaceType>()) {
     299                 :         // It would be nice if protocol qualifiers were only stored with the
     300                 :         // ObjCObjectPointerType. Unfortunately, this isn't possible due
     301                 :         // to the following typedef idiom (which is uncommon, but allowed):
     302                 :         //
     303                 :         // typedef Foo<P> T;
     304                 :         // static void func() {
     305                 :         //   Foo<P> *yy;
     306                 :         //   T *zz;
     307                 :         // }
     308                 :         Result = Context.getObjCInterfaceType(Interface->getDecl(),
     309                 :                                               (ObjCProtocolDecl**)PQ,
     310              105:                                               DS.getNumProtocolQualifiers());
                      217: branch 2 taken
                        8: branch 3 taken
     311              225:       } else if (Result->isObjCIdType())
     312                 :         // id<protocol-list>
     313                 :         Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy,
     314              217:                         (ObjCProtocolDecl**)PQ, DS.getNumProtocolQualifiers());
                        7: branch 2 taken
                        1: branch 3 taken
     315                8:       else if (Result->isObjCClassType()) {
     316                 :         // Class<protocol-list>
     317                 :         Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinClassTy,
     318                7:                         (ObjCProtocolDecl**)PQ, DS.getNumProtocolQualifiers());
     319                 :       } else {
     320                 :         TheSema.Diag(DeclLoc, diag::err_invalid_protocol_qualifiers)
     321                1:           << DS.getSourceRange();
     322                1:         TheDeclarator.setInvalidType(true);
     323                 :       }
     324                 :     }
     325                 : 
     326                 :     // TypeQuals handled by caller.
     327            21125:     break;
     328                 :   }
     329                 :   case DeclSpec::TST_typeofType:
     330                 :     // FIXME: Preserve type source info.
     331               17:     Result = TheSema.GetTypeFromParser(DS.getTypeRep());
                       17: branch 1 taken
                        0: branch 2 not taken
     332               17:     assert(!Result.isNull() && "Didn't get a type for typeof?");
     333                 :     // TypeQuals handled by caller.
     334               17:     Result = Context.getTypeOfType(Result);
     335               17:     break;
     336                 :   case DeclSpec::TST_typeofExpr: {
     337              245:     Expr *E = static_cast<Expr *>(DS.getTypeRep());
                        0: branch 0 not taken
                      245: branch 1 taken
     338              245:     assert(E && "Didn't get an expression for typeof?");
     339                 :     // TypeQuals handled by caller.
     340              245:     Result = TheSema.BuildTypeofExprType(E);
                        1: branch 1 taken
                      244: branch 2 taken
     341              245:     if (Result.isNull()) {
     342                1:       Result = Context.IntTy;
     343                1:       TheDeclarator.setInvalidType(true);
     344                 :     }
     345              245:     break;
     346                 :   }
     347                 :   case DeclSpec::TST_decltype: {
     348               16:     Expr *E = static_cast<Expr *>(DS.getTypeRep());
                        0: branch 0 not taken
                       16: branch 1 taken
     349               16:     assert(E && "Didn't get an expression for decltype?");
     350                 :     // TypeQuals handled by caller.
     351               16:     Result = TheSema.BuildDecltypeType(E);
                        1: branch 1 taken
                       15: branch 2 taken
     352               16:     if (Result.isNull()) {
     353                1:       Result = Context.IntTy;
     354                1:       TheDeclarator.setInvalidType(true);
     355                 :     }
     356               16:     break;
     357                 :   }
     358                 :   case DeclSpec::TST_auto: {
     359                 :     // TypeQuals handled by caller.
     360               10:     Result = Context.UndeducedAutoTy;
     361               10:     break;
     362                 :   }
     363                 : 
     364                 :   case DeclSpec::TST_error:
     365               78:     Result = Context.IntTy;
     366               78:     TheDeclarator.setInvalidType(true);
     367                 :     break;
     368                 :   }
     369                 : 
     370                 :   // Handle complex types.
                      207: branch 1 taken
                    63477: branch 2 taken
     371            63684:   if (DS.getTypeSpecComplex() == DeclSpec::TSC_complex) {
                        9: branch 1 taken
                      198: branch 2 taken
     372              207:     if (TheSema.getLangOptions().Freestanding)
     373                9:       TheSema.Diag(DS.getTypeSpecComplexLoc(), diag::ext_freestanding_complex);
     374              207:     Result = Context.getComplexType(Result);
                      144: branch 1 taken
                    63333: branch 2 taken
     375            63477:   } else if (DS.isTypeAltiVecVector()) {
     376              144:     unsigned typeSize = static_cast<unsigned>(Context.getTypeSize(Result));
                        0: branch 0 not taken
                      144: branch 1 taken
     377              144:     assert(typeSize > 0 && "type size for vector must be greater than 0 bits");
     378                 :     Result = Context.getVectorType(Result, 128/typeSize, true,
     379              144:       DS.isTypeAltiVecPixel());
     380                 :   }
     381                 : 
     382                 :   assert(DS.getTypeSpecComplex() != DeclSpec::TSC_imaginary &&
                    63684: branch 1 taken
                        0: branch 2 not taken
     383            63684:          "FIXME: imaginary types not supported yet!");
     384                 : 
     385                 :   // See if there are any attributes on the declspec that apply to the type (as
     386                 :   // opposed to the decl).
                     1748: branch 1 taken
                    61936: branch 2 taken
     387            63684:   if (const AttributeList *AL = DS.getAttributes())
     388             1748:     ProcessTypeAttributeList(TheSema, Result, AL, Delayed);
     389                 : 
     390                 :   // Apply const/volatile/restrict qualifiers to T.
                     2537: branch 1 taken
                    61147: branch 2 taken
     391            63684:   if (unsigned TypeQuals = DS.getTypeQualifiers()) {
     392                 : 
     393                 :     // Enforce C99 6.7.3p2: "Types other than pointer types derived from object
     394                 :     // or incomplete types shall not be restrict-qualified."  C++ also allows
     395                 :     // restrict-qualified references.
                        8: branch 0 taken
                     2529: branch 1 taken
     396             2537:     if (TypeQuals & DeclSpec::TQ_restrict) {
                        2: branch 2 taken
                        6: branch 3 taken
                        0: branch 6 not taken
                        2: branch 7 taken
                        6: branch 8 taken
                        2: branch 9 taken
     397                8:       if (Result->isAnyPointerType() || Result->isReferenceType()) {
     398                6:         QualType EltTy;
                        4: branch 2 taken
                        2: branch 3 taken
     399                6:         if (Result->isObjCObjectPointerType())
     400                4:           EltTy = Result;
     401                 :         else
     402                 :           EltTy = Result->isPointerType() ?
     403                 :                     Result->getAs<PointerType>()->getPointeeType() :
                        2: branch 2 taken
                        0: branch 3 not taken
     404                2:                     Result->getAs<ReferenceType>()->getPointeeType();
     405                 : 
     406                 :         // If we have a pointer or reference, the pointee must have an object
     407                 :         // incomplete type.
                        1: branch 2 taken
                        5: branch 3 taken
     408                6:         if (!EltTy->isIncompleteOrObjectType()) {
     409                 :           TheSema.Diag(DS.getRestrictSpecLoc(),
     410                 :                diag::err_typecheck_invalid_restrict_invalid_pointee)
     411                1:             << EltTy << DS.getSourceRange();
     412                1:           TypeQuals &= ~DeclSpec::TQ_restrict; // Remove the restrict qualifier.
     413                 :         }
     414                 :       } else {
     415                 :         TheSema.Diag(DS.getRestrictSpecLoc(),
     416                 :              diag::err_typecheck_invalid_restrict_not_pointer)
     417                2:           << Result << DS.getSourceRange();
     418                2:         TypeQuals &= ~DeclSpec::TQ_restrict; // Remove the restrict qualifier.
     419                 :       }
     420                 :     }
     421                 : 
     422                 :     // Warn about CV qualifiers on functions: C99 6.7.3p8: "If the specification
     423                 :     // of a function type includes any type qualifiers, the behavior is
     424                 :     // undefined."
                        2: branch 2 taken
                     2535: branch 3 taken
                        1: branch 4 taken
                        1: branch 5 taken
                        1: branch 6 taken
                     2536: branch 7 taken
     425             2537:     if (Result->isFunctionType() && TypeQuals) {
     426                 :       // Get some location to point at, either the C or V location.
     427                1:       SourceLocation Loc;
                        1: branch 0 taken
                        0: branch 1 not taken
     428                1:       if (TypeQuals & DeclSpec::TQ_const)
     429                1:         Loc = DS.getConstSpecLoc();
                        0: branch 0 not taken
                        0: branch 1 not taken
     430                0:       else if (TypeQuals & DeclSpec::TQ_volatile)
     431                0:         Loc = DS.getVolatileSpecLoc();
     432                 :       else {
     433                 :         assert((TypeQuals & DeclSpec::TQ_restrict) &&
                        0: branch 0 not taken
                        0: branch 1 not taken
     434                0:                "Has CVR quals but not C, V, or R?");
     435                0:         Loc = DS.getRestrictSpecLoc();
     436                 :       }
     437                 :       TheSema.Diag(Loc, diag::warn_typecheck_function_qualifiers)
     438                1:         << Result << DS.getSourceRange();
     439                 :     }
     440                 : 
     441                 :     // C++ [dcl.ref]p1:
     442                 :     //   Cv-qualified references are ill-formed except when the
     443                 :     //   cv-qualifiers are introduced through the use of a typedef
     444                 :     //   (7.1.3) or of a template type argument (14.3), in which
     445                 :     //   case the cv-qualifiers are ignored.
     446                 :     // FIXME: Shouldn't we be checking SCS_typedef here?
                      707: branch 1 taken
                     1830: branch 2 taken
                      704: branch 3 taken
                        3: branch 4 taken
                        3: branch 7 taken
                      701: branch 8 taken
                        3: branch 9 taken
                     2534: branch 10 taken
     447             2537:     if (DS.getTypeSpecType() == DeclSpec::TST_typename &&
     448                 :         TypeQuals && Result->isReferenceType()) {
     449                3:       TypeQuals &= ~DeclSpec::TQ_const;
     450                3:       TypeQuals &= ~DeclSpec::TQ_volatile;
     451                 :     }
     452                 : 
     453             2537:     Qualifiers Quals = Qualifiers::fromCVRMask(TypeQuals);
     454             2537:     Result = Context.getQualifiedType(Result, Quals);
     455                 :   }
     456                 : 
     457                 :   return Result;
     458                 : }
     459                 : 
     460               32: static std::string getPrintableNameForEntity(DeclarationName Entity) {
                       23: branch 1 taken
                        9: branch 2 taken
     461               32:   if (Entity)
     462               23:     return Entity.getAsString();
     463                 : 
     464                9:   return "type name";
     465                 : }
     466                 : 
     467                 : /// \brief Build a pointer type.
     468                 : ///
     469                 : /// \param T The type to which we'll be building a pointer.
     470                 : ///
     471                 : /// \param Quals The cvr-qualifiers to be applied to the pointer type.
     472                 : ///
     473                 : /// \param Loc The location of the entity whose type involves this
     474                 : /// pointer type or, if there is no such entity, the location of the
     475                 : /// type that will have pointer type.
     476                 : ///
     477                 : /// \param Entity The name of the entity that involves the pointer
     478                 : /// type, if known.
     479                 : ///
     480                 : /// \returns A suitable pointer type, if there are no
     481                 : /// errors. Otherwise, returns a NULL type.
     482                 : QualType Sema::BuildPointerType(QualType T, unsigned Quals,
     483            13079:                                 SourceLocation Loc, DeclarationName Entity) {
                       16: branch 2 taken
                    13063: branch 3 taken
     484            13079:   if (T->isReferenceType()) {
     485                 :     // C++ 8.3.2p4: There shall be no ... pointers to references ...
     486                 :     Diag(Loc, diag::err_illegal_decl_pointer_to_reference)
     487               16:       << getPrintableNameForEntity(Entity) << T;
     488               16:     return QualType();
     489                 :   }
     490                 : 
     491            13063:   Qualifiers Qs = Qualifiers::fromCVRMask(Quals);
     492                 : 
     493                 :   // Enforce C99 6.7.3p2: "Types other than pointer types derived from
     494                 :   // object or incomplete types shall not be restrict-qualified."
                      632: branch 1 taken
                    12431: branch 2 taken
                        1: branch 5 taken
                      631: branch 6 taken
                        1: branch 7 taken
                    13062: branch 8 taken
     495            13063:   if (Qs.hasRestrict() && !T->isIncompleteOrObjectType()) {
     496                 :     Diag(Loc, diag::err_typecheck_invalid_restrict_invalid_pointee)
     497                1:       << T;
     498                1:     Qs.removeRestrict();
     499                 :   }
     500                 : 
     501                 :   // Build the pointer type.
     502            13063:   return Context.getQualifiedType(Context.getPointerType(T), Qs);
     503                 : }
     504                 : 
     505                 : /// \brief Build a reference type.
     506                 : ///
     507                 : /// \param T The type to which we'll be building a reference.
     508                 : ///
     509                 : /// \param CVR The cvr-qualifiers to be applied to the reference type.
     510                 : ///
     511                 : /// \param Loc The location of the entity whose type involves this
     512                 : /// reference type or, if there is no such entity, the location of the
     513                 : /// type that will have reference type.
     514                 : ///
     515                 : /// \param Entity The name of the entity that involves the reference
     516                 : /// type, if known.
     517                 : ///
     518                 : /// \returns A suitable reference type, if there are no
     519                 : /// errors. Otherwise, returns a NULL type.
     520                 : QualType Sema::BuildReferenceType(QualType T, bool SpelledAsLValue,
     521                 :                                   unsigned CVR, SourceLocation Loc,
     522             1886:                                   DeclarationName Entity) {
     523             1886:   Qualifiers Quals = Qualifiers::fromCVRMask(CVR);
     524                 : 
                       41: branch 0 taken
                     1845: branch 1 taken
                        3: branch 4 taken
                       38: branch 5 taken
     525             1886:   bool LValueRef = SpelledAsLValue || T->getAs<LValueReferenceType>();
     526                 : 
     527                 :   // C++0x [dcl.typedef]p9: If a typedef TD names a type that is a
     528                 :   //   reference to a type T, and attempt to create the type "lvalue
     529                 :   //   reference to cv TD" creates the type "lvalue reference to T".
     530                 :   // We use the qualifiers (restrict or none) of the original reference,
     531                 :   // not the new ones. This is consistent with GCC.
     532                 : 
     533                 :   // C++ [dcl.ref]p4: There shall be no references to references.
     534                 :   //
     535                 :   // According to C++ DR 106, references to references are only
     536                 :   // diagnosed when they are written directly (e.g., "int & &"),
     537                 :   // but not when they happen via a typedef:
     538                 :   //
     539                 :   //   typedef int& intref;
     540                 :   //   typedef intref& intref2;
     541                 :   //
     542                 :   // Parser::ParseDeclaratorInternal diagnoses the case where
     543                 :   // references are written directly; here, we handle the
     544                 :   // collapsing of references-to-references as described in C++
     545                 :   // DR 106 and amended by C++ DR 540.
     546                 : 
     547                 :   // C++ [dcl.ref]p1:
     548                 :   //   A declarator that specifies the type "reference to cv void"
     549                 :   //   is ill-formed.
                        3: branch 2 taken
                     1883: branch 3 taken
     550             1886:   if (T->isVoidType()) {
     551                3:     Diag(Loc, diag::err_reference_to_void);
     552                3:     return QualType();
     553                 :   }
     554                 : 
     555                 :   // Enforce C99 6.7.3p2: "Types other than pointer types derived from
     556                 :   // object or incomplete types shall not be restrict-qualified."
                        0: branch 1 not taken
                     1883: branch 2 taken
                        0: branch 5 not taken
                        0: branch 6 not taken
                        0: branch 7 not taken
                     1883: branch 8 taken
     557             1883:   if (Quals.hasRestrict() && !T->isIncompleteOrObjectType()) {
     558                 :     Diag(Loc, diag::err_typecheck_invalid_restrict_invalid_pointee)
     559                0:       << T;
     560                0:     Quals.removeRestrict();
     561                 :   }
     562                 : 
     563                 :   // C++ [dcl.ref]p1:
     564                 :   //   [...] Cv-qualified references are ill-formed except when the
     565                 :   //   cv-qualifiers are introduced through the use of a typedef
     566                 :   //   (7.1.3) or of a template type argument (14.3), in which case
     567                 :   //   the cv-qualifiers are ignored.
     568                 :   //
     569                 :   // We diagnose extraneous cv-qualifiers for the non-typedef,
     570                 :   // non-template type argument case within the parser. Here, we just
     571                 :   // ignore any extraneous cv-qualifiers.
     572             1883:   Quals.removeConst();
     573             1883:   Quals.removeVolatile();
     574                 : 
     575                 :   // Handle restrict on references.
                     1845: branch 0 taken
                       38: branch 1 taken
     576             1883:   if (LValueRef)
     577                 :     return Context.getQualifiedType(
     578             1845:                Context.getLValueReferenceType(T, SpelledAsLValue), Quals);
     579               38:   return Context.getQualifiedType(Context.getRValueReferenceType(T), Quals);
     580                 : }
     581                 : 
     582                 : /// \brief Build an array type.
     583                 : ///
     584                 : /// \param T The type of each element in the array.
     585                 : ///
     586                 : /// \param ASM C99 array size modifier (e.g., '*', 'static').
     587                 : ///
     588                 : /// \param ArraySize Expression describing the size of the array.
     589                 : ///
     590                 : /// \param Quals The cvr-qualifiers to be applied to the array's
     591                 : /// element type.
     592                 : ///
     593                 : /// \param Loc The location of the entity whose type involves this
     594                 : /// array type or, if there is no such entity, the location of the
     595                 : /// type that will have array type.
     596                 : ///
     597                 : /// \param Entity The name of the entity that involves the array
     598                 : /// type, if known.
     599                 : ///
     600                 : /// \returns A suitable array type, if there are no errors. Otherwise,
     601                 : /// returns a NULL type.
     602                 : QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
     603                 :                               Expr *ArraySize, unsigned Quals,
     604             2353:                               SourceRange Brackets, DeclarationName Entity) {
     605                 : 
     606             2353:   SourceLocation Loc = Brackets.getBegin();
     607                 :   // C99 6.7.5.2p1: If the element type is an incomplete or function type,
     608                 :   // reject it (e.g. void ary[7], struct foo ary[7], void ary[7]())
     609                 :   // Not in C++, though. There we only dislike void.
                      894: branch 1 taken
                     1459: branch 2 taken
     610             2353:   if (getLangOptions().CPlusPlus) {
                        1: branch 2 taken
                      893: branch 3 taken
     611              894:     if (T->isVoidType()) {
     612                1:       Diag(Loc, diag::err_illegal_decl_array_incomplete_type) << T;
     613                1:       return QualType();
     614                 :     }
     615                 :   } else {
                        9: branch 8 taken
                     1450: branch 9 taken
     616             1459:     if (RequireCompleteType(Loc, T,
     617                 :                             diag::err_illegal_decl_array_incomplete_type))
     618                9:       return QualType();
     619                 :   }
     620                 : 
                        6: branch 2 taken
                     2337: branch 3 taken
     621             2343:   if (T->isFunctionType()) {
     622                 :     Diag(Loc, diag::err_illegal_decl_array_of_functions)
     623                6:       << getPrintableNameForEntity(Entity) << T;
     624                6:     return QualType();
     625                 :   }
     626                 : 
     627                 :   // C++ 8.3.2p4: There shall be no ... arrays of references ...
                        9: branch 2 taken
                     2328: branch 3 taken
     628             2337:   if (T->isReferenceType()) {
     629                 :     Diag(Loc, diag::err_illegal_decl_array_of_references)
     630                9:       << getPrintableNameForEntity(Entity) << T;
     631                9:     return QualType();
     632                 :   }
     633                 : 
                        1: branch 2 taken
                     2327: branch 3 taken
     634             2328:   if (Context.getCanonicalType(T) == Context.UndeducedAutoTy) {
     635                 :     Diag(Loc,  diag::err_illegal_decl_array_of_auto)
     636                1:       << getPrintableNameForEntity(Entity);
     637                1:     return QualType();
     638                 :   }
     639                 : 
                      345: branch 2 taken
                     1982: branch 3 taken
     640             2327:   if (const RecordType *EltTy = T->getAs<RecordType>()) {
     641                 :     // If the element type is a struct or union that contains a variadic
     642                 :     // array, accept it as a GNU extension: C99 6.7.2.1p2.
                        3: branch 2 taken
                      342: branch 3 taken
     643              345:     if (EltTy->getDecl()->hasFlexibleArrayMember())
     644                3:       Diag(Loc, diag::ext_flexible_array_in_array) << T;
                        1: branch 2 taken
                     1981: branch 3 taken
     645             1982:   } else if (T->isObjCInterfaceType()) {
     646                1:     Diag(Loc, diag::err_objc_array_of_interfaces) << T;
     647                1:     return QualType();
     648                 :   }
     649                 : 
     650                 :   // C99 6.7.5.2p1: The size expression shall have integer type.
                     1979: branch 0 taken
                      347: branch 1 taken
                     1979: branch 3 taken
                        0: branch 4 not taken
                        2: branch 8 taken
                     1977: branch 9 taken
                        2: branch 10 taken
                     2324: branch 11 taken
     651             2326:   if (ArraySize && !ArraySize->isTypeDependent() &&
     652                 :       !ArraySize->getType()->isIntegerType()) {
     653                 :     Diag(ArraySize->getLocStart(), diag::err_array_size_non_int)
     654                2:       << ArraySize->getType() << ArraySize->getSourceRange();
     655                2:     ArraySize->Destroy(Context);
     656                2:     return QualType();
     657                 :   }
     658             2324:   llvm::APSInt ConstVal(32);
                      347: branch 0 taken
                     1977: branch 1 taken
     659             2324:   if (!ArraySize) {
                        8: branch 0 taken
                      339: branch 1 taken
     660              347:     if (ASM == ArrayType::Star)
     661                8:       T = Context.getVariableArrayType(T, 0, ASM, Quals, Brackets);
     662                 :     else
     663              339:       T = Context.getIncompleteArrayType(T, ASM, Quals);
                       44: branch 1 taken
                     1933: branch 2 taken
     664             1977:   } else if (ArraySize->isValueDependent()) {
     665               44:     T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals, Brackets);
                     1754: branch 1 taken
                      179: branch 2 taken
                     1749: branch 5 taken
                        5: branch 6 taken
                     1744: branch 9 taken
                        5: branch 10 taken
                        4: branch 13 taken
                     1740: branch 14 taken
                      183: branch 15 taken
                     1750: branch 16 taken
     666             1933:   } else if (!ArraySize->isIntegerConstantExpr(ConstVal, Context) ||
     667                 :              (!T->isDependentType() && !T->isIncompleteType() &&
     668                 :               !T->isConstantSizeType())) {
     669                 :     // Per C99, a variable array is an array with either a non-constant
     670                 :     // size or an element type that has a non-constant-size
     671              183:     T = Context.getVariableArrayType(T, ArraySize, ASM, Quals, Brackets);
     672                 :   } else {
     673                 :     // C99 6.7.5.2p1: If the expression is a constant expression, it shall
     674                 :     // have a value greater than zero.
                     1702: branch 1 taken
                       48: branch 2 taken
                       10: branch 4 taken
                     1692: branch 5 taken
                       10: branch 6 taken
                     1740: branch 7 taken
     675             1750:     if (ConstVal.isSigned() && ConstVal.isNegative()) {
     676                 :       Diag(ArraySize->getLocStart(),
     677                 :            diag::err_typecheck_negative_array_size)
     678               10:         << ArraySize->getSourceRange();
     679               10:       return QualType();
     680                 :     }
                        9: branch 1 taken
                     1731: branch 2 taken
     681             1740:     if (ConstVal == 0) {
     682                 :       // GCC accepts zero sized static arrays.
     683                 :       Diag(ArraySize->getLocStart(), diag::ext_typecheck_zero_array_size)
     684                9:         << ArraySize->getSourceRange();
     685                 :     }
     686             1740:     T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);
     687                 :   }
     688                 :   // If this is not C99, extwarn about VLA's and C99 array size modifiers.
                      887: branch 1 taken
                     1427: branch 2 taken
     689             2314:   if (!getLangOptions().C99) {
                      826: branch 0 taken
                       61: branch 1 taken
                      826: branch 3 taken
                        0: branch 4 not taken
                      782: branch 6 taken
                       44: branch 7 taken
                        5: branch 9 taken
                      777: branch 10 taken
                        5: branch 11 taken
                      882: branch 12 taken
     690              887:     if (ArraySize && !ArraySize->isTypeDependent() &&
     691                 :         !ArraySize->isValueDependent() &&
     692                 :         !ArraySize->isIntegerConstantExpr(Context))
                        2: branch 1 taken
                        3: branch 2 taken
     693                5:       Diag(Loc, getLangOptions().CPlusPlus? diag::err_vla_cxx : diag::ext_vla);
                      879: branch 0 taken
                        3: branch 1 taken
                        1: branch 2 taken
                      878: branch 3 taken
     694              882:     else if (ASM != ArrayType::Normal || Quals != 0)
     695                 :       Diag(Loc, 
     696                 :            getLangOptions().CPlusPlus? diag::err_c99_array_usage_cxx
                        1: branch 1 taken
                        3: branch 2 taken
     697                4:                                      : diag::ext_c99_array_usage);
     698                 :   }
     699                 : 
     700             2314:   return T;
     701                 : }
     702                 : 
     703                 : /// \brief Build an ext-vector type.
     704                 : ///
     705                 : /// Run the required checks for the extended vector type.
     706                 : QualType Sema::BuildExtVectorType(QualType T, ExprArg ArraySize,
     707               71:                                   SourceLocation AttrLoc) {
     708                 : 
     709               71:   Expr *Arg = (Expr *)ArraySize.get();
     710                 : 
     711                 :   // unlike gcc's vector_size attribute, we do not allow vectors to be defined
     712                 :   // in conjunction with complex types (pointers, arrays, functions, etc.).
                       64: branch 2 taken
                        7: branch 3 taken
                       52: branch 6 taken
                       12: branch 7 taken
                        2: branch 10 taken
                       50: branch 11 taken
                        2: branch 12 taken
                       69: branch 13 taken
     713               71:   if (!T->isDependentType() &&
     714                 :       !T->isIntegerType() && !T->isRealFloatingType()) {
     715                2:     Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << T;
     716                2:     return QualType();
     717                 :   }
     718                 : 
                       68: branch 1 taken
                        1: branch 2 taken
                       61: branch 4 taken
                        7: branch 5 taken
                       61: branch 6 taken
                        8: branch 7 taken
     719               69:   if (!Arg->isTypeDependent() && !Arg->isValueDependent()) {
     720               61:     llvm::APSInt vecSize(32);
                        0: branch 1 not taken
                       61: branch 2 taken
     721               61:     if (!Arg->isIntegerConstantExpr(vecSize, Context)) {
     722                 :       Diag(AttrLoc, diag::err_attribute_argument_not_int)
     723                0:       << "ext_vector_type" << Arg->getSourceRange();
     724               61:       return QualType();
     725                 :     }
     726                 : 
     727                 :     // unlike gcc's vector_size attribute, the size is specified as the
     728                 :     // number of elements, not the number of bytes.
     729               61:     unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue());
     730                 : 
                        1: branch 0 taken
                       60: branch 1 taken
     731               61:     if (vectorSize == 0) {
     732                 :       Diag(AttrLoc, diag::err_attribute_zero_size)
     733                1:       << Arg->getSourceRange();
     734                1:       return QualType();
     735                 :     }
     736                 : 
                       60: branch 2 taken
                        0: branch 3 not taken
     737               60:     if (!T->isDependentType())
                        0: branch 2 not taken
                       61: branch 3 taken
     738               60:       return Context.getExtVectorType(T, vectorSize);
     739                 :   }
     740                 : 
     741                 :   return Context.getDependentSizedExtVectorType(T, ArraySize.takeAs<Expr>(),
     742                8:                                                 AttrLoc);
     743                 : }
     744                 : 
     745                 : /// \brief Build a function type.
     746                 : ///
     747                 : /// This routine checks the function type according to C++ rules and
     748                 : /// under the assumption that the result type and parameter types have
     749                 : /// just been instantiated from a template. It therefore duplicates
     750                 : /// some of the behavior of GetTypeForDeclarator, but in a much
     751                 : /// simpler form that is only suitable for this narrow use case.
     752                 : ///
     753                 : /// \param T The return type of the function.
     754                 : ///
     755                 : /// \param ParamTypes The parameter types of the function. This array
     756                 : /// will be modified to account for adjustments to the types of the
     757                 : /// function parameters.
     758                 : ///
     759                 : /// \param NumParamTypes The number of parameter types in ParamTypes.
     760                 : ///
     761                 : /// \param Variadic Whether this is a variadic function type.
     762                 : ///
     763                 : /// \param Quals The cvr-qualifiers to be applied to the function type.
     764                 : ///
     765                 : /// \param Loc The location of the entity whose type involves this
     766                 : /// function type or, if there is no such entity, the location of the
     767                 : /// type that will have function type.
     768                 : ///
     769                 : /// \param Entity The name of the entity that involves the function
     770                 : /// type, if known.
     771                 : ///
     772                 : /// \returns A suitable function type, if there are no
     773                 : /// errors. Otherwise, returns a NULL type.
     774                 : QualType Sema::BuildFunctionType(QualType T,
     775                 :                                  QualType *ParamTypes,
     776                 :                                  unsigned NumParamTypes,
     777                 :                                  bool Variadic, unsigned Quals,
     778             1237:                                  SourceLocation Loc, DeclarationName Entity) {
                     1237: branch 2 taken
                        0: branch 3 not taken
                        0: branch 6 not taken
                     1237: branch 7 taken
                        0: branch 8 not taken
                     1237: branch 9 taken
     779             1237:   if (T->isArrayType() || T->isFunctionType()) {
     780                 :     Diag(Loc, diag::err_func_returning_array_function) 
     781                0:       << T->isFunctionType() << T;
     782                0:     return QualType();
     783                 :   }
     784                 : 
     785             1237:   bool Invalid = false;
                     1135: branch 0 taken
                     1237: branch 1 taken
     786             2372:   for (unsigned Idx = 0; Idx < NumParamTypes; ++Idx) {
     787             1135:     QualType ParamType = adjustParameterType(ParamTypes[Idx]);
                        0: branch 2 not taken
                     1135: branch 3 taken
     788             1135:     if (ParamType->isVoidType()) {
     789                0:       Diag(Loc, diag::err_param_with_void_type);
     790                0:       Invalid = true;
     791                 :     }
     792                 : 
     793             1135:     ParamTypes[Idx] = ParamType;
     794                 :   }
     795                 : 
                        0: branch 0 not taken
                     1237: branch 1 taken
     796             1237:   if (Invalid)
     797                0:     return QualType();
     798                 : 
     799                 :   return Context.getFunctionType(T, ParamTypes, NumParamTypes, Variadic,
     800             1237:                                  Quals);
     801                 : }
     802                 : 
     803                 : /// \brief Build a member pointer type \c T Class::*.
     804                 : ///
     805                 : /// \param T the type to which the member pointer refers.
     806                 : /// \param Class the class type into which the member pointer points.
     807                 : /// \param CVR Qualifiers applied to the member pointer type
     808                 : /// \param Loc the location where this type begins
     809                 : /// \param Entity the name of the entity that will have this member pointer type
     810                 : ///
     811                 : /// \returns a member pointer type, if successful, or a NULL type if there was
     812                 : /// an error.
     813                 : QualType Sema::BuildMemberPointerType(QualType T, QualType Class,
     814                 :                                       unsigned CVR, SourceLocation Loc,
     815              318:                                       DeclarationName Entity) {
     816              318:   Qualifiers Quals = Qualifiers::fromCVRMask(CVR);
     817                 : 
     818                 :   // Verify that we're not building a pointer to pointer to function with
     819                 :   // exception specification.
                        0: branch 1 not taken
                      318: branch 2 taken
     820              318:   if (CheckDistantExceptionSpec(T)) {
     821                0:     Diag(Loc, diag::err_distant_exception_spec);
     822                 : 
     823                 :     // FIXME: If we're doing this as part of template instantiation,
     824                 :     // we should return immediately.
     825                 : 
     826                 :     // Build the type anyway, but use the canonical type so that the
     827                 :     // exception specifiers are stripped off.
     828                0:     T = Context.getCanonicalType(T);
     829                 :   }
     830                 : 
     831                 :   // C++ 8.3.3p3: A pointer to member shall not pointer to ... a member
     832                 :   //   with reference type, or "cv void."
                        2: branch 2 taken
                      316: branch 3 taken
     833              318:   if (T->isReferenceType()) {
     834                 :     Diag(Loc, diag::err_illegal_decl_mempointer_to_reference)
                        2: branch 1 taken
                        0: branch 2 not taken
                        0: branch 12 not taken
                        2: branch 13 taken
     835                2:       << (Entity? Entity.getAsString() : "type name") << T;
     836                2:     return QualType();
     837                 :   }
     838                 : 
                        3: branch 2 taken
                      313: branch 3 taken
     839              316:   if (T->isVoidType()) {
     840                 :     Diag(Loc, diag::err_illegal_decl_mempointer_to_void)
                        3: branch 1 taken
                        0: branch 2 not taken
                        0: branch 11 not taken
                        3: branch 12 taken
     841                3:       << (Entity? Entity.getAsString() : "type name");
     842                3:     return QualType();
     843                 :   }
     844                 : 
     845                 :   // Enforce C99 6.7.3p2: "Types other than pointer types derived from
     846                 :   // object or incomplete types shall not be restrict-qualified."
                        0: branch 1 not taken
                      313: branch 2 taken
                        0: branch 5 not taken
                        0: branch 6 not taken
                        0: branch 7 not taken
                      313: branch 8 taken
     847              313:   if (Quals.hasRestrict() && !T->isIncompleteOrObjectType()) {
     848                 :     Diag(Loc, diag::err_typecheck_invalid_restrict_invalid_pointee)
     849                0:       << T;
     850                 : 
     851                 :     // FIXME: If we're doing this as part of template instantiation,
     852                 :     // we should return immediately.
     853                0:     Quals.removeRestrict();
     854                 :   }
     855                 : 
                      292: branch 2 taken
                       21: branch 3 taken
                        3: branch 6 taken
                      289: branch 7 taken
                        3: branch 8 taken
                      310: branch 9 taken
     856              313:   if (!Class->isDependentType() && !Class->isRecordType()) {
     857                3:     Diag(Loc, diag::err_mempointer_in_nonclass_type) << Class;
     858                3:     return QualType();
     859                 :   }
     860                 : 
     861                 :   return Context.getQualifiedType(
     862              310:            Context.getMemberPointerType(T, Class.getTypePtr()), Quals);
     863                 : }
     864                 : 
     865                 : /// \brief Build a block pointer type.
     866                 : ///
     867                 : /// \param T The type to which we'll be building a block pointer.
     868                 : ///
     869                 : /// \param CVR The cvr-qualifiers to be applied to the block pointer type.
     870                 : ///
     871                 : /// \param Loc The location of the entity whose type involves this
     872                 : /// block pointer type or, if there is no such entity, the location of the
     873                 : /// type that will have block pointer type.
     874                 : ///
     875                 : /// \param Entity The name of the entity that involves the block pointer
     876                 : /// type, if known.
     877                 : ///
     878                 : /// \returns A suitable block pointer type, if there are no
     879                 : /// errors. Otherwise, returns a NULL type.
     880                 : QualType Sema::BuildBlockPointerType(QualType T, unsigned CVR,
     881                 :                                      SourceLocation Loc,
     882              236:                                      DeclarationName Entity) {
                        4: branch 2 taken
                      232: branch 3 taken
     883              236:   if (!T->isFunctionType()) {
     884                4:     Diag(Loc, diag::err_nonfunction_block_type);
     885                4:     return QualType();
     886                 :   }
     887                 : 
     888              232:   Qualifiers Quals = Qualifiers::fromCVRMask(CVR);
     889              232:   return Context.getQualifiedType(Context.getBlockPointerType(T), Quals);
     890                 : }
     891                 : 
     892            42636: QualType Sema::GetTypeFromParser(TypeTy *Ty, TypeSourceInfo **TInfo) {
     893            42636:   QualType QT = QualType::getFromOpaquePtr(Ty);
                        4: branch 1 taken
                    42632: branch 2 taken
     894            42636:   if (QT.isNull()) {
                        4: branch 0 taken
                        0: branch 1 not taken
     895                4:     if (TInfo) *TInfo = 0;
     896                4:     return QualType();
     897                 :   }
     898                 : 
     899            42632:   TypeSourceInfo *DI = 0;
                    18517: branch 1 taken
                    24115: branch 2 taken
     900            42632:   if (LocInfoType *LIT = dyn_cast<LocInfoType>(QT)) {
     901            18517:     QT = LIT->getType();
     902            18517:     DI = LIT->getTypeSourceInfo();
     903                 :   }
     904                 : 
                    11597: branch 0 taken
                    31035: branch 1 taken
     905            42632:   if (TInfo) *TInfo = DI;
     906            42632:   return QT;
     907                 : }
     908                 : 
     909                 : /// GetTypeForDeclarator - Convert the type for the specified
     910                 : /// declarator to Type instances.
     911                 : ///
     912                 : /// If OwnedDecl is non-NULL, and this declarator's decl-specifier-seq
     913                 : /// owns the declaration of a type (e.g., the definition of a struct
     914                 : /// type), then *OwnedDecl will receive the owned declaration.
     915                 : QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
     916                 :                                     TypeSourceInfo **TInfo,
     917            64784:                                     TagDecl **OwnedDecl) {
     918                 :   // Determine the type of the declarator. Not all forms of declarator
     919                 :   // have a type.
     920            64784:   QualType T;
     921                 : 
     922            64784:   llvm::SmallVector<DelayedAttribute,4> FnAttrsFromDeclSpec;
     923                 : 
                    63684: branch 2 taken
                      839: branch 3 taken
                      261: branch 4 taken
                        0: branch 5 not taken
     924            64784:   switch (D.getName().getKind()) {
     925                 :   case UnqualifiedId::IK_Identifier:
     926                 :   case UnqualifiedId::IK_OperatorFunctionId:
     927                 :   case UnqualifiedId::IK_LiteralOperatorId:
     928                 :   case UnqualifiedId::IK_TemplateId:
     929            63684:     T = ConvertDeclSpecToType(*this, D, FnAttrsFromDeclSpec);
     930                 :     
                    63563: branch 1 taken
                      121: branch 2 taken
                     1626: branch 5 taken
                    61937: branch 6 taken
                     1626: branch 7 taken
                    62058: branch 8 taken
     931            63684:     if (!D.isInvalidType() && D.getDeclSpec().isTypeSpecOwned()) {
     932             1626:       TagDecl* Owned = cast<TagDecl>((Decl *)D.getDeclSpec().getTypeRep());
     933             1626:       Owned->setDefinedInDeclarator(Owned->isDefinition());
                       65: branch 0 taken
                     1561: branch 1 taken
     934             1626:       if (OwnedDecl) *OwnedDecl = Owned;
     935                 :     }
     936            63684:     break;
     937                 : 
     938                 :   case UnqualifiedId::IK_ConstructorName:
     939                 :   case UnqualifiedId::IK_ConstructorTemplateId:
     940                 :   case UnqualifiedId::IK_DestructorName:
     941                 :     // Constructors and destructors don't have return types. Use
     942                 :     // "void" instead. 
     943              839:     T = Context.VoidTy;
     944              839:     break;
     945                 : 
     946                 :   case UnqualifiedId::IK_ConversionFunctionId:
     947                 :     // The result type of a conversion function is the type that it
     948                 :     // converts to.
     949              261:     T = GetTypeFromParser(D.getName().ConversionFunctionId);
     950                 :     break;
     951                 :   }
     952                 :   
                    64784: branch 1 taken
                        0: branch 2 not taken
     953            64784:   if (T.isNull())
     954                 :     return T;
     955                 : 
                       10: branch 2 taken
                    64774: branch 3 taken
     956            64784:   if (T == Context.UndeducedAutoTy) {
     957               10:     int Error = -1;
     958                 : 
                        0: branch 1 not taken
                        1: branch 2 taken
                        1: branch 3 taken
                        1: branch 4 taken
                        1: branch 5 taken
                        0: branch 6 not taken
                        6: branch 7 taken
     959               10:     switch (D.getContext()) {
     960                 :     case Declarator::KNRTypeListContext:
     961                0:       assert(0 && "K&R type lists aren't allowed in C++");
     962                 :       break;
     963                 :     case Declarator::PrototypeContext:
     964                1:       Error = 0; // Function prototype
     965                1:       break;
     966                 :     case Declarator::MemberContext:
                        0: branch 2 not taken
                        1: branch 3 taken
                        0: branch 4 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     967                1:       switch (cast<TagDecl>(CurContext)->getTagKind()) {
     968                0:       case TagDecl::TK_enum: assert(0 && "unhandled tag kind"); break;
     969                1:       case TagDecl::TK_struct: Error = 1; /* Struct member */ break;
     970                0:       case TagDecl::TK_union:  Error = 2; /* Union member */ break;
     971                0:       case TagDecl::TK_class:  Error = 3; /* Class member */ break;
     972                 :       }
     973                1:       break;
     974                 :     case Declarator::CXXCatchContext:
     975                1:       Error = 4; // Exception declaration
     976                1:       break;
     977                 :     case Declarator::TemplateParamContext:
     978                1:       Error = 5; // Template parameter
     979                1:       break;
     980                 :     case Declarator::BlockLiteralContext:
     981                0:       Error = 6;  // Block literal
     982                 :       break;
     983                 :     case Declarator::FileContext:
     984                 :     case Declarator::BlockContext:
     985                 :     case Declarator::ForContext:
     986                 :     case Declarator::ConditionContext:
     987                 :     case Declarator::TypeNameContext:
     988                 :       break;
     989                 :     }
     990                 : 
                        4: branch 0 taken
                        6: branch 1 taken
     991               10:     if (Error != -1) {
     992                 :       Diag(D.getDeclSpec().getTypeSpecTypeLoc(), diag::err_auto_not_allowed)
     993                4:         << Error;
     994                4:       T = Context.IntTy;
     995                4:       D.setInvalidType(true);
     996                 :     }
     997                 :   }
     998                 : 
     999                 :   // The name we're declaring, if any.
    1000            64784:   DeclarationName Name;
                    44471: branch 1 taken
                    20313: branch 2 taken
    1001            64784:   if (D.getIdentifier())
    1002            44471:     Name = D.getIdentifier();
    1003                 : 
    1004            64784:   llvm::SmallVector<DelayedAttribute,4> FnAttrsFromPreviousChunk;
    1005                 : 
    1006                 :   // Walk the DeclTypeInfo, building the recursive type as we go.
    1007                 :   // DeclTypeInfos are ordered from the identifier out, which is
    1008                 :   // opposite of what we want :).
                    33725: branch 1 taken
                    64784: branch 2 taken
    1009            98509:   for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
    1010            33725:     DeclaratorChunk &DeclType = D.getTypeObject(e-i-1);
                        0: branch 0 not taken
                      233: branch 1 taken
                    14613: branch 2 taken
                     1603: branch 3 taken
                     2287: branch 4 taken
                    14697: branch 5 taken
                      292: branch 6 taken
    1011            33725:     switch (DeclType.Kind) {
    1012                0:     default: assert(0 && "Unknown decltype!");
    1013                 :     case DeclaratorChunk::BlockPointer:
    1014                 :       // If blocks are disabled, emit an error.
                        1: branch 0 taken
                      232: branch 1 taken
    1015              233:       if (!LangOpts.Blocks)
    1016                1:         Diag(DeclType.Loc, diag::err_blocks_disable);
    1017                 : 
    1018                 :       T = BuildBlockPointerType(T, DeclType.Cls.TypeQuals, D.getIdentifierLoc(),
    1019              233:                                 Name);
    1020              233:       break;
    1021                 :     case DeclaratorChunk::Pointer:
    1022                 :       // Verify that we're not building a pointer to pointer to function with
    1023                 :       // exception specification.
                     5066: branch 1 taken
                     9547: branch 2 taken
                        2: branch 4 taken
                     5064: branch 5 taken
                        2: branch 6 taken
                    14611: branch 7 taken
    1024            14613:       if (getLangOptions().CPlusPlus && CheckDistantExceptionSpec(T)) {
    1025                2:         Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec);
    1026                2:         D.setInvalidType(true);
    1027                 :         // Build the type anyway.
    1028                 :       }
                     5524: branch 1 taken
                     9089: branch 2 taken
                     1973: branch 5 taken
                     3551: branch 6 taken
                     1973: branch 7 taken
                    12640: branch 8 taken
    1029            14613:       if (getLangOptions().ObjC1 && T->isObjCInterfaceType()) {
    1030             1973:         const ObjCInterfaceType *OIT = T->getAs<ObjCInterfaceType>();
    1031                 :         T = Context.getObjCObjectPointerType(T,
    1032                 :                                          (ObjCProtocolDecl **)OIT->qual_begin(),
    1033             1973:                                          OIT->getNumProtocols());
    1034             1973:         break;
    1035                 :       }
    1036            12640:       T = BuildPointerType(T, DeclType.Ptr.TypeQuals, DeclType.Loc, Name);
    1037            12640:       break;
    1038                 :     case DeclaratorChunk::Reference: {
    1039             1603:       Qualifiers Quals;
                        0: branch 0 not taken
                     1603: branch 1 taken
    1040             1603:       if (DeclType.Ref.HasRestrict) Quals.addRestrict();
    1041                 : 
    1042                 :       // Verify that we're not building a reference to pointer to function with
    1043                 :       // exception specification.
                     1603: branch 1 taken
                        0: branch 2 not taken
                        0: branch 4 not taken
                     1603: branch 5 taken
                        0: branch 6 not taken
                     1603: branch 7 taken
    1044             1603:       if (getLangOptions().CPlusPlus && CheckDistantExceptionSpec(T)) {
    1045                0:         Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec);
    1046                0:         D.setInvalidType(true);
    1047                 :         // Build the type anyway.
    1048                 :       }
    1049                 :       T = BuildReferenceType(T, DeclType.Ref.LValueRef, Quals,
    1050             1603:                              DeclType.Loc, Name);
    1051             1603:       break;
    1052                 :     }
    1053                 :     case DeclaratorChunk::Array: {
    1054                 :       // Verify that we're not building an array of pointers to function with
    1055                 :       // exception specification.
                      828: branch 1 taken
                     1459: branch 2 taken
                        0: branch 4 not taken
                      828: branch 5 taken
                        0: branch 6 not taken
                     2287: branch 7 taken
    1056             2287:       if (getLangOptions().CPlusPlus && CheckDistantExceptionSpec(T)) {
    1057                0:         Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec);
    1058                0:         D.setInvalidType(true);
    1059                 :         // Build the type anyway.
    1060                 :       }
    1061             2287:       DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
    1062             2287:       Expr *ArraySize = static_cast<Expr*>(ATI.NumElts);
    1063                 :       ArrayType::ArraySizeModifier ASM;
                        9: branch 0 taken
                     2278: branch 1 taken
    1064             2287:       if (ATI.isStar)
    1065                9:         ASM = ArrayType::Star;
                        2: branch 0 taken
                     2276: branch 1 taken
    1066             2278:       else if (ATI.hasStatic)
    1067                2:         ASM = ArrayType::Static;
    1068                 :       else
    1069             2276:         ASM = ArrayType::Normal;
                        9: branch 0 taken
                     2278: branch 1 taken
                        1: branch 3 taken
                        8: branch 4 taken
                        1: branch 5 taken
                     2286: branch 6 taken
    1070             2287:       if (ASM == ArrayType::Star &&
    1071                 :           D.getContext() != Declarator::PrototypeContext) {
    1072                 :         // FIXME: This check isn't quite right: it allows star in prototypes
    1073                 :         // for function definitions, and disallows some edge cases detailed
    1074                 :         // in http://gcc.gnu.org/ml/gcc-patches/2009-02/msg00133.html
    1075                1:         Diag(DeclType.Loc, diag::err_array_star_outside_prototype);
    1076                1:         ASM = ArrayType::Normal;
    1077                1:         D.setInvalidType(true);
    1078                 :       }
    1079                 :       T = BuildArrayType(T, ASM, ArraySize,
    1080                 :                          Qualifiers::fromCVRMask(ATI.TypeQuals),
    1081             2287:                          SourceRange(DeclType.Loc, DeclType.EndLoc), Name);
    1082             2287:       break;
    1083                 :     }
    1084                 :     case DeclaratorChunk::Function: {
    1085                 :       // If the function declarator has a prototype (i.e. it is not () and
    1086                 :       // does not have a K&R-style identifier list), then the arguments are part
    1087                 :       // of the type, otherwise the argument list is ().
    1088            14697:       const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
    1089                 : 
    1090                 :       // C99 6.7.5.3p1: The return type may not be a function or array type.
    1091                 :       // For conversion functions, we'll diagnose this particular error later.
                    14695: branch 2 taken
                        2: branch 3 taken
                        3: branch 6 taken
                    14692: branch 7 taken
                        3: branch 10 taken
                        2: branch 11 taken
                        3: branch 12 taken
                    14694: branch 13 taken
    1092            14697:       if ((T->isArrayType() || T->isFunctionType()) &&
    1093                 :           (D.getName().getKind() != UnqualifiedId::IK_ConversionFunctionId)) {
    1094                 :         Diag(DeclType.Loc, diag::err_func_returning_array_function) 
    1095                3:           << T->isFunctionType() << T;
    1096                3:         T = Context.IntTy;
    1097                3:         D.setInvalidType(true);
    1098                 :       }
    1099                 : 
                     6979: branch 1 taken
                     7718: branch 2 taken
                        4: branch 5 taken
                     6975: branch 6 taken
                        4: branch 7 taken
                    14693: branch 8 taken
    1100            14697:       if (getLangOptions().CPlusPlus && D.getDeclSpec().isTypeSpecOwned()) {
    1101                 :         // C++ [dcl.fct]p6:
    1102                 :         //   Types shall not be defined in return or parameter types.
    1103                4:         TagDecl *Tag = cast<TagDecl>((Decl *)D.getDeclSpec().getTypeRep());
                        1: branch 1 taken
                        3: branch 2 taken
    1104                4:         if (Tag->isDefinition())
    1105                 :           Diag(Tag->getLocation(), diag::err_type_defined_in_result_type)
    1106                1:             << Context.getTypeDeclType(Tag);
    1107                 :       }
    1108                 : 
    1109                 :       // Exception specs are not allowed in typedefs. Complain, but add it
    1110                 :       // anyway.
                      328: branch 0 taken
                    14369: branch 1 taken
                        1: branch 4 taken
                      327: branch 5 taken
                        1: branch 6 taken
                    14696: branch 7 taken
    1111            14697:       if (FTI.hasExceptionSpec &&
    1112                 :           D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
    1113                1:         Diag(FTI.getThrowLoc(), diag::err_exception_spec_in_typedef);
    1114                 : 
                     5504: branch 0 taken
                     9193: branch 1 taken
    1115            14697:       if (FTI.NumArgs == 0) {
                     3279: branch 1 taken
                     2225: branch 2 taken
    1116             5504:         if (getLangOptions().CPlusPlus) {
    1117                 :           // C++ 8.3.5p2: If the parameter-declaration-clause is empty, the
    1118                 :           // function takes no arguments.
    1119             3279:           llvm::SmallVector<QualType, 4> Exceptions;
    1120             3279:           Exceptions.reserve(FTI.NumExceptions);
                       97: branch 0 taken
                     3279: branch 1 taken
    1121             3376:           for (unsigned ei = 0, ee = FTI.NumExceptions; ei != ee; ++ei) {
    1122                 :             // FIXME: Preserve type source info.
    1123               97:             QualType ET = GetTypeFromParser(FTI.Exceptions[ei].Ty);
    1124                 :             // Check that the type is valid for an exception spec, and drop it
    1125                 :             // if not.
                       92: branch 1 taken
                        5: branch 2 taken
    1126               97:             if (!CheckSpecifiedExceptionType(ET, FTI.Exceptions[ei].Range))
    1127               92:               Exceptions.push_back(ET);
    1128                 :           }
    1129                 :           T = Context.getFunctionType(T, NULL, 0, FTI.isVariadic, FTI.TypeQuals,
    1130                 :                                       FTI.hasExceptionSpec,
    1131                 :                                       FTI.hasAnyExceptionSpec,
    1132             3279:                                       Exceptions.size(), Exceptions.data());
                        1: branch 0 taken
                     2224: branch 1 taken
    1133             2225:         } else if (FTI.isVariadic) {
    1134                 :           // We allow a zero-parameter variadic function in C if the
    1135                 :           // function is marked with the "overloadable"
    1136                 :           // attribute. Scan for this attribute now.
    1137                1:           bool Overloadable = false;
                        2: branch 2 taken
                        0: branch 3 not taken
    1138                2:           for (const AttributeList *Attrs = D.getAttributes();
    1139                 :                Attrs; Attrs = Attrs->getNext()) {
                        1: branch 1 taken
                        1: branch 2 taken
    1140                2:             if (Attrs->getKind() == AttributeList::AT_overloadable) {
    1141                1:               Overloadable = true;
    1142                1:               break;
    1143                 :             }
    1144                 :           }
    1145                 : 
                        0: branch 0 not taken
                        1: branch 1 taken
    1146                1:           if (!Overloadable)
    1147                0:             Diag(FTI.getEllipsisLoc(), diag::err_ellipsis_first_arg);
    1148                1:           T = Context.getFunctionType(T, NULL, 0, FTI.isVariadic, 0);
    1149                 :         } else {
    1150                 :           // Simple void foo(), where the incoming T is the result type.
    1151             2224:           T = Context.getFunctionNoProtoType(T);
    1152                 :         }
                        1: branch 1 taken
                     9192: branch 2 taken
    1153             9193:       } else if (FTI.ArgInfo[0].Param == 0) {
    1154                 :         // C99 6.7.5.3p3: Reject int(x,y,z) when it's not a function definition.
    1155                1:         Diag(FTI.ArgInfo[0].IdentLoc, diag::err_ident_list_in_fn_declaration);
    1156                1:         D.setInvalidType(true);
    1157                 :       } else {
    1158                 :         // Otherwise, we have a function with an argument list that is
    1159                 :         // potentially variadic.
    1160             9192:         llvm::SmallVector<QualType, 16> ArgTys;
    1161                 : 
                    13878: branch 0 taken
                     8139: branch 1 taken
    1162            22017:         for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
    1163                 :           ParmVarDecl *Param =
    1164            13878:             cast<ParmVarDecl>(FTI.ArgInfo[i].Param.getAs<Decl>());
    1165            13878:           QualType ArgTy = Param->getType();
                    13878: branch 1 taken
                        0: branch 2 not taken
    1166            13878:           assert(!ArgTy.isNull() && "Couldn't parse type?");
    1167                 : 
    1168                 :           // Adjust the parameter type.
                    13878: branch 2 taken
                        0: branch 3 not taken
    1169            13878:           assert((ArgTy == adjustParameterType(ArgTy)) && "Unadjusted type?");
    1170                 : 
    1171                 :           // Look for 'void'.  void is allowed only as a single argument to a
    1172                 :           // function with no other parameters (C99 6.7.5.3p10).  We record
    1173                 :           // int(void) as a FunctionProtoType with an empty argument list.
                     1060: branch 2 taken
                    12818: branch 3 taken
    1174            13878:           if (ArgTy->isVoidType()) {
    1175                 :             // If this is something like 'float(int, void)', reject it.  'void'
    1176                 :             // is an incomplete type (C99 6.2.5p19) and function decls cannot
    1177                 :             // have arguments of incomplete type.
                     1058: branch 0 taken
                        2: branch 1 taken
                        2: branch 2 taken
                     1056: branch 3 taken
    1178             1064:             if (FTI.NumArgs != 1 || FTI.isVariadic) {
    1179                4:               Diag(DeclType.Loc, diag::err_void_only_param);
    1180                4:               ArgTy = Context.IntTy;
    1181                4:               Param->setType(ArgTy);
                        3: branch 0 taken
                     1053: branch 1 taken
    1182             1056:             } else if (FTI.ArgInfo[i].Ident) {
    1183                 :               // Reject, but continue to parse 'int(void abc)'.
    1184                 :               Diag(FTI.ArgInfo[i].IdentLoc,
    1185                3:                    diag::err_param_with_void_type);
    1186                3:               ArgTy = Context.IntTy;
    1187                3:               Param->setType(ArgTy);
    1188                 :             } else {
    1189                 :               // Reject, but continue to parse 'float(const void)'.
                        1: branch 1 taken
                     1052: branch 2 taken
    1190             1053:               if (ArgTy.hasQualifiers())
    1191                1:                 Diag(DeclType.Loc, diag::err_void_param_qualified);
    1192                 : 
    1193                 :               // Do not add 'void' to the ArgTys list.
    1194             1053:               break;
    1195                 :             }
                       64: branch 0 taken
                    12754: branch 1 taken
    1196            12818:           } else if (!FTI.hasPrototype) {
                       13: branch 2 taken
                       51: branch 3 taken
    1197               64:             if (ArgTy->isPromotableIntegerType()) {
    1198               13:               ArgTy = Context.getPromotedIntegerType(ArgTy);
                       43: branch 2 taken
                        8: branch 3 taken
    1199               51:             } else if (const BuiltinType* BTy = ArgTy->getAs<BuiltinType>()) {
                       14: branch 1 taken
                       29: branch 2 taken
    1200               43:               if (BTy->getKind() == BuiltinType::Float)
    1201               14:                 ArgTy = Context.DoubleTy;
    1202                 :             }
    1203                 :           }
    1204                 : 
    1205            12825:           ArgTys.push_back(ArgTy);
    1206                 :         }
    1207                 : 
    1208             9192:         llvm::SmallVector<QualType, 4> Exceptions;
    1209             9192:         Exceptions.reserve(FTI.NumExceptions);
                        5: branch 0 taken
                     9192: branch 1 taken
    1210             9197:         for (unsigned ei = 0, ee = FTI.NumExceptions; ei != ee; ++ei) {
    1211                 :           // FIXME: Preserve type source info.
    1212                5:           QualType ET = GetTypeFromParser(FTI.Exceptions[ei].Ty);
    1213                 :           // Check that the type is valid for an exception spec, and drop it if
    1214                 :           // not.
                        5: branch 1 taken
                        0: branch 2 not taken
    1215                5:           if (!CheckSpecifiedExceptionType(ET, FTI.Exceptions[ei].Range))
    1216                5:             Exceptions.push_back(ET);
    1217                 :         }
    1218                 : 
    1219                 :         T = Context.getFunctionType(T, ArgTys.data(), ArgTys.size(),
    1220                 :                                     FTI.isVariadic, FTI.TypeQuals,
    1221                 :                                     FTI.hasExceptionSpec,
    1222                 :                                     FTI.hasAnyExceptionSpec,
    1223             9192:                                     Exceptions.size(), Exceptions.data());
    1224                 :       }
    1225                 : 
    1226                 :       // For GCC compatibility, we allow attributes that apply only to
    1227                 :       // function types to be placed on a function's return type
    1228                 :       // instead (as long as that type doesn't happen to be function
    1229                 :       // or function-pointer itself).
    1230            14697:       ProcessDelayedFnAttrs(*this, T, FnAttrsFromPreviousChunk);
    1231                 : 
    1232            14697:       break;
    1233                 :     }
    1234                 :     case DeclaratorChunk::MemberPointer:
    1235                 :       // Verify that we're not building a pointer to pointer to function with
    1236                 :       // exception specification.
                      292: branch 1 taken
                        0: branch 2 not taken
                        0: branch 4 not taken
                      292: branch 5 taken
                        0: branch 6 not taken
                      292: branch 7 taken
    1237              292:       if (getLangOptions().CPlusPlus && CheckDistantExceptionSpec(T)) {
    1238                0:         Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec);
    1239                0:         D.setInvalidType(true);
    1240                 :         // Build the type anyway.
    1241                 :       }
    1242                 :       // The scope spec must refer to a class, or be dependent.
    1243              292:       QualType ClsType;
                      273: branch 2 taken
                       19: branch 3 taken
                      271: branch 7 taken
                        2: branch 8 taken
                      290: branch 9 taken
                        2: branch 10 taken
    1244              292:       if (isDependentScopeSpecifier(DeclType.Mem.Scope())
    1245                 :             || dyn_cast_or_null<CXXRecordDecl>(
    1246                 :                                    computeDeclContext(DeclType.Mem.Scope()))) {
    1247                 :         NestedNameSpecifier *NNS
    1248              290:           = (NestedNameSpecifier *)DeclType.Mem.Scope().getScopeRep();
    1249              290:         NestedNameSpecifier *NNSPrefix = NNS->getPrefix();
                        1: branch 1 taken
                        0: branch 2 not taken
                      289: branch 3 taken
                        0: branch 4 not taken
    1250              290:         switch (NNS->getKind()) {
    1251                 :         case NestedNameSpecifier::Identifier:
    1252                1:           ClsType = Context.getTypenameType(NNSPrefix, NNS->getAsIdentifier());
    1253                1:           break;
    1254                 : 
    1255                 :         case NestedNameSpecifier::Namespace:
    1256                 :         case NestedNameSpecifier::Global:
    1257                0:           llvm_unreachable("Nested-name-specifier must name a type");
    1258                 :           break;
    1259                 :             
    1260                 :         case NestedNameSpecifier::TypeSpec:
    1261                 :         case NestedNameSpecifier::TypeSpecWithTemplate:
    1262              289:           ClsType = QualType(NNS->getAsType(), 0);
                        2: branch 0 taken
                      287: branch 1 taken
    1263              289:           if (NNSPrefix)
    1264                2:             ClsType = Context.getQualifiedNameType(NNSPrefix, ClsType);
    1265                 :           break;
    1266                 :         }
    1267                 :       } else {
    1268                 :         Diag(DeclType.Mem.Scope().getBeginLoc(),
    1269                 :              diag::err_illegal_decl_mempointer_in_nonclass)
    1270                 :           << (D.getIdentifier() ? D.getIdentifier()->getName() : "type name")
                        2: branch 3 taken
                        0: branch 4 not taken
    1271                2:           << DeclType.Mem.Scope().getRange();
    1272                2:         D.setInvalidType(true);
    1273                 :       }
    1274                 : 
                      290: branch 1 taken
                        2: branch 2 taken
    1275              292:       if (!ClsType.isNull())
    1276                 :         T = BuildMemberPointerType(T, ClsType, DeclType.Mem.TypeQuals,
    1277              290:                                    DeclType.Loc, D.getIdentifier());
                        3: branch 1 taken
                      289: branch 2 taken
    1278              292:       if (T.isNull()) {
    1279                3:         T = Context.IntTy;
    1280                3:         D.setInvalidType(true);
    1281                 :       }
    1282                 :       break;
    1283                 :     }
    1284                 : 
                       39: branch 1 taken
                    33686: branch 2 taken
    1285            33725:     if (T.isNull()) {
    1286               39:       D.setInvalidType(true);
    1287               39:       T = Context.IntTy;
    1288                 :     }
    1289                 : 
    1290            33725:     DiagnoseDelayedFnAttrs(*this, FnAttrsFromPreviousChunk);
    1291                 : 
    1292                 :     // See if there are any attributes on this declarator chunk.
                       33: branch 1 taken
                    33692: branch 2 taken
    1293            33725:     if (const AttributeList *AL = DeclType.getAttrs())
    1294               33:       ProcessTypeAttributeList(*this, T, AL, FnAttrsFromPreviousChunk);
    1295                 :   }
    1296                 : 
                    25484: branch 1 taken
                    39300: branch 2 taken
                     6573: branch 5 taken
                    18911: branch 6 taken
                     6573: branch 7 taken
                    58211: branch 8 taken
    1297            64784:   if (getLangOptions().CPlusPlus && T->isFunctionType()) {
    1298             6573:     const FunctionProtoType *FnTy = T->getAs<FunctionProtoType>();
                        0: branch 0 not taken
                     6573: branch 1 taken
    1299             6573:     assert(FnTy && "Why oh why is there not a FunctionProtoType here?");
    1300                 : 
    1301                 :     // C++ 8.3.5p4: A cv-qualifier-seq shall only be part of the function type
    1302                 :     // for a nonstatic member function, the function type to which a pointer
    1303                 :     // to member refers, or the top-level function type of a function typedef
    1304                 :     // declaration.
                      154: branch 1 taken
                     6419: branch 2 taken
                      153: branch 5 taken
                        1: branch 6 taken
                       18: branch 8 taken
                      135: branch 9 taken
                       16: branch 12 taken
                        2: branch 13 taken
                       16: branch 17 taken
                        0: branch 18 not taken
                        3: branch 21 taken
                      148: branch 22 taken
                        5: branch 23 taken
                     6568: branch 24 taken
    1305             6573:     if (FnTy->getTypeQuals() != 0 &&
    1306                 :         D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
    1307                 :         ((D.getContext() != Declarator::MemberContext &&
    1308                 :           (!D.getCXXScopeSpec().isSet() ||
    1309                 :            !computeDeclContext(D.getCXXScopeSpec(), /*FIXME:*/true)
    1310                 :               ->isRecord())) ||
    1311                 :          D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static)) {
                        3: branch 1 taken
                        2: branch 2 taken
    1312                5:       if (D.isFunctionDeclarator())
    1313                3:         Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_function_type);
    1314                 :       else
    1315                 :         Diag(D.getIdentifierLoc(),
    1316                2:              diag::err_invalid_qualified_typedef_function_type_use);
    1317                 : 
    1318                 :       // Strip the cv-quals from the type.
    1319                 :       T = Context.getFunctionType(FnTy->getResultType(), FnTy->arg_type_begin(),
    1320                5:                                   FnTy->getNumArgs(), FnTy->isVariadic(), 0);
    1321                 :     }
    1322                 :   }
    1323                 : 
    1324                 :   // Process any function attributes we might have delayed from the
    1325                 :   // declaration-specifiers.
    1326            64784:   ProcessDelayedFnAttrs(*this, T, FnAttrsFromDeclSpec);
    1327                 : 
    1328                 :   // If there were any type attributes applied to the decl itself, not
    1329                 :   // the type, apply them to the result type.  But don't do this for
    1330                 :   // block-literal expressions, which are parsed wierdly.
                    64521: branch 1 taken
                      263: branch 2 taken
    1331            64784:   if (D.getContext() != Declarator::BlockLiteralContext)
                     1378: branch 1 taken
                    63143: branch 2 taken
    1332            64521:     if (const AttributeList *Attrs = D.getAttributes())
    1333             1378:       ProcessTypeAttributeList(*this, T, Attrs, FnAttrsFromPreviousChunk);
    1334                 : 
    1335            64784:   DiagnoseDelayedFnAttrs(*this, FnAttrsFromPreviousChunk);
    1336                 : 
                    63865: branch 0 taken
                      919: branch 1 taken
    1337            64784:   if (TInfo) {
                      174: branch 1 taken
                    63691: branch 2 taken
    1338            63865:     if (D.isInvalidType())
    1339              174:       *TInfo = 0;
    1340                 :     else
    1341            63691:       *TInfo = GetTypeSourceInfoForDeclarator(D, T);
    1342                 :   }
    1343                 : 
    1344            64784:   return T;
    1345                 : }
    1346                 : 
    1347                 : namespace {
    1348                 :   class TypeSpecLocFiller : public TypeLocVisitor<TypeSpecLocFiller> {
    1349                 :     const DeclSpec &DS;
    1350                 : 
    1351                 :   public:
    1352            63691:     TypeSpecLocFiller(const DeclSpec &DS) : DS(DS) {}
    1353                 : 
    1354                0:     void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
    1355                0:       Visit(TL.getUnqualifiedLoc());
    1356                0:     }
    1357            12470:     void VisitTypedefTypeLoc(TypedefTypeLoc TL) {
    1358            12470:       TL.setNameLoc(DS.getTypeSpecTypeLoc());
    1359            12470:     }
    1360             1963:     void VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
    1361             1963:       TL.setNameLoc(DS.getTypeSpecTypeLoc());
    1362                 : 
                      104: branch 1 taken
                     1859: branch 2 taken
    1363             1963:       if (DS.getProtocolQualifiers()) {
                        0: branch 1 not taken
                      104: branch 2 taken
    1364              104:         assert(TL.getNumProtocols() > 0);
                        0: branch 2 not taken
                      104: branch 3 taken
    1365              104:         assert(TL.getNumProtocols() == DS.getNumProtocolQualifiers());
    1366              104:         TL.setLAngleLoc(DS.getProtocolLAngleLoc());
    1367              104:         TL.setRAngleLoc(DS.getSourceRange().getEnd());
                      150: branch 1 taken
                      104: branch 2 taken
    1368              254:         for (unsigned i = 0, e = DS.getNumProtocolQualifiers(); i != e; ++i)
    1369              150:           TL.setProtocolLoc(i, DS.getProtocolLocs()[i]);
    1370                 :       } else {
                        0: branch 1 not taken
                     1859: branch 2 taken
    1371             1859:         assert(TL.getNumProtocols() == 0);
    1372             1859:         TL.setLAngleLoc(SourceLocation());
    1373             1859:         TL.setRAngleLoc(SourceLocation());
    1374                 :       }
    1375             1963:     }
    1376              219:     void VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
                        0: branch 2 not taken
                      219: branch 3 taken
    1377              219:       assert(TL.getNumProtocols() == DS.getNumProtocolQualifiers());
    1378                 : 
    1379              219:       TL.setStarLoc(SourceLocation());
    1380                 : 
                      219: branch 1 taken
                        0: branch 2 not taken
    1381              219:       if (DS.getProtocolQualifiers()) {
                        0: branch 1 not taken
                      219: branch 2 taken
    1382              219:         assert(TL.getNumProtocols() > 0);
                        0: branch 2 not taken
                      219: branch 3 taken
    1383              219:         assert(TL.getNumProtocols() == DS.getNumProtocolQualifiers());
    1384              219:         TL.setHasProtocolsAsWritten(true);
    1385              219:         TL.setLAngleLoc(DS.getProtocolLAngleLoc());
    1386              219:         TL.setRAngleLoc(DS.getSourceRange().getEnd());
                      259: branch 1 taken
                      219: branch 2 taken
    1387              478:         for (unsigned i = 0, e = DS.getNumProtocolQualifiers(); i != e; ++i)
    1388              259:           TL.setProtocolLoc(i, DS.getProtocolLocs()[i]);
    1389                 : 
    1390                 :       } else {
                        0: branch 1 not taken
                        0: branch 2 not taken
    1391                0:         assert(TL.getNumProtocols() == 0);
    1392                0:         TL.setHasProtocolsAsWritten(false);
    1393                0:         TL.setLAngleLoc(SourceLocation());
    1394                0:         TL.setRAngleLoc(SourceLocation());
    1395                 :       }
    1396                 : 
    1397                 :       // This might not have been written with an inner type.
                        3: branch 1 taken
                      216: branch 2 taken
    1398              219:       if (DS.getTypeSpecType() == DeclSpec::TST_unspecified) {
    1399                3:         TL.setHasBaseTypeAsWritten(false);
    1400                3:         TL.getBaseTypeLoc().initialize(SourceLocation());
    1401                 :       } else {
    1402              216:         TL.setHasBaseTypeAsWritten(true);
    1403              216:         Visit(TL.getBaseTypeLoc());
    1404                 :       }
    1405              219:     }
    1406              949:     void VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
    1407              949:       TypeSourceInfo *TInfo = 0;
    1408              949:       Sema::GetTypeFromParser(DS.getTypeRep(), &TInfo);
    1409                 : 
    1410                 :       // If we got no declarator info from previous Sema routines,
    1411                 :       // just fill with the typespec loc.
                       60: branch 0 taken
                      889: branch 1 taken
    1412              949:       if (!TInfo) {
    1413               60:         TL.initialize(DS.getTypeSpecTypeLoc());
    1414               60:         return;
    1415                 :       }
    1416                 : 
    1417                 :       TemplateSpecializationTypeLoc OldTL =
    1418              889:         cast<TemplateSpecializationTypeLoc>(TInfo->getTypeLoc());
    1419              889:       TL.copy(OldTL);
    1420                 :     }
    1421              244:     void VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
                        0: branch 1 not taken
                      244: branch 2 taken
    1422              244:       assert(DS.getTypeSpecType() == DeclSpec::TST_typeofExpr);
    1423              244:       TL.setTypeofLoc(DS.getTypeSpecTypeLoc());
    1424              244:       TL.setParensRange(DS.getTypeofParensRange());
    1425              244:     }
    1426               17:     void VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
                        0: branch 1 not taken
                       17: branch 2 taken
    1427               17:       assert(DS.getTypeSpecType() == DeclSpec::TST_typeofType);
    1428               17:       TL.setTypeofLoc(DS.getTypeSpecTypeLoc());
    1429               17:       TL.setParensRange(DS.getTypeofParensRange());
                        0: branch 1 not taken
                       17: branch 2 taken
    1430               17:       assert(DS.getTypeRep());
    1431               17:       TypeSourceInfo *TInfo = 0;
    1432               17:       Sema::GetTypeFromParser(DS.getTypeRep(), &TInfo);
    1433               17:       TL.setUnderlyingTInfo(TInfo);
    1434               17:     }
    1435            39200:     void VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
    1436                 :       // By default, use the source location of the type specifier.
    1437            39200:       TL.setBuiltinLoc(DS.getTypeSpecTypeLoc());
                    21341: branch 1 taken
                    17859: branch 2 taken
    1438            39200:       if (TL.needsExtraLocalData()) {
    1439                 :         // Set info for the written builtin specifiers.
    1440            21341:         TL.getWrittenBuiltinSpecs() = DS.getWrittenBuiltinSpecs();
    1441                 :         // Try to have a meaningful source location.
                     3134: branch 1 taken
                    18207: branch 2 taken
    1442            21341:         if (TL.getWrittenSignSpec() != TSS_unspecified)
    1443                 :           // Sign spec loc overrides the others (e.g., 'unsigned long').
    1444             3134:           TL.setBuiltinLoc(DS.getTypeSpecSignLoc());
                     1426: branch 1 taken
                    16781: branch 2 taken
    1445            18207:         else if (TL.getWrittenWidthSpec() != TSW_unspecified)
    1446                 :           // Width spec loc overrides type spec loc (e.g., 'short int').
    1447             1426:           TL.setBuiltinLoc(DS.getTypeSpecWidthLoc());
    1448                 :       }
    1449            39200:     }
    1450             8845:     void VisitTypeLoc(TypeLoc TL) {
    1451                 :       // FIXME: add other typespec types and change this to an assert.
    1452             8845:       TL.initialize(DS.getTypeSpecTypeLoc());
    1453             8845:     }
    1454                 :   };
    1455                 : 
    1456                 :   class DeclaratorLocFiller : public TypeLocVisitor<DeclaratorLocFiller> {
    1457                 :     const DeclaratorChunk &Chunk;
    1458                 : 
    1459                 :   public:
    1460            33157:     DeclaratorLocFiller(const DeclaratorChunk &Chunk) : Chunk(Chunk) {}
    1461                 : 
    1462                0:     void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
    1463                0:       llvm_unreachable("qualified type locs not expected here!");
    1464                 :     }
    1465                 : 
    1466              226:     void VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
                        0: branch 0 not taken
                      226: branch 1 taken
    1467              226:       assert(Chunk.Kind == DeclaratorChunk::BlockPointer);
    1468              226:       TL.setCaretLoc(Chunk.Loc);
    1469              226:     }
    1470            12569:     void VisitPointerTypeLoc(PointerTypeLoc TL) {
                        0: branch 0 not taken
                    12569: branch 1 taken
    1471            12569:       assert(Chunk.Kind == DeclaratorChunk::Pointer);
    1472            12569:       TL.setStarLoc(Chunk.Loc);
    1473            12569:     }
    1474             1929:     void VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
                        0: branch 0 not taken
                     1929: branch 1 taken
    1475             1929:       assert(Chunk.Kind == DeclaratorChunk::Pointer);
    1476             1929:       TL.setStarLoc(Chunk.Loc);
    1477             1929:       TL.setHasBaseTypeAsWritten(true);
    1478             1929:       TL.setHasProtocolsAsWritten(false);
    1479             1929:       TL.setLAngleLoc(SourceLocation());
    1480             1929:       TL.setRAngleLoc(SourceLocation());
    1481             1929:     }
    1482              287:     void VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
                        0: branch 0 not taken
                      287: branch 1 taken
    1483              287:       assert(Chunk.Kind == DeclaratorChunk::MemberPointer);
    1484              287:       TL.setStarLoc(Chunk.Loc);
    1485                 :       // FIXME: nested name specifier
    1486              287:     }
    1487             1554:     void VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
                        0: branch 0 not taken
                     1554: branch 1 taken
    1488             1554:       assert(Chunk.Kind == DeclaratorChunk::Reference);
    1489                 :       // 'Amp' is misleading: this might have been originally
    1490                 :       /// spelled with AmpAmp.
    1491             1554:       TL.setAmpLoc(Chunk.Loc);
    1492             1554:     }
    1493               36:     void VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
                        0: branch 0 not taken
                       36: branch 1 taken
    1494               36:       assert(Chunk.Kind == DeclaratorChunk::Reference);
                        0: branch 0 not taken
                       36: branch 1 taken
    1495               36:       assert(!Chunk.Ref.LValueRef);
    1496               36:       TL.setAmpAmpLoc(Chunk.Loc);
    1497               36:     }
    1498             2249:     void VisitArrayTypeLoc(ArrayTypeLoc TL) {
                        0: branch 0 not taken
                     2249: branch 1 taken
    1499             2249:       assert(Chunk.Kind == DeclaratorChunk::Array);
    1500             2249:       TL.setLBracketLoc(Chunk.Loc);
    1501             2249:       TL.setRBracketLoc(Chunk.EndLoc);
    1502             2249:       TL.setSizeExpr(static_cast<Expr*>(Chunk.Arr.NumElts));
    1503             2249:     }
    1504            14307:     void VisitFunctionTypeLoc(FunctionTypeLoc TL) {
                        0: branch 0 not taken
                    14307: branch 1 taken
    1505            14307:       assert(Chunk.Kind == DeclaratorChunk::Function);
    1506            14307:       TL.setLParenLoc(Chunk.Loc);
    1507            14307:       TL.setRParenLoc(Chunk.EndLoc);
    1508                 : 
    1509            14307:       const DeclaratorChunk::FunctionTypeInfo &FTI = Chunk.Fun;
                    12638: branch 1 taken
                    14307: branch 2 taken
    1510            26945:       for (unsigned i = 0, e = TL.getNumArgs(), tpi = 0; i != e; ++i) {
    1511            12638:         ParmVarDecl *Param = FTI.ArgInfo[i].Param.getAs<ParmVarDecl>();
    1512            12638:         TL.setArg(tpi++, Param);
    1513                 :       }
    1514                 :       // FIXME: exception specs
    1515            14307:     }
    1516                 : 
    1517                0:     void VisitTypeLoc(TypeLoc TL) {
    1518                0:       llvm_unreachable("unsupported TypeLoc kind in declarator!");
    1519                 :     }
    1520                 :   };
    1521                 : }
    1522                 : 
    1523                 : /// \brief Create and instantiate a TypeSourceInfo with type source information.
    1524                 : ///
    1525                 : /// \param T QualType referring to the type as written in source code.
    1526                 : TypeSourceInfo *
    1527            63691: Sema::GetTypeSourceInfoForDeclarator(Declarator &D, QualType T) {
    1528            63691:   TypeSourceInfo *TInfo = Context.CreateTypeSourceInfo(T);
    1529            63691:   UnqualTypeLoc CurrTL = TInfo->getTypeLoc().getUnqualifiedLoc();
    1530                 : 
                    33157: branch 1 taken
                    63691: branch 2 taken
    1531            96848:   for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
    1532            33157:     DeclaratorLocFiller(D.getTypeObject(i)).Visit(CurrTL);
    1533            33157:     CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc();
    1534                 :   }
    1535                 :   
    1536            63691:   TypeSpecLocFiller(D.getDeclSpec()).Visit(CurrTL);
    1537                 : 
    1538            63691:   return TInfo;
    1539                 : }
    1540                 : 
    1541                 : /// \brief Create a LocInfoType to hold the given QualType and TypeSourceInfo.
    1542            16302: QualType Sema::CreateLocInfoType(QualType T, TypeSourceInfo *TInfo) {
    1543                 :   // FIXME: LocInfoTypes are "transient", only needed for passing to/from Parser
    1544                 :   // and Sema during declaration parsing. Try deallocating/caching them when
    1545                 :   // it's appropriate, instead of allocating them and keeping them around.
    1546            16302:   LocInfoType *LocT = (LocInfoType*)BumpAlloc.Allocate(sizeof(LocInfoType), 8);
                    16302: branch 1 taken
                        0: branch 2 not taken
    1547            16302:   new (LocT) LocInfoType(T, TInfo);
    1548                 :   assert(LocT->getTypeClass() != T->getTypeClass() &&
                    16302: branch 3 taken
                        0: branch 4 not taken
    1549            16302:          "LocInfoType's TypeClass conflicts with an existing Type class");
    1550            16302:   return QualType(LocT, 0);
    1551                 : }
    1552                 : 
    1553                 : void LocInfoType::getAsStringInternal(std::string &Str,
    1554                0:                                       const PrintingPolicy &Policy) const {
    1555                 :   assert(false && "LocInfoType leaked into the type system; an opaque TypeTy*"
    1556                 :          " was used directly instead of getting the QualType through"
    1557                0:          " GetTypeFromParser");
    1558                 : }
    1559                 : 
    1560                 : /// UnwrapSimilarPointerTypes - If T1 and T2 are pointer types  that
    1561                 : /// may be similar (C++ 4.4), replaces T1 and T2 with the type that
    1562                 : /// they point to and return true. If T1 and T2 aren't pointer types
    1563                 : /// or pointer-to-member types, or if they are not similar at this
    1564                 : /// level, returns false and leaves T1 and T2 unchanged. Top-level
    1565                 : /// qualifiers on T1 and T2 are ignored. This function will typically
    1566                 : /// be called in a loop that successively "unwraps" pointer and
    1567                 : /// pointer-to-member types to compare them at each level.
    1568             5078: bool Sema::UnwrapSimilarPointerTypes(QualType& T1, QualType& T2) {
    1569             5078:   const PointerType *T1PtrType = T1->getAs<PointerType>(),
    1570             5078:                     *T2PtrType = T2->getAs<PointerType>();
                     3139: branch 0 taken
                     1939: branch 1 taken
                      784: branch 2 taken
                     2355: branch 3 taken
    1571             5078:   if (T1PtrType && T2PtrType) {
    1572              784:     T1 = T1PtrType->getPointeeType();
    1573              784:     T2 = T2PtrType->getPointeeType();
    1574              784:     return true;
    1575                 :   }
    1576                 : 
    1577             4294:   const MemberPointerType *T1MPType = T1->getAs<MemberPointerType>(),
    1578             4294:                           *T2MPType = T2->getAs<MemberPointerType>();
                      468: branch 0 taken
                     3826: branch 1 taken
                      162: branch 2 taken
                      306: branch 3 taken
                      137: branch 8 taken
                       25: branch 9 taken
                      137: branch 10 taken
                     4157: branch 11 taken
    1579             4294:   if (T1MPType && T2MPType &&
    1580                 :       Context.getCanonicalType(T1MPType->getClass()) ==
    1581                 :       Context.getCanonicalType(T2MPType->getClass())) {
    1582              137:     T1 = T1MPType->getPointeeType();
    1583              137:     T2 = T2MPType->getPointeeType();
    1584              137:     return true;
    1585                 :   }
    1586             4157:   return false;
    1587                 : }
    1588                 : 
    1589            14493: Sema::TypeResult Sema::ActOnTypeName(Scope *S, Declarator &D) {
    1590                 :   // C99 6.7.6: Type names have no identifier.  This is already validated by
    1591                 :   // the parser.
                    14493: branch 1 taken
                        0: branch 2 not taken
    1592            14493:   assert(D.getIdentifier() == 0 && "Type name should have no identifier!");
    1593                 : 
    1594            14493:   TypeSourceInfo *TInfo = 0;
    1595            14493:   TagDecl *OwnedTag = 0;
    1596            14493:   QualType T = GetTypeForDeclarator(D, S, &TInfo, &OwnedTag);
                        6: branch 1 taken
                    14487: branch 2 taken
    1597            14493:   if (D.isInvalidType())
    1598                6:     return true;
    1599                 : 
                     6033: branch 1 taken
                     8454: branch 2 taken
    1600            14487:   if (getLangOptions().CPlusPlus) {
    1601                 :     // Check that there are no default arguments (C++ only).
    1602             6033:     CheckExtraCXXDefaultArguments(D);
    1603                 : 
    1604                 :     // C++0x [dcl.type]p3:
    1605                 :     //   A type-specifier-seq shall not define a class or enumeration
    1606                 :     //   unless it appears in the type-id of an alias-declaration
    1607                 :     //   (7.1.3).
                        3: branch 0 taken
                     6030: branch 1 taken
                        2: branch 3 taken
                        1: branch 4 taken
                        2: branch 5 taken
                     6031: branch 6 taken
    1608             6033:     if (OwnedTag && OwnedTag->isDefinition())
    1609                 :       Diag(OwnedTag->getLocation(), diag::err_type_defined_in_type_specifier)
    1610                2:         << Context.getTypeDeclType(OwnedTag);
    1611                 :   }
    1612                 : 
                    14487: branch 0 taken
                        0: branch 1 not taken
    1613            14487:   if (TInfo)
    1614            14487:     T = CreateLocInfoType(T, TInfo);
    1615                 : 
    1616            14487:   return T.getAsOpaquePtr();
    1617                 : }
    1618                 : 
    1619                 : 
    1620                 : 
    1621                 : //===----------------------------------------------------------------------===//
    1622                 : // Type Attribute Processing
    1623                 : //===----------------------------------------------------------------------===//
    1624                 : 
    1625                 : /// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the
    1626                 : /// specified type.  The attribute contains 1 argument, the id of the address
    1627                 : /// space for the type.
    1628                 : static void HandleAddressSpaceTypeAttribute(QualType &Type,
    1629               55:                                             const AttributeList &Attr, Sema &S){
    1630                 : 
    1631                 :   // If this type is already address space qualified, reject it.
    1632                 :   // Clause 6.7.3 - Type qualifiers: "No type shall be qualified by qualifiers
    1633                 :   // for two or more different address spaces."
                        2: branch 1 taken
                       53: branch 2 taken
    1634               55:   if (Type.getAddressSpace()) {
    1635                2:     S.Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers);
    1636                2:     return;
    1637                 :   }
    1638                 : 
    1639                 :   // Check the attribute arguments.
                        0: branch 1 not taken
                       53: branch 2 taken
    1640               53:   if (Attr.getNumArgs() != 1) {
    1641                0:     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
    1642                0:     return;
    1643                 :   }
    1644               53:   Expr *ASArgExpr = static_cast<Expr *>(Attr.getArg(0));
    1645               53:   llvm::APSInt addrSpace(32);
                        0: branch 1 not taken
                       53: branch 2 taken
    1646               53:   if (!ASArgExpr->isIntegerConstantExpr(addrSpace, S.Context)) {
    1647                 :     S.Diag(Attr.getLoc(), diag::err_attribute_address_space_not_int)
    1648                0:       << ASArgExpr->getSourceRange();
    1649                3:     return;
    1650                 :   }
    1651                 : 
    1652                 :   // Bounds checking.
                       53: branch 1 taken
                        0: branch 2 not taken
    1653               53:   if (addrSpace.isSigned()) {
                        1: branch 1 taken
                       52: branch 2 taken
    1654               53:     if (addrSpace.isNegative()) {
    1655                 :       S.Diag(Attr.getLoc(), diag::err_attribute_address_space_negative)
    1656                1:         << ASArgExpr->getSourceRange();
    1657                 :       return;
    1658                 :     }
    1659               52:     addrSpace.setIsSigned(false);
    1660                 :   }
    1661               52:   llvm::APSInt max(addrSpace.getBitWidth());
    1662               52:   max = Qualifiers::MaxAddressSpace;
                        2: branch 1 taken
                       50: branch 2 taken
    1663               52:   if (addrSpace > max) {
    1664                 :     S.Diag(Attr.getLoc(), diag::err_attribute_address_space_too_high)
    1665                2:       << Qualifiers::MaxAddressSpace << ASArgExpr->getSourceRange();
    1666                 :     return;
    1667                 :   }
    1668                 : 
    1669               50:   unsigned ASIdx = static_cast<unsigned>(addrSpace.getZExtValue());
                       50: branch 2 taken
                        2: branch 3 taken
                       50: branch 5 taken
                        3: branch 6 taken
    1670               50:   Type = S.Context.getAddrSpaceQualType(Type, ASIdx);
    1671                 : }
    1672                 : 
    1673                 : /// HandleObjCGCTypeAttribute - Process an objc's gc attribute on the
    1674                 : /// specified type.  The attribute contains 1 argument, weak or strong.
    1675                 : static void HandleObjCGCTypeAttribute(QualType &Type,
    1676               91:                                       const AttributeList &Attr, Sema &S) {
                        0: branch 1 not taken
                       91: branch 2 taken
    1677               91:   if (Type.getObjCGCAttr() != Qualifiers::GCNone) {
    1678                0:     S.Diag(Attr.getLoc(), diag::err_attribute_multiple_objc_gc);
    1679                0:     return;
    1680                 :   }
    1681                 : 
    1682                 :   // Check the attribute arguments.
                        2: branch 1 taken
                       89: branch 2 taken
    1683               91:   if (!Attr.getParameterName()) {
    1684                 :     S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string)
    1685                2:       << "objc_gc" << 1;
    1686                2:     return;
    1687                 :   }
    1688                 :   Qualifiers::GC GCAttr;
                        1: branch 1 taken
                       88: branch 2 taken
    1689               89:   if (Attr.getNumArgs() != 0) {
    1690                1:     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
    1691                1:     return;
    1692                 :   }
                       41: branch 2 taken
                       47: branch 3 taken
    1693               88:   if (Attr.getParameterName()->isStr("weak"))
    1694               41:     GCAttr = Qualifiers::Weak;
                       46: branch 2 taken
                        1: branch 3 taken
    1695               47:   else if (Attr.getParameterName()->isStr("strong"))
    1696               46:     GCAttr = Qualifiers::Strong;
    1697                 :   else {
    1698                 :     S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported)
    1699                1:       << "objc_gc" << Attr.getParameterName();
    1700                1:     return;
    1701                 :   }
    1702                 : 
    1703               87:   Type = S.Context.getObjCGCQualType(Type, GCAttr);
    1704                 : }
    1705                 : 
    1706                 : /// Process an individual function attribute.  Returns true if the
    1707                 : /// attribute does not make sense to apply to this type.
    1708              159: bool ProcessFnAttr(Sema &S, QualType &Type, const AttributeList &Attr) {
                      112: branch 1 taken
                       47: branch 2 taken
    1709              159:   if (Attr.getKind() == AttributeList::AT_noreturn) {
    1710                 :     // Complain immediately if the arg count is wrong.
                        1: branch 1 taken
                      111: branch 2 taken
    1711              112:     if (Attr.getNumArgs() != 0) {
    1712                1:       S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
    1713                1:       return false;
    1714                 :     }
    1715                 : 
    1716                 :     // Delay if this is not a function or pointer to block.
                      104: branch 2 taken
                        7: branch 3 taken
                      102: branch 6 taken
                        2: branch 7 taken
                       13: branch 10 taken
                       89: branch 11 taken
                       13: branch 12 taken
                       98: branch 13 taken
    1717              111:     if (!Type->isFunctionPointerType()
    1718                 :         && !Type->isBlockPointerType()
    1719                 :         && !Type->isFunctionType())
    1720               13:       return true;
    1721                 : 
    1722                 :     // Otherwise we can process right away.
    1723               98:     Type = S.Context.getNoReturnType(Type);
    1724               98:     return false;
    1725                 :   }
    1726                 : 
    1727                 :   // Otherwise, a calling convention.
                        2: branch 1 taken
                       45: branch 2 taken
    1728               47:   if (Attr.getNumArgs() != 0) {
    1729                2:     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
    1730                2:     return false;
    1731                 :   }
    1732                 : 
    1733               45:   QualType T = Type;
                       10: branch 2 taken
                       35: branch 3 taken
    1734               45:   if (const PointerType *PT = Type->getAs<PointerType>())
    1735               10:     T = PT->getPointeeType();
    1736               45:   const FunctionType *Fn = T->getAs<FunctionType>();
    1737                 : 
    1738                 :   // Delay if the type didn't work out to a function.
                       19: branch 0 taken
                       26: branch 1 taken
    1739               45:   if (!Fn) return true;
    1740                 : 
    1741                 :   // TODO: diagnose uses of these conventions on the wrong target.
    1742                 :   CallingConv CC;
                        3: branch 1 taken
                       14: branch 2 taken
                        9: branch 3 taken
                        0: branch 4 not taken
    1743               26:   switch (Attr.getKind()) {
    1744                3:   case AttributeList::AT_cdecl: CC = CC_C; break;
    1745               14:   case AttributeList::AT_fastcall: CC = CC_X86FastCall; break;
    1746                9:   case AttributeList::AT_stdcall: CC = CC_X86StdCall; break;
    1747                0:   default: llvm_unreachable("unexpected attribute kind"); return false;
    1748                 :   }
    1749                 : 
    1750               26:   CallingConv CCOld = Fn->getCallConv();
                        0: branch 0 not taken
                       26: branch 1 taken
    1751               26:   if (CC == CCOld) return false;
    1752                 : 
                        1: branch 0 taken
                       25: branch 1 taken
    1753               26:   if (CCOld != CC_Default) {
    1754                 :     // Should we diagnose reapplications of the same convention?
    1755                 :     S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
    1756                 :       << FunctionType::getNameForCallConv(CC)
    1757                1:       << FunctionType::getNameForCallConv(CCOld);
    1758                1:     return false;
    1759                 :   }
    1760                 : 
    1761                 :   // Diagnose the use of X86 fastcall on varargs or unprototyped functions.
                       14: branch 0 taken
                       11: branch 1 taken
    1762               25:   if (CC == CC_X86FastCall) {
                        1: branch 1 taken
                       13: branch 2 taken
    1763               14:     if (isa<FunctionNoProtoType>(Fn)) {
    1764                 :       S.Diag(Attr.getLoc(), diag::err_cconv_knr)
    1765                1:         << FunctionType::getNameForCallConv(CC);
    1766                1:       return false;
    1767                 :     }
    1768                 : 
    1769               13:     const FunctionProtoType *FnP = cast<FunctionProtoType>(Fn);
                        1: branch 1 taken
                       12: branch 2 taken
    1770               13:     if (FnP->isVariadic()) {
    1771                 :       S.Diag(Attr.getLoc(), diag::err_cconv_varargs)
    1772                1:         << FunctionType::getNameForCallConv(CC);
    1773                1:       return false;
    1774                 :     }
    1775                 :   }
    1776                 : 
    1777               23:   Type = S.Context.getCallConvType(Type, CC);
    1778               23:   return false;
    1779                 : }
    1780                 : 
    1781                 : /// HandleVectorSizeAttribute - this attribute is only applicable to integral
    1782                 : /// and float scalars, although arrays, pointers, and function return values are
    1783                 : /// allowed in conjunction with this construct. Aggregates with this attribute
    1784                 : /// are invalid, even if they are of the same size as a corresponding scalar.
    1785                 : /// The raw attribute should contain precisely 1 argument, the vector size for
    1786                 : /// the variable, measured in bytes. If curType and rawAttr are well formed,
    1787                 : /// this routine will return a new vector type.
    1788              182: static void HandleVectorSizeAttr(QualType& CurType, const AttributeList &Attr, Sema &S) {
    1789                 :   // Check the attribute arugments.
                        0: branch 1 not taken
                      182: branch 2 taken
    1790              182:   if (Attr.getNumArgs() != 1) {
    1791                0:     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
    1792                0:     return;
    1793                 :   }
    1794              182:   Expr *sizeExpr = static_cast<Expr *>(Attr.getArg(0));
    1795              182:   llvm::APSInt vecSize(32);
                        0: branch 1 not taken
                      182: branch 2 taken
    1796              182:   if (!sizeExpr->isIntegerConstantExpr(vecSize, S.Context)) {
    1797                 :     S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int)
    1798                0:       << "vector_size" << sizeExpr->getSourceRange();
    1799                1:     return;
    1800                 :   }
    1801                 :   // the base type must be integer or float, and can't already be a vector.
                      181: branch 2 taken
                        1: branch 3 taken
                       40: branch 6 taken
                      141: branch 7 taken
                        0: branch 10 not taken
                       40: branch 11 taken
                        1: branch 12 taken
                      181: branch 13 taken
    1802              182:   if (CurType->isVectorType() ||
    1803                 :       (!CurType->isIntegerType() && !CurType->isRealFloatingType())) {
    1804                1:     S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type) << CurType;
    1805                 :     return;
    1806                 :   }
    1807              181:   unsigned typeSize = static_cast<unsigned>(S.Context.getTypeSize(CurType));
    1808                 :   // vecSize is specified in bytes - convert to bits.
    1809              181:   unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue() * 8);
    1810                 : 
    1811                 :   // the vector size needs to be an integral multiple of the type size.
                        0: branch 0 not taken
                      181: branch 1 taken
    1812              181:   if (vectorSize % typeSize) {
    1813                 :     S.Diag(Attr.getLoc(), diag::err_attribute_invalid_size)
    1814                0:       << sizeExpr->getSourceRange();
    1815                 :     return;
    1816                 :   }
                        0: branch 0 not taken
                      181: branch 1 taken
    1817              181:   if (vectorSize == 0) {
    1818                 :     S.Diag(Attr.getLoc(), diag::err_attribute_zero_size)
    1819                0:       << sizeExpr->getSourceRange();
    1820                 :     return;
    1821                 :   }
    1822                 : 
    1823                 :   // Success! Instantiate the vector type, the number of elements is > 0, and
    1824                 :   // not required to be a power of 2, unlike GCC.
                      181: branch 2 taken
                        1: branch 3 taken
    1825              181:   CurType = S.Context.getVectorType(CurType, vectorSize/typeSize, false, false);
    1826                 : }
    1827                 : 
    1828                 : void ProcessTypeAttributeList(Sema &S, QualType &Result,
    1829                 :                               const AttributeList *AL,
    1830             3159:                               DelayedAttributeSet &FnAttrs) {
    1831                 :   // Scan through and apply attributes to this type where it makes sense.  Some
    1832                 :   // attributes (such as __address_space__, __vector_size__, etc) apply to the
    1833                 :   // type, but others can be present in the type specifiers even though they
    1834                 :   // apply to the decl.  Here we apply type attributes and ignore the rest.
                     4767: branch 1 taken
                     3159: branch 2 taken
    1835             7926:   for (; AL; AL = AL->getNext()) {
    1836                 :     // If this is an attribute we can handle, do so now, otherwise, add it to
    1837                 :     // the LeftOverAttrs list for rechaining.
                     4309: branch 1 taken
                       55: branch 2 taken
                       91: branch 3 taken
                      182: branch 4 taken
                      130: branch 5 taken
    1838             4767:     switch (AL->getKind()) {
    1839             4309:     default: break;
    1840                 : 
    1841                 :     case AttributeList::AT_address_space:
    1842               55:       HandleAddressSpaceTypeAttribute(Result, *AL, S);
    1843               55:       break;
    1844                 :     case AttributeList::AT_objc_gc:
    1845               91:       HandleObjCGCTypeAttribute(Result, *AL, S);
    1846               91:       break;
    1847                 :     case AttributeList::AT_vector_size:
    1848              182:       HandleVectorSizeAttr(Result, *AL, S);
    1849              182:       break;
    1850                 : 
    1851                 :     case AttributeList::AT_noreturn:
    1852                 :     case AttributeList::AT_cdecl:
    1853                 :     case AttributeList::AT_fastcall:
    1854                 :     case AttributeList::AT_stdcall:
                       30: branch 1 taken
                      100: branch 2 taken
    1855              130:       if (ProcessFnAttr(S, Result, *AL))
    1856               30:         FnAttrs.push_back(DelayedAttribute(AL, Result));
    1857                 :       break;
    1858                 :     }
    1859                 :   }
    1860             3159: }
    1861                 : 
    1862                 : /// @brief Ensure that the type T is a complete type.
    1863                 : ///
    1864                 : /// This routine checks whether the type @p T is complete in any
    1865                 : /// context where a complete type is required. If @p T is a complete
    1866                 : /// type, returns false. If @p T is a class template specialization,
    1867                 : /// this routine then attempts to perform class template
    1868                 : /// instantiation. If instantiation fails, or if @p T is incomplete
    1869                 : /// and cannot be completed, issues the diagnostic @p diag (giving it
    1870                 : /// the type @p T) and returns true.
    1871                 : ///
    1872                 : /// @param Loc  The location in the source that the incomplete type
    1873                 : /// diagnostic should refer to.
    1874                 : ///
    1875                 : /// @param T  The type that this routine is examining for completeness.
    1876                 : ///
    1877                 : /// @param PD The partial diagnostic that will be printed out if T is not a
    1878                 : /// complete type.
    1879                 : ///
    1880                 : /// @returns @c true if @p T is incomplete and a diagnostic was emitted,
    1881                 : /// @c false otherwise.
    1882                 : bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
    1883                 :                                const PartialDiagnostic &PD,
    1884                 :                                std::pair<SourceLocation, 
    1885           108941:                                          PartialDiagnostic> Note) {
    1886           108941:   unsigned diag = PD.getDiagID();
    1887                 : 
    1888                 :   // FIXME: Add this assertion to make sure we always get instantiation points.
    1889                 :   //  assert(!Loc.isInvalid() && "Invalid location in RequireCompleteType");
    1890                 :   // FIXME: Add this assertion to help us flush out problems with
    1891                 :   // checking for dependent types and type-dependent expressions.
    1892                 :   //
    1893                 :   //  assert(!T->isDependentType() &&
    1894                 :   //         "Can't ask whether a dependent type is complete");
    1895                 : 
    1896                 :   // If we have a complete type, we're done.
                   107466: branch 2 taken
                     1475: branch 3 taken
    1897           108941:   if (!T->isIncompleteType())
    1898           107466:     return false;
    1899                 : 
    1900                 :   // If we have a class template specialization or a class member of a
    1901                 :   // class template specialization, or an array with known size of such,
    1902                 :   // try to instantiate it.
    1903             1475:   QualType MaybeTemplate = T;
                        1: branch 1 taken
                     1474: branch 2 taken
    1904             1475:   if (const ConstantArrayType *Array = Context.getAsConstantArrayType(T))
    1905                1:     MaybeTemplate = Array->getElementType();
                     1335: branch 2 taken
                      140: branch 3 taken
    1906             1475:   if (const RecordType *Record = MaybeTemplate->getAs<RecordType>()) {
                     1186: branch 0 taken
                      149: branch 1 taken
    1907             1335:     if (ClassTemplateSpecializationDecl *ClassTemplateSpec
    1908             1335:           = dyn_cast<ClassTemplateSpecializationDecl>(Record->getDecl())) {
                     1182: branch 1 taken
                        4: branch 2 taken
    1909             1186:       if (ClassTemplateSpec->getSpecializationKind() == TSK_Undeclared)
    1910                 :         return InstantiateClassTemplateSpecialization(Loc, ClassTemplateSpec,
    1911                 :                                                       TSK_ImplicitInstantiation,
    1912             1182:                                                       /*Complain=*/diag != 0);
                      122: branch 0 taken
                       27: branch 1 taken
    1913              149:     } else if (CXXRecordDecl *Rec
    1914              149:                  = dyn_cast<CXXRecordDecl>(Record->getDecl())) {
                       36: branch 1 taken
                       86: branch 2 taken
    1915              122:       if (CXXRecordDecl *Pattern = Rec->getInstantiatedFromMemberClass()) {
    1916               36:         MemberSpecializationInfo *MSInfo = Rec->getMemberSpecializationInfo();
                        0: branch 0 not taken
                       36: branch 1 taken
    1917               36:         assert(MSInfo && "Missing member specialization information?");
    1918                 :         // This record was instantiated from a class within a template.
                       34: branch 1 taken
                        2: branch 2 taken
    1919               36:         if (MSInfo->getTemplateSpecializationKind() 
    1920                 :                                                != TSK_ExplicitSpecialization)
    1921                 :           return InstantiateClass(Loc, Rec, Pattern,
    1922                 :                                   getTemplateInstantiationArgs(Rec),
    1923                 :                                   TSK_ImplicitInstantiation,
    1924               34:                                   /*Complain=*/diag != 0);
    1925                 :       }
    1926                 :     }
    1927                 :   }
    1928                 : 
                      144: branch 0 taken
                      115: branch 1 taken
    1929              259:   if (diag == 0)
    1930              144:     return true;
    1931                 : 
    1932                 :   // We have an incomplete type. Produce a diagnostic.
    1933              115:   Diag(Loc, PD) << T;
    1934                 : 
    1935                 :   // If we have a note, produce it.
                       13: branch 1 taken
                      102: branch 2 taken
    1936              115:   if (!Note.first.isInvalid())
    1937               13:     Diag(Note.first, Note.second);
    1938                 :     
    1939                 :   // If the type was a forward declaration of a class/struct/union
    1940                 :   // type, produce
    1941              115:   const TagType *Tag = 0;
                       86: branch 2 taken
                       29: branch 3 taken
    1942              115:   if (const RecordType *Record = T->getAs<RecordType>())
    1943               86:     Tag = Record;
                        3: branch 2 taken
                       26: branch 3 taken
    1944               29:   else if (const EnumType *Enum = T->getAs<EnumType>())
    1945                3:     Tag = Enum;
    1946                 : 
                       89: branch 0 taken
                       26: branch 1 taken
                       87: branch 4 taken
                        2: branch 5 taken
                       87: branch 6 taken
                       28: branch 7 taken
    1947              115:   if (Tag && !Tag->getDecl()->isInvalidDecl())
    1948                 :     Diag(Tag->getDecl()->getLocation(),
    1949                 :          Tag->isBeingDefined() ? diag::note_type_being_defined
    1950                 :                                : diag::note_forward_declaration)
                        2: branch 2 taken
                       85: branch 3 taken
    1951               87:         << QualType(Tag, 0);
    1952                 : 
    1953              115:   return true;
    1954                 : }
    1955                 : 
    1956                 : /// \brief Retrieve a version of the type 'T' that is qualified by the
    1957                 : /// nested-name-specifier contained in SS.
    1958            11792: QualType Sema::getQualifiedNameType(const CXXScopeSpec &SS, QualType T) {
                      353: branch 1 taken
                    11439: branch 2 taken
                      353: branch 4 taken
                        0: branch 5 not taken
                        0: branch 7 not taken
                      353: branch 8 taken
                    11439: branch 9 taken
                      353: branch 10 taken
    1959            11792:   if (!SS.isSet() || SS.isInvalid() || T.isNull())
    1960            11439:     return T;
    1961                 : 
    1962                 :   NestedNameSpecifier *NNS
    1963              353:     = static_cast<NestedNameSpecifier *>(SS.getScopeRep());
    1964              353:   return Context.getQualifiedNameType(NNS, T);
    1965                 : }
    1966                 : 
    1967              247: QualType Sema::BuildTypeofExprType(Expr *E) {
                        3: branch 3 taken
                      244: branch 4 taken
    1968              247:   if (E->getType() == Context.OverloadTy) {
    1969                 :     // C++ [temp.arg.explicit]p3 allows us to resolve a template-id to a 
    1970                 :     // function template specialization wherever deduction cannot occur.
                        2: branch 0 taken
                        1: branch 1 taken
    1971                3:     if (FunctionDecl *Specialization
    1972                3:         = ResolveSingleFunctionTemplateSpecialization(E)) {
    1973                2:       E = FixOverloadedFunctionReference(E, Specialization);
                        0: branch 0 not taken
                        2: branch 1 taken
    1974                2:       if (!E)
    1975                0:         return QualType();      
    1976                 :     } else {
    1977                 :       Diag(E->getLocStart(),
    1978                 :            diag::err_cannot_determine_declared_type_of_overloaded_function)
    1979                1:         << false << E->getSourceRange();
    1980                1:       return QualType();
    1981                 :     }
    1982                 :   }
    1983                 :   
    1984              246:   return Context.getTypeOfExprType(E);
    1985                 : }
    1986                 : 
    1987               18: QualType Sema::BuildDecltypeType(Expr *E) {
                        2: branch 3 taken
                       16: branch 4 taken
    1988               18:   if (E->getType() == Context.OverloadTy) {
    1989                 :     // C++ [temp.arg.explicit]p3 allows us to resolve a template-id to a 
    1990                 :     // function template specialization wherever deduction cannot occur.
                        0: branch 0 not taken
                        2: branch 1 taken
    1991                2:     if (FunctionDecl *Specialization
    1992                2:           = ResolveSingleFunctionTemplateSpecialization(E)) {
    1993                0:       E = FixOverloadedFunctionReference(E, Specialization);
                        0: branch 0 not taken
                        0: branch 1 not taken
    1994                0:       if (!E)
    1995                0:         return QualType();      
    1996                 :     } else {
    1997                 :       Diag(E->getLocStart(),
    1998                 :            diag::err_cannot_determine_declared_type_of_overloaded_function)
    1999                2:         << true << E->getSourceRange();
    2000                2:       return QualType();
    2001                 :     }
    2002                 :   }
    2003                 :   
    2004               16:   return Context.getDecltypeType(E);
    2005                 : }

Generated: 2010-02-10 01:31 by zcov