SemaType.cpp revision 5f9e272e632e951b1efe824cd16acb4d96077930
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- SemaType.cpp - Semantic Analysis for Types -----------------------===// 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 type-related semantic analysis. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 142d88708cbe4e4ec5e04e4acb6bd7f5be68557379John McCall#include "clang/Sema/SemaInternal.h" 157cd088e519d7e6caa4c4c12db52e0e4ae35d25c2John McCall#include "clang/Sema/Template.h" 16207f4d8543529221932af82836016a2ef066c917Peter Collingbourne#include "clang/Basic/OpenCL.h" 175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/ASTContext.h" 1836f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor#include "clang/AST/ASTMutationListener.h" 19a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor#include "clang/AST/CXXInheritance.h" 20980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/DeclObjC.h" 212943aed177b33ae3f14273b11a7b398e5276ec62Douglas Gregor#include "clang/AST/DeclTemplate.h" 224adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis#include "clang/AST/TypeLoc.h" 2351bd803fbdade51d674598ed45da3d54190a656cJohn McCall#include "clang/AST/TypeLocVisitor.h" 24e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar#include "clang/AST/Expr.h" 2591a0cc913ecc5619b76d2e40742fd09725be8c56Anders Carlsson#include "clang/Basic/PartialDiagnostic.h" 26d18f9f965bcfe56edcdf9b0d8375ffaad9866b3fCharles Davis#include "clang/Basic/TargetInfo.h" 272792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall#include "clang/Lex/Preprocessor.h" 2819510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h" 29f85e193739c953358c865005855253af4f68a497John McCall#include "clang/Sema/DelayedDiagnostic.h" 304994d2d50ceacdc8908f750c55589c0a20942a0aSebastian Redl#include "llvm/ADT/SmallPtrSet.h" 3187c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor#include "llvm/Support/ErrorHandling.h" 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 345db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner/// isOmittedBlockReturnType - Return true if this declarator is missing a 355db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner/// return type because this is a omitted return type on a block literal. 368ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redlstatic bool isOmittedBlockReturnType(const Declarator &D) { 375db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner if (D.getContext() != Declarator::BlockLiteralContext || 388ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl D.getDeclSpec().hasTypeSpecifier()) 395db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner return false; 405db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner 415db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner if (D.getNumTypeObjects() == 0) 42a64ef0ab5cb6ac9cfb7d40661a9152c4aa488386Chris Lattner return true; // ^{ ... } 435db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner 445db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner if (D.getNumTypeObjects() == 1 && 455db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner D.getTypeObject(0).Kind == DeclaratorChunk::Function) 46a64ef0ab5cb6ac9cfb7d40661a9152c4aa488386Chris Lattner return true; // ^(int X, float Y) { ... } 475db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner 485db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner return false; 495db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner} 505db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner 512792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall/// diagnoseBadTypeAttribute - Diagnoses a type attribute which 522792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall/// doesn't apply to the given type. 532792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCallstatic void diagnoseBadTypeAttribute(Sema &S, const AttributeList &attr, 542792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall QualType type) { 552792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall bool useInstantiationLoc = false; 562792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall 572792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall unsigned diagID = 0; 582792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall switch (attr.getKind()) { 592792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall case AttributeList::AT_objc_gc: 602792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall diagID = diag::warn_pointer_attribute_wrong_type; 612792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall useInstantiationLoc = true; 622792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall break; 632792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall 6405d4876a64865e34366b58fc8a6848c3cde895d9Argyrios Kyrtzidis case AttributeList::AT_objc_ownership: 6505d4876a64865e34366b58fc8a6848c3cde895d9Argyrios Kyrtzidis diagID = diag::warn_objc_object_attribute_wrong_type; 6605d4876a64865e34366b58fc8a6848c3cde895d9Argyrios Kyrtzidis useInstantiationLoc = true; 6705d4876a64865e34366b58fc8a6848c3cde895d9Argyrios Kyrtzidis break; 6805d4876a64865e34366b58fc8a6848c3cde895d9Argyrios Kyrtzidis 692792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall default: 702792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall // Assume everything else was a function attribute. 712792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall diagID = diag::warn_function_attribute_wrong_type; 722792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall break; 732792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall } 742792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall 752792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall SourceLocation loc = attr.getLoc(); 765f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef name = attr.getName()->getName(); 772792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall 782792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall // The GC attributes are usually written with macros; special-case them. 792792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall if (useInstantiationLoc && loc.isMacroID() && attr.getParameterName()) { 80834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall if (attr.getParameterName()->isStr("strong")) { 81834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall if (S.findMacroSpelling(loc, "__strong")) name = "__strong"; 82834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall } else if (attr.getParameterName()->isStr("weak")) { 83834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall if (S.findMacroSpelling(loc, "__weak")) name = "__weak"; 842792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall } 852792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall } 862792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall 872792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall S.Diag(loc, diagID) << name << type; 882792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall} 892792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall 90711c52bb20d0c69063b52a99826fb7d2835501f1John McCall// objc_gc applies to Objective-C pointers or, otherwise, to the 91711c52bb20d0c69063b52a99826fb7d2835501f1John McCall// smallest available pointer type (i.e. 'void*' in 'void**'). 92711c52bb20d0c69063b52a99826fb7d2835501f1John McCall#define OBJC_POINTER_TYPE_ATTRS_CASELIST \ 93f85e193739c953358c865005855253af4f68a497John McCall case AttributeList::AT_objc_gc: \ 94b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis case AttributeList::AT_objc_ownership 95711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 96711c52bb20d0c69063b52a99826fb7d2835501f1John McCall// Function type attributes. 97711c52bb20d0c69063b52a99826fb7d2835501f1John McCall#define FUNCTION_TYPE_ATTRS_CASELIST \ 98711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case AttributeList::AT_noreturn: \ 99711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case AttributeList::AT_cdecl: \ 100711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case AttributeList::AT_fastcall: \ 101711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case AttributeList::AT_stdcall: \ 102711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case AttributeList::AT_thiscall: \ 103711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case AttributeList::AT_pascal: \ 104414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case AttributeList::AT_regparm: \ 105414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case AttributeList::AT_pcs \ 106711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 107711c52bb20d0c69063b52a99826fb7d2835501f1John McCallnamespace { 108711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// An object which stores processing state for the entire 109711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// GetTypeForDeclarator process. 110711c52bb20d0c69063b52a99826fb7d2835501f1John McCall class TypeProcessingState { 111711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Sema &sema; 112711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 113711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// The declarator being processed. 114711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Declarator &declarator; 115711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 116711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// The index of the declarator chunk we're currently processing. 117711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// May be the total number of valid chunks, indicating the 118711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// DeclSpec. 119711c52bb20d0c69063b52a99826fb7d2835501f1John McCall unsigned chunkIndex; 120711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 121711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// Whether there are non-trivial modifications to the decl spec. 122711c52bb20d0c69063b52a99826fb7d2835501f1John McCall bool trivial; 123711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 1247ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall /// Whether we saved the attributes in the decl spec. 1257ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall bool hasSavedAttrs; 1267ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall 127711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// The original set of attributes on the DeclSpec. 1285f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<AttributeList*, 2> savedAttrs; 129711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 130711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// A list of attributes to diagnose the uselessness of when the 131711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// processing is complete. 1325f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<AttributeList*, 2> ignoredTypeAttrs; 133711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 134711c52bb20d0c69063b52a99826fb7d2835501f1John McCall public: 135711c52bb20d0c69063b52a99826fb7d2835501f1John McCall TypeProcessingState(Sema &sema, Declarator &declarator) 136711c52bb20d0c69063b52a99826fb7d2835501f1John McCall : sema(sema), declarator(declarator), 137711c52bb20d0c69063b52a99826fb7d2835501f1John McCall chunkIndex(declarator.getNumTypeObjects()), 1387ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall trivial(true), hasSavedAttrs(false) {} 139711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 140711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Sema &getSema() const { 141711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return sema; 142711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 143711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 144711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Declarator &getDeclarator() const { 145711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return declarator; 146711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 147711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 148711c52bb20d0c69063b52a99826fb7d2835501f1John McCall unsigned getCurrentChunkIndex() const { 149711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return chunkIndex; 150711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 151711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 152711c52bb20d0c69063b52a99826fb7d2835501f1John McCall void setCurrentChunkIndex(unsigned idx) { 153711c52bb20d0c69063b52a99826fb7d2835501f1John McCall assert(idx <= declarator.getNumTypeObjects()); 154711c52bb20d0c69063b52a99826fb7d2835501f1John McCall chunkIndex = idx; 155711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 156711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 157711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *&getCurrentAttrListRef() const { 158711c52bb20d0c69063b52a99826fb7d2835501f1John McCall assert(chunkIndex <= declarator.getNumTypeObjects()); 159711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (chunkIndex == declarator.getNumTypeObjects()) 160711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return getMutableDeclSpec().getAttributes().getListRef(); 161711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return declarator.getTypeObject(chunkIndex).getAttrListRef(); 162711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 163711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 164711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// Save the current set of attributes on the DeclSpec. 165711c52bb20d0c69063b52a99826fb7d2835501f1John McCall void saveDeclSpecAttrs() { 166711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Don't try to save them multiple times. 1677ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall if (hasSavedAttrs) return; 168711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 169711c52bb20d0c69063b52a99826fb7d2835501f1John McCall DeclSpec &spec = getMutableDeclSpec(); 170711c52bb20d0c69063b52a99826fb7d2835501f1John McCall for (AttributeList *attr = spec.getAttributes().getList(); attr; 171711c52bb20d0c69063b52a99826fb7d2835501f1John McCall attr = attr->getNext()) 172711c52bb20d0c69063b52a99826fb7d2835501f1John McCall savedAttrs.push_back(attr); 173711c52bb20d0c69063b52a99826fb7d2835501f1John McCall trivial &= savedAttrs.empty(); 1747ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall hasSavedAttrs = true; 175711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 176711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 177711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// Record that we had nowhere to put the given type attribute. 178711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// We will diagnose such attributes later. 179711c52bb20d0c69063b52a99826fb7d2835501f1John McCall void addIgnoredTypeAttr(AttributeList &attr) { 180711c52bb20d0c69063b52a99826fb7d2835501f1John McCall ignoredTypeAttrs.push_back(&attr); 181711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 182711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 183711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// Diagnose all the ignored type attributes, given that the 184711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// declarator worked out to the given type. 185711c52bb20d0c69063b52a99826fb7d2835501f1John McCall void diagnoseIgnoredTypeAttrs(QualType type) const { 1865f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner for (SmallVectorImpl<AttributeList*>::const_iterator 187711c52bb20d0c69063b52a99826fb7d2835501f1John McCall i = ignoredTypeAttrs.begin(), e = ignoredTypeAttrs.end(); 1882792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall i != e; ++i) 1892792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall diagnoseBadTypeAttribute(getSema(), **i, type); 190711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 191711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 192711c52bb20d0c69063b52a99826fb7d2835501f1John McCall ~TypeProcessingState() { 193711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (trivial) return; 194711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 195711c52bb20d0c69063b52a99826fb7d2835501f1John McCall restoreDeclSpecAttrs(); 196711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 197711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 198711c52bb20d0c69063b52a99826fb7d2835501f1John McCall private: 199711c52bb20d0c69063b52a99826fb7d2835501f1John McCall DeclSpec &getMutableDeclSpec() const { 200711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return const_cast<DeclSpec&>(declarator.getDeclSpec()); 201711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 202711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 203711c52bb20d0c69063b52a99826fb7d2835501f1John McCall void restoreDeclSpecAttrs() { 2047ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall assert(hasSavedAttrs); 2057ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall 2067ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall if (savedAttrs.empty()) { 2077ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall getMutableDeclSpec().getAttributes().set(0); 2087ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall return; 2097ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall } 2107ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall 211711c52bb20d0c69063b52a99826fb7d2835501f1John McCall getMutableDeclSpec().getAttributes().set(savedAttrs[0]); 212711c52bb20d0c69063b52a99826fb7d2835501f1John McCall for (unsigned i = 0, e = savedAttrs.size() - 1; i != e; ++i) 213711c52bb20d0c69063b52a99826fb7d2835501f1John McCall savedAttrs[i]->setNext(savedAttrs[i+1]); 214711c52bb20d0c69063b52a99826fb7d2835501f1John McCall savedAttrs.back()->setNext(0); 215711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 216711c52bb20d0c69063b52a99826fb7d2835501f1John McCall }; 217711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 218711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// Basically std::pair except that we really want to avoid an 219711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// implicit operator= for safety concerns. It's also a minor 220711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// link-time optimization for this to be a private type. 221711c52bb20d0c69063b52a99826fb7d2835501f1John McCall struct AttrAndList { 222711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// The attribute. 223711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &first; 224711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 225711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// The head of the list the attribute is currently in. 226711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *&second; 227711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 228711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttrAndList(AttributeList &attr, AttributeList *&head) 229711c52bb20d0c69063b52a99826fb7d2835501f1John McCall : first(attr), second(head) {} 230711c52bb20d0c69063b52a99826fb7d2835501f1John McCall }; 23104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall} 23204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 233711c52bb20d0c69063b52a99826fb7d2835501f1John McCallnamespace llvm { 234711c52bb20d0c69063b52a99826fb7d2835501f1John McCall template <> struct isPodLike<AttrAndList> { 235711c52bb20d0c69063b52a99826fb7d2835501f1John McCall static const bool value = true; 236711c52bb20d0c69063b52a99826fb7d2835501f1John McCall }; 237711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 238711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 239711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void spliceAttrIntoList(AttributeList &attr, AttributeList *&head) { 240711c52bb20d0c69063b52a99826fb7d2835501f1John McCall attr.setNext(head); 241711c52bb20d0c69063b52a99826fb7d2835501f1John McCall head = &attr; 242711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 243711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 244711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void spliceAttrOutOfList(AttributeList &attr, AttributeList *&head) { 245711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (head == &attr) { 246711c52bb20d0c69063b52a99826fb7d2835501f1John McCall head = attr.getNext(); 247711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return; 24804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 249711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 250711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *cur = head; 251711c52bb20d0c69063b52a99826fb7d2835501f1John McCall while (true) { 252711c52bb20d0c69063b52a99826fb7d2835501f1John McCall assert(cur && cur->getNext() && "ran out of attrs?"); 253711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (cur->getNext() == &attr) { 254711c52bb20d0c69063b52a99826fb7d2835501f1John McCall cur->setNext(attr.getNext()); 255711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return; 256711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 257711c52bb20d0c69063b52a99826fb7d2835501f1John McCall cur = cur->getNext(); 258711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 259711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 260711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 261711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void moveAttrFromListToList(AttributeList &attr, 262711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *&fromList, 263711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *&toList) { 264711c52bb20d0c69063b52a99826fb7d2835501f1John McCall spliceAttrOutOfList(attr, fromList); 265711c52bb20d0c69063b52a99826fb7d2835501f1John McCall spliceAttrIntoList(attr, toList); 266711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 267711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 268711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void processTypeAttrs(TypeProcessingState &state, 269711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType &type, bool isDeclSpec, 270711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *attrs); 271711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 272711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic bool handleFunctionTypeAttr(TypeProcessingState &state, 273711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, 274711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType &type); 275711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 276711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic bool handleObjCGCTypeAttr(TypeProcessingState &state, 277711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, QualType &type); 278711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 279b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidisstatic bool handleObjCOwnershipTypeAttr(TypeProcessingState &state, 280f85e193739c953358c865005855253af4f68a497John McCall AttributeList &attr, QualType &type); 281f85e193739c953358c865005855253af4f68a497John McCall 282711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic bool handleObjCPointerTypeAttr(TypeProcessingState &state, 283711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, QualType &type) { 284f85e193739c953358c865005855253af4f68a497John McCall if (attr.getKind() == AttributeList::AT_objc_gc) 285f85e193739c953358c865005855253af4f68a497John McCall return handleObjCGCTypeAttr(state, attr, type); 286b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis assert(attr.getKind() == AttributeList::AT_objc_ownership); 287b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis return handleObjCOwnershipTypeAttr(state, attr, type); 288711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 289711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 290711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// Given that an objc_gc attribute was written somewhere on a 291711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// declaration *other* than on the declarator itself (for which, use 292711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// distributeObjCPointerTypeAttrFromDeclarator), and given that it 293711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// didn't apply in whatever position it was written in, try to move 294711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// it to a more appropriate position. 295711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void distributeObjCPointerTypeAttr(TypeProcessingState &state, 296711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, 297711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType type) { 298711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Declarator &declarator = state.getDeclarator(); 299711c52bb20d0c69063b52a99826fb7d2835501f1John McCall for (unsigned i = state.getCurrentChunkIndex(); i != 0; --i) { 300711c52bb20d0c69063b52a99826fb7d2835501f1John McCall DeclaratorChunk &chunk = declarator.getTypeObject(i-1); 301711c52bb20d0c69063b52a99826fb7d2835501f1John McCall switch (chunk.Kind) { 302711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Pointer: 303711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::BlockPointer: 304711c52bb20d0c69063b52a99826fb7d2835501f1John McCall moveAttrFromListToList(attr, state.getCurrentAttrListRef(), 305711c52bb20d0c69063b52a99826fb7d2835501f1John McCall chunk.getAttrListRef()); 306711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return; 307711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 308711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Paren: 309711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Array: 310711c52bb20d0c69063b52a99826fb7d2835501f1John McCall continue; 311711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 312711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Don't walk through these. 313711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Reference: 314711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Function: 315711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::MemberPointer: 316711c52bb20d0c69063b52a99826fb7d2835501f1John McCall goto error; 317711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 318711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 319711c52bb20d0c69063b52a99826fb7d2835501f1John McCall error: 3202792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall 3212792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall diagnoseBadTypeAttribute(state.getSema(), attr, type); 322711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 323711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 324711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// Distribute an objc_gc type attribute that was written on the 325711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// declarator. 326711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void 327711c52bb20d0c69063b52a99826fb7d2835501f1John McCalldistributeObjCPointerTypeAttrFromDeclarator(TypeProcessingState &state, 328711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, 329711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType &declSpecType) { 330711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Declarator &declarator = state.getDeclarator(); 331711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 332711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // objc_gc goes on the innermost pointer to something that's not a 333711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // pointer. 334711c52bb20d0c69063b52a99826fb7d2835501f1John McCall unsigned innermost = -1U; 335711c52bb20d0c69063b52a99826fb7d2835501f1John McCall bool considerDeclSpec = true; 336711c52bb20d0c69063b52a99826fb7d2835501f1John McCall for (unsigned i = 0, e = declarator.getNumTypeObjects(); i != e; ++i) { 337711c52bb20d0c69063b52a99826fb7d2835501f1John McCall DeclaratorChunk &chunk = declarator.getTypeObject(i); 338711c52bb20d0c69063b52a99826fb7d2835501f1John McCall switch (chunk.Kind) { 339711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Pointer: 340711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::BlockPointer: 341711c52bb20d0c69063b52a99826fb7d2835501f1John McCall innermost = i; 342ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall continue; 343711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 344711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Reference: 345711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::MemberPointer: 346711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Paren: 347711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Array: 348711c52bb20d0c69063b52a99826fb7d2835501f1John McCall continue; 349711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 350711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Function: 351711c52bb20d0c69063b52a99826fb7d2835501f1John McCall considerDeclSpec = false; 352711c52bb20d0c69063b52a99826fb7d2835501f1John McCall goto done; 353711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 354711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 355711c52bb20d0c69063b52a99826fb7d2835501f1John McCall done: 356711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 357711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // That might actually be the decl spec if we weren't blocked by 358711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // anything in the declarator. 359711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (considerDeclSpec) { 3607ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall if (handleObjCPointerTypeAttr(state, attr, declSpecType)) { 3617ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall // Splice the attribute into the decl spec. Prevents the 3627ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall // attribute from being applied multiple times and gives 3637ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall // the source-location-filler something to work with. 3647ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall state.saveDeclSpecAttrs(); 3657ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall moveAttrFromListToList(attr, declarator.getAttrListRef(), 3667ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall declarator.getMutableDeclSpec().getAttributes().getListRef()); 367711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return; 3687ea21937de6f849a7f44f10549c3d69c5a8cb3f3John McCall } 369711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 370711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 371711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Otherwise, if we found an appropriate chunk, splice the attribute 372711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // into it. 373711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (innermost != -1U) { 374711c52bb20d0c69063b52a99826fb7d2835501f1John McCall moveAttrFromListToList(attr, declarator.getAttrListRef(), 375711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.getTypeObject(innermost).getAttrListRef()); 376711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return; 377711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 378711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 379711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Otherwise, diagnose when we're done building the type. 380711c52bb20d0c69063b52a99826fb7d2835501f1John McCall spliceAttrOutOfList(attr, declarator.getAttrListRef()); 381711c52bb20d0c69063b52a99826fb7d2835501f1John McCall state.addIgnoredTypeAttr(attr); 382711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 383711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 384711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// A function type attribute was written somewhere in a declaration 385711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// *other* than on the declarator itself or in the decl spec. Given 386711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// that it didn't apply in whatever position it was written in, try 387711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// to move it to a more appropriate position. 388711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void distributeFunctionTypeAttr(TypeProcessingState &state, 389711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, 390711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType type) { 391711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Declarator &declarator = state.getDeclarator(); 392711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 393711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Try to push the attribute from the return type of a function to 394711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // the function itself. 395711c52bb20d0c69063b52a99826fb7d2835501f1John McCall for (unsigned i = state.getCurrentChunkIndex(); i != 0; --i) { 396711c52bb20d0c69063b52a99826fb7d2835501f1John McCall DeclaratorChunk &chunk = declarator.getTypeObject(i-1); 397711c52bb20d0c69063b52a99826fb7d2835501f1John McCall switch (chunk.Kind) { 398711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Function: 399711c52bb20d0c69063b52a99826fb7d2835501f1John McCall moveAttrFromListToList(attr, state.getCurrentAttrListRef(), 400711c52bb20d0c69063b52a99826fb7d2835501f1John McCall chunk.getAttrListRef()); 401711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return; 402711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 403711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Paren: 404711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Pointer: 405711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::BlockPointer: 406711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Array: 407711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::Reference: 408711c52bb20d0c69063b52a99826fb7d2835501f1John McCall case DeclaratorChunk::MemberPointer: 409711c52bb20d0c69063b52a99826fb7d2835501f1John McCall continue; 410711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 411711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 412711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 4132792fa5115c5de7cbe11d99d23663c569bfb4caeJohn McCall diagnoseBadTypeAttribute(state.getSema(), attr, type); 414711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 415711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 416711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// Try to distribute a function type attribute to the innermost 417711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// function chunk or type. Returns true if the attribute was 418711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// distributed, false if no location was found. 419711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic bool 420711c52bb20d0c69063b52a99826fb7d2835501f1John McCalldistributeFunctionTypeAttrToInnermost(TypeProcessingState &state, 421711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, 422711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *&attrList, 423711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType &declSpecType) { 424711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Declarator &declarator = state.getDeclarator(); 425711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 426711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Put it on the innermost function chunk, if there is one. 427711c52bb20d0c69063b52a99826fb7d2835501f1John McCall for (unsigned i = 0, e = declarator.getNumTypeObjects(); i != e; ++i) { 428711c52bb20d0c69063b52a99826fb7d2835501f1John McCall DeclaratorChunk &chunk = declarator.getTypeObject(i); 429711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (chunk.Kind != DeclaratorChunk::Function) continue; 430711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 431711c52bb20d0c69063b52a99826fb7d2835501f1John McCall moveAttrFromListToList(attr, attrList, chunk.getAttrListRef()); 432711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 433711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 434711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 435f85e193739c953358c865005855253af4f68a497John McCall if (handleFunctionTypeAttr(state, attr, declSpecType)) { 436f85e193739c953358c865005855253af4f68a497John McCall spliceAttrOutOfList(attr, attrList); 437f85e193739c953358c865005855253af4f68a497John McCall return true; 438f85e193739c953358c865005855253af4f68a497John McCall } 439f85e193739c953358c865005855253af4f68a497John McCall 440f85e193739c953358c865005855253af4f68a497John McCall return false; 441711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 442711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 443711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// A function type attribute was written in the decl spec. Try to 444711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// apply it somewhere. 445711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void 446711c52bb20d0c69063b52a99826fb7d2835501f1John McCalldistributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state, 447711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, 448711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType &declSpecType) { 449711c52bb20d0c69063b52a99826fb7d2835501f1John McCall state.saveDeclSpecAttrs(); 450711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 451711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Try to distribute to the innermost. 452711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (distributeFunctionTypeAttrToInnermost(state, attr, 453711c52bb20d0c69063b52a99826fb7d2835501f1John McCall state.getCurrentAttrListRef(), 454711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declSpecType)) 455711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return; 456711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 457711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // If that failed, diagnose the bad attribute when the declarator is 458711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // fully built. 459711c52bb20d0c69063b52a99826fb7d2835501f1John McCall state.addIgnoredTypeAttr(attr); 460711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 461711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 462711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// A function type attribute was written on the declarator. Try to 463711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// apply it somewhere. 464711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void 465711c52bb20d0c69063b52a99826fb7d2835501f1John McCalldistributeFunctionTypeAttrFromDeclarator(TypeProcessingState &state, 466711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, 467711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType &declSpecType) { 468711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Declarator &declarator = state.getDeclarator(); 469711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 470711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Try to distribute to the innermost. 471711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (distributeFunctionTypeAttrToInnermost(state, attr, 472711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.getAttrListRef(), 473711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declSpecType)) 474711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return; 475711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 476711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // If that failed, diagnose the bad attribute when the declarator is 477711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // fully built. 478711c52bb20d0c69063b52a99826fb7d2835501f1John McCall spliceAttrOutOfList(attr, declarator.getAttrListRef()); 479711c52bb20d0c69063b52a99826fb7d2835501f1John McCall state.addIgnoredTypeAttr(attr); 480711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 481711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 482711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// \brief Given that there are attributes written on the declarator 483711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// itself, try to distribute any type attributes to the appropriate 484711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// declarator chunk. 485711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// 486711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// These are attributes like the following: 487711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// int f ATTR; 488711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// int (f ATTR)(); 489711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// but not necessarily this: 490711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// int f() ATTR; 491711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void distributeTypeAttrsFromDeclarator(TypeProcessingState &state, 492711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType &declSpecType) { 493711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Collect all the type attributes from the declarator itself. 494711c52bb20d0c69063b52a99826fb7d2835501f1John McCall assert(state.getDeclarator().getAttributes() && "declarator has no attrs!"); 495711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *attr = state.getDeclarator().getAttributes(); 496711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *next; 497711c52bb20d0c69063b52a99826fb7d2835501f1John McCall do { 498711c52bb20d0c69063b52a99826fb7d2835501f1John McCall next = attr->getNext(); 499711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 500711c52bb20d0c69063b52a99826fb7d2835501f1John McCall switch (attr->getKind()) { 501711c52bb20d0c69063b52a99826fb7d2835501f1John McCall OBJC_POINTER_TYPE_ATTRS_CASELIST: 502711c52bb20d0c69063b52a99826fb7d2835501f1John McCall distributeObjCPointerTypeAttrFromDeclarator(state, *attr, declSpecType); 503711c52bb20d0c69063b52a99826fb7d2835501f1John McCall break; 504711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 505f85e193739c953358c865005855253af4f68a497John McCall case AttributeList::AT_ns_returns_retained: 506f85e193739c953358c865005855253af4f68a497John McCall if (!state.getSema().getLangOptions().ObjCAutoRefCount) 507f85e193739c953358c865005855253af4f68a497John McCall break; 508f85e193739c953358c865005855253af4f68a497John McCall // fallthrough 509f85e193739c953358c865005855253af4f68a497John McCall 510711c52bb20d0c69063b52a99826fb7d2835501f1John McCall FUNCTION_TYPE_ATTRS_CASELIST: 511711c52bb20d0c69063b52a99826fb7d2835501f1John McCall distributeFunctionTypeAttrFromDeclarator(state, *attr, declSpecType); 512711c52bb20d0c69063b52a99826fb7d2835501f1John McCall break; 513711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 514711c52bb20d0c69063b52a99826fb7d2835501f1John McCall default: 515711c52bb20d0c69063b52a99826fb7d2835501f1John McCall break; 516711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 517711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } while ((attr = next)); 518711c52bb20d0c69063b52a99826fb7d2835501f1John McCall} 519711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 520711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// Add a synthetic '()' to a block-literal declarator if it is 521711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// required, given the return type. 522711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void maybeSynthesizeBlockSignature(TypeProcessingState &state, 523711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType declSpecType) { 524711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Declarator &declarator = state.getDeclarator(); 525711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 526711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // First, check whether the declarator would produce a function, 527711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // i.e. whether the innermost semantic chunk is a function. 528711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (declarator.isFunctionDeclarator()) { 529711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // If so, make that declarator a prototyped declarator. 530711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.getFunctionTypeInfo().hasPrototype = true; 531711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return; 532711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 533711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 534da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall // If there are any type objects, the type as written won't name a 535da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall // function, regardless of the decl spec type. This is because a 536da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall // block signature declarator is always an abstract-declarator, and 537da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall // abstract-declarators can't just be parentheses chunks. Therefore 538da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall // we need to build a function chunk unless there are no type 539da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall // objects and the decl spec type is a function. 540711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!declarator.getNumTypeObjects() && declSpecType->isFunctionType()) 541711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return; 542711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 543da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall // Note that there *are* cases with invalid declarators where 544da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall // declarators consist solely of parentheses. In general, these 545da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall // occur only in failed efforts to make function declarators, so 546da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall // faking up the function chunk is still the right thing to do. 547711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 548711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Otherwise, we need to fake up a function declarator. 549711c52bb20d0c69063b52a99826fb7d2835501f1John McCall SourceLocation loc = declarator.getSourceRange().getBegin(); 550711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 551711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // ...and *prepend* it to the declarator. 552711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.AddInnermostTypeInfo(DeclaratorChunk::getFunction( 553711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /*proto*/ true, 554711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /*variadic*/ false, SourceLocation(), 555711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /*args*/ 0, 0, 556711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /*type quals*/ 0, 55783f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /*ref-qualifier*/true, SourceLocation(), 55890ebed0734fac9b464c9bdff53fbf85a86b27f32Douglas Gregor /*mutable qualifier*/SourceLocation(), 5596e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl /*EH*/ EST_None, SourceLocation(), 0, 0, 0, 0, 560711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /*parens*/ loc, loc, 561711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator)); 562711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 563711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // For consistency, make sure the state still has us as processing 564711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // the decl spec. 565711c52bb20d0c69063b52a99826fb7d2835501f1John McCall assert(state.getCurrentChunkIndex() == declarator.getNumTypeObjects() - 1); 566711c52bb20d0c69063b52a99826fb7d2835501f1John McCall state.setCurrentChunkIndex(declarator.getNumTypeObjects()); 56704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall} 56804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 569930d8b5ecc074cca01ecd9a522a55f55f3b72396Douglas Gregor/// \brief Convert the specified declspec to the appropriate type 570930d8b5ecc074cca01ecd9a522a55f55f3b72396Douglas Gregor/// object. 5715db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner/// \param D the declarator containing the declaration specifier. 5725153ee66d6d4fb37b02f85df38e48dc8b46660dfChris Lattner/// \returns The type described by the declaration specifiers. This function 5735153ee66d6d4fb37b02f85df38e48dc8b46660dfChris Lattner/// never returns null. 5748cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidisstatic QualType ConvertDeclSpecToType(TypeProcessingState &state) { 5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // FIXME: Should move the logic from DeclSpec::Finish to here for validity 5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // checking. 577711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 5788cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis Sema &S = state.getSema(); 579711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Declarator &declarator = state.getDeclarator(); 580711c52bb20d0c69063b52a99826fb7d2835501f1John McCall const DeclSpec &DS = declarator.getDeclSpec(); 581711c52bb20d0c69063b52a99826fb7d2835501f1John McCall SourceLocation DeclLoc = declarator.getIdentifierLoc(); 5825db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner if (DeclLoc.isInvalid()) 5835db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner DeclLoc = DS.getSourceRange().getBegin(); 5841564e3906cad604a42bd131e584751a75589a9c4Chris Lattner 585711c52bb20d0c69063b52a99826fb7d2835501f1John McCall ASTContext &Context = S.Context; 5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5875db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner QualType Result; 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (DS.getTypeSpecType()) { 58996b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner case DeclSpec::TST_void: 59096b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner Result = Context.VoidTy; 59196b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner break; 5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DeclSpec::TST_char: 5935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified) 594fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner Result = Context.CharTy; 5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed) 596fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner Result = Context.SignedCharTy; 5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else { 5985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned && 5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Unknown TSS value"); 600fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner Result = Context.UnsignedCharTy; 6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 602958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner break; 60364c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis case DeclSpec::TST_wchar: 60464c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified) 60564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis Result = Context.WCharTy; 60664c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed) { 607711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec) 608f3a41af4d5c98a72a1d6720bbbfd658e57ef2541Chris Lattner << DS.getSpecifierName(DS.getTypeSpecType()); 60964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis Result = Context.getSignedWCharType(); 61064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis } else { 61164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned && 61264c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis "Unknown TSS value"); 613711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec) 614f3a41af4d5c98a72a1d6720bbbfd658e57ef2541Chris Lattner << DS.getSpecifierName(DS.getTypeSpecType()); 61564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis Result = Context.getUnsignedWCharType(); 61664c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis } 61764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis break; 618f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case DeclSpec::TST_char16: 619f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith assert(DS.getTypeSpecSign() == DeclSpec::TSS_unspecified && 620f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith "Unknown TSS value"); 621f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Result = Context.Char16Ty; 622f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 623f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case DeclSpec::TST_char32: 624f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith assert(DS.getTypeSpecSign() == DeclSpec::TSS_unspecified && 625f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith "Unknown TSS value"); 626f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Result = Context.Char32Ty; 627f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 628d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner case DeclSpec::TST_unspecified: 62962f5f7ffad57e0c2af2b308af3735351505937cbChris Lattner // "<proto1,proto2>" is an objc qualified ID with a missing id. 630097e916b617bb4a069a03764024c310ed42a6424Chris Lattner if (DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers()) { 631c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = Context.getObjCObjectType(Context.ObjCBuiltinIdTy, 632c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall (ObjCProtocolDecl**)PQ, 633c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall DS.getNumProtocolQualifiers()); 634c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = Context.getObjCObjectPointerType(Result); 63562f5f7ffad57e0c2af2b308af3735351505937cbChris Lattner break; 63662f5f7ffad57e0c2af2b308af3735351505937cbChris Lattner } 6375db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner 6385db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner // If this is a missing declspec in a block literal return context, then it 6395db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner // is inferred from the return statements inside the block. 640711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (isOmittedBlockReturnType(declarator)) { 6415db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner Result = Context.DependentTy; 6425db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner break; 6435db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner } 6441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 645d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // Unspecified typespec defaults to int in C90. However, the C90 grammar 646d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // [C90 6.5] only allows a decl-spec if there was *some* type-specifier, 647d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // type-qualifier, or storage-class-specifier. If not, emit an extwarn. 648d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // Note that the one exception to this is function definitions, which are 649d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // allowed to be completely missing a declspec. This is handled in the 650d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // parser already though by it pretending to have seen an 'int' in this 651d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // case. 652711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (S.getLangOptions().ImplicitInt) { 65335d276f443462249b436951c1c663820569e1768Chris Lattner // In C89 mode, we only warn if there is a completely missing declspec 65435d276f443462249b436951c1c663820569e1768Chris Lattner // when one is not allowed. 6553f84ad22acc25353a47ee88f55ab05dffef5d9a9Chris Lattner if (DS.isEmpty()) { 656711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DeclLoc, diag::ext_missing_declspec) 6573f84ad22acc25353a47ee88f55ab05dffef5d9a9Chris Lattner << DS.getSourceRange() 658849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateInsertion(DS.getSourceRange().getBegin(), "int"); 6593f84ad22acc25353a47ee88f55ab05dffef5d9a9Chris Lattner } 6604310f4ee260e6c7ceeaf299e240f4d789ecc730dDouglas Gregor } else if (!DS.hasTypeSpecifier()) { 661d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // C99 and C++ require a type specifier. For example, C99 6.7.2p2 says: 662d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // "At least one type specifier shall be given in the declaration 663d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // specifiers in each declaration, and in the specifier-qualifier list in 664d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner // each struct declaration and type name." 6654310f4ee260e6c7ceeaf299e240f4d789ecc730dDouglas Gregor // FIXME: Does Microsoft really have the implicit int extension in C++? 666711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (S.getLangOptions().CPlusPlus && 667711c52bb20d0c69063b52a99826fb7d2835501f1John McCall !S.getLangOptions().Microsoft) { 668711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DeclLoc, diag::err_missing_type_specifier) 6693f84ad22acc25353a47ee88f55ab05dffef5d9a9Chris Lattner << DS.getSourceRange(); 6701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 671b78d833b12f7c4baab138f305f72efd49455a3f9Chris Lattner // When this occurs in C++ code, often something is very broken with the 672b78d833b12f7c4baab138f305f72efd49455a3f9Chris Lattner // value being declared, poison it as invalid so we don't get chains of 673b78d833b12f7c4baab138f305f72efd49455a3f9Chris Lattner // errors. 674711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.setInvalidType(true); 675b78d833b12f7c4baab138f305f72efd49455a3f9Chris Lattner } else { 676711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DeclLoc, diag::ext_missing_type_specifier) 6773f84ad22acc25353a47ee88f55ab05dffef5d9a9Chris Lattner << DS.getSourceRange(); 678b78d833b12f7c4baab138f305f72efd49455a3f9Chris Lattner } 679d658b562e80d6ef7a1118e34ff12802c6e2fccedChris Lattner } 6801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FALL THROUGH. 6823cbc38bd3569d37f53bd76fa89d24803f48f5036Chris Lattner case DeclSpec::TST_int: { 6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (DS.getTypeSpecSign() != DeclSpec::TSS_unsigned) { 6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (DS.getTypeSpecWidth()) { 685fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner case DeclSpec::TSW_unspecified: Result = Context.IntTy; break; 686fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner case DeclSpec::TSW_short: Result = Context.ShortTy; break; 687fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner case DeclSpec::TSW_long: Result = Context.LongTy; break; 688311157fa6be96e2769bf317390dc9fb85087d5faChris Lattner case DeclSpec::TSW_longlong: 689311157fa6be96e2769bf317390dc9fb85087d5faChris Lattner Result = Context.LongLongTy; 690311157fa6be96e2769bf317390dc9fb85087d5faChris Lattner 691311157fa6be96e2769bf317390dc9fb85087d5faChris Lattner // long long is a C99 feature. 692711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!S.getLangOptions().C99 && 693711c52bb20d0c69063b52a99826fb7d2835501f1John McCall !S.getLangOptions().CPlusPlus0x) 694711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DS.getTypeSpecWidthLoc(), diag::ext_longlong); 695311157fa6be96e2769bf317390dc9fb85087d5faChris Lattner break; 6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } else { 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (DS.getTypeSpecWidth()) { 699fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner case DeclSpec::TSW_unspecified: Result = Context.UnsignedIntTy; break; 700fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner case DeclSpec::TSW_short: Result = Context.UnsignedShortTy; break; 701fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner case DeclSpec::TSW_long: Result = Context.UnsignedLongTy; break; 702311157fa6be96e2769bf317390dc9fb85087d5faChris Lattner case DeclSpec::TSW_longlong: 703311157fa6be96e2769bf317390dc9fb85087d5faChris Lattner Result = Context.UnsignedLongLongTy; 704311157fa6be96e2769bf317390dc9fb85087d5faChris Lattner 705311157fa6be96e2769bf317390dc9fb85087d5faChris Lattner // long long is a C99 feature. 706711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!S.getLangOptions().C99 && 707711c52bb20d0c69063b52a99826fb7d2835501f1John McCall !S.getLangOptions().CPlusPlus0x) 708711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DS.getTypeSpecWidthLoc(), diag::ext_longlong); 709311157fa6be96e2769bf317390dc9fb85087d5faChris Lattner break; 7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 712958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner break; 7133cbc38bd3569d37f53bd76fa89d24803f48f5036Chris Lattner } 714fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner case DeclSpec::TST_float: Result = Context.FloatTy; break; 715958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner case DeclSpec::TST_double: 716958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner if (DS.getTypeSpecWidth() == DeclSpec::TSW_long) 717fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner Result = Context.LongDoubleTy; 718958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner else 719fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner Result = Context.DoubleTy; 72039d3e7a26c1969fcb76bceb4ee0a410c60ea5954Peter Collingbourne 72139d3e7a26c1969fcb76bceb4ee0a410c60ea5954Peter Collingbourne if (S.getLangOptions().OpenCL && !S.getOpenCLOptions().cl_khr_fp64) { 72239d3e7a26c1969fcb76bceb4ee0a410c60ea5954Peter Collingbourne S.Diag(DS.getTypeSpecTypeLoc(), diag::err_double_requires_fp64); 72339d3e7a26c1969fcb76bceb4ee0a410c60ea5954Peter Collingbourne declarator.setInvalidType(true); 72439d3e7a26c1969fcb76bceb4ee0a410c60ea5954Peter Collingbourne } 725958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner break; 726fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner case DeclSpec::TST_bool: Result = Context.BoolTy; break; // _Bool or bool 7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DeclSpec::TST_decimal32: // _Decimal32 7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DeclSpec::TST_decimal64: // _Decimal64 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DeclSpec::TST_decimal128: // _Decimal128 730711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DS.getTypeSpecTypeLoc(), diag::err_decimal_unsupported); 7318f12f65fad7bfbbdbd4234efe0d484f68c3924b6Chris Lattner Result = Context.IntTy; 732711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.setInvalidType(true); 7338f12f65fad7bfbbdbd4234efe0d484f68c3924b6Chris Lattner break; 73499dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner case DeclSpec::TST_class: 7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DeclSpec::TST_enum: 7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DeclSpec::TST_union: 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DeclSpec::TST_struct: { 738b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TypeDecl *D = dyn_cast_or_null<TypeDecl>(DS.getRepAsDecl()); 7396e24726524c2b51b31bb4b622aa678a46b024f42John McCall if (!D) { 7406e24726524c2b51b31bb4b622aa678a46b024f42John McCall // This can happen in C++ with ambiguous lookups. 7416e24726524c2b51b31bb4b622aa678a46b024f42John McCall Result = Context.IntTy; 742711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.setInvalidType(true); 7436e24726524c2b51b31bb4b622aa678a46b024f42John McCall break; 7446e24726524c2b51b31bb4b622aa678a46b024f42John McCall } 7456e24726524c2b51b31bb4b622aa678a46b024f42John McCall 746a64ef0ab5cb6ac9cfb7d40661a9152c4aa488386Chris Lattner // If the type is deprecated or unavailable, diagnose it. 7470daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara S.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeNameLoc()); 748a64ef0ab5cb6ac9cfb7d40661a9152c4aa488386Chris Lattner 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && 750a64ef0ab5cb6ac9cfb7d40661a9152c4aa488386Chris Lattner DS.getTypeSpecSign() == 0 && "No qualifiers on tag names!"); 751a64ef0ab5cb6ac9cfb7d40661a9152c4aa488386Chris Lattner 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // TypeQuals handled by caller. 753a64ef0ab5cb6ac9cfb7d40661a9152c4aa488386Chris Lattner Result = Context.getTypeDeclType(D); 7542191b20bfb31fc0e22a158f6b4204cd0b7dbd0fdJohn McCall 7550daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara // In both C and C++, make an ElaboratedType. 7560daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara ElaboratedTypeKeyword Keyword 7570daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara = ElaboratedType::getKeywordForTypeSpec(DS.getTypeSpecType()); 7580daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara Result = S.getElaboratedType(Keyword, DS.getTypeSpecScope(), Result); 7590daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara 7605153ee66d6d4fb37b02f85df38e48dc8b46660dfChris Lattner if (D->isInvalidDecl()) 761711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.setInvalidType(true); 762958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner break; 7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 7641a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor case DeclSpec::TST_typename: { 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && 7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DS.getTypeSpecSign() == 0 && 7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Can't handle qualifiers on typedef names yet!"); 768711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Result = S.GetTypeFromParser(DS.getRepAsType()); 76927940d2fb346325d6001a7661e4ada099cd8e59cJohn McCall if (Result.isNull()) 770711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.setInvalidType(true); 77127940d2fb346325d6001a7661e4ada099cd8e59cJohn McCall else if (DeclSpec::ProtocolQualifierListTy PQ 77227940d2fb346325d6001a7661e4ada099cd8e59cJohn McCall = DS.getProtocolQualifiers()) { 773c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *ObjT = Result->getAs<ObjCObjectType>()) { 774c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Silently drop any existing protocol qualifiers. 775c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // TODO: determine whether that's the right thing to do. 776c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (ObjT->getNumProtocols()) 777c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = ObjT->getBaseType(); 778c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 779c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (DS.getNumProtocolQualifiers()) 780c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = Context.getObjCObjectType(Result, 781c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall (ObjCProtocolDecl**) PQ, 782c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall DS.getNumProtocolQualifiers()); 783c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } else if (Result->isObjCIdType()) { 784ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner // id<protocol-list> 785c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = Context.getObjCObjectType(Context.ObjCBuiltinIdTy, 786c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall (ObjCProtocolDecl**) PQ, 787c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall DS.getNumProtocolQualifiers()); 788c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = Context.getObjCObjectPointerType(Result); 789c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } else if (Result->isObjCClassType()) { 7904262a07621043c19292f5fd90b1e426d65cd366cSteve Naroff // Class<protocol-list> 791c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = Context.getObjCObjectType(Context.ObjCBuiltinClassTy, 792c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall (ObjCProtocolDecl**) PQ, 793c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall DS.getNumProtocolQualifiers()); 794c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = Context.getObjCObjectPointerType(Result); 7953f84ad22acc25353a47ee88f55ab05dffef5d9a9Chris Lattner } else { 796711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DeclLoc, diag::err_invalid_protocol_qualifiers) 7973f84ad22acc25353a47ee88f55ab05dffef5d9a9Chris Lattner << DS.getSourceRange(); 798711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.setInvalidType(true); 7993f84ad22acc25353a47ee88f55ab05dffef5d9a9Chris Lattner } 800c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 8011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // TypeQuals handled by caller. 803958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner break; 8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 805958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner case DeclSpec::TST_typeofType: 806e8661906d49ef6c9694a9cc845ca62a85dbc016dArgyrios Kyrtzidis // FIXME: Preserve type source info. 807711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Result = S.GetTypeFromParser(DS.getRepAsType()); 808958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner assert(!Result.isNull() && "Didn't get a type for typeof?"); 809730e175910936eae49e65caea8b2ba81c67edff7Fariborz Jahanian if (!Result->isDependentType()) 810730e175910936eae49e65caea8b2ba81c67edff7Fariborz Jahanian if (const TagType *TT = Result->getAs<TagType>()) 811711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.DiagnoseUseOfDecl(TT->getDecl(), DS.getTypeSpecTypeLoc()); 812d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff // TypeQuals handled by caller. 813fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner Result = Context.getTypeOfType(Result); 814958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner break; 815d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff case DeclSpec::TST_typeofExpr: { 816b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *E = DS.getRepAsExpr(); 817d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(E && "Didn't get an expression for typeof?"); 818d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff // TypeQuals handled by caller. 819711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Result = S.BuildTypeofExprType(E, DS.getTypeSpecTypeLoc()); 8204b52e25f3b05ab0f9d2492276a52323a50a84fb7Douglas Gregor if (Result.isNull()) { 8214b52e25f3b05ab0f9d2492276a52323a50a84fb7Douglas Gregor Result = Context.IntTy; 822711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.setInvalidType(true); 8234b52e25f3b05ab0f9d2492276a52323a50a84fb7Douglas Gregor } 824958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner break; 825d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 8266fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson case DeclSpec::TST_decltype: { 827b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *E = DS.getRepAsExpr(); 8286fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson assert(E && "Didn't get an expression for decltype?"); 8296fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // TypeQuals handled by caller. 830711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Result = S.BuildDecltypeType(E, DS.getTypeSpecTypeLoc()); 831af017e682918f7a1a95ff08d9ab7ae3426436ca3Anders Carlsson if (Result.isNull()) { 832af017e682918f7a1a95ff08d9ab7ae3426436ca3Anders Carlsson Result = Context.IntTy; 833711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.setInvalidType(true); 834af017e682918f7a1a95ff08d9ab7ae3426436ca3Anders Carlsson } 8356fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson break; 8366fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson } 837ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt case DeclSpec::TST_underlyingType: 838db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt Result = S.GetTypeFromParser(DS.getRepAsType()); 839db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt assert(!Result.isNull() && "Didn't get a type for __underlying_type?"); 840ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Result = S.BuildUnaryTransformType(Result, 841ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::EnumUnderlyingType, 842ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt DS.getTypeSpecTypeLoc()); 843ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result.isNull()) { 844ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Result = Context.IntTy; 845ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt declarator.setInvalidType(true); 846db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt } 847db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt break; 848db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt 849e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson case DeclSpec::TST_auto: { 850e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // TypeQuals handled by caller. 85134b41d939a1328f484511c6002ba2456db879a29Richard Smith Result = Context.getAutoType(QualType()); 852e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson break; 853e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson } 8541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 855a5fc472b353b88be3b4981da946fb01f5a5cc0c6John McCall case DeclSpec::TST_unknown_anytype: 856a5fc472b353b88be3b4981da946fb01f5a5cc0c6John McCall Result = Context.UnknownAnyTy; 857a5fc472b353b88be3b4981da946fb01f5a5cc0c6John McCall break; 858a5fc472b353b88be3b4981da946fb01f5a5cc0c6John McCall 859809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor case DeclSpec::TST_error: 8605153ee66d6d4fb37b02f85df38e48dc8b46660dfChris Lattner Result = Context.IntTy; 861711c52bb20d0c69063b52a99826fb7d2835501f1John McCall declarator.setInvalidType(true); 8625153ee66d6d4fb37b02f85df38e48dc8b46660dfChris Lattner break; 8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 865958858e04e9f98a42031ba69779e49c21f01ca6cChris Lattner // Handle complex types. 866f244cd7e54753caf6edb76df430dea2f43bb82a8Douglas Gregor if (DS.getTypeSpecComplex() == DeclSpec::TSC_complex) { 867711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (S.getLangOptions().Freestanding) 868711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DS.getTypeSpecComplexLoc(), diag::ext_freestanding_complex); 869fab5b45729db4e24ba43bb94d1bce5f73106be78Chris Lattner Result = Context.getComplexType(Result); 87082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } else if (DS.isTypeAltiVecVector()) { 87182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson unsigned typeSize = static_cast<unsigned>(Context.getTypeSize(Result)); 87282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson assert(typeSize > 0 && "type size for vector must be greater than 0 bits"); 873e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind = VectorType::AltiVecVector; 874788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner if (DS.isTypeAltiVecPixel()) 875e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VecKind = VectorType::AltiVecPixel; 876788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner else if (DS.isTypeAltiVecBool()) 877e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VecKind = VectorType::AltiVecBool; 878e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson Result = Context.getVectorType(Result, 128/typeSize, VecKind); 879f244cd7e54753caf6edb76df430dea2f43bb82a8Douglas Gregor } 8801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 88147423bdaa06a3b9c2a859b57c17fc570094dad1cArgyrios Kyrtzidis // FIXME: Imaginary. 88247423bdaa06a3b9c2a859b57c17fc570094dad1cArgyrios Kyrtzidis if (DS.getTypeSpecComplex() == DeclSpec::TSC_imaginary) 883711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DS.getTypeSpecComplexLoc(), diag::err_imaginary_not_supported); 8841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 885711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Before we process any type attributes, synthesize a block literal 886711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // function declarator if necessary. 887711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (declarator.getContext() == Declarator::BlockLiteralContext) 888711c52bb20d0c69063b52a99826fb7d2835501f1John McCall maybeSynthesizeBlockSignature(state, Result); 889711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 890711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Apply any type attributes from the decl spec. This may cause the 891711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // list of type attributes to be temporarily saved while the type 892711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // attributes are pushed around. 893711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (AttributeList *attrs = DS.getAttributes().getList()) 894711c52bb20d0c69063b52a99826fb7d2835501f1John McCall processTypeAttrs(state, Result, true, attrs); 8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89696b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner // Apply const/volatile/restrict qualifiers to T. 89796b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner if (unsigned TypeQuals = DS.getTypeQualifiers()) { 89896b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner 89996b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner // Enforce C99 6.7.3p2: "Types other than pointer types derived from object 90096b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner // or incomplete types shall not be restrict-qualified." C++ also allows 90196b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner // restrict-qualified references. 9020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (TypeQuals & DeclSpec::TQ_restrict) { 9032b5ff1a1471819192ae805b51b888030ecb52914Fariborz Jahanian if (Result->isAnyPointerType() || Result->isReferenceType()) { 9042b5ff1a1471819192ae805b51b888030ecb52914Fariborz Jahanian QualType EltTy; 9052b5ff1a1471819192ae805b51b888030ecb52914Fariborz Jahanian if (Result->isObjCObjectPointerType()) 9062b5ff1a1471819192ae805b51b888030ecb52914Fariborz Jahanian EltTy = Result; 9072b5ff1a1471819192ae805b51b888030ecb52914Fariborz Jahanian else 9082b5ff1a1471819192ae805b51b888030ecb52914Fariborz Jahanian EltTy = Result->isPointerType() ? 9092b5ff1a1471819192ae805b51b888030ecb52914Fariborz Jahanian Result->getAs<PointerType>()->getPointeeType() : 9102b5ff1a1471819192ae805b51b888030ecb52914Fariborz Jahanian Result->getAs<ReferenceType>()->getPointeeType(); 9111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 912bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor // If we have a pointer or reference, the pointee must have an object 913bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner // incomplete type. 914bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner if (!EltTy->isIncompleteOrObjectType()) { 915711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DS.getRestrictSpecLoc(), 916d3a94e24ddf3fb90de76b17bd176d9ed61e66f2cChris Lattner diag::err_typecheck_invalid_restrict_invalid_pointee) 917d162584991885ab004a02573a73ce06422b921fcChris Lattner << EltTy << DS.getSourceRange(); 9180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall TypeQuals &= ~DeclSpec::TQ_restrict; // Remove the restrict qualifier. 919bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner } 920bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner } else { 921711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(DS.getRestrictSpecLoc(), 922711c52bb20d0c69063b52a99826fb7d2835501f1John McCall diag::err_typecheck_invalid_restrict_not_pointer) 923d162584991885ab004a02573a73ce06422b921fcChris Lattner << Result << DS.getSourceRange(); 9240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall TypeQuals &= ~DeclSpec::TQ_restrict; // Remove the restrict qualifier. 92596b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner } 92696b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner } 9271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92896b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner // Warn about CV qualifiers on functions: C99 6.7.3p8: "If the specification 92996b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner // of a function type includes any type qualifiers, the behavior is 93096b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner // undefined." 93196b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner if (Result->isFunctionType() && TypeQuals) { 93296b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner // Get some location to point at, either the C or V location. 93396b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner SourceLocation Loc; 9340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (TypeQuals & DeclSpec::TQ_const) 93596b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner Loc = DS.getConstSpecLoc(); 9360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall else if (TypeQuals & DeclSpec::TQ_volatile) 93796b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner Loc = DS.getVolatileSpecLoc(); 9380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall else { 9390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert((TypeQuals & DeclSpec::TQ_restrict) && 9400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall "Has CVR quals but not C, V, or R?"); 9410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Loc = DS.getRestrictSpecLoc(); 94296b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner } 943711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(Loc, diag::warn_typecheck_function_qualifiers) 944d162584991885ab004a02573a73ce06422b921fcChris Lattner << Result << DS.getSourceRange(); 94596b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner } 9461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 947f1f9b4e5c7fd087e78f2e387c01098d49d41e784Douglas Gregor // C++ [dcl.ref]p1: 948f1f9b4e5c7fd087e78f2e387c01098d49d41e784Douglas Gregor // Cv-qualified references are ill-formed except when the 949f1f9b4e5c7fd087e78f2e387c01098d49d41e784Douglas Gregor // cv-qualifiers are introduced through the use of a typedef 950f1f9b4e5c7fd087e78f2e387c01098d49d41e784Douglas Gregor // (7.1.3) or of a template type argument (14.3), in which 951f1f9b4e5c7fd087e78f2e387c01098d49d41e784Douglas Gregor // case the cv-qualifiers are ignored. 9521a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor // FIXME: Shouldn't we be checking SCS_typedef here? 9531a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor if (DS.getTypeSpecType() == DeclSpec::TST_typename && 954f1f9b4e5c7fd087e78f2e387c01098d49d41e784Douglas Gregor TypeQuals && Result->isReferenceType()) { 9550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall TypeQuals &= ~DeclSpec::TQ_const; 9560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall TypeQuals &= ~DeclSpec::TQ_volatile; 9571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals = Qualifiers::fromCVRMask(TypeQuals); 9600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Result = Context.getQualifiedType(Result, Quals); 96196b77fc05ed4a052a9e614f72b0e83572408ce48Chris Lattner } 9620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 963f1d705c3e2276f7f5b97b8b3394b9b3068fdf25bChris Lattner return Result; 964f1d705c3e2276f7f5b97b8b3394b9b3068fdf25bChris Lattner} 965f1d705c3e2276f7f5b97b8b3394b9b3068fdf25bChris Lattner 966cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregorstatic std::string getPrintableNameForEntity(DeclarationName Entity) { 967cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor if (Entity) 968cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor return Entity.getAsString(); 9691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 970cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor return "type name"; 971cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor} 972cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor 9732865474261a608c7873b87ba4af110d17907896dJohn McCallQualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc, 9742865474261a608c7873b87ba4af110d17907896dJohn McCall Qualifiers Qs) { 9752865474261a608c7873b87ba4af110d17907896dJohn McCall // Enforce C99 6.7.3p2: "Types other than pointer types derived from 9762865474261a608c7873b87ba4af110d17907896dJohn McCall // object or incomplete types shall not be restrict-qualified." 9772865474261a608c7873b87ba4af110d17907896dJohn McCall if (Qs.hasRestrict()) { 9782865474261a608c7873b87ba4af110d17907896dJohn McCall unsigned DiagID = 0; 9792865474261a608c7873b87ba4af110d17907896dJohn McCall QualType ProblemTy; 9802865474261a608c7873b87ba4af110d17907896dJohn McCall 9812865474261a608c7873b87ba4af110d17907896dJohn McCall const Type *Ty = T->getCanonicalTypeInternal().getTypePtr(); 9822865474261a608c7873b87ba4af110d17907896dJohn McCall if (const ReferenceType *RTy = dyn_cast<ReferenceType>(Ty)) { 9832865474261a608c7873b87ba4af110d17907896dJohn McCall if (!RTy->getPointeeType()->isIncompleteOrObjectType()) { 9842865474261a608c7873b87ba4af110d17907896dJohn McCall DiagID = diag::err_typecheck_invalid_restrict_invalid_pointee; 9852865474261a608c7873b87ba4af110d17907896dJohn McCall ProblemTy = T->getAs<ReferenceType>()->getPointeeType(); 9862865474261a608c7873b87ba4af110d17907896dJohn McCall } 9872865474261a608c7873b87ba4af110d17907896dJohn McCall } else if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) { 9882865474261a608c7873b87ba4af110d17907896dJohn McCall if (!PTy->getPointeeType()->isIncompleteOrObjectType()) { 9892865474261a608c7873b87ba4af110d17907896dJohn McCall DiagID = diag::err_typecheck_invalid_restrict_invalid_pointee; 9902865474261a608c7873b87ba4af110d17907896dJohn McCall ProblemTy = T->getAs<PointerType>()->getPointeeType(); 9912865474261a608c7873b87ba4af110d17907896dJohn McCall } 9922865474261a608c7873b87ba4af110d17907896dJohn McCall } else if (const MemberPointerType *PTy = dyn_cast<MemberPointerType>(Ty)) { 9932865474261a608c7873b87ba4af110d17907896dJohn McCall if (!PTy->getPointeeType()->isIncompleteOrObjectType()) { 9942865474261a608c7873b87ba4af110d17907896dJohn McCall DiagID = diag::err_typecheck_invalid_restrict_invalid_pointee; 9952865474261a608c7873b87ba4af110d17907896dJohn McCall ProblemTy = T->getAs<PointerType>()->getPointeeType(); 9962865474261a608c7873b87ba4af110d17907896dJohn McCall } 9972865474261a608c7873b87ba4af110d17907896dJohn McCall } else if (!Ty->isDependentType()) { 9982865474261a608c7873b87ba4af110d17907896dJohn McCall // FIXME: this deserves a proper diagnostic 9992865474261a608c7873b87ba4af110d17907896dJohn McCall DiagID = diag::err_typecheck_invalid_restrict_invalid_pointee; 10002865474261a608c7873b87ba4af110d17907896dJohn McCall ProblemTy = T; 10012865474261a608c7873b87ba4af110d17907896dJohn McCall } 10022865474261a608c7873b87ba4af110d17907896dJohn McCall 10032865474261a608c7873b87ba4af110d17907896dJohn McCall if (DiagID) { 10042865474261a608c7873b87ba4af110d17907896dJohn McCall Diag(Loc, DiagID) << ProblemTy; 10052865474261a608c7873b87ba4af110d17907896dJohn McCall Qs.removeRestrict(); 10062865474261a608c7873b87ba4af110d17907896dJohn McCall } 10072865474261a608c7873b87ba4af110d17907896dJohn McCall } 10082865474261a608c7873b87ba4af110d17907896dJohn McCall 10092865474261a608c7873b87ba4af110d17907896dJohn McCall return Context.getQualifiedType(T, Qs); 10102865474261a608c7873b87ba4af110d17907896dJohn McCall} 10112865474261a608c7873b87ba4af110d17907896dJohn McCall 1012075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// \brief Build a paren type including \p T. 1013075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType Sema::BuildParenType(QualType T) { 1014075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return Context.getParenType(T); 1015075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 1016075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1017f85e193739c953358c865005855253af4f68a497John McCall/// Given that we're building a pointer or reference to the given 1018f85e193739c953358c865005855253af4f68a497John McCallstatic QualType inferARCLifetimeForPointee(Sema &S, QualType type, 1019f85e193739c953358c865005855253af4f68a497John McCall SourceLocation loc, 1020f85e193739c953358c865005855253af4f68a497John McCall bool isReference) { 1021f85e193739c953358c865005855253af4f68a497John McCall // Bail out if retention is unrequired or already specified. 1022f85e193739c953358c865005855253af4f68a497John McCall if (!type->isObjCLifetimeType() || 1023f85e193739c953358c865005855253af4f68a497John McCall type.getObjCLifetime() != Qualifiers::OCL_None) 1024f85e193739c953358c865005855253af4f68a497John McCall return type; 1025f85e193739c953358c865005855253af4f68a497John McCall 1026f85e193739c953358c865005855253af4f68a497John McCall Qualifiers::ObjCLifetime implicitLifetime = Qualifiers::OCL_None; 1027f85e193739c953358c865005855253af4f68a497John McCall 1028f85e193739c953358c865005855253af4f68a497John McCall // If the object type is const-qualified, we can safely use 1029f85e193739c953358c865005855253af4f68a497John McCall // __unsafe_unretained. This is safe (because there are no read 1030f85e193739c953358c865005855253af4f68a497John McCall // barriers), and it'll be safe to coerce anything but __weak* to 1031f85e193739c953358c865005855253af4f68a497John McCall // the resulting type. 1032f85e193739c953358c865005855253af4f68a497John McCall if (type.isConstQualified()) { 1033f85e193739c953358c865005855253af4f68a497John McCall implicitLifetime = Qualifiers::OCL_ExplicitNone; 1034f85e193739c953358c865005855253af4f68a497John McCall 1035f85e193739c953358c865005855253af4f68a497John McCall // Otherwise, check whether the static type does not require 1036f85e193739c953358c865005855253af4f68a497John McCall // retaining. This currently only triggers for Class (possibly 1037f85e193739c953358c865005855253af4f68a497John McCall // protocol-qualifed, and arrays thereof). 1038f85e193739c953358c865005855253af4f68a497John McCall } else if (type->isObjCARCImplicitlyUnretainedType()) { 1039f85e193739c953358c865005855253af4f68a497John McCall implicitLifetime = Qualifiers::OCL_ExplicitNone; 1040f85e193739c953358c865005855253af4f68a497John McCall 1041f85e193739c953358c865005855253af4f68a497John McCall // If that failed, give an error and recover using __autoreleasing. 1042f85e193739c953358c865005855253af4f68a497John McCall } else { 1043f85e193739c953358c865005855253af4f68a497John McCall // These types can show up in private ivars in system headers, so 1044f85e193739c953358c865005855253af4f68a497John McCall // we need this to not be an error in those cases. Instead we 1045f85e193739c953358c865005855253af4f68a497John McCall // want to delay. 1046f85e193739c953358c865005855253af4f68a497John McCall if (S.DelayedDiagnostics.shouldDelayDiagnostics()) { 1047f85e193739c953358c865005855253af4f68a497John McCall S.DelayedDiagnostics.add( 1048f85e193739c953358c865005855253af4f68a497John McCall sema::DelayedDiagnostic::makeForbiddenType(loc, 1049b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis diag::err_arc_indirect_no_ownership, type, isReference)); 1050f85e193739c953358c865005855253af4f68a497John McCall } else { 1051b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis S.Diag(loc, diag::err_arc_indirect_no_ownership) << type << isReference; 1052f85e193739c953358c865005855253af4f68a497John McCall } 1053f85e193739c953358c865005855253af4f68a497John McCall implicitLifetime = Qualifiers::OCL_Autoreleasing; 1054f85e193739c953358c865005855253af4f68a497John McCall } 1055f85e193739c953358c865005855253af4f68a497John McCall assert(implicitLifetime && "didn't infer any lifetime!"); 1056f85e193739c953358c865005855253af4f68a497John McCall 1057f85e193739c953358c865005855253af4f68a497John McCall Qualifiers qs; 1058f85e193739c953358c865005855253af4f68a497John McCall qs.addObjCLifetime(implicitLifetime); 1059f85e193739c953358c865005855253af4f68a497John McCall return S.Context.getQualifiedType(type, qs); 1060f85e193739c953358c865005855253af4f68a497John McCall} 1061f85e193739c953358c865005855253af4f68a497John McCall 1062cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \brief Build a pointer type. 1063cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1064cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \param T The type to which we'll be building a pointer. 1065cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1066cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \param Loc The location of the entity whose type involves this 1067cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// pointer type or, if there is no such entity, the location of the 1068cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// type that will have pointer type. 1069cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1070cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \param Entity The name of the entity that involves the pointer 1071cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// type, if known. 1072cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1073cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \returns A suitable pointer type, if there are no 1074cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// errors. Otherwise, returns a NULL type. 10752865474261a608c7873b87ba4af110d17907896dJohn McCallQualType Sema::BuildPointerType(QualType T, 1076cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor SourceLocation Loc, DeclarationName Entity) { 1077cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor if (T->isReferenceType()) { 1078cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // C++ 8.3.2p4: There shall be no ... pointers to references ... 1079cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor Diag(Loc, diag::err_illegal_decl_pointer_to_reference) 1080ac406052f7b980f8caa6b07b4a8d0867d53852c4John McCall << getPrintableNameForEntity(Entity) << T; 1081cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor return QualType(); 1082cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor } 1083cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor 1084c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(!T->isObjCObjectType() && "Should build ObjCObjectPointerType"); 108592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 1086f85e193739c953358c865005855253af4f68a497John McCall // In ARC, it is forbidden to build pointers to unqualified pointers. 1087f85e193739c953358c865005855253af4f68a497John McCall if (getLangOptions().ObjCAutoRefCount) 1088f85e193739c953358c865005855253af4f68a497John McCall T = inferARCLifetimeForPointee(*this, T, Loc, /*reference*/ false); 1089f85e193739c953358c865005855253af4f68a497John McCall 1090cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // Build the pointer type. 10912865474261a608c7873b87ba4af110d17907896dJohn McCall return Context.getPointerType(T); 1092cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor} 1093cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor 1094cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \brief Build a reference type. 1095cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1096cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \param T The type to which we'll be building a reference. 1097cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1098cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \param Loc The location of the entity whose type involves this 1099cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// reference type or, if there is no such entity, the location of the 1100cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// type that will have reference type. 1101cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1102cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \param Entity The name of the entity that involves the reference 1103cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// type, if known. 1104cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1105cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \returns A suitable reference type, if there are no 1106cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// errors. Otherwise, returns a NULL type. 110754e14c4db764c0636160d26c5bbf491637c83a76John McCallQualType Sema::BuildReferenceType(QualType T, bool SpelledAsLValue, 11082865474261a608c7873b87ba4af110d17907896dJohn McCall SourceLocation Loc, 110954e14c4db764c0636160d26c5bbf491637c83a76John McCall DeclarationName Entity) { 11109625e44c0252485277a340746ed8ac950686156fDouglas Gregor assert(Context.getCanonicalType(T) != Context.OverloadTy && 11119625e44c0252485277a340746ed8ac950686156fDouglas Gregor "Unresolved overloaded function type"); 11129625e44c0252485277a340746ed8ac950686156fDouglas Gregor 111369d831645f429d3b806d2ae220aee45ca44f8c6cDouglas Gregor // C++0x [dcl.ref]p6: 111469d831645f429d3b806d2ae220aee45ca44f8c6cDouglas Gregor // If a typedef (7.1.3), a type template-parameter (14.3.1), or a 111569d831645f429d3b806d2ae220aee45ca44f8c6cDouglas Gregor // decltype-specifier (7.1.6.2) denotes a type TR that is a reference to a 111669d831645f429d3b806d2ae220aee45ca44f8c6cDouglas Gregor // type T, an attempt to create the type "lvalue reference to cv TR" creates 111769d831645f429d3b806d2ae220aee45ca44f8c6cDouglas Gregor // the type "lvalue reference to T", while an attempt to create the type 111869d831645f429d3b806d2ae220aee45ca44f8c6cDouglas Gregor // "rvalue reference to cv TR" creates the type TR. 111954e14c4db764c0636160d26c5bbf491637c83a76John McCall bool LValueRef = SpelledAsLValue || T->getAs<LValueReferenceType>(); 112054e14c4db764c0636160d26c5bbf491637c83a76John McCall 112154e14c4db764c0636160d26c5bbf491637c83a76John McCall // C++ [dcl.ref]p4: There shall be no references to references. 112254e14c4db764c0636160d26c5bbf491637c83a76John McCall // 112354e14c4db764c0636160d26c5bbf491637c83a76John McCall // According to C++ DR 106, references to references are only 112454e14c4db764c0636160d26c5bbf491637c83a76John McCall // diagnosed when they are written directly (e.g., "int & &"), 112554e14c4db764c0636160d26c5bbf491637c83a76John McCall // but not when they happen via a typedef: 112654e14c4db764c0636160d26c5bbf491637c83a76John McCall // 112754e14c4db764c0636160d26c5bbf491637c83a76John McCall // typedef int& intref; 112854e14c4db764c0636160d26c5bbf491637c83a76John McCall // typedef intref& intref2; 112954e14c4db764c0636160d26c5bbf491637c83a76John McCall // 113054e14c4db764c0636160d26c5bbf491637c83a76John McCall // Parser::ParseDeclaratorInternal diagnoses the case where 113154e14c4db764c0636160d26c5bbf491637c83a76John McCall // references are written directly; here, we handle the 113269d831645f429d3b806d2ae220aee45ca44f8c6cDouglas Gregor // collapsing of references-to-references as described in C++0x. 113369d831645f429d3b806d2ae220aee45ca44f8c6cDouglas Gregor // DR 106 and 540 introduce reference-collapsing into C++98/03. 1134cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor 1135cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // C++ [dcl.ref]p1: 113633a3138a0862cafdd9ff1332b834454a79cd2cdcEli Friedman // A declarator that specifies the type "reference to cv void" 1137cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // is ill-formed. 1138cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor if (T->isVoidType()) { 1139cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor Diag(Loc, diag::err_reference_to_void); 1140cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor return QualType(); 1141cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor } 1142cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor 1143f85e193739c953358c865005855253af4f68a497John McCall // In ARC, it is forbidden to build references to unqualified pointers. 1144f85e193739c953358c865005855253af4f68a497John McCall if (getLangOptions().ObjCAutoRefCount) 1145f85e193739c953358c865005855253af4f68a497John McCall T = inferARCLifetimeForPointee(*this, T, Loc, /*reference*/ true); 1146f85e193739c953358c865005855253af4f68a497John McCall 1147cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // Handle restrict on references. 11487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (LValueRef) 11492865474261a608c7873b87ba4af110d17907896dJohn McCall return Context.getLValueReferenceType(T, SpelledAsLValue); 11502865474261a608c7873b87ba4af110d17907896dJohn McCall return Context.getRValueReferenceType(T); 1151cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor} 1152cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor 1153e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner/// Check whether the specified array size makes the array type a VLA. If so, 1154e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner/// return true, if not, return the size of the array in SizeVal. 1155e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattnerstatic bool isArraySizeVLA(Expr *ArraySize, llvm::APSInt &SizeVal, Sema &S) { 1156e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner // If the size is an ICE, it certainly isn't a VLA. 1157e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner if (ArraySize->isIntegerConstantExpr(SizeVal, S.Context)) 1158e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner return false; 1159e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner 1160e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner // If we're in a GNU mode (like gnu99, but not c99) accept any evaluatable 1161e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner // value as an extension. 1162e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner Expr::EvalResult Result; 1163e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner if (S.LangOpts.GNUMode && ArraySize->Evaluate(Result, S.Context)) { 1164e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner if (!Result.hasSideEffects() && Result.Val.isInt()) { 1165e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner SizeVal = Result.Val.getInt(); 1166e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner S.Diag(ArraySize->getLocStart(), diag::ext_vla_folded_to_constant); 1167e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner return false; 1168e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner } 1169e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner } 1170e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner 1171e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner return true; 1172e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner} 1173e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner 1174e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner 1175cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \brief Build an array type. 1176cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1177cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \param T The type of each element in the array. 1178cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1179cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \param ASM C99 array size modifier (e.g., '*', 'static'). 11801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 11811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \param ArraySize Expression describing the size of the array. 1182cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1183cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \param Loc The location of the entity whose type involves this 1184cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// array type or, if there is no such entity, the location of the 1185cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// type that will have array type. 1186cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1187cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \param Entity The name of the entity that involves the array 1188cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// type, if known. 1189cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// 1190cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// \returns A suitable array type, if there are no errors. Otherwise, 1191cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor/// returns a NULL type. 1192cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas GregorQualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, 1193cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor Expr *ArraySize, unsigned Quals, 11947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets, DeclarationName Entity) { 11950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 11967e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation Loc = Brackets.getBegin(); 1197923d56d436f750bc1f29db50e641078725558a1bSebastian Redl if (getLangOptions().CPlusPlus) { 1198138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor // C++ [dcl.array]p1: 1199138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor // T is called the array element type; this type shall not be a reference 1200138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor // type, the (possibly cv-qualified) type void, a function type or an 1201138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor // abstract class type. 1202138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor // 1203138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor // Note: function types are handled in the common path with C. 1204138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor if (T->isReferenceType()) { 1205138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor Diag(Loc, diag::err_illegal_decl_array_of_references) 1206138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor << getPrintableNameForEntity(Entity) << T; 1207138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor return QualType(); 1208138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor } 1209138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor 1210923d56d436f750bc1f29db50e641078725558a1bSebastian Redl if (T->isVoidType()) { 1211923d56d436f750bc1f29db50e641078725558a1bSebastian Redl Diag(Loc, diag::err_illegal_decl_array_incomplete_type) << T; 1212923d56d436f750bc1f29db50e641078725558a1bSebastian Redl return QualType(); 1213923d56d436f750bc1f29db50e641078725558a1bSebastian Redl } 1214138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor 1215138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor if (RequireNonAbstractType(Brackets.getBegin(), T, 1216138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor diag::err_array_of_abstract_type)) 1217138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor return QualType(); 1218138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor 1219923d56d436f750bc1f29db50e641078725558a1bSebastian Redl } else { 1220138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor // C99 6.7.5.2p1: If the element type is an incomplete or function type, 1221138bb2366baa3856088bae94f36f2d96b2c995b9Douglas Gregor // reject it (e.g. void ary[7], struct foo ary[7], void ary[7]()) 1222923d56d436f750bc1f29db50e641078725558a1bSebastian Redl if (RequireCompleteType(Loc, T, 1223923d56d436f750bc1f29db50e641078725558a1bSebastian Redl diag::err_illegal_decl_array_incomplete_type)) 1224923d56d436f750bc1f29db50e641078725558a1bSebastian Redl return QualType(); 1225923d56d436f750bc1f29db50e641078725558a1bSebastian Redl } 1226cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor 1227cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor if (T->isFunctionType()) { 1228cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor Diag(Loc, diag::err_illegal_decl_array_of_functions) 1229ac406052f7b980f8caa6b07b4a8d0867d53852c4John McCall << getPrintableNameForEntity(Entity) << T; 1230cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor return QualType(); 1231cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor } 12321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 123334b41d939a1328f484511c6002ba2456db879a29Richard Smith if (T->getContainedAutoType()) { 123434b41d939a1328f484511c6002ba2456db879a29Richard Smith Diag(Loc, diag::err_illegal_decl_array_of_auto) 123534b41d939a1328f484511c6002ba2456db879a29Richard Smith << getPrintableNameForEntity(Entity) << T; 1236e7cf07d8df83e083505c7105c50b2797493008a6Anders Carlsson return QualType(); 1237e7cf07d8df83e083505c7105c50b2797493008a6Anders Carlsson } 12381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12396217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *EltTy = T->getAs<RecordType>()) { 1240cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // If the element type is a struct or union that contains a variadic 1241cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // array, accept it as a GNU extension: C99 6.7.2.1p2. 1242cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor if (EltTy->getDecl()->hasFlexibleArrayMember()) 1243cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor Diag(Loc, diag::ext_flexible_array_in_array) << T; 1244c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } else if (T->isObjCObjectType()) { 1245c7c11b1ba6a110f2416889cc3576fe33277b2a33Chris Lattner Diag(Loc, diag::err_objc_array_of_interfaces) << T; 1246c7c11b1ba6a110f2416889cc3576fe33277b2a33Chris Lattner return QualType(); 1247cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor } 12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12495e3c67b4bd894a926282d24b4d0cbc0e123c9f4aJohn McCall // Do lvalue-to-rvalue conversions on the array size expression. 1250429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (ArraySize && !ArraySize->isRValue()) { 1251429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Result = DefaultLvalueConversion(ArraySize); 1252429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid()) 1253429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return QualType(); 1254429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley 1255429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ArraySize = Result.take(); 1256429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley } 12575e3c67b4bd894a926282d24b4d0cbc0e123c9f4aJohn McCall 1258cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // C99 6.7.5.2p1: The size expression shall have integer type. 12595e3c67b4bd894a926282d24b4d0cbc0e123c9f4aJohn McCall // TODO: in theory, if we were insane, we could allow contextual 12605e3c67b4bd894a926282d24b4d0cbc0e123c9f4aJohn McCall // conversions to integer type here. 1261cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor if (ArraySize && !ArraySize->isTypeDependent() && 12621274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor !ArraySize->getType()->isIntegralOrUnscopedEnumerationType()) { 1263cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor Diag(ArraySize->getLocStart(), diag::err_array_size_non_int) 1264cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor << ArraySize->getType() << ArraySize->getSourceRange(); 1265cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor return QualType(); 1266cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor } 12672767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt ConstVal(Context.getTypeSize(Context.getSizeType())); 1268cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor if (!ArraySize) { 1269f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman if (ASM == ArrayType::Star) 12707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T = Context.getVariableArrayType(T, 0, ASM, Quals, Brackets); 1271f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman else 1272f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman T = Context.getIncompleteArrayType(T, ASM, Quals); 1273ac06a0e1e3feb95c2ffd352c086882b492a65b99Douglas Gregor } else if (ArraySize->isTypeDependent() || ArraySize->isValueDependent()) { 12747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals, Brackets); 1275e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner } else if (!T->isDependentType() && !T->isIncompleteType() && 1276e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner !T->isConstantSizeType()) { 1277e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner // C99: an array with an element type that has a non-constant-size is a VLA. 1278e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner T = Context.getVariableArrayType(T, ArraySize, ASM, Quals, Brackets); 1279e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner } else if (isArraySizeVLA(ArraySize, ConstVal, *this)) { 1280e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner // C99: an array with a non-ICE size is a VLA. We accept any expression 1281e1eed38733ed47d44f9d8c7731817c411eaf4141Chris Lattner // that we can fold to a non-zero positive value as an extension. 12827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T = Context.getVariableArrayType(T, ArraySize, ASM, Quals, Brackets); 1283cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor } else { 1284cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // C99 6.7.5.2p1: If the expression is a constant expression, it shall 1285cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // have a value greater than zero. 1286923d56d436f750bc1f29db50e641078725558a1bSebastian Redl if (ConstVal.isSigned() && ConstVal.isNegative()) { 1287b2b5cc0cf908d516a107d373db963f692449a8a8Chandler Carruth if (Entity) 1288b2b5cc0cf908d516a107d373db963f692449a8a8Chandler Carruth Diag(ArraySize->getLocStart(), diag::err_decl_negative_array_size) 1289b2b5cc0cf908d516a107d373db963f692449a8a8Chandler Carruth << getPrintableNameForEntity(Entity) << ArraySize->getSourceRange(); 1290b2b5cc0cf908d516a107d373db963f692449a8a8Chandler Carruth else 1291b2b5cc0cf908d516a107d373db963f692449a8a8Chandler Carruth Diag(ArraySize->getLocStart(), diag::err_typecheck_negative_array_size) 1292b2b5cc0cf908d516a107d373db963f692449a8a8Chandler Carruth << ArraySize->getSourceRange(); 1293923d56d436f750bc1f29db50e641078725558a1bSebastian Redl return QualType(); 1294923d56d436f750bc1f29db50e641078725558a1bSebastian Redl } 1295923d56d436f750bc1f29db50e641078725558a1bSebastian Redl if (ConstVal == 0) { 129602024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor // GCC accepts zero sized static arrays. We allow them when 129702024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor // we're not in a SFINAE context. 129802024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor Diag(ArraySize->getLocStart(), 129902024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor isSFINAEContext()? diag::err_typecheck_zero_array_size 130002024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor : diag::ext_typecheck_zero_array_size) 1301923d56d436f750bc1f29db50e641078725558a1bSebastian Redl << ArraySize->getSourceRange(); 13022767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor } else if (!T->isDependentType() && !T->isVariablyModifiedType() && 13032767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor !T->isIncompleteType()) { 13042767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // Is the array too large? 13052767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned ActiveSizeBits 13062767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor = ConstantArrayType::getNumAddressingBits(Context, T, ConstVal); 13072767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor if (ActiveSizeBits > ConstantArrayType::getMaxSizeBits(Context)) 13082767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor Diag(ArraySize->getLocStart(), diag::err_array_too_large) 13092767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor << ConstVal.toString(10) 13102767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor << ArraySize->getSourceRange(); 13111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 13122767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 131346a617a792bfab0d9b1e057371ea3b9540802226John McCall T = Context.getConstantArrayType(T, ConstVal, ASM, Quals); 1314cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor } 1315af40776922bc5c28e740adb0342faa09f35b0068David Chisnall // If this is not C99, extwarn about VLA's and C99 array size modifiers. 1316af40776922bc5c28e740adb0342faa09f35b0068David Chisnall if (!getLangOptions().C99) { 13170fddb97901dbe36a8253dee29961cba8e0a87cf6Douglas Gregor if (T->isVariableArrayType()) { 13180fddb97901dbe36a8253dee29961cba8e0a87cf6Douglas Gregor // Prohibit the use of non-POD types in VLAs. 1319f85e193739c953358c865005855253af4f68a497John McCall QualType BaseT = Context.getBaseElementType(T); 1320204ce17e0cfd9bbe229627e1e5a20c3f2f587c8cDouglas Gregor if (!T->isDependentType() && 1321f85e193739c953358c865005855253af4f68a497John McCall !BaseT.isPODType(Context) && 1322f85e193739c953358c865005855253af4f68a497John McCall !BaseT->isObjCLifetimeType()) { 13230fddb97901dbe36a8253dee29961cba8e0a87cf6Douglas Gregor Diag(Loc, diag::err_vla_non_pod) 1324f85e193739c953358c865005855253af4f68a497John McCall << BaseT; 13250fddb97901dbe36a8253dee29961cba8e0a87cf6Douglas Gregor return QualType(); 13260fddb97901dbe36a8253dee29961cba8e0a87cf6Douglas Gregor } 1327a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor // Prohibit the use of VLAs during template argument deduction. 1328a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor else if (isSFINAEContext()) { 1329a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor Diag(Loc, diag::err_vla_in_sfinae); 1330a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor return QualType(); 1331a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor } 13320fddb97901dbe36a8253dee29961cba8e0a87cf6Douglas Gregor // Just extwarn about VLAs. 13330fddb97901dbe36a8253dee29961cba8e0a87cf6Douglas Gregor else 13340fddb97901dbe36a8253dee29961cba8e0a87cf6Douglas Gregor Diag(Loc, diag::ext_vla); 13350fddb97901dbe36a8253dee29961cba8e0a87cf6Douglas Gregor } else if (ASM != ArrayType::Normal || Quals != 0) 1336043cad21b78c6b02597cdc7b6ead32388e27ebc7Douglas Gregor Diag(Loc, 1337043cad21b78c6b02597cdc7b6ead32388e27ebc7Douglas Gregor getLangOptions().CPlusPlus? diag::err_c99_array_usage_cxx 1338043cad21b78c6b02597cdc7b6ead32388e27ebc7Douglas Gregor : diag::ext_c99_array_usage); 1339cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor } 1340cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor 1341cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor return T; 1342cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor} 13439cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 13449cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// \brief Build an ext-vector type. 13459cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// 13469cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// Run the required checks for the extended vector type. 13479ae2f076ca5ab1feb3ba95629099ec2319833701John McCallQualType Sema::BuildExtVectorType(QualType T, Expr *ArraySize, 13489cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation AttrLoc) { 13499cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor // unlike gcc's vector_size attribute, we do not allow vectors to be defined 13509cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor // in conjunction with complex types (pointers, arrays, functions, etc.). 13511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (!T->isDependentType() && 13529cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor !T->isIntegerType() && !T->isRealFloatingType()) { 13539cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << T; 13549cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return QualType(); 13559cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 13569cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 13579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!ArraySize->isTypeDependent() && !ArraySize->isValueDependent()) { 13589cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor llvm::APSInt vecSize(32); 13599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!ArraySize->isIntegerConstantExpr(vecSize, Context)) { 13609cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Diag(AttrLoc, diag::err_attribute_argument_not_int) 13619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall << "ext_vector_type" << ArraySize->getSourceRange(); 13629cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return QualType(); 13639cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // unlike gcc's vector_size attribute, the size is specified as the 13669cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor // number of elements, not the number of bytes. 13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue()); 13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13699cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor if (vectorSize == 0) { 13709cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Diag(AttrLoc, diag::err_attribute_zero_size) 13719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall << ArraySize->getSourceRange(); 13729cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return QualType(); 13739cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13754ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor return Context.getExtVectorType(T, vectorSize); 13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 13771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Context.getDependentSizedExtVectorType(T, ArraySize, AttrLoc); 13799cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor} 13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1381724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// \brief Build a function type. 1382724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// 1383724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// This routine checks the function type according to C++ rules and 1384724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// under the assumption that the result type and parameter types have 1385724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// just been instantiated from a template. It therefore duplicates 13862943aed177b33ae3f14273b11a7b398e5276ec62Douglas Gregor/// some of the behavior of GetTypeForDeclarator, but in a much 1387724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// simpler form that is only suitable for this narrow use case. 1388724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// 1389724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// \param T The return type of the function. 1390724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// 1391724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// \param ParamTypes The parameter types of the function. This array 1392724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// will be modified to account for adjustments to the types of the 1393724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// function parameters. 1394724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// 1395724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// \param NumParamTypes The number of parameter types in ParamTypes. 1396724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// 1397724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// \param Variadic Whether this is a variadic function type. 1398724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// 1399724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// \param Quals The cvr-qualifiers to be applied to the function type. 1400724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// 1401724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// \param Loc The location of the entity whose type involves this 1402724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// function type or, if there is no such entity, the location of the 1403724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// type that will have function type. 1404724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// 1405724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// \param Entity The name of the entity that involves the function 1406724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// type, if known. 1407724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// 1408724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// \returns A suitable function type, if there are no 1409724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor/// errors. Otherwise, returns a NULL type. 1410724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas GregorQualType Sema::BuildFunctionType(QualType T, 14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 1412724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor unsigned NumParamTypes, 1413724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor bool Variadic, unsigned Quals, 1414c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 1415fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman SourceLocation Loc, DeclarationName Entity, 1416e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionType::ExtInfo Info) { 1417724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor if (T->isArrayType() || T->isFunctionType()) { 141858408bc4ead86b08af56cd06fc966fd858b48b2dDouglas Gregor Diag(Loc, diag::err_func_returning_array_function) 141958408bc4ead86b08af56cd06fc966fd858b48b2dDouglas Gregor << T->isFunctionType() << T; 1420724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor return QualType(); 1421724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor } 14225291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 1423724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor bool Invalid = false; 1424724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor for (unsigned Idx = 0; Idx < NumParamTypes; ++Idx) { 142579e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor QualType ParamType = Context.getAdjustedParameterType(ParamTypes[Idx]); 14262dc0e64e57b2a1786fa53a7dbd1d5c8e255eadb0Douglas Gregor if (ParamType->isVoidType()) { 1427724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor Diag(Loc, diag::err_param_with_void_type); 1428724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor Invalid = true; 1429724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor } 1430cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor 143154e14c4db764c0636160d26c5bbf491637c83a76John McCall ParamTypes[Idx] = ParamType; 1432724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor } 1433724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor 1434724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor if (Invalid) 1435724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor return QualType(); 1436724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor 1437e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI; 1438e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.Variadic = Variadic; 1439e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.TypeQuals = Quals; 1440c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor EPI.RefQualifier = RefQualifier; 1441e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = Info; 1442e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 1443e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return Context.getFunctionType(T, ParamTypes, NumParamTypes, EPI); 1444724651c3523e25fbf2f6cd0419bc3466e0afdb07Douglas Gregor} 14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1446949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor/// \brief Build a member pointer type \c T Class::*. 1447949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor/// 1448949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor/// \param T the type to which the member pointer refers. 1449949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor/// \param Class the class type into which the member pointer points. 14500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// \param CVR Qualifiers applied to the member pointer type 1451949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor/// \param Loc the location where this type begins 1452949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor/// \param Entity the name of the entity that will have this member pointer type 1453949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor/// 1454949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor/// \returns a member pointer type, if successful, or a NULL type if there was 1455949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor/// an error. 14561eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType Sema::BuildMemberPointerType(QualType T, QualType Class, 14572865474261a608c7873b87ba4af110d17907896dJohn McCall SourceLocation Loc, 1458949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor DeclarationName Entity) { 1459949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor // Verify that we're not building a pointer to pointer to function with 1460949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor // exception specification. 1461949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor if (CheckDistantExceptionSpec(T)) { 1462949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor Diag(Loc, diag::err_distant_exception_spec); 1463949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor 1464949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor // FIXME: If we're doing this as part of template instantiation, 1465949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor // we should return immediately. 1466949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor 1467949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor // Build the type anyway, but use the canonical type so that the 1468949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor // exception specifiers are stripped off. 1469949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor T = Context.getCanonicalType(T); 1470949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor } 1471949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor 1472737801257f795632175517ffce4a80c62fc7bff7Sebastian Redl // C++ 8.3.3p3: A pointer to member shall not point to ... a member 1473949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor // with reference type, or "cv void." 1474949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor if (T->isReferenceType()) { 14758d4655d3b966da02fe0588767160448594cddd61Anders Carlsson Diag(Loc, diag::err_illegal_decl_mempointer_to_reference) 1476ac406052f7b980f8caa6b07b4a8d0867d53852c4John McCall << (Entity? Entity.getAsString() : "type name") << T; 1477949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor return QualType(); 1478949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor } 1479949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor 1480949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor if (T->isVoidType()) { 1481949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor Diag(Loc, diag::err_illegal_decl_mempointer_to_void) 1482949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor << (Entity? Entity.getAsString() : "type name"); 1483949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor return QualType(); 1484949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor } 1485949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor 1486949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor if (!Class->isDependentType() && !Class->isRecordType()) { 1487949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor Diag(Loc, diag::err_mempointer_in_nonclass_type) << Class; 1488949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor return QualType(); 1489949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor } 1490949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor 1491d18f9f965bcfe56edcdf9b0d8375ffaad9866b3fCharles Davis // In the Microsoft ABI, the class is allowed to be an incomplete 1492d18f9f965bcfe56edcdf9b0d8375ffaad9866b3fCharles Davis // type. In such cases, the compiler makes a worst-case assumption. 1493d18f9f965bcfe56edcdf9b0d8375ffaad9866b3fCharles Davis // We make no such assumption right now, so emit an error if the 1494d18f9f965bcfe56edcdf9b0d8375ffaad9866b3fCharles Davis // class isn't a complete type. 149520cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis if (Context.Target.getCXXABI() == CXXABI_Microsoft && 1496d18f9f965bcfe56edcdf9b0d8375ffaad9866b3fCharles Davis RequireCompleteType(Loc, Class, diag::err_incomplete_type)) 1497d18f9f965bcfe56edcdf9b0d8375ffaad9866b3fCharles Davis return QualType(); 1498d18f9f965bcfe56edcdf9b0d8375ffaad9866b3fCharles Davis 14992865474261a608c7873b87ba4af110d17907896dJohn McCall return Context.getMemberPointerType(T, Class.getTypePtr()); 1500949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor} 15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15029a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// \brief Build a block pointer type. 15039a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// 15049a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// \param T The type to which we'll be building a block pointer. 15059a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// 15060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// \param CVR The cvr-qualifiers to be applied to the block pointer type. 15079a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// 15089a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// \param Loc The location of the entity whose type involves this 15099a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// block pointer type or, if there is no such entity, the location of the 15109a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// type that will have block pointer type. 15119a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// 15129a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// \param Entity The name of the entity that involves the block pointer 15139a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// type, if known. 15149a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// 15159a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// \returns A suitable block pointer type, if there are no 15169a917e4fac79aba20fbd25983c78396475078918Anders Carlsson/// errors. Otherwise, returns a NULL type. 15172865474261a608c7873b87ba4af110d17907896dJohn McCallQualType Sema::BuildBlockPointerType(QualType T, 15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation Loc, 15199a917e4fac79aba20fbd25983c78396475078918Anders Carlsson DeclarationName Entity) { 15200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!T->isFunctionType()) { 15219a917e4fac79aba20fbd25983c78396475078918Anders Carlsson Diag(Loc, diag::err_nonfunction_block_type); 15229a917e4fac79aba20fbd25983c78396475078918Anders Carlsson return QualType(); 15239a917e4fac79aba20fbd25983c78396475078918Anders Carlsson } 15241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15252865474261a608c7873b87ba4af110d17907896dJohn McCall return Context.getBlockPointerType(T); 15269a917e4fac79aba20fbd25983c78396475078918Anders Carlsson} 15279a917e4fac79aba20fbd25983c78396475078918Anders Carlsson 1528b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCallQualType Sema::GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo) { 1529b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall QualType QT = Ty.get(); 15303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (QT.isNull()) { 1531a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall if (TInfo) *TInfo = 0; 15323f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return QualType(); 15333f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 15343f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 1535a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = 0; 1536f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT)) { 1537e8661906d49ef6c9694a9cc845ca62a85dbc016dArgyrios Kyrtzidis QT = LIT->getType(); 1538a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall DI = LIT->getTypeSourceInfo(); 1539e8661906d49ef6c9694a9cc845ca62a85dbc016dArgyrios Kyrtzidis } 15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1541a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall if (TInfo) *TInfo = DI; 1542e8661906d49ef6c9694a9cc845ca62a85dbc016dArgyrios Kyrtzidis return QT; 1543e8661906d49ef6c9694a9cc845ca62a85dbc016dArgyrios Kyrtzidis} 1544e8661906d49ef6c9694a9cc845ca62a85dbc016dArgyrios Kyrtzidis 1545a8349f5e60d1b5b0e658195a60d385b56ed440ecArgyrios Kyrtzidisstatic void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state, 1546a8349f5e60d1b5b0e658195a60d385b56ed440ecArgyrios Kyrtzidis Qualifiers::ObjCLifetime ownership, 1547a8349f5e60d1b5b0e658195a60d385b56ed440ecArgyrios Kyrtzidis unsigned chunkIndex); 1548a8349f5e60d1b5b0e658195a60d385b56ed440ecArgyrios Kyrtzidis 1549f85e193739c953358c865005855253af4f68a497John McCall/// Given that this is the declaration of a parameter under ARC, 1550f85e193739c953358c865005855253af4f68a497John McCall/// attempt to infer attributes and such for pointer-to-whatever 1551f85e193739c953358c865005855253af4f68a497John McCall/// types. 1552f85e193739c953358c865005855253af4f68a497John McCallstatic void inferARCWriteback(TypeProcessingState &state, 1553f85e193739c953358c865005855253af4f68a497John McCall QualType &declSpecType) { 1554f85e193739c953358c865005855253af4f68a497John McCall Sema &S = state.getSema(); 1555f85e193739c953358c865005855253af4f68a497John McCall Declarator &declarator = state.getDeclarator(); 1556f85e193739c953358c865005855253af4f68a497John McCall 1557f85e193739c953358c865005855253af4f68a497John McCall // TODO: should we care about decl qualifiers? 1558f85e193739c953358c865005855253af4f68a497John McCall 1559f85e193739c953358c865005855253af4f68a497John McCall // Check whether the declarator has the expected form. We walk 1560f85e193739c953358c865005855253af4f68a497John McCall // from the inside out in order to make the block logic work. 1561f85e193739c953358c865005855253af4f68a497John McCall unsigned outermostPointerIndex = 0; 1562f85e193739c953358c865005855253af4f68a497John McCall bool isBlockPointer = false; 1563f85e193739c953358c865005855253af4f68a497John McCall unsigned numPointers = 0; 1564f85e193739c953358c865005855253af4f68a497John McCall for (unsigned i = 0, e = declarator.getNumTypeObjects(); i != e; ++i) { 1565f85e193739c953358c865005855253af4f68a497John McCall unsigned chunkIndex = i; 1566f85e193739c953358c865005855253af4f68a497John McCall DeclaratorChunk &chunk = declarator.getTypeObject(chunkIndex); 1567f85e193739c953358c865005855253af4f68a497John McCall switch (chunk.Kind) { 1568f85e193739c953358c865005855253af4f68a497John McCall case DeclaratorChunk::Paren: 1569f85e193739c953358c865005855253af4f68a497John McCall // Ignore parens. 1570f85e193739c953358c865005855253af4f68a497John McCall break; 1571f85e193739c953358c865005855253af4f68a497John McCall 1572f85e193739c953358c865005855253af4f68a497John McCall case DeclaratorChunk::Reference: 1573f85e193739c953358c865005855253af4f68a497John McCall case DeclaratorChunk::Pointer: 1574f85e193739c953358c865005855253af4f68a497John McCall // Count the number of pointers. Treat references 1575f85e193739c953358c865005855253af4f68a497John McCall // interchangeably as pointers; if they're mis-ordered, normal 1576f85e193739c953358c865005855253af4f68a497John McCall // type building will discover that. 1577f85e193739c953358c865005855253af4f68a497John McCall outermostPointerIndex = chunkIndex; 1578f85e193739c953358c865005855253af4f68a497John McCall numPointers++; 1579f85e193739c953358c865005855253af4f68a497John McCall break; 1580f85e193739c953358c865005855253af4f68a497John McCall 1581f85e193739c953358c865005855253af4f68a497John McCall case DeclaratorChunk::BlockPointer: 1582f85e193739c953358c865005855253af4f68a497John McCall // If we have a pointer to block pointer, that's an acceptable 1583f85e193739c953358c865005855253af4f68a497John McCall // indirect reference; anything else is not an application of 1584f85e193739c953358c865005855253af4f68a497John McCall // the rules. 1585f85e193739c953358c865005855253af4f68a497John McCall if (numPointers != 1) return; 1586f85e193739c953358c865005855253af4f68a497John McCall numPointers++; 1587f85e193739c953358c865005855253af4f68a497John McCall outermostPointerIndex = chunkIndex; 1588f85e193739c953358c865005855253af4f68a497John McCall isBlockPointer = true; 1589f85e193739c953358c865005855253af4f68a497John McCall 1590f85e193739c953358c865005855253af4f68a497John McCall // We don't care about pointer structure in return values here. 1591f85e193739c953358c865005855253af4f68a497John McCall goto done; 1592f85e193739c953358c865005855253af4f68a497John McCall 1593f85e193739c953358c865005855253af4f68a497John McCall case DeclaratorChunk::Array: // suppress if written (id[])? 1594f85e193739c953358c865005855253af4f68a497John McCall case DeclaratorChunk::Function: 1595f85e193739c953358c865005855253af4f68a497John McCall case DeclaratorChunk::MemberPointer: 1596f85e193739c953358c865005855253af4f68a497John McCall return; 1597f85e193739c953358c865005855253af4f68a497John McCall } 1598f85e193739c953358c865005855253af4f68a497John McCall } 1599f85e193739c953358c865005855253af4f68a497John McCall done: 1600f85e193739c953358c865005855253af4f68a497John McCall 1601f85e193739c953358c865005855253af4f68a497John McCall // If we have *one* pointer, then we want to throw the qualifier on 1602f85e193739c953358c865005855253af4f68a497John McCall // the declaration-specifiers, which means that it needs to be a 1603f85e193739c953358c865005855253af4f68a497John McCall // retainable object type. 1604f85e193739c953358c865005855253af4f68a497John McCall if (numPointers == 1) { 1605f85e193739c953358c865005855253af4f68a497John McCall // If it's not a retainable object type, the rule doesn't apply. 1606f85e193739c953358c865005855253af4f68a497John McCall if (!declSpecType->isObjCRetainableType()) return; 1607f85e193739c953358c865005855253af4f68a497John McCall 1608f85e193739c953358c865005855253af4f68a497John McCall // If it already has lifetime, don't do anything. 1609f85e193739c953358c865005855253af4f68a497John McCall if (declSpecType.getObjCLifetime()) return; 1610f85e193739c953358c865005855253af4f68a497John McCall 1611f85e193739c953358c865005855253af4f68a497John McCall // Otherwise, modify the type in-place. 1612f85e193739c953358c865005855253af4f68a497John McCall Qualifiers qs; 1613f85e193739c953358c865005855253af4f68a497John McCall 1614f85e193739c953358c865005855253af4f68a497John McCall if (declSpecType->isObjCARCImplicitlyUnretainedType()) 1615f85e193739c953358c865005855253af4f68a497John McCall qs.addObjCLifetime(Qualifiers::OCL_ExplicitNone); 1616f85e193739c953358c865005855253af4f68a497John McCall else 1617f85e193739c953358c865005855253af4f68a497John McCall qs.addObjCLifetime(Qualifiers::OCL_Autoreleasing); 1618f85e193739c953358c865005855253af4f68a497John McCall declSpecType = S.Context.getQualifiedType(declSpecType, qs); 1619f85e193739c953358c865005855253af4f68a497John McCall 1620f85e193739c953358c865005855253af4f68a497John McCall // If we have *two* pointers, then we want to throw the qualifier on 1621f85e193739c953358c865005855253af4f68a497John McCall // the outermost pointer. 1622f85e193739c953358c865005855253af4f68a497John McCall } else if (numPointers == 2) { 1623f85e193739c953358c865005855253af4f68a497John McCall // If we don't have a block pointer, we need to check whether the 1624f85e193739c953358c865005855253af4f68a497John McCall // declaration-specifiers gave us something that will turn into a 1625f85e193739c953358c865005855253af4f68a497John McCall // retainable object pointer after we slap the first pointer on it. 1626f85e193739c953358c865005855253af4f68a497John McCall if (!isBlockPointer && !declSpecType->isObjCObjectType()) 1627f85e193739c953358c865005855253af4f68a497John McCall return; 1628f85e193739c953358c865005855253af4f68a497John McCall 1629f85e193739c953358c865005855253af4f68a497John McCall // Look for an explicit lifetime attribute there. 1630f85e193739c953358c865005855253af4f68a497John McCall DeclaratorChunk &chunk = declarator.getTypeObject(outermostPointerIndex); 16311c73dcbe1f1921bad8311cfb5089d30b4bd75b66Argyrios Kyrtzidis if (chunk.Kind != DeclaratorChunk::Pointer && 16321c73dcbe1f1921bad8311cfb5089d30b4bd75b66Argyrios Kyrtzidis chunk.Kind != DeclaratorChunk::BlockPointer) 16331c73dcbe1f1921bad8311cfb5089d30b4bd75b66Argyrios Kyrtzidis return; 1634f85e193739c953358c865005855253af4f68a497John McCall for (const AttributeList *attr = chunk.getAttrs(); attr; 1635f85e193739c953358c865005855253af4f68a497John McCall attr = attr->getNext()) 1636b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis if (attr->getKind() == AttributeList::AT_objc_ownership) 1637f85e193739c953358c865005855253af4f68a497John McCall return; 1638f85e193739c953358c865005855253af4f68a497John McCall 1639a8349f5e60d1b5b0e658195a60d385b56ed440ecArgyrios Kyrtzidis transferARCOwnershipToDeclaratorChunk(state, Qualifiers::OCL_Autoreleasing, 1640a8349f5e60d1b5b0e658195a60d385b56ed440ecArgyrios Kyrtzidis outermostPointerIndex); 1641f85e193739c953358c865005855253af4f68a497John McCall 1642f85e193739c953358c865005855253af4f68a497John McCall // Any other number of pointers/references does not trigger the rule. 1643f85e193739c953358c865005855253af4f68a497John McCall } else return; 1644f85e193739c953358c865005855253af4f68a497John McCall 1645f85e193739c953358c865005855253af4f68a497John McCall // TODO: mark whether we did this inference? 1646f85e193739c953358c865005855253af4f68a497John McCall} 1647f85e193739c953358c865005855253af4f68a497John McCall 1648d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruthstatic void DiagnoseIgnoredQualifiers(unsigned Quals, 1649d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth SourceLocation ConstQualLoc, 1650d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth SourceLocation VolatileQualLoc, 1651d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth SourceLocation RestrictQualLoc, 1652d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth Sema& S) { 1653d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth std::string QualStr; 1654d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth unsigned NumQuals = 0; 1655d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth SourceLocation Loc; 1656d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 1657d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth FixItHint ConstFixIt; 1658d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth FixItHint VolatileFixIt; 1659d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth FixItHint RestrictFixIt; 1660d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 1661a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg const SourceManager &SM = S.getSourceManager(); 1662a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg 1663d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth // FIXME: The locations here are set kind of arbitrarily. It'd be nicer to 1664d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth // find a range and grow it to encompass all the qualifiers, regardless of 1665d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth // the order in which they textually appear. 1666d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth if (Quals & Qualifiers::Const) { 1667d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth ConstFixIt = FixItHint::CreateRemoval(ConstQualLoc); 1668d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth QualStr = "const"; 1669a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg ++NumQuals; 1670a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg if (!Loc.isValid() || SM.isBeforeInTranslationUnit(ConstQualLoc, Loc)) 1671a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg Loc = ConstQualLoc; 1672d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth } 1673d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth if (Quals & Qualifiers::Volatile) { 1674d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth VolatileFixIt = FixItHint::CreateRemoval(VolatileQualLoc); 1675a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg QualStr += (NumQuals == 0 ? "volatile" : " volatile"); 1676d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth ++NumQuals; 1677a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg if (!Loc.isValid() || SM.isBeforeInTranslationUnit(VolatileQualLoc, Loc)) 1678a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg Loc = VolatileQualLoc; 1679d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth } 1680d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth if (Quals & Qualifiers::Restrict) { 1681d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth RestrictFixIt = FixItHint::CreateRemoval(RestrictQualLoc); 1682a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg QualStr += (NumQuals == 0 ? "restrict" : " restrict"); 1683d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth ++NumQuals; 1684a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg if (!Loc.isValid() || SM.isBeforeInTranslationUnit(RestrictQualLoc, Loc)) 1685a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg Loc = RestrictQualLoc; 1686d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth } 1687d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 1688d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth assert(NumQuals > 0 && "No known qualifiers?"); 1689d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 1690d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth S.Diag(Loc, diag::warn_qual_return_type) 1691a08fcb8105bf53f3640ad17f61bdcde2d8ace78aHans Wennborg << QualStr << NumQuals << ConstFixIt << VolatileFixIt << RestrictFixIt; 1692d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth} 1693d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 16948cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidisstatic QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state, 16958cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis TypeSourceInfo *&ReturnTypeInfo) { 16968cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis Sema &SemaRef = state.getSema(); 16978cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis Declarator &D = state.getDeclarator(); 1698930d8b5ecc074cca01ecd9a522a55f55f3b72396Douglas Gregor QualType T; 16998cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis ReturnTypeInfo = 0; 1700711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 17018cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // The TagDecl owned by the DeclSpec. 17028cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis TagDecl *OwnedTagDecl = 0; 17038999fe1bc367b3ecc878d135c7b31e3479da56f4Sebastian Redl 17043f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor switch (D.getName().getKind()) { 170598a5403ecf1d2b60ae8cbf43e54194bd762cacaaFariborz Jahanian case UnqualifiedId::IK_ImplicitSelfParam: 17063f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor case UnqualifiedId::IK_OperatorFunctionId: 17078999fe1bc367b3ecc878d135c7b31e3479da56f4Sebastian Redl case UnqualifiedId::IK_Identifier: 17080486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt case UnqualifiedId::IK_LiteralOperatorId: 17093f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor case UnqualifiedId::IK_TemplateId: 17108cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = ConvertDeclSpecToType(state); 17115db2bb1cb0c040dcbca1b5000f091d6d225b4bfeChris Lattner 1712591bd3cb605f1f0229b4b1d8a4b8183377064ec5Douglas Gregor if (!D.isInvalidType() && D.getDeclSpec().isTypeSpecOwned()) { 1713d3880f8458bb6a03818ee01f758c32f945de3eaaArgyrios Kyrtzidis OwnedTagDecl = cast<TagDecl>(D.getDeclSpec().getRepAsDecl()); 171415987970eeaa1842c29ec8797affd1c1dea05585Abramo Bagnara // Owned declaration is embedded in declarator. 1715d3880f8458bb6a03818ee01f758c32f945de3eaaArgyrios Kyrtzidis OwnedTagDecl->setEmbeddedInDeclarator(true); 1716591bd3cb605f1f0229b4b1d8a4b8183377064ec5Douglas Gregor } 1717930d8b5ecc074cca01ecd9a522a55f55f3b72396Douglas Gregor break; 1718930d8b5ecc074cca01ecd9a522a55f55f3b72396Douglas Gregor 17193f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor case UnqualifiedId::IK_ConstructorName: 17200efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor case UnqualifiedId::IK_ConstructorTemplateId: 17213f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor case UnqualifiedId::IK_DestructorName: 1722930d8b5ecc074cca01ecd9a522a55f55f3b72396Douglas Gregor // Constructors and destructors don't have return types. Use 172348026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor // "void" instead. 17248cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = SemaRef.Context.VoidTy; 1725930d8b5ecc074cca01ecd9a522a55f55f3b72396Douglas Gregor break; 172648026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor 172748026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor case UnqualifiedId::IK_ConversionFunctionId: 172848026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor // The result type of a conversion function is the type that it 172948026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor // converts to. 17308cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = SemaRef.GetTypeFromParser(D.getName().ConversionFunctionId, 17318cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis &ReturnTypeInfo); 173248026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor break; 1733930d8b5ecc074cca01ecd9a522a55f55f3b72396Douglas Gregor } 1734dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 1735711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (D.getAttributes()) 1736711c52bb20d0c69063b52a99826fb7d2835501f1John McCall distributeTypeAttrsFromDeclarator(state, T); 1737711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 1738e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith // C++0x [dcl.spec.auto]p5: reject 'auto' if it is not in an allowed context. 17398110f04b39fd028496dd6bf9e3a78278c3e0a6adRichard Smith // In C++0x, a function declarator using 'auto' must have a trailing return 17408110f04b39fd028496dd6bf9e3a78278c3e0a6adRichard Smith // type (this is checked later) and we can skip this. In other languages 17418110f04b39fd028496dd6bf9e3a78278c3e0a6adRichard Smith // using auto, we need to check regardless. 174234b41d939a1328f484511c6002ba2456db879a29Richard Smith if (D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto && 17438cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis (!SemaRef.getLangOptions().CPlusPlus0x || !D.isFunctionDeclarator())) { 1744baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson int Error = -1; 17451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1746baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson switch (D.getContext()) { 1747baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson case Declarator::KNRTypeListContext: 1748baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson assert(0 && "K&R type lists aren't allowed in C++"); 1749baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson break; 1750c05a94b7accd4035bf5d5897c434c445b22da855John McCall case Declarator::ObjCPrototypeContext: 1751baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson case Declarator::PrototypeContext: 1752baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson Error = 0; // Function prototype 1753baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson break; 1754baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson case Declarator::MemberContext: 17557a614d8380297fcd2bc23986241905d97222948cRichard Smith if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static) 17567a614d8380297fcd2bc23986241905d97222948cRichard Smith break; 17578cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis switch (cast<TagDecl>(SemaRef.CurContext)->getTagKind()) { 1758465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Enum: assert(0 && "unhandled tag kind"); break; 1759465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Struct: Error = 1; /* Struct member */ break; 1760465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Union: Error = 2; /* Union member */ break; 1761465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Class: Error = 3; /* Class member */ break; 17621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1763baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson break; 1764baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson case Declarator::CXXCatchContext: 176517b6399f8461c5b7e1c6f367b0a0dde49f921240Argyrios Kyrtzidis case Declarator::ObjCCatchContext: 1766baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson Error = 4; // Exception declaration 1767baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson break; 1768baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson case Declarator::TemplateParamContext: 1769baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson Error = 5; // Template parameter 1770baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson break; 1771baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson case Declarator::BlockLiteralContext: 177234b41d939a1328f484511c6002ba2456db879a29Richard Smith Error = 6; // Block literal 177334b41d939a1328f484511c6002ba2456db879a29Richard Smith break; 177434b41d939a1328f484511c6002ba2456db879a29Richard Smith case Declarator::TemplateTypeArgContext: 177534b41d939a1328f484511c6002ba2456db879a29Richard Smith Error = 7; // Template type argument 177634b41d939a1328f484511c6002ba2456db879a29Richard Smith break; 1777162e1c1b487352434552147967c3dd296ebee2f7Richard Smith case Declarator::AliasDeclContext: 17783e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith case Declarator::AliasTemplateContext: 1779162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Error = 9; // Type alias 1780162e1c1b487352434552147967c3dd296ebee2f7Richard Smith break; 178134b41d939a1328f484511c6002ba2456db879a29Richard Smith case Declarator::TypeNameContext: 17820b8c98f3ddf83adcb9e9d98b68ce38e970cdee73Argyrios Kyrtzidis Error = 11; // Generic 1783baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson break; 1784baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson case Declarator::FileContext: 1785baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson case Declarator::BlockContext: 1786baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson case Declarator::ForContext: 1787baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson case Declarator::ConditionContext: 17880b8c98f3ddf83adcb9e9d98b68ce38e970cdee73Argyrios Kyrtzidis case Declarator::CXXNewContext: 1789baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson break; 1790baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson } 1791baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson 1792ddc83f9255834217f0559b09ff75a1c50b8ce457Richard Smith if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) 1793ddc83f9255834217f0559b09ff75a1c50b8ce457Richard Smith Error = 8; 1794ddc83f9255834217f0559b09ff75a1c50b8ce457Richard Smith 17958110f04b39fd028496dd6bf9e3a78278c3e0a6adRichard Smith // In Objective-C it is an error to use 'auto' on a function declarator. 17968110f04b39fd028496dd6bf9e3a78278c3e0a6adRichard Smith if (D.isFunctionDeclarator()) 1797162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Error = 10; 17988110f04b39fd028496dd6bf9e3a78278c3e0a6adRichard Smith 1799e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith // C++0x [dcl.spec.auto]p2: 'auto' is always fine if the declarator 1800e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith // contains a trailing return type. That is only legal at the outermost 1801e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith // level. Check all declarator chunks (outermost first) anyway, to give 1802e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith // better diagnostics. 18038cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (SemaRef.getLangOptions().CPlusPlus0x && Error != -1) { 1804e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { 1805e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith unsigned chunkIndex = e - i - 1; 1806e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith state.setCurrentChunkIndex(chunkIndex); 1807e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith DeclaratorChunk &DeclType = D.getTypeObject(chunkIndex); 1808e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith if (DeclType.Kind == DeclaratorChunk::Function) { 1809e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun; 1810e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith if (FTI.TrailingReturnType) { 1811e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith Error = -1; 1812e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith break; 1813e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith } 1814e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith } 1815e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith } 1816e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith } 1817e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith 1818baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson if (Error != -1) { 18198cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis SemaRef.Diag(D.getDeclSpec().getTypeSpecTypeLoc(), 18208cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis diag::err_auto_not_allowed) 1821baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson << Error; 18228cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = SemaRef.Context.IntTy; 1823baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson D.setInvalidType(true); 1824baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson } 1825baf45d31f18e6d5b3d2a33695c2af6e6cbc4ee29Anders Carlsson } 18268cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis 18278cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (SemaRef.getLangOptions().CPlusPlus && 18288cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis OwnedTagDecl && OwnedTagDecl->isDefinition()) { 18298cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // Check the contexts where C++ forbids the declaration of a new class 18308cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // or enumeration in a type-specifier-seq. 18318cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis switch (D.getContext()) { 18328cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::FileContext: 18338cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::MemberContext: 18348cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::BlockContext: 18358cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::ForContext: 18368cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::BlockLiteralContext: 18378cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // C++0x [dcl.type]p3: 18388cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // A type-specifier-seq shall not define a class or enumeration unless 18398cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // it appears in the type-id of an alias-declaration (7.1.3) that is not 18408cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // the declaration of a template-declaration. 18418cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::AliasDeclContext: 18428cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis break; 18438cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::AliasTemplateContext: 18448cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis SemaRef.Diag(OwnedTagDecl->getLocation(), 18458cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis diag::err_type_defined_in_alias_template) 18468cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis << SemaRef.Context.getTypeDeclType(OwnedTagDecl); 18478cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis break; 18488cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::TypeNameContext: 18498cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::TemplateParamContext: 18508cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::CXXNewContext: 18518cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::CXXCatchContext: 18528cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::ObjCCatchContext: 18538cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::TemplateTypeArgContext: 18548cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis SemaRef.Diag(OwnedTagDecl->getLocation(), 18558cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis diag::err_type_defined_in_type_specifier) 18568cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis << SemaRef.Context.getTypeDeclType(OwnedTagDecl); 18578cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis break; 18588cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::PrototypeContext: 18598cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::ObjCPrototypeContext: 18608cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::KNRTypeListContext: 18618cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // C++ [dcl.fct]p6: 18628cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // Types shall not be defined in return or parameter types. 18638cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis SemaRef.Diag(OwnedTagDecl->getLocation(), 18648cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis diag::err_type_defined_in_param_type) 18658cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis << SemaRef.Context.getTypeDeclType(OwnedTagDecl); 18668cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis break; 18678cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis case Declarator::ConditionContext: 18688cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // C++ 6.4p2: 18698cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // The type-specifier-seq shall not contain typedef and shall not declare 18708cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // a new class or enumeration. 18718cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis SemaRef.Diag(OwnedTagDecl->getLocation(), 18728cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis diag::err_type_defined_in_condition); 18738cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis break; 18748cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis } 18758cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis } 18768cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis 18778cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis return T; 18788cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis} 18798cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis 18808cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidisstatic TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, 18818cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis QualType declSpecType, 18828cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis TypeSourceInfo *TInfo) { 18838cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis 18848cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis QualType T = declSpecType; 18858cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis Declarator &D = state.getDeclarator(); 18868cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis Sema &S = state.getSema(); 18878cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis ASTContext &Context = S.Context; 18888cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis const LangOptions &LangOpts = S.getLangOptions(); 18898cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis 18908cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis bool ImplicitlyNoexcept = false; 18918cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (D.getName().getKind() == UnqualifiedId::IK_OperatorFunctionId && 18928cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis LangOpts.CPlusPlus0x) { 18938cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis OverloadedOperatorKind OO = D.getName().OperatorFunctionId.Operator; 18948cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis /// In C++0x, deallocation functions (normal and array operator delete) 18958cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis /// are implicitly noexcept. 18968cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (OO == OO_Delete || OO == OO_Array_Delete) 18978cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis ImplicitlyNoexcept = true; 18988cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis } 189934b41d939a1328f484511c6002ba2456db879a29Richard Smith 1900cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor // The name we're declaring, if any. 1901cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor DeclarationName Name; 1902cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor if (D.getIdentifier()) 1903cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor Name = D.getIdentifier(); 19041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1905162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // Does this declaration declare a typedef-name? 1906162e1c1b487352434552147967c3dd296ebee2f7Richard Smith bool IsTypedefName = 1907162e1c1b487352434552147967c3dd296ebee2f7Richard Smith D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef || 19083e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith D.getContext() == Declarator::AliasDeclContext || 19093e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith D.getContext() == Declarator::AliasTemplateContext; 1910162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 191198eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump // Walk the DeclTypeInfo, building the recursive type as we go. 191298eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump // DeclTypeInfos are ordered from the identifier out, which is 191398eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump // opposite of what we want :). 19148ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { 1915711c52bb20d0c69063b52a99826fb7d2835501f1John McCall unsigned chunkIndex = e - i - 1; 1916711c52bb20d0c69063b52a99826fb7d2835501f1John McCall state.setCurrentChunkIndex(chunkIndex); 1917711c52bb20d0c69063b52a99826fb7d2835501f1John McCall DeclaratorChunk &DeclType = D.getTypeObject(chunkIndex); 19185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (DeclType.Kind) { 19195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: assert(0 && "Unknown decltype!"); 1920075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Paren: 19218cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildParenType(T); 1922075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara break; 19235618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff case DeclaratorChunk::BlockPointer: 19249af5500f3f132f9a2f9abbe82113a7c7bb751472Chris Lattner // If blocks are disabled, emit an error. 19259af5500f3f132f9a2f9abbe82113a7c7bb751472Chris Lattner if (!LangOpts.Blocks) 19268cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(DeclType.Loc, diag::err_blocks_disable); 19271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19288cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildBlockPointerType(T, D.getIdentifierLoc(), Name); 19292865474261a608c7873b87ba4af110d17907896dJohn McCall if (DeclType.Cls.TypeQuals) 19308cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Cls.TypeQuals); 19315618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff break; 19325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DeclaratorChunk::Pointer: 19336a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl // Verify that we're not building a pointer to pointer to function with 19346a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl // exception specification. 19358cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (LangOpts.CPlusPlus && S.CheckDistantExceptionSpec(T)) { 19368cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec); 19376a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl D.setInvalidType(true); 19386a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl // Build the type anyway. 19396a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl } 19408cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (LangOpts.ObjC1 && T->getAs<ObjCObjectType>()) { 1941c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T = Context.getObjCObjectPointerType(T); 19422865474261a608c7873b87ba4af110d17907896dJohn McCall if (DeclType.Ptr.TypeQuals) 19438cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Ptr.TypeQuals); 194414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff break; 194514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 19468cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildPointerType(T, DeclType.Loc, Name); 19472865474261a608c7873b87ba4af110d17907896dJohn McCall if (DeclType.Ptr.TypeQuals) 19488cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Ptr.TypeQuals); 1949711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 19505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 19510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall case DeclaratorChunk::Reference: { 19526a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl // Verify that we're not building a reference to pointer to function with 19536a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl // exception specification. 19548cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (LangOpts.CPlusPlus && S.CheckDistantExceptionSpec(T)) { 19558cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec); 19566a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl D.setInvalidType(true); 19576a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl // Build the type anyway. 19586a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl } 19598cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildReferenceType(T, DeclType.Ref.LValueRef, DeclType.Loc, Name); 19602865474261a608c7873b87ba4af110d17907896dJohn McCall 19612865474261a608c7873b87ba4af110d17907896dJohn McCall Qualifiers Quals; 19622865474261a608c7873b87ba4af110d17907896dJohn McCall if (DeclType.Ref.HasRestrict) 19638cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildQualifiedType(T, DeclType.Loc, Qualifiers::Restrict); 19645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 19650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 19665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DeclaratorChunk::Array: { 19676a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl // Verify that we're not building an array of pointers to function with 19686a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl // exception specification. 19698cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (LangOpts.CPlusPlus && S.CheckDistantExceptionSpec(T)) { 19708cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec); 19716a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl D.setInvalidType(true); 19726a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl // Build the type anyway. 19736a7330c20cabf1cf1cd46f5dfc183ec3a72add66Sebastian Redl } 1974fd89bc825026e44c68a68db72d4012fd6752e70fChris Lattner DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr; 197594f81fd0b0f81a99d215b225c8c5616295b063f6Chris Lattner Expr *ArraySize = static_cast<Expr*>(ATI.NumElts); 19765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArrayType::ArraySizeModifier ASM; 19775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ATI.isStar) 19785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASM = ArrayType::Star; 19795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (ATI.hasStatic) 19805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASM = ArrayType::Static; 19815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 19825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASM = ArrayType::Normal; 1983c05a94b7accd4035bf5d5897c434c445b22da855John McCall if (ASM == ArrayType::Star && !D.isPrototypeContext()) { 1984f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman // FIXME: This check isn't quite right: it allows star in prototypes 1985f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman // for function definitions, and disallows some edge cases detailed 1986f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman // in http://gcc.gnu.org/ml/gcc-patches/2009-02/msg00133.html 19878cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(DeclType.Loc, diag::err_array_star_outside_prototype); 1988f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman ASM = ArrayType::Normal; 1989f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman D.setInvalidType(true); 1990f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman } 19918cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildArrayType(T, ASM, ArraySize, 19928cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis Qualifiers::fromCVRMask(ATI.TypeQuals), 19938cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis SourceRange(DeclType.Loc, DeclType.EndLoc), Name); 19945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 19955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1996f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::Function: { 19975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the function declarator has a prototype (i.e. it is not () and 19985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // does not have a K&R-style identifier list), then the arguments are part 19995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // of the type, otherwise the argument list is (). 20005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun; 20013cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl 200234b41d939a1328f484511c6002ba2456db879a29Richard Smith // Check for auto functions and trailing return type and adjust the 200334b41d939a1328f484511c6002ba2456db879a29Richard Smith // return type accordingly. 200434b41d939a1328f484511c6002ba2456db879a29Richard Smith if (!D.isInvalidType()) { 200534b41d939a1328f484511c6002ba2456db879a29Richard Smith // trailing-return-type is only required if we're declaring a function, 200634b41d939a1328f484511c6002ba2456db879a29Richard Smith // and not, for instance, a pointer to a function. 200734b41d939a1328f484511c6002ba2456db879a29Richard Smith if (D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto && 200834b41d939a1328f484511c6002ba2456db879a29Richard Smith !FTI.TrailingReturnType && chunkIndex == 0) { 20098cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(), 201034b41d939a1328f484511c6002ba2456db879a29Richard Smith diag::err_auto_missing_trailing_return); 201134b41d939a1328f484511c6002ba2456db879a29Richard Smith T = Context.IntTy; 201234b41d939a1328f484511c6002ba2456db879a29Richard Smith D.setInvalidType(true); 201334b41d939a1328f484511c6002ba2456db879a29Richard Smith } else if (FTI.TrailingReturnType) { 2014e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith // T must be exactly 'auto' at this point. See CWG issue 681. 2015e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith if (isa<ParenType>(T)) { 20168cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(), 2017e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith diag::err_trailing_return_in_parens) 2018e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith << T << D.getDeclSpec().getSourceRange(); 2019e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith D.setInvalidType(true); 2020e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith } else if (T.hasQualifiers() || !isa<AutoType>(T)) { 20218cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(), 202234b41d939a1328f484511c6002ba2456db879a29Richard Smith diag::err_trailing_return_without_auto) 202334b41d939a1328f484511c6002ba2456db879a29Richard Smith << T << D.getDeclSpec().getSourceRange(); 202434b41d939a1328f484511c6002ba2456db879a29Richard Smith D.setInvalidType(true); 202534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 202634b41d939a1328f484511c6002ba2456db879a29Richard Smith 20278cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.GetTypeFromParser( 202834b41d939a1328f484511c6002ba2456db879a29Richard Smith ParsedType::getFromOpaquePtr(FTI.TrailingReturnType), 20298cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis &TInfo); 203034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 203134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 203234b41d939a1328f484511c6002ba2456db879a29Richard Smith 2033e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith // C99 6.7.5.3p1: The return type may not be a function or array type. 2034e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith // For conversion functions, we'll diagnose this particular error later. 2035e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith if ((T->isArrayType() || T->isFunctionType()) && 2036e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith (D.getName().getKind() != UnqualifiedId::IK_ConversionFunctionId)) { 2037e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith unsigned diagID = diag::err_func_returning_array_function; 2038e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith // Last processing chunk in block context means this function chunk 2039e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith // represents the block. 2040e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith if (chunkIndex == 0 && 2041e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith D.getContext() == Declarator::BlockLiteralContext) 2042e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith diagID = diag::err_block_returning_array_function; 20438cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(DeclType.Loc, diagID) << T->isFunctionType() << T; 2044e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith T = Context.IntTy; 2045e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith D.setInvalidType(true); 2046e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith } 2047e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith 20485291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // cv-qualifiers on return types are pointless except when the type is a 20495291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // class type in C++. 2050fff951371dfc309160a99d423e43a7841aeb35aaDouglas Gregor if (isa<PointerType>(T) && T.getLocalCVRQualifiers() && 20511e15394853bfae25112d9cc6b445504905e1f34aRafael Espindola (D.getName().getKind() != UnqualifiedId::IK_ConversionFunctionId) && 20528cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis (!LangOpts.CPlusPlus || !T->isDependentType())) { 2053d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth assert(chunkIndex + 1 < e && "No DeclaratorChunk for the return type?"); 2054d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth DeclaratorChunk ReturnTypeChunk = D.getTypeObject(chunkIndex + 1); 2055d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth assert(ReturnTypeChunk.Kind == DeclaratorChunk::Pointer); 2056d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 2057d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth DeclaratorChunk::PointerTypeInfo &PTI = ReturnTypeChunk.Ptr; 2058d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 2059d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth DiagnoseIgnoredQualifiers(PTI.TypeQuals, 2060d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth SourceLocation::getFromRawEncoding(PTI.ConstQualLoc), 2061d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth SourceLocation::getFromRawEncoding(PTI.VolatileQualLoc), 2062d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth SourceLocation::getFromRawEncoding(PTI.RestrictQualLoc), 20638cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S); 2064d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 2065d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth } else if (T.getCVRQualifiers() && D.getDeclSpec().getTypeQualifiers() && 20668cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis (!LangOpts.CPlusPlus || 20675291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor (!T->isDependentType() && !T->isRecordType()))) { 2068d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 2069d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth DiagnoseIgnoredQualifiers(D.getDeclSpec().getTypeQualifiers(), 2070d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth D.getDeclSpec().getConstSpecLoc(), 2071d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth D.getDeclSpec().getVolatileSpecLoc(), 2072d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth D.getDeclSpec().getRestrictSpecLoc(), 20738cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S); 20745291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor } 2075d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth 20768cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (LangOpts.CPlusPlus && D.getDeclSpec().isTypeSpecOwned()) { 2077402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor // C++ [dcl.fct]p6: 2078402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor // Types shall not be defined in return or parameter types. 2079b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TagDecl *Tag = cast<TagDecl>(D.getDeclSpec().getRepAsDecl()); 2080402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor if (Tag->isDefinition()) 20818cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(Tag->getLocation(), diag::err_type_defined_in_result_type) 2082402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor << Context.getTypeDeclType(Tag); 2083402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor } 2084402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor 20853cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl // Exception specs are not allowed in typedefs. Complain, but add it 20863cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl // anyway. 2087162e1c1b487352434552147967c3dd296ebee2f7Richard Smith if (IsTypedefName && FTI.getExceptionSpecType()) 20888cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(FTI.getExceptionSpecLoc(), diag::err_exception_spec_in_typedef) 20893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith << (D.getContext() == Declarator::AliasDeclContext || 20903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith D.getContext() == Declarator::AliasTemplateContext); 20913cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl 20928cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (!FTI.NumArgs && !FTI.isVariadic && !LangOpts.CPlusPlus) { 20932865474261a608c7873b87ba4af110d17907896dJohn McCall // Simple void foo(), where the incoming T is the result type. 20942865474261a608c7873b87ba4af110d17907896dJohn McCall T = Context.getFunctionNoProtoType(T); 20952865474261a608c7873b87ba4af110d17907896dJohn McCall } else { 20962865474261a608c7873b87ba4af110d17907896dJohn McCall // We allow a zero-parameter variadic function in C if the 20972865474261a608c7873b87ba4af110d17907896dJohn McCall // function is marked with the "overloadable" attribute. Scan 20982865474261a608c7873b87ba4af110d17907896dJohn McCall // for this attribute now. 20998cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (!FTI.NumArgs && FTI.isVariadic && !LangOpts.CPlusPlus) { 2100965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor bool Overloadable = false; 2101965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor for (const AttributeList *Attrs = D.getAttributes(); 2102965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor Attrs; Attrs = Attrs->getNext()) { 2103965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor if (Attrs->getKind() == AttributeList::AT_overloadable) { 2104965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor Overloadable = true; 2105965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor break; 2106965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor } 2107965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor } 2108965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor 2109965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor if (!Overloadable) 21108cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(FTI.getEllipsisLoc(), diag::err_ellipsis_first_arg); 2111c6f7345e44e079f373d6bdecaa06c7e06574dc27Argyrios Kyrtzidis } 21122865474261a608c7873b87ba4af110d17907896dJohn McCall 21132865474261a608c7873b87ba4af110d17907896dJohn McCall if (FTI.NumArgs && FTI.ArgInfo[0].Param == 0) { 2114788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner // C99 6.7.5.3p3: Reject int(x,y,z) when it's not a function 2115788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner // definition. 21168cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(FTI.ArgInfo[0].IdentLoc, diag::err_ident_list_in_fn_declaration); 21172865474261a608c7873b87ba4af110d17907896dJohn McCall D.setInvalidType(true); 21182865474261a608c7873b87ba4af110d17907896dJohn McCall break; 21192865474261a608c7873b87ba4af110d17907896dJohn McCall } 21202865474261a608c7873b87ba4af110d17907896dJohn McCall 2121e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI; 2122e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.Variadic = FTI.isVariadic; 2123e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.TypeQuals = FTI.TypeQuals; 2124c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor EPI.RefQualifier = !FTI.hasRefQualifier()? RQ_None 2125c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor : FTI.RefQualifierIsLValueRef? RQ_LValue 2126c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor : RQ_RValue; 2127c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 21285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Otherwise, we have a function with an argument list that is 21295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // potentially variadic. 21305f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 16> ArgTys; 21312865474261a608c7873b87ba4af110d17907896dJohn McCall ArgTys.reserve(FTI.NumArgs); 21321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21335f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<bool, 16> ConsumedArguments; 2134f85e193739c953358c865005855253af4f68a497John McCall ConsumedArguments.reserve(FTI.NumArgs); 2135f85e193739c953358c865005855253af4f68a497John McCall bool HasAnyConsumedArguments = false; 2136f85e193739c953358c865005855253af4f68a497John McCall 21375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) { 2138d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParmVarDecl *Param = cast<ParmVarDecl>(FTI.ArgInfo[i].Param); 21398123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner QualType ArgTy = Param->getType(); 214078c75fb3d275079c5fab30eeb33077958f2b0265Chris Lattner assert(!ArgTy.isNull() && "Couldn't parse type?"); 21412dc0e64e57b2a1786fa53a7dbd1d5c8e255eadb0Douglas Gregor 21422dc0e64e57b2a1786fa53a7dbd1d5c8e255eadb0Douglas Gregor // Adjust the parameter type. 214379e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor assert((ArgTy == Context.getAdjustedParameterType(ArgTy)) && 214479e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor "Unadjusted type?"); 21452dc0e64e57b2a1786fa53a7dbd1d5c8e255eadb0Douglas Gregor 21465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Look for 'void'. void is allowed only as a single argument to a 21475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // function with no other parameters (C99 6.7.5.3p10). We record 214872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // int(void) as a FunctionProtoType with an empty argument list. 21492dc0e64e57b2a1786fa53a7dbd1d5c8e255eadb0Douglas Gregor if (ArgTy->isVoidType()) { 21505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If this is something like 'float(int, void)', reject it. 'void' 21515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // is an incomplete type (C99 6.2.5p19) and function decls cannot 21525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // have arguments of incomplete type. 21535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (FTI.NumArgs != 1 || FTI.isVariadic) { 21548cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(DeclType.Loc, diag::err_void_only_param); 21552ff5426cd83ae02378efacdfeb70d6785eb09a30Chris Lattner ArgTy = Context.IntTy; 21568123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner Param->setType(ArgTy); 21572ff5426cd83ae02378efacdfeb70d6785eb09a30Chris Lattner } else if (FTI.ArgInfo[i].Ident) { 21582ff5426cd83ae02378efacdfeb70d6785eb09a30Chris Lattner // Reject, but continue to parse 'int(void abc)'. 21598cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(FTI.ArgInfo[i].IdentLoc, 21604565d4e83cec55356fe9c75929579eacced9da36Chris Lattner diag::err_param_with_void_type); 21612ff5426cd83ae02378efacdfeb70d6785eb09a30Chris Lattner ArgTy = Context.IntTy; 21628123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner Param->setType(ArgTy); 21632ff5426cd83ae02378efacdfeb70d6785eb09a30Chris Lattner } else { 21642ff5426cd83ae02378efacdfeb70d6785eb09a30Chris Lattner // Reject, but continue to parse 'float(const void)'. 21650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (ArgTy.hasQualifiers()) 21668cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(DeclType.Loc, diag::err_void_param_qualified); 21671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21682ff5426cd83ae02378efacdfeb70d6785eb09a30Chris Lattner // Do not add 'void' to the ArgTys list. 21692ff5426cd83ae02378efacdfeb70d6785eb09a30Chris Lattner break; 21702ff5426cd83ae02378efacdfeb70d6785eb09a30Chris Lattner } 2171eb4b7051a596560ef4a1846e3714707f44e9dc30Eli Friedman } else if (!FTI.hasPrototype) { 2172eb4b7051a596560ef4a1846e3714707f44e9dc30Eli Friedman if (ArgTy->isPromotableIntegerType()) { 2173a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman ArgTy = Context.getPromotedIntegerType(ArgTy); 2174eecf5fa12d5426637c47d7072f0c193a8d7ff68bJohn McCall Param->setKNRPromoted(true); 2175183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall } else if (const BuiltinType* BTy = ArgTy->getAs<BuiltinType>()) { 2176eecf5fa12d5426637c47d7072f0c193a8d7ff68bJohn McCall if (BTy->getKind() == BuiltinType::Float) { 2177eb4b7051a596560ef4a1846e3714707f44e9dc30Eli Friedman ArgTy = Context.DoubleTy; 2178eecf5fa12d5426637c47d7072f0c193a8d7ff68bJohn McCall Param->setKNRPromoted(true); 2179eecf5fa12d5426637c47d7072f0c193a8d7ff68bJohn McCall } 2180eb4b7051a596560ef4a1846e3714707f44e9dc30Eli Friedman } 21815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 218256a965c0f77c9e6bffd65cc8f8796442a8527381Fariborz Jahanian 21838cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (LangOpts.ObjCAutoRefCount) { 2184f85e193739c953358c865005855253af4f68a497John McCall bool Consumed = Param->hasAttr<NSConsumedAttr>(); 2185f85e193739c953358c865005855253af4f68a497John McCall ConsumedArguments.push_back(Consumed); 2186f85e193739c953358c865005855253af4f68a497John McCall HasAnyConsumedArguments |= Consumed; 2187f85e193739c953358c865005855253af4f68a497John McCall } 2188f85e193739c953358c865005855253af4f68a497John McCall 218954e14c4db764c0636160d26c5bbf491637c83a76John McCall ArgTys.push_back(ArgTy); 21905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2191465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2192f85e193739c953358c865005855253af4f68a497John McCall if (HasAnyConsumedArguments) 2193f85e193739c953358c865005855253af4f68a497John McCall EPI.ConsumedArguments = ConsumedArguments.data(); 2194f85e193739c953358c865005855253af4f68a497John McCall 21955f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 4> Exceptions; 21968b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl EPI.ExceptionSpecType = FTI.getExceptionSpecType(); 21978b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl if (FTI.getExceptionSpecType() == EST_Dynamic) { 2198e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall Exceptions.reserve(FTI.NumExceptions); 2199e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall for (unsigned ei = 0, ee = FTI.NumExceptions; ei != ee; ++ei) { 2200e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall // FIXME: Preserve type source info. 22018cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis QualType ET = S.GetTypeFromParser(FTI.Exceptions[ei].Ty); 2202e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall // Check that the type is valid for an exception spec, and 2203e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall // drop it if not. 22048cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (!S.CheckSpecifiedExceptionType(ET, FTI.Exceptions[ei].Range)) 2205e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall Exceptions.push_back(ET); 2206e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall } 2207373920bd733b1d28fe7bf209945a62eb9248d948John McCall EPI.NumExceptions = Exceptions.size(); 2208e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.Exceptions = Exceptions.data(); 22098b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl } else if (FTI.getExceptionSpecType() == EST_ComputedNoexcept) { 221060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // If an error occurred, there's no expression here. 221160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (Expr *NoexceptExpr = FTI.NoexceptExpr) { 221260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl assert((NoexceptExpr->isTypeDependent() || 221360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NoexceptExpr->getType()->getCanonicalTypeUnqualified() == 221460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Context.BoolTy) && 221560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl "Parser should have made sure that the expression is boolean"); 221660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl SourceLocation ErrLoc; 221760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl llvm::APSInt Dummy; 221860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (!NoexceptExpr->isValueDependent() && 221960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl !NoexceptExpr->isIntegerConstantExpr(Dummy, Context, &ErrLoc, 222060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /*evaluated*/false)) 22218cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(ErrLoc, diag::err_noexcept_needs_constant_expression) 222260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl << NoexceptExpr->getSourceRange(); 222360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl else 222460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.NoexceptExpr = NoexceptExpr; 222560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 22268999fe1bc367b3ecc878d135c7b31e3479da56f4Sebastian Redl } else if (FTI.getExceptionSpecType() == EST_None && 22278999fe1bc367b3ecc878d135c7b31e3479da56f4Sebastian Redl ImplicitlyNoexcept && chunkIndex == 0) { 22288999fe1bc367b3ecc878d135c7b31e3479da56f4Sebastian Redl // Only the outermost chunk is marked noexcept, of course. 22298999fe1bc367b3ecc878d135c7b31e3479da56f4Sebastian Redl EPI.ExceptionSpecType = EST_BasicNoexcept; 2230ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl } 2231465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2232e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall T = Context.getFunctionType(T, ArgTys.data(), ArgTys.size(), EPI); 22335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 223404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 22355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 22365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2237f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::MemberPointer: 2238f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // The scope spec must refer to a class, or be dependent. 22397bd067635df79f6ce4b9ffee394ea6d9e86e4290Abramo Bagnara CXXScopeSpec &SS = DeclType.Mem.Scope(); 2240f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType ClsType; 22417bd067635df79f6ce4b9ffee394ea6d9e86e4290Abramo Bagnara if (SS.isInvalid()) { 2242edc287751a4b05e3b4d8ff2b38fa30c5b59a548bJeffrey Yasskin // Avoid emitting extra errors if we already errored on the scope. 2243edc287751a4b05e3b4d8ff2b38fa30c5b59a548bJeffrey Yasskin D.setInvalidType(true); 22448cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis } else if (S.isDependentScopeSpecifier(SS) || 22458cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis dyn_cast_or_null<CXXRecordDecl>(S.computeDeclContext(SS))) { 22461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *NNS 22477bd067635df79f6ce4b9ffee394ea6d9e86e4290Abramo Bagnara = static_cast<NestedNameSpecifier*>(SS.getScopeRep()); 224887c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor NestedNameSpecifier *NNSPrefix = NNS->getPrefix(); 224987c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor switch (NNS->getKind()) { 225087c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor case NestedNameSpecifier::Identifier: 22517bd067635df79f6ce4b9ffee394ea6d9e86e4290Abramo Bagnara ClsType = Context.getDependentNameType(ETK_None, NNSPrefix, 22524a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor NNS->getAsIdentifier()); 225387c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor break; 225487c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor 225587c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor case NestedNameSpecifier::Namespace: 225614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor case NestedNameSpecifier::NamespaceAlias: 225787c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor case NestedNameSpecifier::Global: 22589f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("Nested-name-specifier must name a type"); 225987c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor break; 22607bd067635df79f6ce4b9ffee394ea6d9e86e4290Abramo Bagnara 226187c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor case NestedNameSpecifier::TypeSpec: 226287c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 226387c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor ClsType = QualType(NNS->getAsType(), 0); 226491ce2c4484e56cdc8068cebaaf2bb42362b0e1a6Abramo Bagnara // Note: if the NNS has a prefix and ClsType is a nondependent 226591ce2c4484e56cdc8068cebaaf2bb42362b0e1a6Abramo Bagnara // TemplateSpecializationType, then the NNS prefix is NOT included 226691ce2c4484e56cdc8068cebaaf2bb42362b0e1a6Abramo Bagnara // in ClsType; hence we wrap ClsType into an ElaboratedType. 226791ce2c4484e56cdc8068cebaaf2bb42362b0e1a6Abramo Bagnara // NOTE: in particular, no wrap occurs if ClsType already is an 226891ce2c4484e56cdc8068cebaaf2bb42362b0e1a6Abramo Bagnara // Elaborated, DependentName, or DependentTemplateSpecialization. 226991ce2c4484e56cdc8068cebaaf2bb42362b0e1a6Abramo Bagnara if (NNSPrefix && isa<TemplateSpecializationType>(NNS->getAsType())) 22707bd067635df79f6ce4b9ffee394ea6d9e86e4290Abramo Bagnara ClsType = Context.getElaboratedType(ETK_None, NNSPrefix, ClsType); 227187c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor break; 227287c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor } 2273f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } else { 22748cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(DeclType.Mem.Scope().getBeginLoc(), 2275949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor diag::err_illegal_decl_mempointer_in_nonclass) 2276949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor << (D.getIdentifier() ? D.getIdentifier()->getName() : "type name") 2277949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor << DeclType.Mem.Scope().getRange(); 2278f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl D.setInvalidType(true); 2279f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 2280f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2281949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor if (!ClsType.isNull()) 22828cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildMemberPointerType(T, ClsType, DeclType.Loc, D.getIdentifier()); 2283949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor if (T.isNull()) { 2284f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl T = Context.IntTy; 2285949bf69136e07fb7968d84bc21d9272ff343ffdbDouglas Gregor D.setInvalidType(true); 22862865474261a608c7873b87ba4af110d17907896dJohn McCall } else if (DeclType.Mem.TypeQuals) { 22878cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Mem.TypeQuals); 2288f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 2289f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl break; 2290f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 2291f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2292cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor if (T.isNull()) { 2293cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor D.setInvalidType(true); 2294cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor T = Context.IntTy; 2295cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor } 2296cd281c3ded486ced5aad29dd7c3fa22b7514c3d8Douglas Gregor 2297c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner // See if there are any attributes on this declarator chunk. 2298711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (AttributeList *attrs = const_cast<AttributeList*>(DeclType.getAttrs())) 2299711c52bb20d0c69063b52a99826fb7d2835501f1John McCall processTypeAttrs(state, T, false, attrs); 23005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2301971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 23028cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (LangOpts.CPlusPlus && T->isFunctionType()) { 2303183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionProtoType *FnTy = T->getAs<FunctionProtoType>(); 2304778ed741de8ada0049b89608af0abdb5ae6e106eChris Lattner assert(FnTy && "Why oh why is there not a FunctionProtoType here?"); 2305971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 2306708f3b8e350a5c0605889a4f32b26686864495caDouglas Gregor // C++ 8.3.5p4: 2307708f3b8e350a5c0605889a4f32b26686864495caDouglas Gregor // A cv-qualifier-seq shall only be part of the function type 2308708f3b8e350a5c0605889a4f32b26686864495caDouglas Gregor // for a nonstatic member function, the function type to which a pointer 2309708f3b8e350a5c0605889a4f32b26686864495caDouglas Gregor // to member refers, or the top-level function type of a function typedef 2310708f3b8e350a5c0605889a4f32b26686864495caDouglas Gregor // declaration. 2311683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor // 2312683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor // Core issue 547 also allows cv-qualifiers on function types that are 2313683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor // top-level template type arguments. 2314613ef3d4c144f8c35224daf28a187426d2044aeeJohn McCall bool FreeFunction; 2315613ef3d4c144f8c35224daf28a187426d2044aeeJohn McCall if (!D.getCXXScopeSpec().isSet()) { 2316613ef3d4c144f8c35224daf28a187426d2044aeeJohn McCall FreeFunction = (D.getContext() != Declarator::MemberContext || 2317613ef3d4c144f8c35224daf28a187426d2044aeeJohn McCall D.getDeclSpec().isFriendSpecified()); 2318613ef3d4c144f8c35224daf28a187426d2044aeeJohn McCall } else { 23198cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis DeclContext *DC = S.computeDeclContext(D.getCXXScopeSpec()); 2320613ef3d4c144f8c35224daf28a187426d2044aeeJohn McCall FreeFunction = (DC && !DC->isRecord()); 2321613ef3d4c144f8c35224daf28a187426d2044aeeJohn McCall } 2322613ef3d4c144f8c35224daf28a187426d2044aeeJohn McCall 2323c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor // C++0x [dcl.fct]p6: 2324c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor // A ref-qualifier shall only be part of the function type for a 2325c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor // non-static member function, the function type to which a pointer to 2326c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor // member refers, or the top-level function type of a function typedef 2327c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor // declaration. 2328c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor if ((FnTy->getTypeQuals() != 0 || FnTy->getRefQualifier()) && 2329683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor !(D.getContext() == Declarator::TemplateTypeArgContext && 2330162e1c1b487352434552147967c3dd296ebee2f7Richard Smith !D.isFunctionDeclarator()) && !IsTypedefName && 2331c61bb2056148891375bfa591fa2859b9b6ec2734Sebastian Redl (FreeFunction || 2332971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static)) { 2333683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor if (D.getContext() == Declarator::TemplateTypeArgContext) { 2334683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor // Accept qualified function types as template type arguments as a GNU 2335683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor // extension. This is also the subject of C++ core issue 547. 2336683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor std::string Quals; 2337683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor if (FnTy->getTypeQuals() != 0) 2338683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Quals = Qualifiers::fromCVRMask(FnTy->getTypeQuals()).getAsString(); 2339683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor 2340683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor switch (FnTy->getRefQualifier()) { 2341683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor case RQ_None: 2342683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor break; 2343683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor 2344683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor case RQ_LValue: 2345683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor if (!Quals.empty()) 2346683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Quals += ' '; 2347683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Quals += '&'; 2348683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor break; 2349c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 2350683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor case RQ_RValue: 2351683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor if (!Quals.empty()) 2352683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Quals += ' '; 2353683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Quals += "&&"; 2354683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor break; 2355683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor } 2356683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor 23578cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getIdentifierLoc(), 2358683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor diag::ext_qualified_function_type_template_arg) 2359683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor << Quals; 2360683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor } else { 2361683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor if (FnTy->getTypeQuals() != 0) { 2362683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor if (D.isFunctionDeclarator()) 23638cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getIdentifierLoc(), 2364683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor diag::err_invalid_qualified_function_type); 2365683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor else 23668cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getIdentifierLoc(), 2367683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor diag::err_invalid_qualified_typedef_function_type_use) 2368683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor << FreeFunction; 2369683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor } 2370683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor 2371683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor if (FnTy->getRefQualifier()) { 2372683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor if (D.isFunctionDeclarator()) { 2373683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor SourceLocation Loc = D.getIdentifierLoc(); 2374683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) { 2375683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor const DeclaratorChunk &Chunk = D.getTypeObject(N-I-1); 2376683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor if (Chunk.Kind == DeclaratorChunk::Function && 2377683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Chunk.Fun.hasRefQualifier()) { 2378683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Loc = Chunk.Fun.getRefQualifierLoc(); 2379683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor break; 2380683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor } 2381944aa60777e6ea1015c9423107f7925f6d91f4a0Douglas Gregor } 2382944aa60777e6ea1015c9423107f7925f6d91f4a0Douglas Gregor 23838cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(Loc, diag::err_invalid_ref_qualifier_function_type) 2384683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor << (FnTy->getRefQualifier() == RQ_LValue) 2385683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor << FixItHint::CreateRemoval(Loc); 2386683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor } else { 23878cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getIdentifierLoc(), 2388683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor diag::err_invalid_ref_qualifier_typedef_function_type_use) 2389683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor << FreeFunction 2390683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor << (FnTy->getRefQualifier() == RQ_LValue); 2391683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor } 2392c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor } 2393c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 2394683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor // Strip the cv-qualifiers and ref-qualifiers from the type. 2395683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor FunctionProtoType::ExtProtoInfo EPI = FnTy->getExtProtoInfo(); 2396683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor EPI.TypeQuals = 0; 2397683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor EPI.RefQualifier = RQ_None; 2398c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 2399683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor T = Context.getFunctionType(FnTy->getResultType(), 2400683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor FnTy->arg_type_begin(), 2401683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor FnTy->getNumArgs(), EPI); 2402683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor } 2403971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis } 2404971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis } 24051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2406711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Apply any undistributed attributes from the declarator. 2407711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!T.isNull()) 2408711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (AttributeList *attrs = D.getAttributes()) 2409711c52bb20d0c69063b52a99826fb7d2835501f1John McCall processTypeAttrs(state, T, false, attrs); 2410711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 2411711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Diagnose any ignored type attributes. 2412711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!T.isNull()) state.diagnoseIgnoredTypeAttrs(T); 2413711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 2414148f1f7936afd718bac7be95089e77673e43f16fPeter Collingbourne // C++0x [dcl.constexpr]p9: 2415148f1f7936afd718bac7be95089e77673e43f16fPeter Collingbourne // A constexpr specifier used in an object declaration declares the object 2416148f1f7936afd718bac7be95089e77673e43f16fPeter Collingbourne // as const. 2417148f1f7936afd718bac7be95089e77673e43f16fPeter Collingbourne if (D.getDeclSpec().isConstexprSpecified() && T->isObjectType()) { 2418737801257f795632175517ffce4a80c62fc7bff7Sebastian Redl T.addConst(); 2419737801257f795632175517ffce4a80c62fc7bff7Sebastian Redl } 2420737801257f795632175517ffce4a80c62fc7bff7Sebastian Redl 2421a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // If there was an ellipsis in the declarator, the declaration declares a 2422a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // parameter pack whose type may be a pack expansion type. 2423a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor if (D.hasEllipsis() && !T.isNull()) { 2424a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // C++0x [dcl.fct]p13: 2425a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // A declarator-id or abstract-declarator containing an ellipsis shall 2426a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // only be used in a parameter-declaration. Such a parameter-declaration 2427a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // is a parameter pack (14.5.3). [...] 2428a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor switch (D.getContext()) { 2429a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::PrototypeContext: 2430a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // C++0x [dcl.fct]p13: 2431a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // [...] When it is part of a parameter-declaration-clause, the 2432a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // parameter pack is a function parameter pack (14.5.3). The type T 2433a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // of the declarator-id of the function parameter pack shall contain 2434a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // a template parameter pack; each template parameter pack in T is 2435a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // expanded by the function parameter pack. 2436a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // 2437a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // We represent function parameter packs as function parameters whose 2438a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // type is a pack expansion. 2439a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor if (!T->containsUnexpandedParameterPack()) { 24408cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getEllipsisLoc(), 2441a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor diag::err_function_parameter_pack_without_parameter_packs) 2442a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor << T << D.getSourceRange(); 2443a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor D.setEllipsisLoc(SourceLocation()); 2444a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor } else { 2445cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor T = Context.getPackExpansionType(T, llvm::Optional<unsigned>()); 2446a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor } 2447a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor break; 2448a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor 2449a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::TemplateParamContext: 2450a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // C++0x [temp.param]p15: 2451a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // If a template-parameter is a [...] is a parameter-declaration that 2452a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // declares a parameter pack (8.3.5), then the template-parameter is a 2453a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // template parameter pack (14.5.3). 2454a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // 2455a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // Note: core issue 778 clarifies that, if there are any unexpanded 2456a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // parameter packs in the type of the non-type template parameter, then 2457a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // it expands those parameter packs. 2458a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor if (T->containsUnexpandedParameterPack()) 2459cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor T = Context.getPackExpansionType(T, llvm::Optional<unsigned>()); 24608cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis else if (!LangOpts.CPlusPlus0x) 24618cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getEllipsisLoc(), diag::ext_variadic_templates); 2462a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor break; 2463a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor 2464a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::FileContext: 2465a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::KNRTypeListContext: 2466c05a94b7accd4035bf5d5897c434c445b22da855John McCall case Declarator::ObjCPrototypeContext: // FIXME: special diagnostic here? 2467a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::TypeNameContext: 24680b8c98f3ddf83adcb9e9d98b68ce38e970cdee73Argyrios Kyrtzidis case Declarator::CXXNewContext: 2469162e1c1b487352434552147967c3dd296ebee2f7Richard Smith case Declarator::AliasDeclContext: 24703e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith case Declarator::AliasTemplateContext: 2471a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::MemberContext: 2472a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::BlockContext: 2473a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::ForContext: 2474a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::ConditionContext: 2475a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::CXXCatchContext: 247617b6399f8461c5b7e1c6f367b0a0dde49f921240Argyrios Kyrtzidis case Declarator::ObjCCatchContext: 2477a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor case Declarator::BlockLiteralContext: 2478683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor case Declarator::TemplateTypeArgContext: 2479a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // FIXME: We may want to allow parameter packs in block-literal contexts 2480a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // in the future. 24818cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis S.Diag(D.getEllipsisLoc(), diag::err_ellipsis_in_declarator_not_parameter); 2482a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor D.setEllipsisLoc(SourceLocation()); 2483a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor break; 2484a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor } 2485a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor } 2486e7397c6a1bb2b205c5fe678e26199eb26d22e38eRichard Smith 2487bf1a028246d884a540aeafa38e89be59a269b072John McCall if (T.isNull()) 2488bf1a028246d884a540aeafa38e89be59a269b072John McCall return Context.getNullTypeSourceInfo(); 2489bf1a028246d884a540aeafa38e89be59a269b072John McCall else if (D.isInvalidType()) 2490bf1a028246d884a540aeafa38e89be59a269b072John McCall return Context.getTrivialTypeSourceInfo(T); 2491db7abf78dedc2ef6ccb42b3dac6ab330fe2ea469Argyrios Kyrtzidis 24928cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis return S.GetTypeSourceInfoForDeclarator(D, T, TInfo); 24938cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis} 24948cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis 24958cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis/// GetTypeForDeclarator - Convert the type for the specified 24968cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis/// declarator to Type instances. 24978cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis/// 24988cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis/// The result of this call will never be null, but the associated 24998cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis/// type may be a null type if there's an unrecoverable error. 25008cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios KyrtzidisTypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { 25018cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // Determine the type of the declarator. Not all forms of declarator 25028cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis // have a type. 25038cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis 25048cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis TypeProcessingState state(*this, D); 25058cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis 25068cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis TypeSourceInfo *ReturnTypeInfo = 0; 25078cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis QualType T = GetDeclSpecTypeForDeclarator(state, ReturnTypeInfo); 25088cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (T.isNull()) 25098cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis return Context.getNullTypeSourceInfo(); 25108cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis 25118cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis if (D.isPrototypeContext() && getLangOptions().ObjCAutoRefCount) 25128cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis inferARCWriteback(state, T); 2513db7abf78dedc2ef6ccb42b3dac6ab330fe2ea469Argyrios Kyrtzidis 25148cfa57b348d4d5a58d92764a60280bf88e4e49aeArgyrios Kyrtzidis return GetFullTypeForDeclarator(state, T, ReturnTypeInfo); 25155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 25165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 251731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidisstatic void transferARCOwnershipToDeclSpec(Sema &S, 251831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis QualType &declSpecTy, 251931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis Qualifiers::ObjCLifetime ownership) { 252031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (declSpecTy->isObjCRetainableType() && 252131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis declSpecTy.getObjCLifetime() == Qualifiers::OCL_None) { 252231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis Qualifiers qs; 252331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis qs.addObjCLifetime(ownership); 252431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis declSpecTy = S.Context.getQualifiedType(declSpecTy, qs); 252531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis } 252631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis} 252731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 252831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidisstatic void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state, 252931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis Qualifiers::ObjCLifetime ownership, 253031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis unsigned chunkIndex) { 253131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis Sema &S = state.getSema(); 253231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis Declarator &D = state.getDeclarator(); 253331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 253431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis // Look for an explicit lifetime attribute. 253531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis DeclaratorChunk &chunk = D.getTypeObject(chunkIndex); 253631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis for (const AttributeList *attr = chunk.getAttrs(); attr; 253731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis attr = attr->getNext()) 253831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (attr->getKind() == AttributeList::AT_objc_ownership) 253931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return; 254031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 254131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis const char *attrStr = 0; 254231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis switch (ownership) { 254331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case Qualifiers::OCL_None: llvm_unreachable("no ownership!"); break; 254431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case Qualifiers::OCL_ExplicitNone: attrStr = "none"; break; 254531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case Qualifiers::OCL_Strong: attrStr = "strong"; break; 254631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case Qualifiers::OCL_Weak: attrStr = "weak"; break; 254731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case Qualifiers::OCL_Autoreleasing: attrStr = "autoreleasing"; break; 254831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis } 254931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 255031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis // If there wasn't one, add one (with an invalid source location 255131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis // so that we don't make an AttributedType for it). 255231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis AttributeList *attr = D.getAttributePool() 255331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis .create(&S.Context.Idents.get("objc_ownership"), SourceLocation(), 255431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis /*scope*/ 0, SourceLocation(), 255531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis &S.Context.Idents.get(attrStr), SourceLocation(), 255631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis /*args*/ 0, 0, 255731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis /*declspec*/ false, /*C++0x*/ false); 255831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis spliceAttrIntoList(*attr, chunk.getAttrListRef()); 255931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 256031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis // TODO: mark whether we did this inference? 256131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis} 256231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 256331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidisstatic void transferARCOwnership(TypeProcessingState &state, 256431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis QualType &declSpecTy, 256531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis Qualifiers::ObjCLifetime ownership) { 256631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis Sema &S = state.getSema(); 256731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis Declarator &D = state.getDeclarator(); 256831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 256931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis int inner = -1; 257031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { 257131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis DeclaratorChunk &chunk = D.getTypeObject(i); 257231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis switch (chunk.Kind) { 257331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case DeclaratorChunk::Paren: 257431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis // Ignore parens. 257531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis break; 257631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 257731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case DeclaratorChunk::Array: 257831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case DeclaratorChunk::Reference: 257931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case DeclaratorChunk::Pointer: 258031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis inner = i; 258131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis break; 258231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 258331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case DeclaratorChunk::BlockPointer: 258431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return transferARCOwnershipToDeclaratorChunk(state, ownership, i); 258531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 258631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case DeclaratorChunk::Function: 258731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis case DeclaratorChunk::MemberPointer: 258831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return; 258931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis } 259031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis } 259131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 259231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (inner == -1) 259331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return transferARCOwnershipToDeclSpec(S, declSpecTy, ownership); 259431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 259531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis DeclaratorChunk &chunk = D.getTypeObject(inner); 259631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (chunk.Kind == DeclaratorChunk::Pointer) { 259731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (declSpecTy->isObjCRetainableType()) 259831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return transferARCOwnershipToDeclSpec(S, declSpecTy, ownership); 259931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (declSpecTy->isObjCObjectType()) 260031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return transferARCOwnershipToDeclaratorChunk(state, ownership, inner); 260131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis } else { 260231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis assert(chunk.Kind == DeclaratorChunk::Array || 260331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis chunk.Kind == DeclaratorChunk::Reference); 260431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return transferARCOwnershipToDeclSpec(S, declSpecTy, ownership); 260531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis } 260631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis} 260731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 260831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios KyrtzidisTypeSourceInfo *Sema::GetTypeForDeclaratorCast(Declarator &D, QualType FromTy) { 260931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis TypeProcessingState state(*this, D); 261031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 261131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis TypeSourceInfo *ReturnTypeInfo = 0; 261231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis QualType declSpecTy = GetDeclSpecTypeForDeclarator(state, ReturnTypeInfo); 261331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (declSpecTy.isNull()) 261431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return Context.getNullTypeSourceInfo(); 261531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 261631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (getLangOptions().ObjCAutoRefCount) { 261731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis Qualifiers::ObjCLifetime ownership = Context.getInnerObjCOwnership(FromTy); 261831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (ownership != Qualifiers::OCL_None) 261931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis transferARCOwnership(state, declSpecTy, ownership); 262031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis } 262131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 262231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return GetFullTypeForDeclarator(state, declSpecTy, ReturnTypeInfo); 262331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis} 262431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 262514aa2175416f79ef17811282afbf425f87d54ebfJohn McCall/// Map an AttributedType::Kind to an AttributeList::Kind. 262614aa2175416f79ef17811282afbf425f87d54ebfJohn McCallstatic AttributeList::Kind getAttrListKind(AttributedType::Kind kind) { 262714aa2175416f79ef17811282afbf425f87d54ebfJohn McCall switch (kind) { 262814aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_address_space: 262914aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_address_space; 263014aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_regparm: 263114aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_regparm; 263214aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_vector_size: 263314aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_vector_size; 263414aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_neon_vector_type: 263514aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_neon_vector_type; 263614aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_neon_polyvector_type: 263714aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_neon_polyvector_type; 263814aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_objc_gc: 263914aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_objc_gc; 2640b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis case AttributedType::attr_objc_ownership: 2641b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis return AttributeList::AT_objc_ownership; 264214aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_noreturn: 264314aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_noreturn; 264414aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_cdecl: 264514aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_cdecl; 264614aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_fastcall: 264714aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_fastcall; 264814aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_stdcall: 264914aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_stdcall; 265014aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_thiscall: 265114aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_thiscall; 265214aa2175416f79ef17811282afbf425f87d54ebfJohn McCall case AttributedType::attr_pascal: 265314aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::AT_pascal; 2654414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case AttributedType::attr_pcs: 2655414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov return AttributeList::AT_pcs; 265614aa2175416f79ef17811282afbf425f87d54ebfJohn McCall } 265714aa2175416f79ef17811282afbf425f87d54ebfJohn McCall llvm_unreachable("unexpected attribute kind!"); 265814aa2175416f79ef17811282afbf425f87d54ebfJohn McCall return AttributeList::Kind(); 265914aa2175416f79ef17811282afbf425f87d54ebfJohn McCall} 266014aa2175416f79ef17811282afbf425f87d54ebfJohn McCall 266114aa2175416f79ef17811282afbf425f87d54ebfJohn McCallstatic void fillAttributedTypeLoc(AttributedTypeLoc TL, 266214aa2175416f79ef17811282afbf425f87d54ebfJohn McCall const AttributeList *attrs) { 266314aa2175416f79ef17811282afbf425f87d54ebfJohn McCall AttributedType::Kind kind = TL.getAttrKind(); 266414aa2175416f79ef17811282afbf425f87d54ebfJohn McCall 266514aa2175416f79ef17811282afbf425f87d54ebfJohn McCall assert(attrs && "no type attributes in the expected location!"); 266614aa2175416f79ef17811282afbf425f87d54ebfJohn McCall AttributeList::Kind parsedKind = getAttrListKind(kind); 266714aa2175416f79ef17811282afbf425f87d54ebfJohn McCall while (attrs->getKind() != parsedKind) { 266814aa2175416f79ef17811282afbf425f87d54ebfJohn McCall attrs = attrs->getNext(); 266914aa2175416f79ef17811282afbf425f87d54ebfJohn McCall assert(attrs && "no matching attribute in expected location!"); 267014aa2175416f79ef17811282afbf425f87d54ebfJohn McCall } 267114aa2175416f79ef17811282afbf425f87d54ebfJohn McCall 267214aa2175416f79ef17811282afbf425f87d54ebfJohn McCall TL.setAttrNameLoc(attrs->getLoc()); 267314aa2175416f79ef17811282afbf425f87d54ebfJohn McCall if (TL.hasAttrExprOperand()) 267414aa2175416f79ef17811282afbf425f87d54ebfJohn McCall TL.setAttrExprOperand(attrs->getArg(0)); 267514aa2175416f79ef17811282afbf425f87d54ebfJohn McCall else if (TL.hasAttrEnumOperand()) 267614aa2175416f79ef17811282afbf425f87d54ebfJohn McCall TL.setAttrEnumOperandLoc(attrs->getParameterLoc()); 267714aa2175416f79ef17811282afbf425f87d54ebfJohn McCall 267814aa2175416f79ef17811282afbf425f87d54ebfJohn McCall // FIXME: preserve this information to here. 267914aa2175416f79ef17811282afbf425f87d54ebfJohn McCall if (TL.hasAttrOperand()) 268014aa2175416f79ef17811282afbf425f87d54ebfJohn McCall TL.setAttrOperandParensRange(SourceRange()); 268114aa2175416f79ef17811282afbf425f87d54ebfJohn McCall} 268214aa2175416f79ef17811282afbf425f87d54ebfJohn McCall 268351bd803fbdade51d674598ed45da3d54190a656cJohn McCallnamespace { 268451bd803fbdade51d674598ed45da3d54190a656cJohn McCall class TypeSpecLocFiller : public TypeLocVisitor<TypeSpecLocFiller> { 2685c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor ASTContext &Context; 268651bd803fbdade51d674598ed45da3d54190a656cJohn McCall const DeclSpec &DS; 2687f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 268851bd803fbdade51d674598ed45da3d54190a656cJohn McCall public: 2689c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TypeSpecLocFiller(ASTContext &Context, const DeclSpec &DS) 2690c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor : Context(Context), DS(DS) {} 2691f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 269214aa2175416f79ef17811282afbf425f87d54ebfJohn McCall void VisitAttributedTypeLoc(AttributedTypeLoc TL) { 269314aa2175416f79ef17811282afbf425f87d54ebfJohn McCall fillAttributedTypeLoc(TL, DS.getAttributes().getList()); 269414aa2175416f79ef17811282afbf425f87d54ebfJohn McCall Visit(TL.getModifiedLoc()); 269514aa2175416f79ef17811282afbf425f87d54ebfJohn McCall } 269651bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { 269751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Visit(TL.getUnqualifiedLoc()); 269851bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 269951bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitTypedefTypeLoc(TypedefTypeLoc TL) { 270051bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setNameLoc(DS.getTypeSpecTypeLoc()); 270151bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 270251bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { 270351bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setNameLoc(DS.getTypeSpecTypeLoc()); 2704c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 2705c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall void VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { 2706c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Handle the base type, which might not have been written explicitly. 2707c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (DS.getTypeSpecType() == DeclSpec::TST_unspecified) { 2708c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TL.setHasBaseTypeAsWritten(false); 2709c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TL.getBaseLoc().initialize(Context, SourceLocation()); 2710c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } else { 2711c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TL.setHasBaseTypeAsWritten(true); 2712c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Visit(TL.getBaseLoc()); 2713c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 271454e14c4db764c0636160d26c5bbf491637c83a76John McCall 2715c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Protocol qualifiers. 271654e14c4db764c0636160d26c5bbf491637c83a76John McCall if (DS.getProtocolQualifiers()) { 271754e14c4db764c0636160d26c5bbf491637c83a76John McCall assert(TL.getNumProtocols() > 0); 271854e14c4db764c0636160d26c5bbf491637c83a76John McCall assert(TL.getNumProtocols() == DS.getNumProtocolQualifiers()); 271954e14c4db764c0636160d26c5bbf491637c83a76John McCall TL.setLAngleLoc(DS.getProtocolLAngleLoc()); 272054e14c4db764c0636160d26c5bbf491637c83a76John McCall TL.setRAngleLoc(DS.getSourceRange().getEnd()); 272154e14c4db764c0636160d26c5bbf491637c83a76John McCall for (unsigned i = 0, e = DS.getNumProtocolQualifiers(); i != e; ++i) 272254e14c4db764c0636160d26c5bbf491637c83a76John McCall TL.setProtocolLoc(i, DS.getProtocolLocs()[i]); 272354e14c4db764c0636160d26c5bbf491637c83a76John McCall } else { 272454e14c4db764c0636160d26c5bbf491637c83a76John McCall assert(TL.getNumProtocols() == 0); 272554e14c4db764c0636160d26c5bbf491637c83a76John McCall TL.setLAngleLoc(SourceLocation()); 272654e14c4db764c0636160d26c5bbf491637c83a76John McCall TL.setRAngleLoc(SourceLocation()); 272754e14c4db764c0636160d26c5bbf491637c83a76John McCall } 272851bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 272954e14c4db764c0636160d26c5bbf491637c83a76John McCall void VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { 273054e14c4db764c0636160d26c5bbf491637c83a76John McCall TL.setStarLoc(SourceLocation()); 2731c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Visit(TL.getPointeeLoc()); 273251bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 2733833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) { 2734a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *TInfo = 0; 2735b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); 2736833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2737833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // If we got no declarator info from previous Sema routines, 2738833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // just fill with the typespec loc. 2739a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall if (!TInfo) { 27400daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara TL.initialize(Context, DS.getTypeSpecTypeNameLoc()); 2741833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return; 2742833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 2743833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2744e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TypeLoc OldTL = TInfo->getTypeLoc(); 2745e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (TInfo->getType()->getAs<ElaboratedType>()) { 2746e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeLoc ElabTL = cast<ElaboratedTypeLoc>(OldTL); 2747e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TemplateSpecializationTypeLoc NamedTL = 2748e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara cast<TemplateSpecializationTypeLoc>(ElabTL.getNamedTypeLoc()); 2749e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TL.copy(NamedTL); 2750e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 2751e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara else 2752e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TL.copy(cast<TemplateSpecializationTypeLoc>(OldTL)); 2753833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 2754cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall void VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { 2755cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall assert(DS.getTypeSpecType() == DeclSpec::TST_typeofExpr); 2756cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TL.setTypeofLoc(DS.getTypeSpecTypeLoc()); 2757cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TL.setParensRange(DS.getTypeofParensRange()); 2758cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 2759cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall void VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { 2760cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall assert(DS.getTypeSpecType() == DeclSpec::TST_typeofType); 2761cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TL.setTypeofLoc(DS.getTypeSpecTypeLoc()); 2762cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TL.setParensRange(DS.getTypeofParensRange()); 2763b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(DS.getRepAsType()); 2764cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo *TInfo = 0; 2765b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); 2766cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TL.setUnderlyingTInfo(TInfo); 2767cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 2768ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt void VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { 2769ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt // FIXME: This holds only because we only have one unary transform. 2770ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt assert(DS.getTypeSpecType() == DeclSpec::TST_underlyingType); 2771ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TL.setKWLoc(DS.getTypeSpecTypeLoc()); 2772ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TL.setParensRange(DS.getTypeofParensRange()); 2773ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt assert(DS.getRepAsType()); 2774ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TypeSourceInfo *TInfo = 0; 2775ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); 2776ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TL.setUnderlyingTInfo(TInfo); 2777ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 2778ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor void VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { 2779ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // By default, use the source location of the type specifier. 2780ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor TL.setBuiltinLoc(DS.getTypeSpecTypeLoc()); 2781ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (TL.needsExtraLocalData()) { 2782ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // Set info for the written builtin specifiers. 2783ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor TL.getWrittenBuiltinSpecs() = DS.getWrittenBuiltinSpecs(); 2784ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // Try to have a meaningful source location. 2785ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (TL.getWrittenSignSpec() != TSS_unspecified) 2786ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // Sign spec loc overrides the others (e.g., 'unsigned long'). 2787ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor TL.setBuiltinLoc(DS.getTypeSpecSignLoc()); 2788ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor else if (TL.getWrittenWidthSpec() != TSW_unspecified) 2789ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // Width spec loc overrides type spec loc (e.g., 'short int'). 2790ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor TL.setBuiltinLoc(DS.getTypeSpecWidthLoc()); 2791ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 2792ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 2793e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara void VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { 2794e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeKeyword Keyword 2795e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara = TypeWithKeyword::getKeywordForTypeSpec(DS.getTypeSpecType()); 2796253e80b019727451edb4cbcad71277fcbe05ff0eNico Weber if (DS.getTypeSpecType() == TST_typename) { 2797e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TypeSourceInfo *TInfo = 0; 2798b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); 2799e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (TInfo) { 2800e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TL.copy(cast<ElaboratedTypeLoc>(TInfo->getTypeLoc())); 2801e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara return; 2802e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 2803e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 2804e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TL.setKeywordLoc(Keyword != ETK_None 2805e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ? DS.getTypeSpecTypeLoc() 2806e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara : SourceLocation()); 2807e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara const CXXScopeSpec& SS = DS.getTypeSpecScope(); 28089e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor TL.setQualifierLoc(SS.getWithLocInContext(Context)); 2809e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara Visit(TL.getNextTypeLoc().getUnqualifiedLoc()); 2810e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 2811e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara void VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { 2812e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeKeyword Keyword 2813e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara = TypeWithKeyword::getKeywordForTypeSpec(DS.getTypeSpecType()); 2814253e80b019727451edb4cbcad71277fcbe05ff0eNico Weber if (DS.getTypeSpecType() == TST_typename) { 2815e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TypeSourceInfo *TInfo = 0; 2816b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); 2817e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (TInfo) { 2818e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TL.copy(cast<DependentNameTypeLoc>(TInfo->getTypeLoc())); 2819e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara return; 2820e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 2821e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 2822e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TL.setKeywordLoc(Keyword != ETK_None 2823e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ? DS.getTypeSpecTypeLoc() 2824e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara : SourceLocation()); 2825e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara const CXXScopeSpec& SS = DS.getTypeSpecScope(); 28262494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor TL.setQualifierLoc(SS.getWithLocInContext(Context)); 28270daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); 282833500955d731c73717af52088b7fc0e7a85681e7John McCall } 282933500955d731c73717af52088b7fc0e7a85681e7John McCall void VisitDependentTemplateSpecializationTypeLoc( 283033500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypeLoc TL) { 283133500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword 283233500955d731c73717af52088b7fc0e7a85681e7John McCall = TypeWithKeyword::getKeywordForTypeSpec(DS.getTypeSpecType()); 283333500955d731c73717af52088b7fc0e7a85681e7John McCall if (Keyword == ETK_Typename) { 283433500955d731c73717af52088b7fc0e7a85681e7John McCall TypeSourceInfo *TInfo = 0; 2835b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); 283633500955d731c73717af52088b7fc0e7a85681e7John McCall if (TInfo) { 283733500955d731c73717af52088b7fc0e7a85681e7John McCall TL.copy(cast<DependentTemplateSpecializationTypeLoc>( 283833500955d731c73717af52088b7fc0e7a85681e7John McCall TInfo->getTypeLoc())); 283933500955d731c73717af52088b7fc0e7a85681e7John McCall return; 284033500955d731c73717af52088b7fc0e7a85681e7John McCall } 284133500955d731c73717af52088b7fc0e7a85681e7John McCall } 2842c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TL.initializeLocal(Context, SourceLocation()); 284333500955d731c73717af52088b7fc0e7a85681e7John McCall TL.setKeywordLoc(Keyword != ETK_None 284433500955d731c73717af52088b7fc0e7a85681e7John McCall ? DS.getTypeSpecTypeLoc() 284533500955d731c73717af52088b7fc0e7a85681e7John McCall : SourceLocation()); 284633500955d731c73717af52088b7fc0e7a85681e7John McCall const CXXScopeSpec& SS = DS.getTypeSpecScope(); 284794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TL.setQualifierLoc(SS.getWithLocInContext(Context)); 28480daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); 28490daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara } 28500daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara void VisitTagTypeLoc(TagTypeLoc TL) { 28510daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); 2852e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 2853e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 285451bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitTypeLoc(TypeLoc TL) { 285551bd803fbdade51d674598ed45da3d54190a656cJohn McCall // FIXME: add other typespec types and change this to an assert. 2856c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TL.initialize(Context, DS.getTypeSpecTypeLoc()); 285751bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 285851bd803fbdade51d674598ed45da3d54190a656cJohn McCall }; 2859eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis 286051bd803fbdade51d674598ed45da3d54190a656cJohn McCall class DeclaratorLocFiller : public TypeLocVisitor<DeclaratorLocFiller> { 2861b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara ASTContext &Context; 286251bd803fbdade51d674598ed45da3d54190a656cJohn McCall const DeclaratorChunk &Chunk; 2863f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 286451bd803fbdade51d674598ed45da3d54190a656cJohn McCall public: 2865b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara DeclaratorLocFiller(ASTContext &Context, const DeclaratorChunk &Chunk) 2866b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara : Context(Context), Chunk(Chunk) {} 28674adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis 286851bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { 28699f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("qualified type locs not expected here!"); 287051bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 28714adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis 2872f85e193739c953358c865005855253af4f68a497John McCall void VisitAttributedTypeLoc(AttributedTypeLoc TL) { 2873f85e193739c953358c865005855253af4f68a497John McCall fillAttributedTypeLoc(TL, Chunk.getAttrs()); 2874f85e193739c953358c865005855253af4f68a497John McCall } 287551bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { 287651bd803fbdade51d674598ed45da3d54190a656cJohn McCall assert(Chunk.Kind == DeclaratorChunk::BlockPointer); 287751bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setCaretLoc(Chunk.Loc); 28784adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis } 287951bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitPointerTypeLoc(PointerTypeLoc TL) { 288051bd803fbdade51d674598ed45da3d54190a656cJohn McCall assert(Chunk.Kind == DeclaratorChunk::Pointer); 288151bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setStarLoc(Chunk.Loc); 28824adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis } 288351bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { 288451bd803fbdade51d674598ed45da3d54190a656cJohn McCall assert(Chunk.Kind == DeclaratorChunk::Pointer); 288551bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setStarLoc(Chunk.Loc); 28864adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis } 288751bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { 288851bd803fbdade51d674598ed45da3d54190a656cJohn McCall assert(Chunk.Kind == DeclaratorChunk::MemberPointer); 2889b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara const CXXScopeSpec& SS = Chunk.Mem.Scope(); 2890b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NestedNameSpecifierLoc NNSLoc = SS.getWithLocInContext(Context); 2891b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 2892b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara const Type* ClsTy = TL.getClass(); 2893b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType ClsQT = QualType(ClsTy, 0); 2894b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo *ClsTInfo = Context.CreateTypeSourceInfo(ClsQT, 0); 2895b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara // Now copy source location info into the type loc component. 2896b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeLoc ClsTL = ClsTInfo->getTypeLoc(); 2897b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara switch (NNSLoc.getNestedNameSpecifier()->getKind()) { 2898b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara case NestedNameSpecifier::Identifier: 2899b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara assert(isa<DependentNameType>(ClsTy) && "Unexpected TypeLoc"); 2900b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara { 2901fd9c42ed22fb4f7f865f7d8f8848df84ddf8262cAbramo Bagnara DependentNameTypeLoc DNTLoc = cast<DependentNameTypeLoc>(ClsTL); 2902b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara DNTLoc.setKeywordLoc(SourceLocation()); 2903b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara DNTLoc.setQualifierLoc(NNSLoc.getPrefix()); 2904b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara DNTLoc.setNameLoc(NNSLoc.getLocalBeginLoc()); 2905b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 2906b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara break; 2907b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 2908b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara case NestedNameSpecifier::TypeSpec: 2909b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara case NestedNameSpecifier::TypeSpecWithTemplate: 2910b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (isa<ElaboratedType>(ClsTy)) { 2911b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara ElaboratedTypeLoc ETLoc = *cast<ElaboratedTypeLoc>(&ClsTL); 2912b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara ETLoc.setKeywordLoc(SourceLocation()); 2913b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara ETLoc.setQualifierLoc(NNSLoc.getPrefix()); 2914b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeLoc NamedTL = ETLoc.getNamedTypeLoc(); 2915b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NamedTL.initializeFullCopy(NNSLoc.getTypeLoc()); 2916b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } else { 2917b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara ClsTL.initializeFullCopy(NNSLoc.getTypeLoc()); 2918b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 2919b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara break; 2920b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 2921b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara case NestedNameSpecifier::Namespace: 2922b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara case NestedNameSpecifier::NamespaceAlias: 2923b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara case NestedNameSpecifier::Global: 2924b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara llvm_unreachable("Nested-name-specifier must name a type"); 2925b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara break; 2926b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 2927b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 2928b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara // Finally fill in MemberPointerLocInfo fields. 292951bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setStarLoc(Chunk.Loc); 2930b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TL.setClassTInfo(ClsTInfo); 29314adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis } 293251bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { 293351bd803fbdade51d674598ed45da3d54190a656cJohn McCall assert(Chunk.Kind == DeclaratorChunk::Reference); 293454e14c4db764c0636160d26c5bbf491637c83a76John McCall // 'Amp' is misleading: this might have been originally 293554e14c4db764c0636160d26c5bbf491637c83a76John McCall /// spelled with AmpAmp. 293651bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setAmpLoc(Chunk.Loc); 293751bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 293851bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { 293951bd803fbdade51d674598ed45da3d54190a656cJohn McCall assert(Chunk.Kind == DeclaratorChunk::Reference); 294051bd803fbdade51d674598ed45da3d54190a656cJohn McCall assert(!Chunk.Ref.LValueRef); 294151bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setAmpAmpLoc(Chunk.Loc); 294251bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 294351bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitArrayTypeLoc(ArrayTypeLoc TL) { 294451bd803fbdade51d674598ed45da3d54190a656cJohn McCall assert(Chunk.Kind == DeclaratorChunk::Array); 294551bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setLBracketLoc(Chunk.Loc); 294651bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setRBracketLoc(Chunk.EndLoc); 294751bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL.setSizeExpr(static_cast<Expr*>(Chunk.Arr.NumElts)); 294851bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 294951bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitFunctionTypeLoc(FunctionTypeLoc TL) { 295051bd803fbdade51d674598ed45da3d54190a656cJohn McCall assert(Chunk.Kind == DeclaratorChunk::Function); 2951796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara TL.setLocalRangeBegin(Chunk.Loc); 2952796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara TL.setLocalRangeEnd(Chunk.EndLoc); 2953dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor TL.setTrailingReturn(!!Chunk.Fun.TrailingReturnType); 295451bd803fbdade51d674598ed45da3d54190a656cJohn McCall 295551bd803fbdade51d674598ed45da3d54190a656cJohn McCall const DeclaratorChunk::FunctionTypeInfo &FTI = Chunk.Fun; 295654e14c4db764c0636160d26c5bbf491637c83a76John McCall for (unsigned i = 0, e = TL.getNumArgs(), tpi = 0; i != e; ++i) { 2957d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParmVarDecl *Param = cast<ParmVarDecl>(FTI.ArgInfo[i].Param); 295854e14c4db764c0636160d26c5bbf491637c83a76John McCall TL.setArg(tpi++, Param); 29594adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis } 296051bd803fbdade51d674598ed45da3d54190a656cJohn McCall // FIXME: exception specs 29614adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis } 2962075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara void VisitParenTypeLoc(ParenTypeLoc TL) { 2963075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara assert(Chunk.Kind == DeclaratorChunk::Paren); 2964075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara TL.setLParenLoc(Chunk.Loc); 2965075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara TL.setRParenLoc(Chunk.EndLoc); 2966075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 29671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 296851bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitTypeLoc(TypeLoc TL) { 29699f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("unsupported TypeLoc kind in declarator!"); 29704adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis } 297151bd803fbdade51d674598ed45da3d54190a656cJohn McCall }; 297251bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 29734adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis 2974a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall/// \brief Create and instantiate a TypeSourceInfo with type source information. 297551bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// 297651bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \param T QualType referring to the type as written in source code. 297705baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor/// 297805baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor/// \param ReturnTypeInfo For declarators whose return type does not show 297905baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor/// up in the normal place in the declaration specifiers (such as a C++ 298005baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor/// conversion function), this pointer will refer to a type source information 298105baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor/// for that return type. 2982a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCallTypeSourceInfo * 298305baacbfd67017b2724f3e0503fd23609f5d32bcDouglas GregorSema::GetTypeSourceInfoForDeclarator(Declarator &D, QualType T, 298405baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor TypeSourceInfo *ReturnTypeInfo) { 2985a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *TInfo = Context.CreateTypeSourceInfo(T); 2986a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall UnqualTypeLoc CurrTL = TInfo->getTypeLoc().getUnqualifiedLoc(); 298751bd803fbdade51d674598ed45da3d54190a656cJohn McCall 2988a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor // Handle parameter packs whose type is a pack expansion. 2989a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor if (isa<PackExpansionType>(T)) { 2990a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor cast<PackExpansionTypeLoc>(CurrTL).setEllipsisLoc(D.getEllipsisLoc()); 2991a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc(); 2992a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor } 2993a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor 29948ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { 299514aa2175416f79ef17811282afbf425f87d54ebfJohn McCall while (isa<AttributedTypeLoc>(CurrTL)) { 299614aa2175416f79ef17811282afbf425f87d54ebfJohn McCall AttributedTypeLoc TL = cast<AttributedTypeLoc>(CurrTL); 299714aa2175416f79ef17811282afbf425f87d54ebfJohn McCall fillAttributedTypeLoc(TL, D.getTypeObject(i).getAttrs()); 299814aa2175416f79ef17811282afbf425f87d54ebfJohn McCall CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc(); 299914aa2175416f79ef17811282afbf425f87d54ebfJohn McCall } 300014aa2175416f79ef17811282afbf425f87d54ebfJohn McCall 3001b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara DeclaratorLocFiller(Context, D.getTypeObject(i)).Visit(CurrTL); 300251bd803fbdade51d674598ed45da3d54190a656cJohn McCall CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc(); 30034adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis } 3004f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 3005b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall // If we have different source information for the return type, use 3006b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall // that. This really only applies to C++ conversion functions. 3007b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall if (ReturnTypeInfo) { 300805baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor TypeLoc TL = ReturnTypeInfo->getTypeLoc(); 300905baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor assert(TL.getFullDataSize() == CurrTL.getFullDataSize()); 301005baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor memcpy(CurrTL.getOpaqueData(), TL.getOpaqueData(), TL.getFullDataSize()); 3011b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } else { 3012c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TypeSpecLocFiller(Context, D.getDeclSpec()).Visit(CurrTL); 301305baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor } 301405baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor 3015a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TInfo; 30164adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis} 30174adab7fcb4cb1e23622f4849f7ef7981ff169616Argyrios Kyrtzidis 3018a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall/// \brief Create a LocInfoType to hold the given QualType and TypeSourceInfo. 3019b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCallParsedType Sema::CreateParsedType(QualType T, TypeSourceInfo *TInfo) { 30201bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis // FIXME: LocInfoTypes are "transient", only needed for passing to/from Parser 30211bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis // and Sema during declaration parsing. Try deallocating/caching them when 30221bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis // it's appropriate, instead of allocating them and keeping them around. 3023eb0eb49ce5f5294902769702b9322e42e89e972eDouglas Gregor LocInfoType *LocT = (LocInfoType*)BumpAlloc.Allocate(sizeof(LocInfoType), 3024eb0eb49ce5f5294902769702b9322e42e89e972eDouglas Gregor TypeAlignment); 3025a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall new (LocT) LocInfoType(T, TInfo); 30261bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis assert(LocT->getTypeClass() != T->getTypeClass() && 30271bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis "LocInfoType's TypeClass conflicts with an existing Type class"); 3028b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParsedType::make(QualType(LocT, 0)); 30291bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis} 30301bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 30311bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidisvoid LocInfoType::getAsStringInternal(std::string &Str, 30321bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis const PrintingPolicy &Policy) const { 303335d44e5673e772d1cc7eab66818de8d9796b89caArgyrios Kyrtzidis assert(false && "LocInfoType leaked into the type system; an opaque TypeTy*" 303435d44e5673e772d1cc7eab66818de8d9796b89caArgyrios Kyrtzidis " was used directly instead of getting the QualType through" 303535d44e5673e772d1cc7eab66818de8d9796b89caArgyrios Kyrtzidis " GetTypeFromParser"); 30361bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis} 30371bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 3038f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCallTypeResult Sema::ActOnTypeName(Scope *S, Declarator &D) { 30395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7.6: Type names have no identifier. This is already validated by 30405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // the parser. 30415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(D.getIdentifier() == 0 && "Type name should have no identifier!"); 30421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3043d3880f8458bb6a03818ee01f758c32f945de3eaaArgyrios Kyrtzidis TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S); 3044bf1a028246d884a540aeafa38e89be59a269b072John McCall QualType T = TInfo->getType(); 30455153ee66d6d4fb37b02f85df38e48dc8b46660dfChris Lattner if (D.isInvalidType()) 3046809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor return true; 30475912a3544e438a92832b8c52c13f48d4f54795dcSteve Naroff 3048402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor if (getLangOptions().CPlusPlus) { 3049402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor // Check that there are no default arguments (C++ only). 30506d6eb57225b53fb627c565861d1d0e90645400d1Douglas Gregor CheckExtraCXXDefaultArguments(D); 3051402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor } 3052402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor 3053b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return CreateParsedType(T, TInfo); 30545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 30555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3056c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner//===----------------------------------------------------------------------===// 3057c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner// Type Attribute Processing 3058c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner//===----------------------------------------------------------------------===// 3059232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner 3060232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner/// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the 3061c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner/// specified type. The attribute contains 1 argument, the id of the address 3062c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner/// space for the type. 30631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpstatic void HandleAddressSpaceTypeAttribute(QualType &Type, 3064c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner const AttributeList &Attr, Sema &S){ 30650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3066232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner // If this type is already address space qualified, reject it. 3067232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner // Clause 6.7.3 - Type qualifiers: "No type shall be qualified by qualifiers 3068232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner // for two or more different address spaces." 3069232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner if (Type.getAddressSpace()) { 3070c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner S.Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers); 3071e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara Attr.setInvalid(); 3072c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner return; 3073232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner } 30741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3075232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner // Check the attribute arguments. 3076545dd3401e7f31c256d69cb948a45d5ca781064cChris Lattner if (Attr.getNumArgs() != 1) { 3077f3a41af4d5c98a72a1d6720bbbfd658e57ef2541Chris Lattner S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; 3078e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara Attr.setInvalid(); 3079c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner return; 3080232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner } 3081545dd3401e7f31c256d69cb948a45d5ca781064cChris Lattner Expr *ASArgExpr = static_cast<Expr *>(Attr.getArg(0)); 3082232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner llvm::APSInt addrSpace(32); 3083ac06a0e1e3feb95c2ffd352c086882b492a65b99Douglas Gregor if (ASArgExpr->isTypeDependent() || ASArgExpr->isValueDependent() || 3084ac06a0e1e3feb95c2ffd352c086882b492a65b99Douglas Gregor !ASArgExpr->isIntegerConstantExpr(addrSpace, S.Context)) { 3085dcd5ef12488e4c7ea844327835896ca86b609a97Chris Lattner S.Diag(Attr.getLoc(), diag::err_attribute_address_space_not_int) 3086dcd5ef12488e4c7ea844327835896ca86b609a97Chris Lattner << ASArgExpr->getSourceRange(); 3087e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara Attr.setInvalid(); 3088c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner return; 3089232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner } 3090232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner 3091efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall // Bounds checking. 3092efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall if (addrSpace.isSigned()) { 3093efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall if (addrSpace.isNegative()) { 3094efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall S.Diag(Attr.getLoc(), diag::err_attribute_address_space_negative) 3095efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall << ASArgExpr->getSourceRange(); 3096e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara Attr.setInvalid(); 3097efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall return; 3098efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall } 3099efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall addrSpace.setIsSigned(false); 3100efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall } 3101efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall llvm::APSInt max(addrSpace.getBitWidth()); 31020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall max = Qualifiers::MaxAddressSpace; 3103efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall if (addrSpace > max) { 3104efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall S.Diag(Attr.getLoc(), diag::err_attribute_address_space_too_high) 31050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall << Qualifiers::MaxAddressSpace << ASArgExpr->getSourceRange(); 3106e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara Attr.setInvalid(); 3107efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall return; 3108efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall } 3109efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall 31101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned ASIdx = static_cast<unsigned>(addrSpace.getZExtValue()); 3111f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian Type = S.Context.getAddrSpaceQualType(Type, ASIdx); 3112c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner} 3113c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner 3114b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis/// handleObjCOwnershipTypeAttr - Process an objc_ownership 3115f85e193739c953358c865005855253af4f68a497John McCall/// attribute on the specified type. 3116f85e193739c953358c865005855253af4f68a497John McCall/// 3117f85e193739c953358c865005855253af4f68a497John McCall/// Returns 'true' if the attribute was handled. 3118b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidisstatic bool handleObjCOwnershipTypeAttr(TypeProcessingState &state, 3119f85e193739c953358c865005855253af4f68a497John McCall AttributeList &attr, 3120f85e193739c953358c865005855253af4f68a497John McCall QualType &type) { 3121f85e193739c953358c865005855253af4f68a497John McCall if (!type->isObjCRetainableType() && !type->isDependentType()) 3122f85e193739c953358c865005855253af4f68a497John McCall return false; 3123f85e193739c953358c865005855253af4f68a497John McCall 3124f85e193739c953358c865005855253af4f68a497John McCall Sema &S = state.getSema(); 3125f85e193739c953358c865005855253af4f68a497John McCall 3126f85e193739c953358c865005855253af4f68a497John McCall if (type.getQualifiers().getObjCLifetime()) { 3127b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis S.Diag(attr.getLoc(), diag::err_attr_objc_ownership_redundant) 3128f85e193739c953358c865005855253af4f68a497John McCall << type; 3129f85e193739c953358c865005855253af4f68a497John McCall return true; 3130f85e193739c953358c865005855253af4f68a497John McCall } 3131f85e193739c953358c865005855253af4f68a497John McCall 3132f85e193739c953358c865005855253af4f68a497John McCall if (!attr.getParameterName()) { 3133f85e193739c953358c865005855253af4f68a497John McCall S.Diag(attr.getLoc(), diag::err_attribute_argument_n_not_string) 3134b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis << "objc_ownership" << 1; 3135f85e193739c953358c865005855253af4f68a497John McCall attr.setInvalid(); 3136f85e193739c953358c865005855253af4f68a497John McCall return true; 3137f85e193739c953358c865005855253af4f68a497John McCall } 3138f85e193739c953358c865005855253af4f68a497John McCall 3139f85e193739c953358c865005855253af4f68a497John McCall Qualifiers::ObjCLifetime lifetime; 3140f85e193739c953358c865005855253af4f68a497John McCall if (attr.getParameterName()->isStr("none")) 3141f85e193739c953358c865005855253af4f68a497John McCall lifetime = Qualifiers::OCL_ExplicitNone; 3142f85e193739c953358c865005855253af4f68a497John McCall else if (attr.getParameterName()->isStr("strong")) 3143f85e193739c953358c865005855253af4f68a497John McCall lifetime = Qualifiers::OCL_Strong; 3144f85e193739c953358c865005855253af4f68a497John McCall else if (attr.getParameterName()->isStr("weak")) 3145f85e193739c953358c865005855253af4f68a497John McCall lifetime = Qualifiers::OCL_Weak; 3146f85e193739c953358c865005855253af4f68a497John McCall else if (attr.getParameterName()->isStr("autoreleasing")) 3147f85e193739c953358c865005855253af4f68a497John McCall lifetime = Qualifiers::OCL_Autoreleasing; 3148f85e193739c953358c865005855253af4f68a497John McCall else { 3149f85e193739c953358c865005855253af4f68a497John McCall S.Diag(attr.getLoc(), diag::warn_attribute_type_not_supported) 3150b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis << "objc_ownership" << attr.getParameterName(); 3151f85e193739c953358c865005855253af4f68a497John McCall attr.setInvalid(); 3152f85e193739c953358c865005855253af4f68a497John McCall return true; 3153f85e193739c953358c865005855253af4f68a497John McCall } 3154f85e193739c953358c865005855253af4f68a497John McCall 3155f85e193739c953358c865005855253af4f68a497John McCall // Consume lifetime attributes without further comment outside of 3156f85e193739c953358c865005855253af4f68a497John McCall // ARC mode. 3157f85e193739c953358c865005855253af4f68a497John McCall if (!S.getLangOptions().ObjCAutoRefCount) 3158f85e193739c953358c865005855253af4f68a497John McCall return true; 3159f85e193739c953358c865005855253af4f68a497John McCall 3160f85e193739c953358c865005855253af4f68a497John McCall Qualifiers qs; 3161f85e193739c953358c865005855253af4f68a497John McCall qs.setObjCLifetime(lifetime); 3162f85e193739c953358c865005855253af4f68a497John McCall QualType origType = type; 3163f85e193739c953358c865005855253af4f68a497John McCall type = S.Context.getQualifiedType(type, qs); 3164f85e193739c953358c865005855253af4f68a497John McCall 3165f85e193739c953358c865005855253af4f68a497John McCall // If we have a valid source location for the attribute, use an 3166f85e193739c953358c865005855253af4f68a497John McCall // AttributedType instead. 3167f85e193739c953358c865005855253af4f68a497John McCall if (attr.getLoc().isValid()) 3168b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis type = S.Context.getAttributedType(AttributedType::attr_objc_ownership, 3169f85e193739c953358c865005855253af4f68a497John McCall origType, type); 3170f85e193739c953358c865005855253af4f68a497John McCall 31719f084a3166b684573ba49df28fc5792bc37d92e1John McCall // Forbid __weak if the runtime doesn't support it. 3172f85e193739c953358c865005855253af4f68a497John McCall if (lifetime == Qualifiers::OCL_Weak && 31739f084a3166b684573ba49df28fc5792bc37d92e1John McCall !S.getLangOptions().ObjCRuntimeHasWeak) { 3174f85e193739c953358c865005855253af4f68a497John McCall 3175f85e193739c953358c865005855253af4f68a497John McCall // Actually, delay this until we know what we're parsing. 3176f85e193739c953358c865005855253af4f68a497John McCall if (S.DelayedDiagnostics.shouldDelayDiagnostics()) { 3177f85e193739c953358c865005855253af4f68a497John McCall S.DelayedDiagnostics.add( 3178f85e193739c953358c865005855253af4f68a497John McCall sema::DelayedDiagnostic::makeForbiddenType(attr.getLoc(), 3179f85e193739c953358c865005855253af4f68a497John McCall diag::err_arc_weak_no_runtime, type, /*ignored*/ 0)); 3180f85e193739c953358c865005855253af4f68a497John McCall } else { 3181f85e193739c953358c865005855253af4f68a497John McCall S.Diag(attr.getLoc(), diag::err_arc_weak_no_runtime); 3182f85e193739c953358c865005855253af4f68a497John McCall } 3183f85e193739c953358c865005855253af4f68a497John McCall 3184f85e193739c953358c865005855253af4f68a497John McCall attr.setInvalid(); 3185f85e193739c953358c865005855253af4f68a497John McCall return true; 3186f85e193739c953358c865005855253af4f68a497John McCall } 3187742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian 3188742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian // Forbid __weak for class objects marked as 3189742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian // objc_arc_weak_reference_unavailable 3190742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian if (lifetime == Qualifiers::OCL_Weak) { 3191742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian QualType T = type; 3192742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian while (const PointerType *ptr = T->getAs<PointerType>()) 3193742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian T = ptr->getPointeeType(); 3194742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) { 3195742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl(); 31967263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian if (Class->isArcWeakrefUnavailable()) { 3197742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian S.Diag(attr.getLoc(), diag::err_arc_unsupported_weak_class); 3198742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian S.Diag(ObjT->getInterfaceDecl()->getLocation(), 3199742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian diag::note_class_declared); 3200742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian } 3201742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian } 3202742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian } 3203742352a3984aeef9ecf911be23e673e97b34595fFariborz Jahanian 3204f85e193739c953358c865005855253af4f68a497John McCall return true; 3205f85e193739c953358c865005855253af4f68a497John McCall} 3206f85e193739c953358c865005855253af4f68a497John McCall 3207711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// handleObjCGCTypeAttr - Process the __attribute__((objc_gc)) type 3208711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// attribute on the specified type. Returns true to indicate that 3209711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// the attribute was handled, false to indicate that the type does 3210711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// not permit the attribute. 3211711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic bool handleObjCGCTypeAttr(TypeProcessingState &state, 3212711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, 3213711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType &type) { 3214711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Sema &S = state.getSema(); 3215711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 3216711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Delay if this isn't some kind of pointer. 3217711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!type->isPointerType() && 3218711c52bb20d0c69063b52a99826fb7d2835501f1John McCall !type->isObjCObjectPointerType() && 3219711c52bb20d0c69063b52a99826fb7d2835501f1John McCall !type->isBlockPointerType()) 3220711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return false; 3221711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 3222711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (type.getObjCGCAttr() != Qualifiers::GCNone) { 3223711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(attr.getLoc(), diag::err_attribute_multiple_objc_gc); 3224711c52bb20d0c69063b52a99826fb7d2835501f1John McCall attr.setInvalid(); 3225711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 3226d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian } 32271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3228d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian // Check the attribute arguments. 3229711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!attr.getParameterName()) { 3230711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(attr.getLoc(), diag::err_attribute_argument_n_not_string) 3231ba372b85524f712e5b97a176f6ce0197d365835dFariborz Jahanian << "objc_gc" << 1; 3232711c52bb20d0c69063b52a99826fb7d2835501f1John McCall attr.setInvalid(); 3233711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 3234ba372b85524f712e5b97a176f6ce0197d365835dFariborz Jahanian } 32350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GCAttr; 3236711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (attr.getNumArgs() != 0) { 3237711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; 3238711c52bb20d0c69063b52a99826fb7d2835501f1John McCall attr.setInvalid(); 3239711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 3240d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian } 3241711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (attr.getParameterName()->isStr("weak")) 32420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall GCAttr = Qualifiers::Weak; 3243711c52bb20d0c69063b52a99826fb7d2835501f1John McCall else if (attr.getParameterName()->isStr("strong")) 32440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall GCAttr = Qualifiers::Strong; 3245d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian else { 3246711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(attr.getLoc(), diag::warn_attribute_type_not_supported) 3247711c52bb20d0c69063b52a99826fb7d2835501f1John McCall << "objc_gc" << attr.getParameterName(); 3248711c52bb20d0c69063b52a99826fb7d2835501f1John McCall attr.setInvalid(); 3249711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 3250d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian } 32511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 325214aa2175416f79ef17811282afbf425f87d54ebfJohn McCall QualType origType = type; 325314aa2175416f79ef17811282afbf425f87d54ebfJohn McCall type = S.Context.getObjCGCQualType(origType, GCAttr); 325414aa2175416f79ef17811282afbf425f87d54ebfJohn McCall 325514aa2175416f79ef17811282afbf425f87d54ebfJohn McCall // Make an attributed type to preserve the source information. 325614aa2175416f79ef17811282afbf425f87d54ebfJohn McCall if (attr.getLoc().isValid()) 325714aa2175416f79ef17811282afbf425f87d54ebfJohn McCall type = S.Context.getAttributedType(AttributedType::attr_objc_gc, 325814aa2175416f79ef17811282afbf425f87d54ebfJohn McCall origType, type); 325914aa2175416f79ef17811282afbf425f87d54ebfJohn McCall 3260711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 3261d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 3262d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 3263e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCallnamespace { 3264e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall /// A helper class to unwrap a type down to a function for the 3265e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall /// purposes of applying attributes there. 3266e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall /// 3267e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall /// Use: 3268e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall /// FunctionTypeUnwrapper unwrapped(SemaRef, T); 3269e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall /// if (unwrapped.isFunctionType()) { 3270e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall /// const FunctionType *fn = unwrapped.get(); 3271e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall /// // change fn somehow 3272e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall /// T = unwrapped.wrap(fn); 3273e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall /// } 3274e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall struct FunctionTypeUnwrapper { 3275e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall enum WrapKind { 3276e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Desugar, 3277e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Parens, 3278e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Pointer, 3279e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall BlockPointer, 3280e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Reference, 3281e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall MemberPointer 3282e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall }; 3283e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3284e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType Original; 3285e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall const FunctionType *Fn; 32865f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<unsigned char /*WrapKind*/, 8> Stack; 3287e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3288e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FunctionTypeUnwrapper(Sema &S, QualType T) : Original(T) { 3289e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall while (true) { 3290e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall const Type *Ty = T.getTypePtr(); 3291e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (isa<FunctionType>(Ty)) { 3292e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Fn = cast<FunctionType>(Ty); 3293e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return; 3294e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } else if (isa<ParenType>(Ty)) { 3295e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall T = cast<ParenType>(Ty)->getInnerType(); 3296e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Stack.push_back(Parens); 3297e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } else if (isa<PointerType>(Ty)) { 3298e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall T = cast<PointerType>(Ty)->getPointeeType(); 3299e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Stack.push_back(Pointer); 3300e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } else if (isa<BlockPointerType>(Ty)) { 3301e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall T = cast<BlockPointerType>(Ty)->getPointeeType(); 3302e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Stack.push_back(BlockPointer); 3303e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } else if (isa<MemberPointerType>(Ty)) { 3304e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall T = cast<MemberPointerType>(Ty)->getPointeeType(); 3305e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Stack.push_back(MemberPointer); 3306e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } else if (isa<ReferenceType>(Ty)) { 3307e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall T = cast<ReferenceType>(Ty)->getPointeeType(); 3308e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Stack.push_back(Reference); 3309e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } else { 3310e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall const Type *DTy = Ty->getUnqualifiedDesugaredType(); 3311e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (Ty == DTy) { 3312e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Fn = 0; 3313e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return; 3314e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3315e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3316e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall T = QualType(DTy, 0); 3317e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Stack.push_back(Desugar); 3318e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3319e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3320e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3321e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3322e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall bool isFunctionType() const { return (Fn != 0); } 3323e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall const FunctionType *get() const { return Fn; } 3324e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3325e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType wrap(Sema &S, const FunctionType *New) { 3326e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall // If T wasn't modified from the unwrapped type, do nothing. 3327e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (New == get()) return Original; 3328e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3329e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Fn = New; 3330e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return wrap(S.Context, Original, 0); 3331e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3332e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3333e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall private: 3334e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType wrap(ASTContext &C, QualType Old, unsigned I) { 3335e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (I == Stack.size()) 3336e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return C.getQualifiedType(Fn, Old.getQualifiers()); 3337e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3338e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall // Build up the inner type, applying the qualifiers from the old 3339e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall // type to the new type. 3340e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall SplitQualType SplitOld = Old.split(); 3341e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3342e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall // As a special case, tail-recurse if there are no qualifiers. 3343e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (SplitOld.second.empty()) 3344e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return wrap(C, SplitOld.first, I); 3345e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return C.getQualifiedType(wrap(C, SplitOld.first, I), SplitOld.second); 3346e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3347e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3348e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType wrap(ASTContext &C, const Type *Old, unsigned I) { 3349e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (I == Stack.size()) return QualType(Fn, 0); 3350e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3351e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall switch (static_cast<WrapKind>(Stack[I++])) { 3352e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall case Desugar: 3353e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall // This is the point at which we potentially lose source 3354e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall // information. 3355e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return wrap(C, Old->getUnqualifiedDesugaredType(), I); 3356e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3357e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall case Parens: { 3358e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType New = wrap(C, cast<ParenType>(Old)->getInnerType(), I); 3359e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return C.getParenType(New); 3360e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3361e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3362e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall case Pointer: { 3363e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType New = wrap(C, cast<PointerType>(Old)->getPointeeType(), I); 3364e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return C.getPointerType(New); 3365e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3366e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3367e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall case BlockPointer: { 3368e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType New = wrap(C, cast<BlockPointerType>(Old)->getPointeeType(),I); 3369e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return C.getBlockPointerType(New); 3370e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3371e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3372e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall case MemberPointer: { 3373e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall const MemberPointerType *OldMPT = cast<MemberPointerType>(Old); 3374e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType New = wrap(C, OldMPT->getPointeeType(), I); 3375e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return C.getMemberPointerType(New, OldMPT->getClass()); 3376e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3377e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3378e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall case Reference: { 3379e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall const ReferenceType *OldRef = cast<ReferenceType>(Old); 3380e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType New = wrap(C, OldRef->getPointeeType(), I); 3381e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (isa<LValueReferenceType>(OldRef)) 3382e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return C.getLValueReferenceType(New, OldRef->isSpelledAsLValue()); 3383e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall else 3384e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return C.getRValueReferenceType(New); 3385e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3386e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3387e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3388e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall llvm_unreachable("unknown wrapping kind"); 3389e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return QualType(); 3390e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 3391e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall }; 3392e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall} 3393e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3394711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// Process an individual function attribute. Returns true to 3395711c52bb20d0c69063b52a99826fb7d2835501f1John McCall/// indicate that the attribute was handled, false if it wasn't. 3396711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic bool handleFunctionTypeAttr(TypeProcessingState &state, 3397711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr, 3398711c52bb20d0c69063b52a99826fb7d2835501f1John McCall QualType &type) { 3399711c52bb20d0c69063b52a99826fb7d2835501f1John McCall Sema &S = state.getSema(); 3400e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3401711c52bb20d0c69063b52a99826fb7d2835501f1John McCall FunctionTypeUnwrapper unwrapped(S, type); 34022455636163fdd18581d7fdae816433f886d88213Mike Stump 3403711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (attr.getKind() == AttributeList::AT_noreturn) { 3404711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (S.CheckNoReturnAttr(attr)) 340504a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall return true; 3406e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 3407e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall // Delay if this is not a function type. 3408711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!unwrapped.isFunctionType()) 3409711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return false; 3410425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 3411425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // Otherwise we can process right away. 3412711c52bb20d0c69063b52a99826fb7d2835501f1John McCall FunctionType::ExtInfo EI = unwrapped.get()->getExtInfo().withNoReturn(true); 3413711c52bb20d0c69063b52a99826fb7d2835501f1John McCall type = unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); 3414711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 3415711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 3416425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 3417f85e193739c953358c865005855253af4f68a497John McCall // ns_returns_retained is not always a type attribute, but if we got 3418f85e193739c953358c865005855253af4f68a497John McCall // here, we're treating it as one right now. 3419f85e193739c953358c865005855253af4f68a497John McCall if (attr.getKind() == AttributeList::AT_ns_returns_retained) { 3420f85e193739c953358c865005855253af4f68a497John McCall assert(S.getLangOptions().ObjCAutoRefCount && 3421f85e193739c953358c865005855253af4f68a497John McCall "ns_returns_retained treated as type attribute in non-ARC"); 3422f85e193739c953358c865005855253af4f68a497John McCall if (attr.getNumArgs()) return true; 3423f85e193739c953358c865005855253af4f68a497John McCall 3424f85e193739c953358c865005855253af4f68a497John McCall // Delay if this is not a function type. 3425f85e193739c953358c865005855253af4f68a497John McCall if (!unwrapped.isFunctionType()) 3426f85e193739c953358c865005855253af4f68a497John McCall return false; 3427f85e193739c953358c865005855253af4f68a497John McCall 3428f85e193739c953358c865005855253af4f68a497John McCall FunctionType::ExtInfo EI 3429f85e193739c953358c865005855253af4f68a497John McCall = unwrapped.get()->getExtInfo().withProducesResult(true); 3430f85e193739c953358c865005855253af4f68a497John McCall type = unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); 3431f85e193739c953358c865005855253af4f68a497John McCall return true; 3432f85e193739c953358c865005855253af4f68a497John McCall } 3433f85e193739c953358c865005855253af4f68a497John McCall 3434711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (attr.getKind() == AttributeList::AT_regparm) { 3435711c52bb20d0c69063b52a99826fb7d2835501f1John McCall unsigned value; 3436711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (S.CheckRegparmAttr(attr, value)) 3437711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 34381e030eb1194763b42c1752723be23b1515f48981John McCall 3439711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Delay if this is not a function type. 3440711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!unwrapped.isFunctionType()) 3441008df5dce3938456ae7ea2e7ab3b2d12391ebf3eJohn McCall return false; 34421e030eb1194763b42c1752723be23b1515f48981John McCall 3443ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis // Diagnose regparm with fastcall. 3444ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis const FunctionType *fn = unwrapped.get(); 3445ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis CallingConv CC = fn->getCallConv(); 3446ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis if (CC == CC_X86FastCall) { 3447ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis S.Diag(attr.getLoc(), diag::err_attributes_are_not_compatible) 3448ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis << FunctionType::getNameForCallConv(CC) 3449ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis << "regparm"; 3450ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis attr.setInvalid(); 3451ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis return true; 3452ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis } 3453ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis 3454e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FunctionType::ExtInfo EI = 3455711c52bb20d0c69063b52a99826fb7d2835501f1John McCall unwrapped.get()->getExtInfo().withRegParm(value); 3456711c52bb20d0c69063b52a99826fb7d2835501f1John McCall type = unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); 3457711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 3458425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola } 3459425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 346004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall // Otherwise, a calling convention. 3461711c52bb20d0c69063b52a99826fb7d2835501f1John McCall CallingConv CC; 3462711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (S.CheckCallingConvAttr(attr, CC)) 3463711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 3464f82b4e85b1219295cad4b5851b035575bc293010John McCall 346504a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall // Delay if the type didn't work out to a function. 3466711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!unwrapped.isFunctionType()) return false; 346704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 3468711c52bb20d0c69063b52a99826fb7d2835501f1John McCall const FunctionType *fn = unwrapped.get(); 3469711c52bb20d0c69063b52a99826fb7d2835501f1John McCall CallingConv CCOld = fn->getCallConv(); 3470064f7db69def9299f5f4d9a32114afc10b6a6420Charles Davis if (S.Context.getCanonicalCallConv(CC) == 3471e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara S.Context.getCanonicalCallConv(CCOld)) { 3472ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis FunctionType::ExtInfo EI= unwrapped.get()->getExtInfo().withCallingConv(CC); 3473ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis type = unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); 3474711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 3475e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara } 347604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 347704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall if (CCOld != CC_Default) { 347804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall // Should we diagnose reapplications of the same convention? 3479711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(attr.getLoc(), diag::err_attributes_are_not_compatible) 348004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall << FunctionType::getNameForCallConv(CC) 348104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall << FunctionType::getNameForCallConv(CCOld); 3482711c52bb20d0c69063b52a99826fb7d2835501f1John McCall attr.setInvalid(); 3483711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 348404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 348504a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 348604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall // Diagnose the use of X86 fastcall on varargs or unprototyped functions. 348704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall if (CC == CC_X86FastCall) { 3488711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (isa<FunctionNoProtoType>(fn)) { 3489711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(attr.getLoc(), diag::err_cconv_knr) 349004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall << FunctionType::getNameForCallConv(CC); 3491711c52bb20d0c69063b52a99826fb7d2835501f1John McCall attr.setInvalid(); 3492711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 349304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 349404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 3495711c52bb20d0c69063b52a99826fb7d2835501f1John McCall const FunctionProtoType *FnP = cast<FunctionProtoType>(fn); 349604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall if (FnP->isVariadic()) { 3497711c52bb20d0c69063b52a99826fb7d2835501f1John McCall S.Diag(attr.getLoc(), diag::err_cconv_varargs) 349804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall << FunctionType::getNameForCallConv(CC); 3499711c52bb20d0c69063b52a99826fb7d2835501f1John McCall attr.setInvalid(); 3500711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 350104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 3502ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis 3503ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis // Also diagnose fastcall with regparm. 3504a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman if (fn->getHasRegParm()) { 3505ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis S.Diag(attr.getLoc(), diag::err_attributes_are_not_compatible) 3506ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis << "regparm" 3507ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis << FunctionType::getNameForCallConv(CC); 3508ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis attr.setInvalid(); 3509ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis return true; 3510ce95566b36a4ff16e90507633dad8b7a76572999Argyrios Kyrtzidis } 351104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 3512f82b4e85b1219295cad4b5851b035575bc293010John McCall 3513711c52bb20d0c69063b52a99826fb7d2835501f1John McCall FunctionType::ExtInfo EI = unwrapped.get()->getExtInfo().withCallingConv(CC); 3514711c52bb20d0c69063b52a99826fb7d2835501f1John McCall type = unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); 3515711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return true; 3516f82b4e85b1219295cad4b5851b035575bc293010John McCall} 3517f82b4e85b1219295cad4b5851b035575bc293010John McCall 3518207f4d8543529221932af82836016a2ef066c917Peter Collingbourne/// Handle OpenCL image access qualifiers: read_only, write_only, read_write 3519207f4d8543529221932af82836016a2ef066c917Peter Collingbournestatic void HandleOpenCLImageAccessAttribute(QualType& CurType, 3520207f4d8543529221932af82836016a2ef066c917Peter Collingbourne const AttributeList &Attr, 3521207f4d8543529221932af82836016a2ef066c917Peter Collingbourne Sema &S) { 3522207f4d8543529221932af82836016a2ef066c917Peter Collingbourne // Check the attribute arguments. 3523207f4d8543529221932af82836016a2ef066c917Peter Collingbourne if (Attr.getNumArgs() != 1) { 3524207f4d8543529221932af82836016a2ef066c917Peter Collingbourne S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; 3525207f4d8543529221932af82836016a2ef066c917Peter Collingbourne Attr.setInvalid(); 3526207f4d8543529221932af82836016a2ef066c917Peter Collingbourne return; 3527207f4d8543529221932af82836016a2ef066c917Peter Collingbourne } 3528207f4d8543529221932af82836016a2ef066c917Peter Collingbourne Expr *sizeExpr = static_cast<Expr *>(Attr.getArg(0)); 3529207f4d8543529221932af82836016a2ef066c917Peter Collingbourne llvm::APSInt arg(32); 3530207f4d8543529221932af82836016a2ef066c917Peter Collingbourne if (sizeExpr->isTypeDependent() || sizeExpr->isValueDependent() || 3531207f4d8543529221932af82836016a2ef066c917Peter Collingbourne !sizeExpr->isIntegerConstantExpr(arg, S.Context)) { 3532207f4d8543529221932af82836016a2ef066c917Peter Collingbourne S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int) 3533207f4d8543529221932af82836016a2ef066c917Peter Collingbourne << "opencl_image_access" << sizeExpr->getSourceRange(); 3534207f4d8543529221932af82836016a2ef066c917Peter Collingbourne Attr.setInvalid(); 3535207f4d8543529221932af82836016a2ef066c917Peter Collingbourne return; 3536207f4d8543529221932af82836016a2ef066c917Peter Collingbourne } 3537207f4d8543529221932af82836016a2ef066c917Peter Collingbourne unsigned iarg = static_cast<unsigned>(arg.getZExtValue()); 3538207f4d8543529221932af82836016a2ef066c917Peter Collingbourne switch (iarg) { 3539207f4d8543529221932af82836016a2ef066c917Peter Collingbourne case CLIA_read_only: 3540207f4d8543529221932af82836016a2ef066c917Peter Collingbourne case CLIA_write_only: 3541207f4d8543529221932af82836016a2ef066c917Peter Collingbourne case CLIA_read_write: 3542207f4d8543529221932af82836016a2ef066c917Peter Collingbourne // Implemented in a separate patch 3543207f4d8543529221932af82836016a2ef066c917Peter Collingbourne break; 3544207f4d8543529221932af82836016a2ef066c917Peter Collingbourne default: 3545207f4d8543529221932af82836016a2ef066c917Peter Collingbourne // Implemented in a separate patch 3546207f4d8543529221932af82836016a2ef066c917Peter Collingbourne S.Diag(Attr.getLoc(), diag::err_attribute_invalid_size) 3547207f4d8543529221932af82836016a2ef066c917Peter Collingbourne << sizeExpr->getSourceRange(); 3548207f4d8543529221932af82836016a2ef066c917Peter Collingbourne Attr.setInvalid(); 3549207f4d8543529221932af82836016a2ef066c917Peter Collingbourne break; 3550207f4d8543529221932af82836016a2ef066c917Peter Collingbourne } 3551207f4d8543529221932af82836016a2ef066c917Peter Collingbourne} 3552207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 35536e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson/// HandleVectorSizeAttribute - this attribute is only applicable to integral 35546e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson/// and float scalars, although arrays, pointers, and function return values are 35556e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson/// allowed in conjunction with this construct. Aggregates with this attribute 35566e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson/// are invalid, even if they are of the same size as a corresponding scalar. 35576e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson/// The raw attribute should contain precisely 1 argument, the vector size for 35586e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson/// the variable, measured in bytes. If curType and rawAttr are well formed, 35596e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson/// this routine will return a new vector type. 3560788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerstatic void HandleVectorSizeAttr(QualType& CurType, const AttributeList &Attr, 3561788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner Sema &S) { 356256affbcaeff9a01caa70b2a237f7e6ac31c8ded6Bob Wilson // Check the attribute arguments. 35636e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson if (Attr.getNumArgs() != 1) { 35646e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; 3565e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara Attr.setInvalid(); 35666e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson return; 35676e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson } 35686e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson Expr *sizeExpr = static_cast<Expr *>(Attr.getArg(0)); 35696e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson llvm::APSInt vecSize(32); 3570ac06a0e1e3feb95c2ffd352c086882b492a65b99Douglas Gregor if (sizeExpr->isTypeDependent() || sizeExpr->isValueDependent() || 3571ac06a0e1e3feb95c2ffd352c086882b492a65b99Douglas Gregor !sizeExpr->isIntegerConstantExpr(vecSize, S.Context)) { 35726e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int) 35736e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson << "vector_size" << sizeExpr->getSourceRange(); 3574e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara Attr.setInvalid(); 35756e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson return; 35766e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson } 35776e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson // the base type must be integer or float, and can't already be a vector. 3578f60946222721d9ba3c059563935c17b84703187aDouglas Gregor if (!CurType->isIntegerType() && !CurType->isRealFloatingType()) { 35796e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type) << CurType; 3580e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara Attr.setInvalid(); 35816e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson return; 35826e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson } 35836e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson unsigned typeSize = static_cast<unsigned>(S.Context.getTypeSize(CurType)); 35846e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson // vecSize is specified in bytes - convert to bits. 35856e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue() * 8); 35866e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson 35876e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson // the vector size needs to be an integral multiple of the type size. 35886e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson if (vectorSize % typeSize) { 35896e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson S.Diag(Attr.getLoc(), diag::err_attribute_invalid_size) 35906e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson << sizeExpr->getSourceRange(); 3591e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara Attr.setInvalid(); 35926e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson return; 35936e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson } 35946e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson if (vectorSize == 0) { 35956e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson S.Diag(Attr.getLoc(), diag::err_attribute_zero_size) 35966e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson << sizeExpr->getSourceRange(); 3597e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara Attr.setInvalid(); 35986e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson return; 35996e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson } 36006e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson 36016e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson // Success! Instantiate the vector type, the number of elements is > 0, and 36026e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson // not required to be a power of 2, unlike GCC. 3603788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner CurType = S.Context.getVectorType(CurType, vectorSize/typeSize, 3604e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::GenericVector); 36056e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson} 36066e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson 36074ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor/// \brief Process the OpenCL-like ext_vector_type attribute when it occurs on 36084ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor/// a type. 36094ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregorstatic void HandleExtVectorTypeAttr(QualType &CurType, 36104ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor const AttributeList &Attr, 36114ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor Sema &S) { 36124ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor Expr *sizeExpr; 36134ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor 36144ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor // Special case where the argument is a template id. 36154ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor if (Attr.getParameterName()) { 36164ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor CXXScopeSpec SS; 36174ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor UnqualifiedId id; 36184ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor id.setIdentifier(Attr.getParameterName(), Attr.getLoc()); 36194ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor 36204ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor ExprResult Size = S.ActOnIdExpression(S.getCurScope(), SS, id, false, 36214ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor false); 36224ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor if (Size.isInvalid()) 36234ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor return; 36244ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor 36254ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor sizeExpr = Size.get(); 36264ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor } else { 36274ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor // check the attribute arguments. 36284ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor if (Attr.getNumArgs() != 1) { 36294ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; 36304ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor return; 36314ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor } 36324ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor sizeExpr = Attr.getArg(0); 36334ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor } 36344ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor 36354ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor // Create the vector type. 36364ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor QualType T = S.BuildExtVectorType(CurType, sizeExpr, Attr.getLoc()); 36374ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor if (!T.isNull()) 36384ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor CurType = T; 36394ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor} 36404ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor 36414211bb68cff1f310be280f66a59520548ef99d8fBob Wilson/// HandleNeonVectorTypeAttr - The "neon_vector_type" and 36424211bb68cff1f310be280f66a59520548ef99d8fBob Wilson/// "neon_polyvector_type" attributes are used to create vector types that 36434211bb68cff1f310be280f66a59520548ef99d8fBob Wilson/// are mangled according to ARM's ABI. Otherwise, these types are identical 36444211bb68cff1f310be280f66a59520548ef99d8fBob Wilson/// to those created with the "vector_size" attribute. Unlike "vector_size" 36454211bb68cff1f310be280f66a59520548ef99d8fBob Wilson/// the argument to these Neon attributes is the number of vector elements, 36464211bb68cff1f310be280f66a59520548ef99d8fBob Wilson/// not the vector size in bytes. The vector width and element type must 36474211bb68cff1f310be280f66a59520548ef99d8fBob Wilson/// match one of the standard Neon vector types. 36484211bb68cff1f310be280f66a59520548ef99d8fBob Wilsonstatic void HandleNeonVectorTypeAttr(QualType& CurType, 36494211bb68cff1f310be280f66a59520548ef99d8fBob Wilson const AttributeList &Attr, Sema &S, 36504211bb68cff1f310be280f66a59520548ef99d8fBob Wilson VectorType::VectorKind VecKind, 36514211bb68cff1f310be280f66a59520548ef99d8fBob Wilson const char *AttrName) { 36524211bb68cff1f310be280f66a59520548ef99d8fBob Wilson // Check the attribute arguments. 36534211bb68cff1f310be280f66a59520548ef99d8fBob Wilson if (Attr.getNumArgs() != 1) { 36544211bb68cff1f310be280f66a59520548ef99d8fBob Wilson S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; 36554211bb68cff1f310be280f66a59520548ef99d8fBob Wilson Attr.setInvalid(); 36564211bb68cff1f310be280f66a59520548ef99d8fBob Wilson return; 36574211bb68cff1f310be280f66a59520548ef99d8fBob Wilson } 36584211bb68cff1f310be280f66a59520548ef99d8fBob Wilson // The number of elements must be an ICE. 36594211bb68cff1f310be280f66a59520548ef99d8fBob Wilson Expr *numEltsExpr = static_cast<Expr *>(Attr.getArg(0)); 36604211bb68cff1f310be280f66a59520548ef99d8fBob Wilson llvm::APSInt numEltsInt(32); 36614211bb68cff1f310be280f66a59520548ef99d8fBob Wilson if (numEltsExpr->isTypeDependent() || numEltsExpr->isValueDependent() || 36624211bb68cff1f310be280f66a59520548ef99d8fBob Wilson !numEltsExpr->isIntegerConstantExpr(numEltsInt, S.Context)) { 36634211bb68cff1f310be280f66a59520548ef99d8fBob Wilson S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int) 36644211bb68cff1f310be280f66a59520548ef99d8fBob Wilson << AttrName << numEltsExpr->getSourceRange(); 36654211bb68cff1f310be280f66a59520548ef99d8fBob Wilson Attr.setInvalid(); 36664211bb68cff1f310be280f66a59520548ef99d8fBob Wilson return; 36674211bb68cff1f310be280f66a59520548ef99d8fBob Wilson } 36684211bb68cff1f310be280f66a59520548ef99d8fBob Wilson // Only certain element types are supported for Neon vectors. 36694211bb68cff1f310be280f66a59520548ef99d8fBob Wilson const BuiltinType* BTy = CurType->getAs<BuiltinType>(); 36704211bb68cff1f310be280f66a59520548ef99d8fBob Wilson if (!BTy || 36714211bb68cff1f310be280f66a59520548ef99d8fBob Wilson (VecKind == VectorType::NeonPolyVector && 36724211bb68cff1f310be280f66a59520548ef99d8fBob Wilson BTy->getKind() != BuiltinType::SChar && 36734211bb68cff1f310be280f66a59520548ef99d8fBob Wilson BTy->getKind() != BuiltinType::Short) || 36744211bb68cff1f310be280f66a59520548ef99d8fBob Wilson (BTy->getKind() != BuiltinType::SChar && 36754211bb68cff1f310be280f66a59520548ef99d8fBob Wilson BTy->getKind() != BuiltinType::UChar && 36764211bb68cff1f310be280f66a59520548ef99d8fBob Wilson BTy->getKind() != BuiltinType::Short && 36774211bb68cff1f310be280f66a59520548ef99d8fBob Wilson BTy->getKind() != BuiltinType::UShort && 36784211bb68cff1f310be280f66a59520548ef99d8fBob Wilson BTy->getKind() != BuiltinType::Int && 36794211bb68cff1f310be280f66a59520548ef99d8fBob Wilson BTy->getKind() != BuiltinType::UInt && 36804211bb68cff1f310be280f66a59520548ef99d8fBob Wilson BTy->getKind() != BuiltinType::LongLong && 36814211bb68cff1f310be280f66a59520548ef99d8fBob Wilson BTy->getKind() != BuiltinType::ULongLong && 36824211bb68cff1f310be280f66a59520548ef99d8fBob Wilson BTy->getKind() != BuiltinType::Float)) { 36834211bb68cff1f310be280f66a59520548ef99d8fBob Wilson S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type) <<CurType; 36844211bb68cff1f310be280f66a59520548ef99d8fBob Wilson Attr.setInvalid(); 36854211bb68cff1f310be280f66a59520548ef99d8fBob Wilson return; 36864211bb68cff1f310be280f66a59520548ef99d8fBob Wilson } 36874211bb68cff1f310be280f66a59520548ef99d8fBob Wilson // The total size of the vector must be 64 or 128 bits. 36884211bb68cff1f310be280f66a59520548ef99d8fBob Wilson unsigned typeSize = static_cast<unsigned>(S.Context.getTypeSize(CurType)); 36894211bb68cff1f310be280f66a59520548ef99d8fBob Wilson unsigned numElts = static_cast<unsigned>(numEltsInt.getZExtValue()); 36904211bb68cff1f310be280f66a59520548ef99d8fBob Wilson unsigned vecSize = typeSize * numElts; 36914211bb68cff1f310be280f66a59520548ef99d8fBob Wilson if (vecSize != 64 && vecSize != 128) { 36924211bb68cff1f310be280f66a59520548ef99d8fBob Wilson S.Diag(Attr.getLoc(), diag::err_attribute_bad_neon_vector_size) << CurType; 36934211bb68cff1f310be280f66a59520548ef99d8fBob Wilson Attr.setInvalid(); 36944211bb68cff1f310be280f66a59520548ef99d8fBob Wilson return; 36954211bb68cff1f310be280f66a59520548ef99d8fBob Wilson } 36964211bb68cff1f310be280f66a59520548ef99d8fBob Wilson 36974211bb68cff1f310be280f66a59520548ef99d8fBob Wilson CurType = S.Context.getVectorType(CurType, numElts, VecKind); 36984211bb68cff1f310be280f66a59520548ef99d8fBob Wilson} 36994211bb68cff1f310be280f66a59520548ef99d8fBob Wilson 3700711c52bb20d0c69063b52a99826fb7d2835501f1John McCallstatic void processTypeAttrs(TypeProcessingState &state, QualType &type, 3701711c52bb20d0c69063b52a99826fb7d2835501f1John McCall bool isDeclSpec, AttributeList *attrs) { 3702c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner // Scan through and apply attributes to this type where it makes sense. Some 3703c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner // attributes (such as __address_space__, __vector_size__, etc) apply to the 3704c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner // type, but others can be present in the type specifiers even though they 3705c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner // apply to the decl. Here we apply type attributes and ignore the rest. 3706711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 3707711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *next; 3708711c52bb20d0c69063b52a99826fb7d2835501f1John McCall do { 3709711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList &attr = *attrs; 3710711c52bb20d0c69063b52a99826fb7d2835501f1John McCall next = attr.getNext(); 3711711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 3712e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara // Skip attributes that were marked to be invalid. 3713711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (attr.isInvalid()) 3714e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara continue; 3715e215f7232dd4aa65ebf2a1ecd07cd95fe1ce3481Abramo Bagnara 3716b1f1b267351be74013f966f4834cde1eddbe0233Abramo Bagnara // If this is an attribute we can handle, do so now, 3717b1f1b267351be74013f966f4834cde1eddbe0233Abramo Bagnara // otherwise, add it to the FnAttrs list for rechaining. 3718711c52bb20d0c69063b52a99826fb7d2835501f1John McCall switch (attr.getKind()) { 3719c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner default: break; 372004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 3721c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner case AttributeList::AT_address_space: 3722711c52bb20d0c69063b52a99826fb7d2835501f1John McCall HandleAddressSpaceTypeAttribute(type, attr, state.getSema()); 3723c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner break; 3724711c52bb20d0c69063b52a99826fb7d2835501f1John McCall OBJC_POINTER_TYPE_ATTRS_CASELIST: 3725711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!handleObjCPointerTypeAttr(state, attr, type)) 3726711c52bb20d0c69063b52a99826fb7d2835501f1John McCall distributeObjCPointerTypeAttr(state, attr, type); 3727d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian break; 372804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case AttributeList::AT_vector_size: 3729711c52bb20d0c69063b52a99826fb7d2835501f1John McCall HandleVectorSizeAttr(type, attr, state.getSema()); 3730f82b4e85b1219295cad4b5851b035575bc293010John McCall break; 37314ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor case AttributeList::AT_ext_vector_type: 37324ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor if (state.getDeclarator().getDeclSpec().getStorageClassSpec() 37334ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor != DeclSpec::SCS_typedef) 37344ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor HandleExtVectorTypeAttr(type, attr, state.getSema()); 37354ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor break; 37364211bb68cff1f310be280f66a59520548ef99d8fBob Wilson case AttributeList::AT_neon_vector_type: 3737711c52bb20d0c69063b52a99826fb7d2835501f1John McCall HandleNeonVectorTypeAttr(type, attr, state.getSema(), 3738711c52bb20d0c69063b52a99826fb7d2835501f1John McCall VectorType::NeonVector, "neon_vector_type"); 37394211bb68cff1f310be280f66a59520548ef99d8fBob Wilson break; 37404211bb68cff1f310be280f66a59520548ef99d8fBob Wilson case AttributeList::AT_neon_polyvector_type: 3741711c52bb20d0c69063b52a99826fb7d2835501f1John McCall HandleNeonVectorTypeAttr(type, attr, state.getSema(), 3742711c52bb20d0c69063b52a99826fb7d2835501f1John McCall VectorType::NeonPolyVector, 37434211bb68cff1f310be280f66a59520548ef99d8fBob Wilson "neon_polyvector_type"); 37444211bb68cff1f310be280f66a59520548ef99d8fBob Wilson break; 3745207f4d8543529221932af82836016a2ef066c917Peter Collingbourne case AttributeList::AT_opencl_image_access: 3746207f4d8543529221932af82836016a2ef066c917Peter Collingbourne HandleOpenCLImageAccessAttribute(type, attr, state.getSema()); 3747207f4d8543529221932af82836016a2ef066c917Peter Collingbourne break; 3748207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 3749f85e193739c953358c865005855253af4f68a497John McCall case AttributeList::AT_ns_returns_retained: 3750f85e193739c953358c865005855253af4f68a497John McCall if (!state.getSema().getLangOptions().ObjCAutoRefCount) 3751f85e193739c953358c865005855253af4f68a497John McCall break; 3752f85e193739c953358c865005855253af4f68a497John McCall // fallthrough into the function attrs 3753f85e193739c953358c865005855253af4f68a497John McCall 3754711c52bb20d0c69063b52a99826fb7d2835501f1John McCall FUNCTION_TYPE_ATTRS_CASELIST: 3755711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Never process function type attributes as part of the 3756711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // declaration-specifiers. 3757711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (isDeclSpec) 3758711c52bb20d0c69063b52a99826fb7d2835501f1John McCall distributeFunctionTypeAttrFromDeclSpec(state, attr, type); 3759711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 3760711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Otherwise, handle the possible delays. 3761711c52bb20d0c69063b52a99826fb7d2835501f1John McCall else if (!handleFunctionTypeAttr(state, attr, type)) 3762711c52bb20d0c69063b52a99826fb7d2835501f1John McCall distributeFunctionTypeAttr(state, attr, type); 37636e132aab867c189b1c3ee7463ef9d2b1f03a294dJohn Thompson break; 3764c9b346d7b3b24f8bf940735cc812893dfcef1d4bChris Lattner } 3765711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } while ((attrs = next)); 3766232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner} 3767232e882226aa116807ee08a700dfc2350fbfabb1Chris Lattner 3768e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// \brief Ensure that the type of the given expression is complete. 3769e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// 3770e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// This routine checks whether the expression \p E has a complete type. If the 3771e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// expression refers to an instantiable construct, that instantiation is 3772e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// performed as needed to complete its type. Furthermore 3773e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// Sema::RequireCompleteType is called for the expression's type (or in the 3774e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// case of a reference type, the referred-to type). 3775e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// 3776e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// \param E The expression whose type is required to be complete. 3777e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// \param PD The partial diagnostic that will be printed out if the type cannot 3778e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// be completed. 3779e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// 3780e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// \returns \c true if the type of \p E is incomplete and diagnosed, \c false 3781e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth/// otherwise. 3782e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruthbool Sema::RequireCompleteExprType(Expr *E, const PartialDiagnostic &PD, 3783e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth std::pair<SourceLocation, 3784e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth PartialDiagnostic> Note) { 3785e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth QualType T = E->getType(); 3786e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth 3787e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth // Fast path the case where the type is already complete. 3788e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth if (!T->isIncompleteType()) 3789e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth return false; 3790e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth 3791e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth // Incomplete array types may be completed by the initializer attached to 3792e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth // their definitions. For static data members of class templates we need to 3793e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth // instantiate the definition to get this initializer and complete the type. 3794e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth if (T->isIncompleteArrayType()) { 3795e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParens())) { 3796e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth if (VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl())) { 3797e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth if (Var->isStaticDataMember() && 3798e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth Var->getInstantiatedFromStaticDataMember()) { 379936f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor 380036f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor MemberSpecializationInfo *MSInfo = Var->getMemberSpecializationInfo(); 380136f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor assert(MSInfo && "Missing member specialization information?"); 380236f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor if (MSInfo->getTemplateSpecializationKind() 380336f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor != TSK_ExplicitSpecialization) { 380436f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor // If we don't already have a point of instantiation, this is it. 380536f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor if (MSInfo->getPointOfInstantiation().isInvalid()) { 380636f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor MSInfo->setPointOfInstantiation(E->getLocStart()); 380736f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor 380836f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor // This is a modification of an existing AST node. Notify 380936f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor // listeners. 381036f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor if (ASTMutationListener *L = getASTMutationListener()) 381136f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor L->StaticDataMemberInstantiated(Var); 381236f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor } 381336f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor 381436f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor InstantiateStaticDataMemberDefinition(E->getExprLoc(), Var); 381536f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor 381636f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor // Update the type to the newly instantiated definition's type both 381736f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor // here and within the expression. 381836f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor if (VarDecl *Def = Var->getDefinition()) { 381936f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor DRE->setDecl(Def); 382036f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor T = Def->getType(); 382136f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor DRE->setType(T); 382236f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor E->setType(T); 382336f255c324d37dd8e0e5ab2e026814e8396a05aaDouglas Gregor } 3824f15748a28c8443eef2924ef83689c358c661e9c5Douglas Gregor } 3825f15748a28c8443eef2924ef83689c358c661e9c5Douglas Gregor 3826e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth // We still go on to try to complete the type independently, as it 3827e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth // may also require instantiations or diagnostics if it remains 3828e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth // incomplete. 3829e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth } 3830e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth } 3831e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth } 3832e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth } 3833e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth 3834e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth // FIXME: Are there other cases which require instantiating something other 3835e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth // than the type to complete the type of an expression? 3836e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth 3837e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth // Look through reference types and complete the referred type. 3838e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth if (const ReferenceType *Ref = T->getAs<ReferenceType>()) 3839e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth T = Ref->getPointeeType(); 3840e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth 3841e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth return RequireCompleteType(E->getExprLoc(), T, PD, Note); 3842e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth} 3843e4d645cbe073042d8abc1a4eb600af4ff7a8dffbChandler Carruth 38441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @brief Ensure that the type T is a complete type. 38454ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// 38464ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// This routine checks whether the type @p T is complete in any 38474ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// context where a complete type is required. If @p T is a complete 384886447ec25fa34aa3c2f48ebc49ec09bc1f03f002Douglas Gregor/// type, returns false. If @p T is a class template specialization, 384986447ec25fa34aa3c2f48ebc49ec09bc1f03f002Douglas Gregor/// this routine then attempts to perform class template 385086447ec25fa34aa3c2f48ebc49ec09bc1f03f002Douglas Gregor/// instantiation. If instantiation fails, or if @p T is incomplete 385186447ec25fa34aa3c2f48ebc49ec09bc1f03f002Douglas Gregor/// and cannot be completed, issues the diagnostic @p diag (giving it 385286447ec25fa34aa3c2f48ebc49ec09bc1f03f002Douglas Gregor/// the type @p T) and returns true. 38534ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// 38544ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// @param Loc The location in the source that the incomplete type 38554ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// diagnostic should refer to. 38564ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// 38574ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// @param T The type that this routine is examining for completeness. 38584ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// 38591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @param PD The partial diagnostic that will be printed out if T is not a 3860b790661a15d93941d2c33a0ea328254277b3d7e3Anders Carlsson/// complete type. 38614ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// 38624ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// @returns @c true if @p T is incomplete and a diagnostic was emitted, 38634ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor/// @c false otherwise. 386491a0cc913ecc5619b76d2e40742fd09725be8c56Anders Carlssonbool Sema::RequireCompleteType(SourceLocation Loc, QualType T, 38658c8d91917c307dc3ba4f60661377c745f2a6bef2Anders Carlsson const PartialDiagnostic &PD, 38668c8d91917c307dc3ba4f60661377c745f2a6bef2Anders Carlsson std::pair<SourceLocation, 38678c8d91917c307dc3ba4f60661377c745f2a6bef2Anders Carlsson PartialDiagnostic> Note) { 386891a0cc913ecc5619b76d2e40742fd09725be8c56Anders Carlsson unsigned diag = PD.getDiagID(); 38691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3870573d9c325279b6e156c7fde163ffe3629c62d596Douglas Gregor // FIXME: Add this assertion to make sure we always get instantiation points. 3871573d9c325279b6e156c7fde163ffe3629c62d596Douglas Gregor // assert(!Loc.isInvalid() && "Invalid location in RequireCompleteType"); 3872690dc7f4f2c0fe87409839b7560c19dee7832195Douglas Gregor // FIXME: Add this assertion to help us flush out problems with 3873690dc7f4f2c0fe87409839b7560c19dee7832195Douglas Gregor // checking for dependent types and type-dependent expressions. 3874690dc7f4f2c0fe87409839b7560c19dee7832195Douglas Gregor // 38751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // assert(!T->isDependentType() && 3876690dc7f4f2c0fe87409839b7560c19dee7832195Douglas Gregor // "Can't ask whether a dependent type is complete"); 3877690dc7f4f2c0fe87409839b7560c19dee7832195Douglas Gregor 38784ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor // If we have a complete type, we're done. 38794ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor if (!T->isIncompleteType()) 38804ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor return false; 38814ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor 3882d475b8d9e6f5ff0e6ab8d15667ce8a64c7cb9a4dDouglas Gregor // If we have a class template specialization or a class member of a 3883923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // class template specialization, or an array with known size of such, 3884923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // try to instantiate it. 3885923d56d436f750bc1f29db50e641078725558a1bSebastian Redl QualType MaybeTemplate = T; 388689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor if (const ConstantArrayType *Array = Context.getAsConstantArrayType(T)) 3887923d56d436f750bc1f29db50e641078725558a1bSebastian Redl MaybeTemplate = Array->getElementType(); 3888923d56d436f750bc1f29db50e641078725558a1bSebastian Redl if (const RecordType *Record = MaybeTemplate->getAs<RecordType>()) { 38892943aed177b33ae3f14273b11a7b398e5276ec62Douglas Gregor if (ClassTemplateSpecializationDecl *ClassTemplateSpec 3890d475b8d9e6f5ff0e6ab8d15667ce8a64c7cb9a4dDouglas Gregor = dyn_cast<ClassTemplateSpecializationDecl>(Record->getDecl())) { 3891972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor if (ClassTemplateSpec->getSpecializationKind() == TSK_Undeclared) 3892972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor return InstantiateClassTemplateSpecialization(Loc, ClassTemplateSpec, 3893d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor TSK_ImplicitInstantiation, 38945842ba9fd482bb2fe5198b32c2ae549cd5474e6dDouglas Gregor /*Complain=*/diag != 0); 38951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (CXXRecordDecl *Rec 3896d475b8d9e6f5ff0e6ab8d15667ce8a64c7cb9a4dDouglas Gregor = dyn_cast<CXXRecordDecl>(Record->getDecl())) { 3897d475b8d9e6f5ff0e6ab8d15667ce8a64c7cb9a4dDouglas Gregor if (CXXRecordDecl *Pattern = Rec->getInstantiatedFromMemberClass()) { 3898b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor MemberSpecializationInfo *MSInfo = Rec->getMemberSpecializationInfo(); 3899b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor assert(MSInfo && "Missing member specialization information?"); 3900357bbd022c1d340c8e255aea7a684ddb34bc76e5Douglas Gregor // This record was instantiated from a class within a template. 3901b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor if (MSInfo->getTemplateSpecializationKind() 3902972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor != TSK_ExplicitSpecialization) 3903f6b1185f0a8a209c06dfc1efdb6a59cc851e970cDouglas Gregor return InstantiateClass(Loc, Rec, Pattern, 3904f6b1185f0a8a209c06dfc1efdb6a59cc851e970cDouglas Gregor getTemplateInstantiationArgs(Rec), 3905f6b1185f0a8a209c06dfc1efdb6a59cc851e970cDouglas Gregor TSK_ImplicitInstantiation, 3906f6b1185f0a8a209c06dfc1efdb6a59cc851e970cDouglas Gregor /*Complain=*/diag != 0); 3907d475b8d9e6f5ff0e6ab8d15667ce8a64c7cb9a4dDouglas Gregor } 3908d475b8d9e6f5ff0e6ab8d15667ce8a64c7cb9a4dDouglas Gregor } 3909d475b8d9e6f5ff0e6ab8d15667ce8a64c7cb9a4dDouglas Gregor } 39102943aed177b33ae3f14273b11a7b398e5276ec62Douglas Gregor 39115842ba9fd482bb2fe5198b32c2ae549cd5474e6dDouglas Gregor if (diag == 0) 39125842ba9fd482bb2fe5198b32c2ae549cd5474e6dDouglas Gregor return true; 39131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3914916c870442978db40404d51348cdf5524e506faaJohn McCall const TagType *Tag = T->getAs<TagType>(); 391501620704304f819b82ecef769ec114e541a364d7Rafael Espindola 391601620704304f819b82ecef769ec114e541a364d7Rafael Espindola // Avoid diagnosing invalid decls as incomplete. 391701620704304f819b82ecef769ec114e541a364d7Rafael Espindola if (Tag && Tag->getDecl()->isInvalidDecl()) 391801620704304f819b82ecef769ec114e541a364d7Rafael Espindola return true; 391901620704304f819b82ecef769ec114e541a364d7Rafael Espindola 3920916c870442978db40404d51348cdf5524e506faaJohn McCall // Give the external AST source a chance to complete the type. 3921916c870442978db40404d51348cdf5524e506faaJohn McCall if (Tag && Tag->getDecl()->hasExternalLexicalStorage()) { 3922916c870442978db40404d51348cdf5524e506faaJohn McCall Context.getExternalSource()->CompleteType(Tag->getDecl()); 3923916c870442978db40404d51348cdf5524e506faaJohn McCall if (!Tag->isIncompleteType()) 3924916c870442978db40404d51348cdf5524e506faaJohn McCall return false; 3925916c870442978db40404d51348cdf5524e506faaJohn McCall } 3926916c870442978db40404d51348cdf5524e506faaJohn McCall 39274ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor // We have an incomplete type. Produce a diagnostic. 392891a0cc913ecc5619b76d2e40742fd09725be8c56Anders Carlsson Diag(Loc, PD) << T; 39293c0eb160ca1361a82b9f15b3b40a2425adc14d0fEli Friedman 39308c8d91917c307dc3ba4f60661377c745f2a6bef2Anders Carlsson // If we have a note, produce it. 39318c8d91917c307dc3ba4f60661377c745f2a6bef2Anders Carlsson if (!Note.first.isInvalid()) 39328c8d91917c307dc3ba4f60661377c745f2a6bef2Anders Carlsson Diag(Note.first, Note.second); 39338c8d91917c307dc3ba4f60661377c745f2a6bef2Anders Carlsson 39344ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor // If the type was a forward declaration of a class/struct/union 393501620704304f819b82ecef769ec114e541a364d7Rafael Espindola // type, produce a note. 39364ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor if (Tag && !Tag->getDecl()->isInvalidDecl()) 39371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Diag(Tag->getDecl()->getLocation(), 39384ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor Tag->isBeingDefined() ? diag::note_type_being_defined 39394ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor : diag::note_forward_declaration) 39404ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor << QualType(Tag, 0); 39414ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor 39424ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor return true; 39434ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor} 3944e6258936178b4c52b43b3b9dbec13552961cd645Douglas Gregor 3945fe6b2d481d91140923f4541f273b253291884214Douglas Gregorbool Sema::RequireCompleteType(SourceLocation Loc, QualType T, 3946fe6b2d481d91140923f4541f273b253291884214Douglas Gregor const PartialDiagnostic &PD) { 3947fe6b2d481d91140923f4541f273b253291884214Douglas Gregor return RequireCompleteType(Loc, T, PD, 3948fe6b2d481d91140923f4541f273b253291884214Douglas Gregor std::make_pair(SourceLocation(), PDiag(0))); 3949fe6b2d481d91140923f4541f273b253291884214Douglas Gregor} 3950fe6b2d481d91140923f4541f273b253291884214Douglas Gregor 3951fe6b2d481d91140923f4541f273b253291884214Douglas Gregorbool Sema::RequireCompleteType(SourceLocation Loc, QualType T, 3952fe6b2d481d91140923f4541f273b253291884214Douglas Gregor unsigned DiagID) { 3953fe6b2d481d91140923f4541f273b253291884214Douglas Gregor return RequireCompleteType(Loc, T, PDiag(DiagID), 3954fe6b2d481d91140923f4541f273b253291884214Douglas Gregor std::make_pair(SourceLocation(), PDiag(0))); 3955fe6b2d481d91140923f4541f273b253291884214Douglas Gregor} 3956fe6b2d481d91140923f4541f273b253291884214Douglas Gregor 3957465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Retrieve a version of the type 'T' that is elaborated by Keyword 3958465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// and qualified by the nested-name-specifier contained in SS. 3959465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraQualType Sema::getElaboratedType(ElaboratedTypeKeyword Keyword, 3960465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara const CXXScopeSpec &SS, QualType T) { 3961465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (T.isNull()) 3962e6258936178b4c52b43b3b9dbec13552961cd645Douglas Gregor return T; 3963465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NestedNameSpecifier *NNS; 3964e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (SS.isValid()) 3965465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); 3966465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else { 3967465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (Keyword == ETK_None) 3968465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return T; 3969465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS = 0; 3970465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 3971465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return Context.getElaboratedType(Keyword, NNS, T); 3972e6258936178b4c52b43b3b9dbec13552961cd645Douglas Gregor} 3973af017e682918f7a1a95ff08d9ab7ae3426436ca3Anders Carlsson 39742a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType Sema::BuildTypeofExprType(Expr *E, SourceLocation Loc) { 3975fb8721ce4c6fef3739b1cbd1e38e3f1949462033John McCall ExprResult ER = CheckPlaceholderExpr(E); 39762a984cad5ac3fdceeff2bd99daa7b90979313475John McCall if (ER.isInvalid()) return QualType(); 39772a984cad5ac3fdceeff2bd99daa7b90979313475John McCall E = ER.take(); 39782a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 39792b1d51bcf891f8887759aebb4b9e78dee8542e6dFariborz Jahanian if (!E->isTypeDependent()) { 39802b1d51bcf891f8887759aebb4b9e78dee8542e6dFariborz Jahanian QualType T = E->getType(); 3981aca7f7bab0102341863a0d1bdb048d69213ae362Fariborz Jahanian if (const TagType *TT = T->getAs<TagType>()) 3982aca7f7bab0102341863a0d1bdb048d69213ae362Fariborz Jahanian DiagnoseUseOfDecl(TT->getDecl(), E->getExprLoc()); 39832b1d51bcf891f8887759aebb4b9e78dee8542e6dFariborz Jahanian } 3984af017e682918f7a1a95ff08d9ab7ae3426436ca3Anders Carlsson return Context.getTypeOfExprType(E); 3985af017e682918f7a1a95ff08d9ab7ae3426436ca3Anders Carlsson} 3986af017e682918f7a1a95ff08d9ab7ae3426436ca3Anders Carlsson 39872a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc) { 3988fb8721ce4c6fef3739b1cbd1e38e3f1949462033John McCall ExprResult ER = CheckPlaceholderExpr(E); 39892a984cad5ac3fdceeff2bd99daa7b90979313475John McCall if (ER.isInvalid()) return QualType(); 39902a984cad5ac3fdceeff2bd99daa7b90979313475John McCall E = ER.take(); 39914b52e25f3b05ab0f9d2492276a52323a50a84fb7Douglas Gregor 3992af017e682918f7a1a95ff08d9ab7ae3426436ca3Anders Carlsson return Context.getDecltypeType(E); 3993af017e682918f7a1a95ff08d9ab7ae3426436ca3Anders Carlsson} 3994ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3995ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType Sema::BuildUnaryTransformType(QualType BaseType, 3996ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 3997ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc) { 3998ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt switch (UKind) { 3999ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt case UnaryTransformType::EnumUnderlyingType: 4000ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (!BaseType->isDependentType() && !BaseType->isEnumeralType()) { 4001ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Diag(Loc, diag::err_only_enums_have_underlying_types); 4002ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return QualType(); 4003ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } else { 4004ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType Underlying = BaseType; 4005ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (!BaseType->isDependentType()) { 4006ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt EnumDecl *ED = BaseType->getAs<EnumType>()->getDecl(); 4007ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt assert(ED && "EnumType has no EnumDecl"); 4008ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt DiagnoseUseOfDecl(ED, Loc); 4009ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Underlying = ED->getIntegerType(); 4010ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 4011ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt assert(!Underlying.isNull()); 4012ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return Context.getUnaryTransformType(BaseType, Underlying, 4013ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::EnumUnderlyingType); 4014ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 4015ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 4016ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt llvm_unreachable("unknown unary transform type"); 4017ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 4018