DeclSpec.cpp revision 7121bdb91b86f6053765bda18dd0a8a118929ace
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file implements semantic analysis for declaration specifiers.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1419510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h"
15c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor#include "clang/AST/ASTContext.h"
16d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner#include "clang/AST/DeclCXX.h"
17555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor#include "clang/AST/Expr.h"
182e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
192e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor#include "clang/AST/TypeLoc.h"
205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/LangOptions.h"
2155fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Lex/Preprocessor.h"
2255fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Parse/ParseDiagnostic.h" // FIXME: remove this back-dependency!
2355fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Sema/LocInfoType.h"
2455fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Sema/ParsedTemplate.h"
2555fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Sema/Sema.h"
2655fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Sema/SemaDiagnostic.h"
275af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner#include "llvm/ADT/STLExtras.h"
28ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith#include "llvm/ADT/SmallString.h"
2932d335e63bd287e5c9297532171284cdf4c7888cJohn McCall#include "llvm/Support/ErrorHandling.h"
30e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include <cstring>
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang;
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
33254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner
34d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikiestatic DiagnosticBuilder Diag(DiagnosticsEngine &D, SourceLocation Loc,
3533e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis                              unsigned DiagID) {
3633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  return D.Report(Loc, DiagID);
37254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner}
38254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner
39314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor
40314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregorvoid UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) {
41314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  assert(TemplateId && "NULL template-id annotation?");
42314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  Kind = IK_TemplateId;
43314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  this->TemplateId = TemplateId;
44314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  StartLocation = TemplateId->TemplateNameLoc;
45314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  EndLocation = TemplateId->RAngleLoc;
46314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor}
47314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor
480efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregorvoid UnqualifiedId::setConstructorTemplateId(TemplateIdAnnotation *TemplateId) {
490efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  assert(TemplateId && "NULL template-id annotation?");
500efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  Kind = IK_ConstructorTemplateId;
510efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  this->TemplateId = TemplateId;
520efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  StartLocation = TemplateId->TemplateNameLoc;
530efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  EndLocation = TemplateId->RAngleLoc;
540efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor}
550efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor
562e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregorvoid CXXScopeSpec::Extend(ASTContext &Context, SourceLocation TemplateKWLoc,
572e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                          TypeLoc TL, SourceLocation ColonColonLoc) {
585f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc);
592e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  if (Range.getBegin().isInvalid())
602e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor    Range.setBegin(TL.getBeginLoc());
612e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  Range.setEnd(ColonColonLoc);
62c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
635f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  assert(Range == Builder.getSourceRange() &&
64c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor         "NestedNameSpecifierLoc range computation incorrect");
652e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor}
662e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
672e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregorvoid CXXScopeSpec::Extend(ASTContext &Context, IdentifierInfo *Identifier,
682e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                          SourceLocation IdentifierLoc,
692e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                          SourceLocation ColonColonLoc) {
705f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.Extend(Context, Identifier, IdentifierLoc, ColonColonLoc);
715f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor
722e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  if (Range.getBegin().isInvalid())
732e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor    Range.setBegin(IdentifierLoc);
742e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  Range.setEnd(ColonColonLoc);
75c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
765f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  assert(Range == Builder.getSourceRange() &&
77c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor         "NestedNameSpecifierLoc range computation incorrect");
782e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor}
792e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
802e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregorvoid CXXScopeSpec::Extend(ASTContext &Context, NamespaceDecl *Namespace,
812e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                          SourceLocation NamespaceLoc,
822e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                          SourceLocation ColonColonLoc) {
835f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc);
845f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor
852e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  if (Range.getBegin().isInvalid())
862e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor    Range.setBegin(NamespaceLoc);
872e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  Range.setEnd(ColonColonLoc);
88c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
895f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  assert(Range == Builder.getSourceRange() &&
90c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor         "NestedNameSpecifierLoc range computation incorrect");
912e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor}
922e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
9314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregorvoid CXXScopeSpec::Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
9414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor                          SourceLocation AliasLoc,
9514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor                          SourceLocation ColonColonLoc) {
965f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.Extend(Context, Alias, AliasLoc, ColonColonLoc);
975f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor
9814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  if (Range.getBegin().isInvalid())
9914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor    Range.setBegin(AliasLoc);
10014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  Range.setEnd(ColonColonLoc);
101c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
1025f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  assert(Range == Builder.getSourceRange() &&
103c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor         "NestedNameSpecifierLoc range computation incorrect");
10414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor}
10514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor
1062e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregorvoid CXXScopeSpec::MakeGlobal(ASTContext &Context,
1072e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor                              SourceLocation ColonColonLoc) {
1085f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.MakeGlobal(Context, ColonColonLoc);
109c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
1105f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Range = SourceRange(ColonColonLoc);
111c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
1125f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  assert(Range == Builder.getSourceRange() &&
113c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor         "NestedNameSpecifierLoc range computation incorrect");
114c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor}
115c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
116c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregorvoid CXXScopeSpec::MakeTrivial(ASTContext &Context,
117c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor                               NestedNameSpecifier *Qualifier, SourceRange R) {
1185f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.MakeTrivial(Context, Qualifier, R);
119c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  Range = R;
120c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor}
121c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
122c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregorvoid CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) {
123c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  if (!Other) {
124c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor    Range = SourceRange();
1255f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor    Builder.Clear();
126c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor    return;
127c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  }
1285f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor
129c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  Range = Other.getSourceRange();
1305f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  Builder.Adopt(Other);
131c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor}
132c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
1339dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCallSourceLocation CXXScopeSpec::getLastQualifierNameLoc() const {
1349dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall  if (!Builder.getRepresentation())
1359dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall    return SourceLocation();
1369dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall  return Builder.getTemporary().getLocalBeginLoc();
1379dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall}
1389dc71d2fddcd283e07d45f3894c8559e2f7dd9a7John McCall
139c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc
140c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorCXXScopeSpec::getWithLocInContext(ASTContext &Context) const {
141b46ae3964ba02535276c71332396e9a7bad2dfa5Douglas Gregor  if (!Builder.getRepresentation())
142c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor    return NestedNameSpecifierLoc();
143c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
1445f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  return Builder.getWithLocInContext(Context);
1452e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor}
1462e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
1475af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner/// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
1485af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner/// "TheDeclarator" is the declarator that this will be added to.
14959c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo BagnaraDeclaratorChunk DeclaratorChunk::getFunction(bool hasProto,
150b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith                                             bool isAmbiguous,
15159c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara                                             SourceLocation LParenLoc,
1525af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner                                             ParamInfo *ArgInfo,
1535af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner                                             unsigned NumArgs,
15459c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara                                             SourceLocation EllipsisLoc,
15559c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara                                             SourceLocation RParenLoc,
1565af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner                                             unsigned TypeQuals,
15783f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor                                             bool RefQualifierIsLvalueRef,
15883f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor                                             SourceLocation RefQualifierLoc,
15943f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor                                             SourceLocation ConstQualifierLoc,
16043f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor                                             SourceLocation
16143f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor                                                 VolatileQualifierLoc,
16290ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor                                             SourceLocation MutableLoc,
1636e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                             ExceptionSpecificationType
1646e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                                 ESpecType,
1656e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                             SourceLocation ESpecLoc,
166b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                             ParsedType *Exceptions,
167ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl                                             SourceRange *ExceptionRanges,
1687dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl                                             unsigned NumExceptions,
1696e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                             Expr *NoexceptExpr,
170796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara                                             SourceLocation LocalRangeBegin,
171796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara                                             SourceLocation LocalRangeEnd,
172dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor                                             Declarator &TheDeclarator,
17354655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith                                             TypeResult TrailingReturnType) {
1744cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith  assert(!(TypeQuals & DeclSpec::TQ_atomic) &&
1754cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith         "function cannot have _Atomic qualifier");
1764cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith
1775af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  DeclaratorChunk I;
1786e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Kind                        = Function;
179796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  I.Loc                         = LocalRangeBegin;
180796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  I.EndLoc                      = LocalRangeEnd;
1810b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  I.Fun.AttrList                = 0;
1826e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.hasPrototype            = hasProto;
18359c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara  I.Fun.isVariadic              = EllipsisLoc.isValid();
184b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith  I.Fun.isAmbiguous             = isAmbiguous;
18559c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara  I.Fun.LParenLoc               = LParenLoc.getRawEncoding();
1866e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.EllipsisLoc             = EllipsisLoc.getRawEncoding();
18759c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara  I.Fun.RParenLoc               = RParenLoc.getRawEncoding();
1886e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.DeleteArgInfo           = false;
1896e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.TypeQuals               = TypeQuals;
1906e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.NumArgs                 = NumArgs;
1916e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.ArgInfo                 = 0;
19283f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor  I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
1936e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.RefQualifierLoc         = RefQualifierLoc.getRawEncoding();
19443f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor  I.Fun.ConstQualifierLoc       = ConstQualifierLoc.getRawEncoding();
19543f5103f8051bbac19022e6edaf7d9138b0f3c0fDouglas Gregor  I.Fun.VolatileQualifierLoc    = VolatileQualifierLoc.getRawEncoding();
19690ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor  I.Fun.MutableLoc              = MutableLoc.getRawEncoding();
1976e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.ExceptionSpecType       = ESpecType;
1986e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.ExceptionSpecLoc        = ESpecLoc.getRawEncoding();
1996e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.NumExceptions           = 0;
2006e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.Exceptions              = 0;
2016e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  I.Fun.NoexceptExpr            = 0;
20254655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith  I.Fun.HasTrailingReturnType   = TrailingReturnType.isUsable() ||
20354655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith                                  TrailingReturnType.isInvalid();
20454655be65585ed6618fdd7a19fa6c70efc321d3aRichard Smith  I.Fun.TrailingReturnType      = TrailingReturnType.get();
2057dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl
2065af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  // new[] an argument array if needed.
2075af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  if (NumArgs) {
2085af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    // If the 'InlineParams' in Declarator is unused and big enough, put our
2095af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    // parameter list there (in an effort to avoid new/delete traffic).  If it
2105af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    // is already used (consider a function returning a function pointer) or too
2115af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    // small (function taking too many arguments), go to the heap.
2121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (!TheDeclarator.InlineParamsUsed &&
2135af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner        NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
2145af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      I.Fun.ArgInfo = TheDeclarator.InlineParams;
2155af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      I.Fun.DeleteArgInfo = false;
2165af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      TheDeclarator.InlineParamsUsed = true;
2175af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    } else {
2185af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs];
2195af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      I.Fun.DeleteArgInfo = true;
2205af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    }
2215af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs);
2225af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  }
2236e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl
2246e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  // Check what exception specification information we should actually store.
2256e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  switch (ESpecType) {
2266e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  default: break; // By default, save nothing.
2276e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  case EST_Dynamic:
2286e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    // new[] an exception array if needed
2296e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    if (NumExceptions) {
2306e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      I.Fun.NumExceptions = NumExceptions;
2316e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
2326e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      for (unsigned i = 0; i != NumExceptions; ++i) {
2336e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl        I.Fun.Exceptions[i].Ty = Exceptions[i];
2346e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl        I.Fun.Exceptions[i].Range = ExceptionRanges[i];
2356e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      }
236ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl    }
2376e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    break;
2386e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl
2396e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl  case EST_ComputedNoexcept:
2406e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    I.Fun.NoexceptExpr = NoexceptExpr;
2416e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    break;
2427dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl  }
2435af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  return I;
2445af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner}
245254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner
246555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregorbool Declarator::isDeclarationOfFunction() const {
2471ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith  for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
2481ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    switch (DeclTypeInfo[i].Kind) {
2491ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::Function:
2501ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith      return true;
2511ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::Paren:
2521ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith      continue;
2531ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::Pointer:
2541ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::Reference:
2551ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::Array:
2561ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::BlockPointer:
2571ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    case DeclaratorChunk::MemberPointer:
2581ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith      return false;
2591ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    }
2601ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith    llvm_unreachable("Invalid type chunk");
2611ab0d90af489b5441d0bf25338d420ddae3ece74Richard Smith  }
262555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
263555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor  switch (DS.getTypeSpecType()) {
264b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    case TST_atomic:
265555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_auto:
266555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_bool:
267555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_char:
268555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_char16:
269555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_char32:
270555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_class:
271555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_decimal128:
272555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_decimal32:
273555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_decimal64:
274555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_double:
275555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_enum:
276555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_error:
277555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_float:
278aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov    case TST_half:
279555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_int:
2805a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith    case TST_int128:
281555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_struct:
2826666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos    case TST_interface:
283555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_union:
284555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_unknown_anytype:
285555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_unspecified:
286555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_void:
287555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_wchar:
288b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei    case TST_image1d_t:
289b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei    case TST_image1d_array_t:
290b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei    case TST_image1d_buffer_t:
291b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei    case TST_image2d_t:
292b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei    case TST_image2d_array_t:
293b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei    case TST_image3d_t:
29421f18c4fda167dc5f72feddbd6a7ac1b63200a0dGuy Benyei    case TST_sampler_t:
295e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei    case TST_event_t:
296555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      return false;
297555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
298a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    case TST_decltype_auto:
299a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith      // This must have an initializer, so can't be a function declaration,
300a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith      // even if the initializer has function type.
301a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith      return false;
302a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith
303555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_decltype:
304555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_typeofExpr:
305555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      if (Expr *E = DS.getRepAsExpr())
306555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor        return E->getType()->isFunctionType();
307555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      return false;
308555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
309555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_underlyingType:
310555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_typename:
311555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    case TST_typeofType: {
312555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      QualType QT = DS.getRepAsType().get();
313555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      if (QT.isNull())
314555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor        return false;
315555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
316555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT))
317555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor        QT = LIT->getType();
318555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
319555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      if (QT.isNull())
320555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor        return false;
321555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
322555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor      return QT->isFunctionType();
323555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor    }
324555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor  }
3257530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie
3267530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie  llvm_unreachable("Invalid TypeSpecType!");
327555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor}
328555f57e3549fb5cc963a2ce38180c4f3643a6f95Douglas Gregor
329d1a32c328bce903fb1b17fc8147b646be818298eReid Klecknerbool Declarator::isStaticMember() {
330d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner  assert(getContext() == MemberContext);
331d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner  return getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
332d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner         CXXMethodDecl::isStaticOverloadedOperator(
333d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner             getName().OperatorFunctionId.Operator);
334d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner}
335d1a32c328bce903fb1b17fc8147b646be818298eReid Kleckner
3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
3372a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner/// declaration specifier includes.
3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerunsigned DeclSpec::getParsedSpecifiers() const {
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Res = 0;
3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (StorageClassSpec != SCS_unspecified ||
342ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      ThreadStorageClassSpec != TSCS_unspecified)
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Res |= PQ_StorageClassSpecifier;
344d42043333a6d6bd35d641efe44b9b40819169384Mike Stump
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TypeQualifiers != TQ_unspecified)
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Res |= PQ_TypeQualifier;
3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (hasTypeSpecifier())
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Res |= PQ_TypeSpecifier;
3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
351de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith  if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified ||
352de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith      FS_noreturn_specified)
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Res |= PQ_FunctionSpecifier;
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return Res;
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
357fec54013fcd0eb72642741584ca04c1bc292bef8John McCalltemplate <class T> static bool BadSpecifier(T TNew, T TPrev,
358fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                            const char *&PrevSpec,
359c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman                                            unsigned &DiagID,
360c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman                                            bool IsExtension = true) {
36132d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  PrevSpec = DeclSpec::getSpecifierName(TPrev);
362c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  if (TNew != TPrev)
363c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman    DiagID = diag::err_invalid_decl_spec_combination;
364c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  else
365c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman    DiagID = IsExtension ? diag::ext_duplicate_declspec :
366c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman                           diag::warn_duplicate_declspec;
36732d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  return true;
3681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
36932d335e63bd287e5c9297532171284cdf4c7888cJohn McCall
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *DeclSpec::getSpecifierName(DeclSpec::SCS S) {
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (S) {
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_unspecified: return "unspecified";
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_typedef:     return "typedef";
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_extern:      return "extern";
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_static:      return "static";
3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_auto:        return "auto";
3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::SCS_register:    return "register";
37863054b39a27ff333487e88247d495a444838b44aEli Friedman  case DeclSpec::SCS_private_extern: return "__private_extern__";
379669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl  case DeclSpec::SCS_mutable:     return "mutable";
3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3819f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
384ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smithconst char *DeclSpec::getSpecifierName(DeclSpec::TSCS S) {
385ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  switch (S) {
386ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  case DeclSpec::TSCS_unspecified:   return "unspecified";
387ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  case DeclSpec::TSCS___thread:      return "__thread";
388ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  case DeclSpec::TSCS_thread_local:  return "thread_local";
389ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  case DeclSpec::TSCS__Thread_local: return "_Thread_local";
390ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  }
391ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  llvm_unreachable("Unknown typespec!");
392ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith}
393ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith
39432d335e63bd287e5c9297532171284cdf4c7888cJohn McCallconst char *DeclSpec::getSpecifierName(TSW W) {
3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (W) {
39632d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSW_unspecified: return "unspecified";
39732d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSW_short:       return "short";
39832d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSW_long:        return "long";
39932d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSW_longlong:    return "long long";
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4019f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
40432d335e63bd287e5c9297532171284cdf4c7888cJohn McCallconst char *DeclSpec::getSpecifierName(TSC C) {
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (C) {
40632d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSC_unspecified: return "unspecified";
40732d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSC_imaginary:   return "imaginary";
40832d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSC_complex:     return "complex";
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4109f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
41432d335e63bd287e5c9297532171284cdf4c7888cJohn McCallconst char *DeclSpec::getSpecifierName(TSS S) {
4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (S) {
41632d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSS_unspecified: return "unspecified";
41732d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSS_signed:      return "signed";
41832d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case TSS_unsigned:    return "unsigned";
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4209f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *DeclSpec::getSpecifierName(DeclSpec::TST T) {
4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (T) {
4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_unspecified: return "unspecified";
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_void:        return "void";
4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_char:        return "char";
42864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis  case DeclSpec::TST_wchar:       return "wchar_t";
429f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  case DeclSpec::TST_char16:      return "char16_t";
430f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  case DeclSpec::TST_char32:      return "char32_t";
4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_int:         return "int";
4325a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith  case DeclSpec::TST_int128:      return "__int128";
433aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov  case DeclSpec::TST_half:        return "half";
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_float:       return "float";
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_double:      return "double";
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_bool:        return "_Bool";
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_decimal32:   return "_Decimal32";
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_decimal64:   return "_Decimal64";
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_decimal128:  return "_Decimal128";
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_enum:        return "enum";
44199dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner  case DeclSpec::TST_class:       return "class";
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_union:       return "union";
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclSpec::TST_struct:      return "struct";
4446666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos  case DeclSpec::TST_interface:   return "__interface";
4451a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor  case DeclSpec::TST_typename:    return "type-name";
446d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  case DeclSpec::TST_typeofType:
447d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  case DeclSpec::TST_typeofExpr:  return "typeof";
44832d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TST_auto:        return "auto";
44932d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TST_decltype:    return "(decltype)";
450a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith  case DeclSpec::TST_decltype_auto: return "decltype(auto)";
451ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  case DeclSpec::TST_underlyingType: return "__underlying_type";
452a5fc472b353b88be3b4981da946fb01f5a5cc0c6John McCall  case DeclSpec::TST_unknown_anytype: return "__unknown_anytype";
453b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  case DeclSpec::TST_atomic: return "_Atomic";
454b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei  case DeclSpec::TST_image1d_t:   return "image1d_t";
455b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei  case DeclSpec::TST_image1d_array_t: return "image1d_array_t";
456b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei  case DeclSpec::TST_image1d_buffer_t: return "image1d_buffer_t";
457b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei  case DeclSpec::TST_image2d_t:   return "image2d_t";
458b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei  case DeclSpec::TST_image2d_array_t: return "image2d_array_t";
459b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei  case DeclSpec::TST_image3d_t:   return "image3d_t";
46021f18c4fda167dc5f72feddbd6a7ac1b63200a0dGuy Benyei  case DeclSpec::TST_sampler_t:   return "sampler_t";
461e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei  case DeclSpec::TST_event_t:     return "event_t";
46232d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TST_error:       return "(error)";
4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4649f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
46732d335e63bd287e5c9297532171284cdf4c7888cJohn McCallconst char *DeclSpec::getSpecifierName(TQ T) {
4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (T) {
46932d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TQ_unspecified: return "unspecified";
47032d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TQ_const:       return "const";
47132d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TQ_restrict:    return "restrict";
47232d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  case DeclSpec::TQ_volatile:    return "volatile";
4734cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith  case DeclSpec::TQ_atomic:      return "_Atomic";
4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4759f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("Unknown typespec!");
4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
478b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbournebool DeclSpec::SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
479fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                   const char *&PrevSpec,
480b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne                                   unsigned &DiagID) {
4815e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner  // OpenCL v1.1 s6.8g: "The extern, static, auto and register storage-class
4825e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner  // specifiers are not supported.
483e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne  // It seems sensible to prohibit private_extern too
484b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne  // The cl_clang_storage_class_specifiers extension enables support for
485b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne  // these storage-class specifiers.
4865e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner  // OpenCL v1.2 s6.8 changes this to "The auto and register storage-class
4875e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner  // specifiers are not supported."
4884e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  if (S.getLangOpts().OpenCL &&
489b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne      !S.getOpenCLOptions().cl_clang_storage_class_specifiers) {
490b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne    switch (SC) {
491e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    case SCS_extern:
492e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    case SCS_private_extern:
4935e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner    case SCS_static:
4945e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner        if (S.getLangOpts().OpenCLVersion < 120) {
4955e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner          DiagID   = diag::err_not_opencl_storage_class_specifier;
4965e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner          PrevSpec = getSpecifierName(SC);
4975e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner          return true;
4985e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner        }
4995e94d6fa2e1d5ca606e060406adee13b96849f2aTanya Lattner        break;
500e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    case SCS_auto:
501e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    case SCS_register:
502e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne      DiagID   = diag::err_not_opencl_storage_class_specifier;
503b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne      PrevSpec = getSpecifierName(SC);
504e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne      return true;
505e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    default:
506e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne      break;
507e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne    }
508e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne  }
509e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne
51035f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara  if (StorageClassSpec != SCS_unspecified) {
511a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    // Maybe this is an attempt to use C++11 'auto' outside of C++11 mode.
5128f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    bool isInvalid = true;
5134e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie    if (TypeSpecType == TST_unspecified && S.getLangOpts().CPlusPlus) {
514b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne      if (SC == SCS_auto)
5158f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith        return SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID);
5168f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith      if (StorageClassSpec == SCS_auto) {
5178f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith        isInvalid = SetTypeSpecType(TST_auto, StorageClassSpecLoc,
5188f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith                                    PrevSpec, DiagID);
5198f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith        assert(!isInvalid && "auto SCS -> TST recovery failed");
5208f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith      }
5218f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    }
5228f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith
52335f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    // Changing storage class is allowed only if the previous one
52435f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    // was the 'extern' that is part of a linkage specification and
52535f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    // the new storage class is 'typedef'.
5268f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    if (isInvalid &&
5278f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith        !(SCS_extern_in_linkage_spec &&
52835f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara          StorageClassSpec == SCS_extern &&
529b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne          SC == SCS_typedef))
530b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne      return BadSpecifier(SC, (SCS)StorageClassSpec, PrevSpec, DiagID);
53135f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara  }
532b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne  StorageClassSpec = SC;
5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  StorageClassSpecLoc = Loc;
534b8b0e75aeec85a7a268fdba311de4f1cd527fae1Peter Collingbourne  assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield");
5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
538ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smithbool DeclSpec::SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
539fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                         const char *&PrevSpec,
540fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                         unsigned &DiagID) {
541ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  if (ThreadStorageClassSpec != TSCS_unspecified)
542ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    return BadSpecifier(TSC, (TSCS)ThreadStorageClassSpec, PrevSpec, DiagID);
543ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith
544ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  ThreadStorageClassSpec = TSC;
545ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  ThreadStorageClassSpecLoc = Loc;
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// These methods set the specified attribute of the DeclSpec, but return true
5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// and ignore the request if invalid (e.g. "extern" then "auto" is
5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified).
5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc,
553fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                const char *&PrevSpec,
554fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                unsigned &DiagID) {
5552553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara  // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that
5562553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara  // for 'long long' we will keep the source location of the first 'long'.
5572553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara  if (TypeSpecWidth == TSW_unspecified)
5582553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara    TSWLoc = Loc;
5592553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara  // Allow turning long -> long long.
5602553eaf4a6b9ca9ca59383287cdfef2a5c9fca83Abramo Bagnara  else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
561fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeSpecWidth = W;
563788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  if (TypeAltiVecVector && !TypeAltiVecBool &&
564788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      ((TypeSpecWidth == TSW_long) || (TypeSpecWidth == TSW_longlong))) {
56582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
56682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    DiagID = diag::warn_vector_long_decl_spec_combination;
56782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    return true;
56882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc,
573fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                  const char *&PrevSpec,
574fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                  unsigned &DiagID) {
5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TypeSpecComplex != TSC_unspecified)
576fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID);
5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeSpecComplex = C;
5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TSCLoc = Loc;
5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc,
583fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                               const char *&PrevSpec,
584fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                               unsigned &DiagID) {
5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TypeSpecSign != TSS_unspecified)
586fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID);
5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeSpecSign = S;
5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TSSLoc = Loc;
5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
593fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                               const char *&PrevSpec,
594fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                               unsigned &DiagID,
595b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               ParsedType Rep) {
5960daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep);
5970daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara}
5980daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara
5990daaf32723ac78549c507c2a68a5300502703673Abramo Bagnarabool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
6000daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               SourceLocation TagNameLoc,
6010daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               const char *&PrevSpec,
6020daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               unsigned &DiagID,
6030daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               ParsedType Rep) {
604b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(isTypeRep(T) && "T does not store a type");
605b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(Rep && "no type provided!");
606b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  if (TypeSpecType != TST_unspecified) {
607b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
608b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    DiagID = diag::err_invalid_decl_spec_combination;
609b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return true;
610b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
611b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecType = T;
612b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeRep = Rep;
6130daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTLoc = TagKwLoc;
6140daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = TagNameLoc;
615b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecOwned = false;
616b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  return false;
617b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall}
618b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
619b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCallbool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
620b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               const char *&PrevSpec,
621b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               unsigned &DiagID,
622b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               Expr *Rep) {
623b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(isExprRep(T) && "T does not store an expr");
624b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(Rep && "no expression provided!");
625b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  if (TypeSpecType != TST_unspecified) {
626b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
627b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    DiagID = diag::err_invalid_decl_spec_combination;
628b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return true;
629b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
630b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecType = T;
631b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ExprRep = Rep;
632b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TSTLoc = Loc;
6330daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = Loc;
634b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecOwned = false;
635b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  return false;
636b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall}
637b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
638b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCallbool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
639b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               const char *&PrevSpec,
640b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               unsigned &DiagID,
641b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               Decl *Rep, bool Owned) {
6420daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned);
6430daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara}
6440daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara
6450daaf32723ac78549c507c2a68a5300502703673Abramo Bagnarabool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
6460daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               SourceLocation TagNameLoc,
6470daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               const char *&PrevSpec,
6480daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               unsigned &DiagID,
6490daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                               Decl *Rep, bool Owned) {
650b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(isDeclRep(T) && "T does not store a decl");
651b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  // Unlike the other cases, we don't assert that we actually get a decl.
652b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
653b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  if (TypeSpecType != TST_unspecified) {
654b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
655b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    DiagID = diag::err_invalid_decl_spec_combination;
656b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return true;
657b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
658b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecType = T;
659b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  DeclRep = Rep;
6600daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTLoc = TagKwLoc;
6610daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = TagNameLoc;
66286a87308f11e7ee7c71ff608aec0cde11aa7df58Douglas Gregor  TypeSpecOwned = Owned && Rep != 0;
663b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  return false;
664b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall}
665b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
666b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCallbool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
667b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               const char *&PrevSpec,
668b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               unsigned &DiagID) {
669b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) &&
670b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall         "rep required for these type-spec kinds!");
671fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  if (TypeSpecType != TST_unspecified) {
672fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
673fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    DiagID = diag::err_invalid_decl_spec_combination;
674fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    return true;
675fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  }
6760daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTLoc = Loc;
6770daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = Loc;
678788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) {
679788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    TypeAltiVecBool = true;
680788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    return false;
681788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  }
6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeSpecType = T;
683b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  TypeSpecOwned = false;
684788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) {
68582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
686788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    DiagID = diag::err_invalid_vector_decl_spec;
68782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    return true;
68882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
68982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  return false;
69082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson}
69182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
69282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompsonbool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
69382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                          const char *&PrevSpec, unsigned &DiagID) {
69482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  if (TypeSpecType != TST_unspecified) {
69582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
69682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    DiagID = diag::err_invalid_vector_decl_spec_combination;
69782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    return true;
69882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
69982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  TypeAltiVecVector = isAltiVecVector;
70082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  AltiVecLoc = Loc;
70182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  return false;
70282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson}
70382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
70482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompsonbool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
70582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                          const char *&PrevSpec, unsigned &DiagID) {
706788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  if (!TypeAltiVecVector || TypeAltiVecPixel ||
707788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      (TypeSpecType != TST_unspecified)) {
70882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
70982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    DiagID = diag::err_invalid_pixel_decl_spec_combination;
71082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    return true;
71182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
71282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  TypeAltiVecPixel = isAltiVecPixel;
71382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  TSTLoc = Loc;
7140daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = Loc;
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7183e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidtbool DeclSpec::SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
7193e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt                          const char *&PrevSpec, unsigned &DiagID) {
7203e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt  if (!TypeAltiVecVector || TypeAltiVecBool ||
7213e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt      (TypeSpecType != TST_unspecified)) {
7223e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
7233e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt    DiagID = diag::err_invalid_vector_bool_decl_spec;
7243e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt    return true;
7253e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt  }
7263e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt  TypeAltiVecBool = isAltiVecBool;
7273e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt  TSTLoc = Loc;
7283e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt  TSTNameLoc = Loc;
7293e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt  return false;
7303e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt}
7313e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt
732ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregorbool DeclSpec::SetTypeSpecError() {
733ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  TypeSpecType = TST_error;
7349e46b8cfb3e6c6feab5664744f52f06a40f9566bJohn McCall  TypeSpecOwned = false;
735ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  TSTLoc = SourceLocation();
7360daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  TSTNameLoc = SourceLocation();
737ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  return false;
738ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor}
739ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
741d654f2d722d4cb6366edcb8f27e99745fcbae486Richard Smith                           unsigned &DiagID, const LangOptions &Lang) {
742d654f2d722d4cb6366edcb8f27e99745fcbae486Richard Smith  // Duplicates are permitted in C99, but are not permitted in C++. However,
743d654f2d722d4cb6366edcb8f27e99745fcbae486Richard Smith  // since this is likely not what the user intended, we will always warn.  We
744d654f2d722d4cb6366edcb8f27e99745fcbae486Richard Smith  // do not need to set the qualifier's location since we already have it.
745c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  if (TypeQualifiers & T) {
746a14f400e4c4239b92137fc8aab1ac4700a209591Aaron Ballman    bool IsExtension = true;
747d654f2d722d4cb6366edcb8f27e99745fcbae486Richard Smith    if (Lang.C99)
748a14f400e4c4239b92137fc8aab1ac4700a209591Aaron Ballman      IsExtension = false;
749c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman    return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension);
750c828620a03b20835a376f6f456a72e44599f4f87Aaron Ballman  }
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeQualifiers |= T;
7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (T) {
7544cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith  case TQ_unspecified: break;
7554cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith  case TQ_const:    TQ_constLoc = Loc; return false;
7564cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith  case TQ_restrict: TQ_restrictLoc = Loc; return false;
7574cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith  case TQ_volatile: TQ_volatileLoc = Loc; return false;
7584cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith  case TQ_atomic:   TQ_atomicLoc = Loc; return false;
7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7604cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith
7614cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith  llvm_unreachable("Unknown type qualifier!");
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
76422aa6901b8134c51771245255b32cd7d026e7913Chad Rosierbool DeclSpec::setFunctionSpecInline(SourceLocation Loc) {
76567a0f6ef5ae38e1abddb278544e18aede6ea7833Chad Rosier  // 'inline inline' is ok.
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FS_inline_specified = true;
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FS_inlineLoc = Loc;
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
77122aa6901b8134c51771245255b32cd7d026e7913Chad Rosierbool DeclSpec::setFunctionSpecVirtual(SourceLocation Loc) {
77267a0f6ef5ae38e1abddb278544e18aede6ea7833Chad Rosier  // 'virtual virtual' is ok.
773b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  FS_virtual_specified = true;
774b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  FS_virtualLoc = Loc;
775b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  return false;
776b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor}
777b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor
77822aa6901b8134c51771245255b32cd7d026e7913Chad Rosierbool DeclSpec::setFunctionSpecExplicit(SourceLocation Loc) {
779b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  // 'explicit explicit' is ok.
780b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  FS_explicit_specified = true;
781b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  FS_explicitLoc = Loc;
782b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  return false;
783b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor}
784b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor
785de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smithbool DeclSpec::setFunctionSpecNoreturn(SourceLocation Loc) {
786de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith  // '_Noreturn _Noreturn' is ok.
787de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith  FS_noreturn_specified = true;
788de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith  FS_noreturnLoc = Loc;
789de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith  return false;
790de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith}
791de03c15ad92b44a4be11507ca2501bb9dd014dceRichard Smith
792fec54013fcd0eb72642741584ca04c1bc292bef8John McCallbool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
793fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                             unsigned &DiagID) {
794f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  if (Friend_specified) {
795f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson    PrevSpec = "friend";
796fec54013fcd0eb72642741584ca04c1bc292bef8John McCall    DiagID = diag::ext_duplicate_declspec;
797f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson    return true;
798f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  }
799fec54013fcd0eb72642741584ca04c1bc292bef8John McCall
800f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  Friend_specified = true;
801f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  FriendLoc = Loc;
802f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  return false;
803f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson}
8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8058d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregorbool DeclSpec::setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
8068d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor                                    unsigned &DiagID) {
8078d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  if (isModulePrivateSpecified()) {
8088d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor    PrevSpec = "__module_private__";
8098d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor    DiagID = diag::ext_duplicate_declspec;
8108d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor    return true;
8118d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  }
8128d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
8138d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  ModulePrivateLoc = Loc;
8148d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  return false;
8158d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor}
8168d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
8172ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redlbool DeclSpec::SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
8182ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl                                unsigned &DiagID) {
8192ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  // 'constexpr constexpr' is ok.
8202ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  Constexpr_specified = true;
8212ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  ConstexprLoc = Loc;
8222ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  return false;
8232ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl}
8242ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl
825d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid DeclSpec::setProtocolQualifiers(Decl * const *Protos,
826e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis                                     unsigned NP,
827e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis                                     SourceLocation *ProtoLocs,
828e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis                                     SourceLocation LAngleLoc) {
829e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis  if (NP == 0) return;
830c23e69d761e369bb7ffeef52926ab0442c41670fDavid Greene  Decl **ProtoQuals = new Decl*[NP];
831c23e69d761e369bb7ffeef52926ab0442c41670fDavid Greene  memcpy(ProtoQuals, Protos, sizeof(Decl*)*NP);
832c23e69d761e369bb7ffeef52926ab0442c41670fDavid Greene  ProtocolQualifiers = ProtoQuals;
833e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis  ProtocolLocs = new SourceLocation[NP];
834e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis  memcpy(ProtocolLocs, ProtoLocs, sizeof(SourceLocation)*NP);
835e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis  NumProtocolQualifiers = NP;
836e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis  ProtocolLAngleLoc = LAngleLoc;
837e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis}
838e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis
839ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorvoid DeclSpec::SaveWrittenBuiltinSpecs() {
840ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  writtenBS.Sign = getTypeSpecSign();
841ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  writtenBS.Width = getTypeSpecWidth();
842ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  writtenBS.Type = getTypeSpecType();
843ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  // Search the list of attributes for the presence of a mode attribute.
844ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  writtenBS.ModeAttr = false;
8457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  AttributeList* attrs = getAttributes().getList();
846ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  while (attrs) {
8478e083e71d48f7f4d6ef40c00531c2e14df745486Sean Hunt    if (attrs->getKind() == AttributeList::AT_Mode) {
848ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      writtenBS.ModeAttr = true;
849ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      break;
850ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    }
851ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    attrs = attrs->getNext();
852ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
853ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor}
854ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Finish - This does final analysis of the declspec, rejecting things like
8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// "_Imaginary" (lacking an FP type).  This returns a diagnostic to issue or
8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// diag::NUM_DIAGNOSTICS if there is no error.  After calling this method,
8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclSpec is guaranteed self-consistent, even if an error occurred.
859d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikievoid DeclSpec::Finish(DiagnosticsEngine &D, Preprocessor &PP) {
860ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  // Before possibly changing their values, save specs as written.
861ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  SaveWrittenBuiltinSpecs();
862ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Check the type specifier components first.
8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
865a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith  // If decltype(auto) is used, no other type specifiers are permitted.
866a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith  if (TypeSpecType == TST_decltype_auto &&
867a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith      (TypeSpecWidth != TSW_unspecified ||
868a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith       TypeSpecComplex != TSC_unspecified ||
869a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith       TypeSpecSign != TSS_unspecified ||
870a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith       TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||
871a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith       TypeQualifiers)) {
872c6a31777fe03c73aca654c7c54224e36e75398ddBenjamin Kramer    const unsigned NumLocs = 8;
873a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    SourceLocation ExtraLocs[NumLocs] = {
874a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith      TSWLoc, TSCLoc, TSSLoc, AltiVecLoc,
875a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith      TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc
876a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    };
877a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    FixItHint Hints[NumLocs];
878a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    SourceLocation FirstLoc;
879a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    for (unsigned I = 0; I != NumLocs; ++I) {
880a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith      if (!ExtraLocs[I].isInvalid()) {
881a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith        if (FirstLoc.isInvalid() ||
882a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith            PP.getSourceManager().isBeforeInTranslationUnit(ExtraLocs[I],
883a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith                                                            FirstLoc))
884a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith          FirstLoc = ExtraLocs[I];
885a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith        Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]);
886a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith      }
887a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    }
888a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    TypeSpecWidth = TSW_unspecified;
889a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    TypeSpecComplex = TSC_unspecified;
890a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    TypeSpecSign = TSS_unspecified;
891a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false;
892a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    TypeQualifiers = 0;
893a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith    Diag(D, TSTLoc, diag::err_decltype_auto_cannot_be_combined)
894a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith      << Hints[0] << Hints[1] << Hints[2] << Hints[3]
895a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith      << Hints[4] << Hints[5] << Hints[6] << Hints[7];
896a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith  }
897a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith
898788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  // Validate and finalize AltiVec vector declspec.
899788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  if (TypeAltiVecVector) {
900788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    if (TypeAltiVecBool) {
901788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      // Sign specifiers are not allowed with vector bool. (PIM 2.1)
902788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      if (TypeSpecSign != TSS_unspecified) {
90333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis        Diag(D, TSSLoc, diag::err_invalid_vector_bool_decl_spec)
904788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner          << getSpecifierName((TSS)TypeSpecSign);
905788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      }
906788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
907788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      // Only char/int are valid with vector bool. (PIM 2.1)
9082e964a922c0826a1216d101df315432c6a0a78f6Duncan Sands      if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) &&
9092e964a922c0826a1216d101df315432c6a0a78f6Duncan Sands           (TypeSpecType != TST_int)) || TypeAltiVecPixel) {
91033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis        Diag(D, TSTLoc, diag::err_invalid_vector_bool_decl_spec)
911788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner          << (TypeAltiVecPixel ? "__pixel" :
912788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner                                 getSpecifierName((TST)TypeSpecType));
913788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      }
914788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
915788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      // Only 'short' is valid with vector bool. (PIM 2.1)
916788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short))
91733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis        Diag(D, TSWLoc, diag::err_invalid_vector_bool_decl_spec)
918788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner          << getSpecifierName((TSW)TypeSpecWidth);
919788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
920788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      // Elements of vector bool are interpreted as unsigned. (PIM 2.1)
921788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) ||
922788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner          (TypeSpecWidth != TSW_unspecified))
923788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner        TypeSpecSign = TSS_unsigned;
924788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    }
925788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
926788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    if (TypeAltiVecPixel) {
927788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      //TODO: perform validation
928788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      TypeSpecType = TST_int;
929788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      TypeSpecSign = TSS_unsigned;
930788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      TypeSpecWidth = TSW_short;
9319e46b8cfb3e6c6feab5664744f52f06a40f9566bJohn McCall      TypeSpecOwned = false;
932788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    }
933788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  }
934788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
93564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis  // signed/unsigned are only valid with int/char/wchar_t.
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TypeSpecSign != TSS_unspecified) {
9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (TypeSpecType == TST_unspecified)
9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
9395a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith    else if (TypeSpecType != TST_int  && TypeSpecType != TST_int128 &&
94064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis             TypeSpecType != TST_char && TypeSpecType != TST_wchar) {
94133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis      Diag(D, TSSLoc, diag::err_invalid_sign_spec)
942254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner        << getSpecifierName((TST)TypeSpecType);
9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // signed double -> double.
9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecSign = TSS_unspecified;
9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Validate the width of the type.
9495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (TypeSpecWidth) {
9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TSW_unspecified: break;
9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TSW_short:    // short int
9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TSW_longlong: // long long int
9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (TypeSpecType == TST_unspecified)
9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_int; // short -> short int, long long -> long long int.
9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (TypeSpecType != TST_int) {
95633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis      Diag(D, TSWLoc,
9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec
958254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner                                      : diag::err_invalid_longlong_spec)
959254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner        <<  getSpecifierName((TST)TypeSpecType);
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_int;
9619e46b8cfb3e6c6feab5664744f52f06a40f9566bJohn McCall      TypeSpecOwned = false;
9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case TSW_long:  // long double, long int
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (TypeSpecType == TST_unspecified)
9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_int;  // long -> long int.
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (TypeSpecType != TST_int && TypeSpecType != TST_double) {
96833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis      Diag(D, TSWLoc, diag::err_invalid_long_spec)
969254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner        << getSpecifierName((TST)TypeSpecType);
9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_int;
9719e46b8cfb3e6c6feab5664744f52f06a40f9566bJohn McCall      TypeSpecOwned = false;
9725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
9735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
9745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // TODO: if the implementation does not implement _Complex or _Imaginary,
9775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // disallow their use.  Need information about the backend.
9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TypeSpecComplex != TSC_unspecified) {
9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (TypeSpecType == TST_unspecified) {
98033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis      Diag(D, TSCLoc, diag::ext_plain_complex)
981849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor        << FixItHint::CreateInsertion(
9829b3064b55f3c858923734e8b1c9831777fc22554Douglas Gregor                              PP.getLocForEndOfToken(getTypeSpecComplexLoc()),
9839b3064b55f3c858923734e8b1c9831777fc22554Douglas Gregor                                                 " double");
9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType = TST_double;   // _Complex -> _Complex double.
9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // Note that this intentionally doesn't include _Complex _Bool.
9874e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie      if (!PP.getLangOpts().CPlusPlus)
9887ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman        Diag(D, TSTLoc, diag::ext_integer_complex);
9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) {
99033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis      Diag(D, TSCLoc, diag::err_invalid_complex_spec)
991254be6ac14092e0bdd9e632dfea09f237850e63dChris Lattner        << getSpecifierName((TST)TypeSpecType);
9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecComplex = TSC_unspecified;
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
996ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  // C11 6.7.1/3, C++11 [dcl.stc]p1, GNU TLS: __thread, thread_local and
997ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  // _Thread_local can only appear with the 'static' and 'extern' storage class
998ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  // specifiers. We also allow __private_extern__ as an extension.
999ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  if (ThreadStorageClassSpec != TSCS_unspecified) {
1000ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    switch (StorageClassSpec) {
1001ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    case SCS_unspecified:
1002ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    case SCS_extern:
1003ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    case SCS_private_extern:
1004ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    case SCS_static:
1005ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      break;
1006ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    default:
1007ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      if (PP.getSourceManager().isBeforeInTranslationUnit(
1008ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith            getThreadStorageClassSpecLoc(), getStorageClassSpecLoc()))
1009ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith        Diag(D, getStorageClassSpecLoc(),
1010ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith             diag::err_invalid_decl_spec_combination)
1011ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith          << DeclSpec::getSpecifierName(getThreadStorageClassSpec())
1012ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith          << SourceRange(getThreadStorageClassSpecLoc());
1013ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      else
1014ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith        Diag(D, getThreadStorageClassSpecLoc(),
1015ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith             diag::err_invalid_decl_spec_combination)
1016ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith          << DeclSpec::getSpecifierName(getStorageClassSpec())
1017ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith          << SourceRange(getStorageClassSpecLoc());
1018ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      // Discard the thread storage class specifier to recover.
1019ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      ThreadStorageClassSpec = TSCS_unspecified;
1020ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      ThreadStorageClassSpecLoc = SourceLocation();
1021ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    }
1022ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  }
1023ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith
10248f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // If no type specifier was provided and we're parsing a language where
10258f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // the type specifier is not optional, but we got 'auto' as a storage
10268f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // class specifier, then assume this is an attempt to use C++0x's 'auto'
10278f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // type specifier.
102858eb37036b47bbe7433f72d92a2cb60848507707Richard Smith  if (PP.getLangOpts().CPlusPlus &&
10298f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith      TypeSpecType == TST_unspecified && StorageClassSpec == SCS_auto) {
10308f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    TypeSpecType = TST_auto;
1031d2615cc53b916e8aae45783ca7113b93de515ce3Rafael Espindola    StorageClassSpec = SCS_unspecified;
10328f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    TSTLoc = TSTNameLoc = StorageClassSpecLoc;
10338f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    StorageClassSpecLoc = SourceLocation();
10348f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  }
10358f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith  // Diagnose if we've recovered from an ill-formed 'auto' storage class
1036a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith  // specifier in a pre-C++11 dialect of C++.
103780ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith  if (!PP.getLangOpts().CPlusPlus11 && TypeSpecType == TST_auto)
10388f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    Diag(D, TSTLoc, diag::ext_auto_type_specifier);
103980ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith  if (PP.getLangOpts().CPlusPlus && !PP.getLangOpts().CPlusPlus11 &&
10408f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith      StorageClassSpec == SCS_auto)
10418f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith    Diag(D, StorageClassSpecLoc, diag::warn_auto_storage_class)
10428f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith      << FixItHint::CreateRemoval(StorageClassSpecLoc);
1043841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith  if (TypeSpecType == TST_char16 || TypeSpecType == TST_char32)
1044841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith    Diag(D, TSTLoc, diag::warn_cxx98_compat_unicode_type)
1045841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith      << (TypeSpecType == TST_char16 ? "char16_t" : "char32_t");
1046841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith  if (Constexpr_specified)
1047841804baff6ea8ba1904a2ba81265aae1479e882Richard Smith    Diag(D, ConstexprLoc, diag::warn_cxx98_compat_constexpr);
10488f4fb190852d3f86787c7e2c3dfc1b96143197aeRichard Smith
104967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  // C++ [class.friend]p6:
105067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  //   No storage-class-specifier shall appear in the decl-specifier-seq
105167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  //   of a friend declaration.
1052ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith  if (isFriendSpecified() &&
1053ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      (getStorageClassSpec() || getThreadStorageClassSpec())) {
1054ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    SmallString<32> SpecName;
1055ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    SourceLocation SCLoc;
1056ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    FixItHint StorageHint, ThreadHint;
1057ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith
1058ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    if (DeclSpec::SCS SC = getStorageClassSpec()) {
1059ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      SpecName = getSpecifierName(SC);
1060ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      SCLoc = getStorageClassSpecLoc();
1061ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      StorageHint = FixItHint::CreateRemoval(SCLoc);
1062ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    }
106367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
1064ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    if (DeclSpec::TSCS TSC = getThreadStorageClassSpec()) {
1065ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      if (!SpecName.empty()) SpecName += " ";
1066ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      SpecName += getSpecifierName(TSC);
1067ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      SCLoc = getThreadStorageClassSpecLoc();
1068ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      ThreadHint = FixItHint::CreateRemoval(SCLoc);
1069ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith    }
107067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
107133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    Diag(D, SCLoc, diag::err_friend_storage_spec)
1072ec64244f5939fa81596fbeddad966cca4b4a4c51Richard Smith      << SpecName << StorageHint << ThreadHint;
107367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
107467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    ClearStorageClassSpecs();
107567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  }
107667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
10776274d30d77870393d83a404dd223b8005f2b8cd5Douglas Gregor  assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType));
10786274d30d77870393d83a404dd223b8005f2b8cd5Douglas Gregor
10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Okay, now we can infer the real type.
10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // TODO: return "auto function" and other bad things based on the real type.
10821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // 'data definition has no type or storage class'?
10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1085e4858a65a93fb36c099d8dd2ea0a98e33e77687eDaniel Dunbar
1086a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redlbool DeclSpec::isMissingDeclaratorOk() {
1087a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl  TST tst = getTypeSpecType();
1088b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  return isDeclRep(tst) && getRepAsDecl() != 0 &&
1089b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    StorageClassSpec != DeclSpec::SCS_typedef;
1090a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl}
10913f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
10923f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorvoid UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc,
10933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                          OverloadedOperatorKind Op,
10943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                          SourceLocation SymbolLocations[3]) {
10953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  Kind = IK_OperatorFunctionId;
10963f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  StartLocation = OperatorLoc;
10973f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  EndLocation = OperatorLoc;
10983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  OperatorFunctionId.Operator = Op;
10993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  for (unsigned I = 0; I != 3; ++I) {
11003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding();
11013f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
11023f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    if (SymbolLocations[I].isValid())
11033f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      EndLocation = SymbolLocations[I];
11043f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  }
11053f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor}
1106b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1107cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlssonbool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc,
110846127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson                                  const char *&PrevSpec) {
1109f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8Douglas Gregor  LastLocation = Loc;
1110f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8Douglas Gregor
1111b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  if (Specifiers & VS) {
1112b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    PrevSpec = getSpecifierName(VS);
1113b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    return true;
1114b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  }
1115b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1116b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  Specifiers |= VS;
1117b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1118b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  switch (VS) {
1119b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  default: llvm_unreachable("Unknown specifier!");
1120b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  case VS_Override: VS_overrideLoc = Loc; break;
11217121bdb91b86f6053765bda18dd0a8a118929aceDavid Majnemer  case VS_Sealed:
1122b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  case VS_Final:    VS_finalLoc = Loc; break;
1123b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  }
112446127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson
1125b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  return false;
1126b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson}
1127b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1128cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlssonconst char *VirtSpecifiers::getSpecifierName(Specifier VS) {
1129c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson  switch (VS) {
1130b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  default: llvm_unreachable("Unknown specifier");
1131c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson  case VS_Override: return "override";
1132c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson  case VS_Final: return "final";
11337121bdb91b86f6053765bda18dd0a8a118929aceDavid Majnemer  case VS_Sealed: return "sealed";
1134c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson  }
1135c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson}
1136