diff options
Diffstat (limited to 'include/clang/Sema')
-rw-r--r-- | include/clang/Sema/AttributeList.h | 12 | ||||
-rw-r--r-- | include/clang/Sema/CodeCompleteConsumer.h | 25 | ||||
-rw-r--r-- | include/clang/Sema/DeclSpec.h | 20 | ||||
-rw-r--r-- | include/clang/Sema/DelayedDiagnostic.h | 15 | ||||
-rw-r--r-- | include/clang/Sema/ExternalSemaSource.h | 26 | ||||
-rw-r--r-- | include/clang/Sema/Initialization.h | 17 | ||||
-rw-r--r-- | include/clang/Sema/Lookup.h | 23 | ||||
-rw-r--r-- | include/clang/Sema/MultiplexExternalSemaSource.h | 36 | ||||
-rw-r--r-- | include/clang/Sema/Overload.h | 4 | ||||
-rw-r--r-- | include/clang/Sema/Ownership.h | 2 | ||||
-rw-r--r-- | include/clang/Sema/Scope.h | 55 | ||||
-rw-r--r-- | include/clang/Sema/ScopeInfo.h | 38 | ||||
-rw-r--r-- | include/clang/Sema/Sema.h | 508 | ||||
-rw-r--r-- | include/clang/Sema/SemaInternal.h | 59 | ||||
-rw-r--r-- | include/clang/Sema/Template.h | 4 | ||||
-rw-r--r-- | include/clang/Sema/TemplateDeduction.h | 18 | ||||
-rw-r--r-- | include/clang/Sema/TypoCorrection.h | 2 |
17 files changed, 489 insertions, 375 deletions
diff --git a/include/clang/Sema/AttributeList.h b/include/clang/Sema/AttributeList.h index 5e543a5..58b1b9e 100644 --- a/include/clang/Sema/AttributeList.h +++ b/include/clang/Sema/AttributeList.h @@ -204,10 +204,10 @@ private: return *reinterpret_cast<const PropertyData*>(this + 1); } - AttributeList(const AttributeList &) LLVM_DELETED_FUNCTION; - void operator=(const AttributeList &) LLVM_DELETED_FUNCTION; - void operator delete(void *) LLVM_DELETED_FUNCTION; - ~AttributeList() LLVM_DELETED_FUNCTION; + AttributeList(const AttributeList &) = delete; + void operator=(const AttributeList &) = delete; + void operator delete(void *) = delete; + ~AttributeList() = delete; size_t allocated_size() const; @@ -670,7 +670,7 @@ public: : pool(factory), list(nullptr) { } - ParsedAttributes(const ParsedAttributes &) LLVM_DELETED_FUNCTION; + ParsedAttributes(const ParsedAttributes &) = delete; AttributePool &getPool() const { return pool; } @@ -822,6 +822,7 @@ enum AttributeDeclKind { ExpectedFunctionMethodOrClass, ExpectedFunctionMethodOrParameter, ExpectedClass, + ExpectedEnum, ExpectedVariable, ExpectedMethod, ExpectedVariableFunctionOrLabel, @@ -842,6 +843,7 @@ enum AttributeDeclKind { ExpectedFunctionVariableOrClass, ExpectedObjectiveCProtocol, ExpectedFunctionGlobalVarMethodOrProperty, + ExpectedStructOrUnionOrTypedef, ExpectedStructOrTypedef, ExpectedObjectiveCInterfaceOrProtocol, ExpectedKernelFunction diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index 92a4e9a..de65c43 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -17,6 +17,7 @@ #include "clang/AST/CanonicalType.h" #include "clang/AST/Type.h" #include "clang/Sema/CodeCompleteOptions.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Allocator.h" @@ -440,15 +441,15 @@ private: /// entity being completed by this result. const char *BriefComment; - CodeCompletionString(const CodeCompletionString &) LLVM_DELETED_FUNCTION; - void operator=(const CodeCompletionString &) LLVM_DELETED_FUNCTION; + CodeCompletionString(const CodeCompletionString &) = delete; + void operator=(const CodeCompletionString &) = delete; CodeCompletionString(const Chunk *Chunks, unsigned NumChunks, unsigned Priority, CXAvailabilityKind Availability, const char **Annotations, unsigned NumAnnotations, StringRef ParentName, const char *BriefComment); - ~CodeCompletionString() { } + ~CodeCompletionString() = default; friend class CodeCompletionBuilder; friend class CodeCompletionResult; @@ -498,20 +499,7 @@ public: class CodeCompletionAllocator : public llvm::BumpPtrAllocator { public: /// \brief Copy the given string into this allocator. - const char *CopyString(StringRef String); - - /// \brief Copy the given string into this allocator. - const char *CopyString(Twine String); - - // \brief Copy the given string into this allocator. - const char *CopyString(const char *String) { - return CopyString(StringRef(String)); - } - - /// \brief Copy the given string into this allocator. - const char *CopyString(const std::string &String) { - return CopyString(StringRef(String)); - } + const char *CopyString(const Twine &String); }; /// \brief Allocator for a cached set of global code completions. @@ -885,7 +873,8 @@ public: CodeCompletionString *CreateSignatureString(unsigned CurrentArg, Sema &S, CodeCompletionAllocator &Allocator, - CodeCompletionTUInfo &CCTUInfo) const; + CodeCompletionTUInfo &CCTUInfo, + bool IncludeBriefComments) const; }; CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, diff --git a/include/clang/Sema/DeclSpec.h b/include/clang/Sema/DeclSpec.h index d368826..de39d83 100644 --- a/include/clang/Sema/DeclSpec.h +++ b/include/clang/Sema/DeclSpec.h @@ -57,7 +57,7 @@ namespace clang { /// These can be in 3 states: /// 1) Not present, identified by isEmpty() /// 2) Present, identified by isNotEmpty() -/// 2.a) Valid, idenified by isValid() +/// 2.a) Valid, identified by isValid() /// 2.b) Invalid, identified by isInvalid(). /// /// isSet() is deprecated because it mostly corresponded to "valid" but was @@ -407,8 +407,8 @@ private: return (T == TST_typeofExpr || T == TST_decltype); } - DeclSpec(const DeclSpec &) LLVM_DELETED_FUNCTION; - void operator=(const DeclSpec &) LLVM_DELETED_FUNCTION; + DeclSpec(const DeclSpec &) = delete; + void operator=(const DeclSpec &) = delete; public: static bool isDeclRep(TST T) { return (T == TST_enum || T == TST_struct || @@ -845,8 +845,8 @@ private: /// \brief Represents a C++ unqualified-id that has been parsed. class UnqualifiedId { private: - UnqualifiedId(const UnqualifiedId &Other) LLVM_DELETED_FUNCTION; - const UnqualifiedId &operator=(const UnqualifiedId &) LLVM_DELETED_FUNCTION; + UnqualifiedId(const UnqualifiedId &Other) = delete; + const UnqualifiedId &operator=(const UnqualifiedId &) = delete; public: /// \brief Describes the kind of unqualified-id parsed. @@ -1415,7 +1415,8 @@ struct DeclaratorChunk { static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, SourceLocation ConstQualLoc, SourceLocation VolatileQualLoc, - SourceLocation RestrictQualLoc) { + SourceLocation RestrictQualLoc, + SourceLocation AtomicQualLoc) { DeclaratorChunk I; I.Kind = Pointer; I.Loc = Loc; @@ -1423,6 +1424,7 @@ struct DeclaratorChunk { I.Ptr.ConstQualLoc = ConstQualLoc.getRawEncoding(); I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding(); I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding(); + I.Ptr.AtomicQualLoc = AtomicQualLoc.getRawEncoding(); I.Ptr.AttrList = nullptr; return I; } @@ -2180,7 +2182,7 @@ public: VS_Sealed = 4 }; - VirtSpecifiers() : Specifiers(0) { } + VirtSpecifiers() : Specifiers(0), LastSpecifier(VS_None) { } bool SetSpecifier(Specifier VS, SourceLocation Loc, const char *&PrevSpec); @@ -2198,12 +2200,16 @@ public: static const char *getSpecifierName(Specifier VS); + SourceLocation getFirstLocation() const { return FirstLocation; } SourceLocation getLastLocation() const { return LastLocation; } + Specifier getLastSpecifier() const { return LastSpecifier; } private: unsigned Specifiers; + Specifier LastSpecifier; SourceLocation VS_overrideLoc, VS_finalLoc; + SourceLocation FirstLocation; SourceLocation LastLocation; }; diff --git a/include/clang/Sema/DelayedDiagnostic.h b/include/clang/Sema/DelayedDiagnostic.h index 7fd6779..155b3aa 100644 --- a/include/clang/Sema/DelayedDiagnostic.h +++ b/include/clang/Sema/DelayedDiagnostic.h @@ -240,8 +240,8 @@ class DelayedDiagnosticPool { const DelayedDiagnosticPool *Parent; SmallVector<DelayedDiagnostic, 4> Diagnostics; - DelayedDiagnosticPool(const DelayedDiagnosticPool &) LLVM_DELETED_FUNCTION; - void operator=(const DelayedDiagnosticPool &) LLVM_DELETED_FUNCTION; + DelayedDiagnosticPool(const DelayedDiagnosticPool &) = delete; + void operator=(const DelayedDiagnosticPool &) = delete; public: DelayedDiagnosticPool(const DelayedDiagnosticPool *parent) : Parent(parent) {} ~DelayedDiagnosticPool() { @@ -250,6 +250,17 @@ public: i->Destroy(); } + DelayedDiagnosticPool(DelayedDiagnosticPool &&Other) + : Parent(Other.Parent), Diagnostics(std::move(Other.Diagnostics)) { + Other.Diagnostics.clear(); + } + DelayedDiagnosticPool &operator=(DelayedDiagnosticPool &&Other) { + Parent = Other.Parent; + Diagnostics = std::move(Other.Diagnostics); + Other.Diagnostics.clear(); + return *this; + } + const DelayedDiagnosticPool *getParent() const { return Parent; } /// Does this pool, or any of its ancestors, contain any diagnostics? diff --git a/include/clang/Sema/ExternalSemaSource.h b/include/clang/Sema/ExternalSemaSource.h index c0ef712..ef3d2db 100644 --- a/include/clang/Sema/ExternalSemaSource.h +++ b/include/clang/Sema/ExternalSemaSource.h @@ -27,6 +27,7 @@ template <class T, unsigned n> class SmallSetVector; namespace clang { class CXXConstructorDecl; +class CXXDeleteExpr; class CXXRecordDecl; class DeclaratorDecl; class LookupResult; @@ -55,7 +56,7 @@ public: ExternalASTSource::SemaSource = true; } - ~ExternalSemaSource(); + ~ExternalSemaSource() override; /// \brief Initialize the semantic source with the Sema instance /// being used to perform semantic analysis on the abstract syntax @@ -79,6 +80,9 @@ public: virtual void ReadUndefinedButUsed( llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined); + virtual void ReadMismatchingDeleteExpressions(llvm::MapVector< + FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &); + /// \brief Do last resort, unqualified lookup on a LookupResult that /// Sema cannot find. /// @@ -128,14 +132,6 @@ public: /// introduce the same declarations repeatedly. virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) {} - /// \brief Read the set of dynamic classes known to the external Sema source. - /// - /// The external source should append its own dynamic classes to - /// the given vector of declarations. Note that this routine may be - /// invoked multiple times; the external source should take care not to - /// introduce the same declarations repeatedly. - virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) {} - /// \brief Read the set of potentially unused typedefs known to the source. /// /// The external source should append its own potentially unused local @@ -145,16 +141,6 @@ public: virtual void ReadUnusedLocalTypedefNameCandidates( llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {}; - /// \brief Read the set of locally-scoped external declarations known to the - /// external Sema source. - /// - /// The external source should append its own locally-scoped external - /// declarations to the given vector of declarations. Note that this routine - /// may be invoked multiple times; the external source should take care not - /// to introduce the same declarations repeatedly. - virtual void ReadLocallyScopedExternCDecls( - SmallVectorImpl<NamedDecl *> &Decls) {} - /// \brief Read the set of referenced selectors known to the /// external Sema source. /// @@ -200,7 +186,7 @@ public: /// external source should take care not to introduce the same map entries /// repeatedly. virtual void ReadLateParsedTemplates( - llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {} + llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {} /// \copydoc Sema::CorrectTypo /// \note LookupKind must correspond to a valid Sema::LookupNameKind diff --git a/include/clang/Sema/Initialization.h b/include/clang/Sema/Initialization.h index 9f342b2..74de00f 100644 --- a/include/clang/Sema/Initialization.h +++ b/include/clang/Sema/Initialization.h @@ -844,6 +844,21 @@ private: /// \brief The incomplete type that caused a failure. QualType FailedIncompleteType; + + /// \brief The fixit that needs to be applied to make this initialization + /// succeed. + std::string ZeroInitializationFixit; + SourceLocation ZeroInitializationFixitLoc; + +public: + /// \brief Call for initializations are invalid but that would be valid + /// zero initialzations if Fixit was applied. + void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) { + ZeroInitializationFixit = Fixit; + ZeroInitializationFixitLoc = L; + } + +private: /// \brief Prints a follow-up note that highlights the location of /// the initialized entity, if it's remote. @@ -921,7 +936,7 @@ public: void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; } /// \brief Determine whether the initialization sequence is valid. - LLVM_EXPLICIT operator bool() const { return !Failed(); } + explicit operator bool() const { return !Failed(); } /// \brief Determine whether the initialization sequence is invalid. bool Failed() const { return SequenceKind == FailedSequence; } diff --git a/include/clang/Sema/Lookup.h b/include/clang/Sema/Lookup.h index 1c6c7bb..5bfee8b 100644 --- a/include/clang/Sema/Lookup.h +++ b/include/clang/Sema/Lookup.h @@ -291,9 +291,6 @@ public: if (!D->isHidden()) return true; - if (SemaRef.ActiveTemplateInstantiations.empty()) - return false; - // During template instantiation, we can refer to hidden declarations, if // they were visible in any module along the path of instantiation. return isVisibleSlow(SemaRef, D); @@ -735,22 +732,18 @@ public: } class iterator - : public std::iterator<std::forward_iterator_tag, NamedDecl *> { - typedef llvm::DenseMap<NamedDecl*,NamedDecl*>::iterator inner_iterator; - inner_iterator iter; - + : public llvm::iterator_adaptor_base< + iterator, llvm::DenseMap<NamedDecl *, NamedDecl *>::iterator, + std::forward_iterator_tag, NamedDecl *> { friend class ADLResult; - iterator(const inner_iterator &iter) : iter(iter) {} - public: - iterator() {} - iterator &operator++() { ++iter; return *this; } - iterator operator++(int) { return iterator(iter++); } + iterator(llvm::DenseMap<NamedDecl *, NamedDecl *>::iterator Iter) + : iterator_adaptor_base(std::move(Iter)) {} - value_type operator*() const { return iter->second; } + public: + iterator() {} - bool operator==(const iterator &other) const { return iter == other.iter; } - bool operator!=(const iterator &other) const { return iter != other.iter; } + value_type operator*() const { return I->second; } }; iterator begin() { return iterator(Decls.begin()); } diff --git a/include/clang/Sema/MultiplexExternalSemaSource.h b/include/clang/Sema/MultiplexExternalSemaSource.h index f06d196..af7083a 100644 --- a/include/clang/Sema/MultiplexExternalSemaSource.h +++ b/include/clang/Sema/MultiplexExternalSemaSource.h @@ -51,7 +51,7 @@ public: /// MultiplexExternalSemaSource(ExternalSemaSource& s1, ExternalSemaSource& s2); - ~MultiplexExternalSemaSource(); + ~MultiplexExternalSemaSource() override; ///\brief Appends new source to the source list. /// @@ -86,10 +86,14 @@ public: /// stream into an array of specifiers. CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override; + /// \brief Resolve a handle to a list of ctor initializers into the list of + /// initializers themselves. + CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override; + /// \brief Find all declarations with the given name in the /// given context. - bool - FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override; + bool FindExternalVisibleDeclsByName(const DeclContext *DC, + DeclarationName Name) override; /// \brief Ensures that the table of all visible declarations inside this /// context is up to date. @@ -226,6 +230,10 @@ public: void ReadUndefinedButUsed( llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined) override; + void ReadMismatchingDeleteExpressions(llvm::MapVector< + FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & + Exprs) override; + /// \brief Do last resort, unqualified lookup on a LookupResult that /// Sema cannot find. /// @@ -274,14 +282,6 @@ public: /// introduce the same declarations repeatedly. void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls) override; - /// \brief Read the set of dynamic classes known to the external Sema source. - /// - /// The external source should append its own dynamic classes to - /// the given vector of declarations. Note that this routine may be - /// invoked multiple times; the external source should take care not to - /// introduce the same declarations repeatedly. - void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl*> &Decls) override; - /// \brief Read the set of potentially unused typedefs known to the source. /// /// The external source should append its own potentially unused local @@ -291,16 +291,6 @@ public: void ReadUnusedLocalTypedefNameCandidates( llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override; - /// \brief Read the set of locally-scoped extern "C" declarations known to the - /// external Sema source. - /// - /// The external source should append its own locally-scoped external - /// declarations to the given vector of declarations. Note that this routine - /// may be invoked multiple times; the external source should take care not - /// to introduce the same declarations repeatedly. - void ReadLocallyScopedExternCDecls( - SmallVectorImpl<NamedDecl*> &Decls) override; - /// \brief Read the set of referenced selectors known to the /// external Sema source. /// @@ -345,8 +335,8 @@ public: /// external source should take care not to introduce the same map entries /// repeatedly. void ReadLateParsedTemplates( - llvm::DenseMap<const FunctionDecl *, - LateParsedTemplate *> &LPTMap) override; + llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) + override; /// \copydoc ExternalSemaSource::CorrectTypo /// \note Returns the first nonempty correction. diff --git a/include/clang/Sema/Overload.h b/include/clang/Sema/Overload.h index 4447db2..2007dcb 100644 --- a/include/clang/Sema/Overload.h +++ b/include/clang/Sema/Overload.h @@ -718,8 +718,8 @@ namespace clang { llvm::AlignedCharArray<llvm::AlignOf<ImplicitConversionSequence>::Alignment, 16 * sizeof(ImplicitConversionSequence)> InlineSpace; - OverloadCandidateSet(const OverloadCandidateSet &) LLVM_DELETED_FUNCTION; - void operator=(const OverloadCandidateSet &) LLVM_DELETED_FUNCTION; + OverloadCandidateSet(const OverloadCandidateSet &) = delete; + void operator=(const OverloadCandidateSet &) = delete; void destroyCandidates(); diff --git a/include/clang/Sema/Ownership.h b/include/clang/Sema/Ownership.h index 8031562..8acf9e8 100644 --- a/include/clang/Sema/Ownership.h +++ b/include/clang/Sema/Ownership.h @@ -79,7 +79,7 @@ namespace clang { Ptr = Traits::getAsVoidPointer(P); } - LLVM_EXPLICIT operator bool() const { return Ptr != nullptr; } + explicit operator bool() const { return Ptr != nullptr; } void *getAsOpaquePtr() const { return Ptr; } static OpaquePtr getFromOpaquePtr(void *P) { return OpaquePtr(P); } diff --git a/include/clang/Sema/Scope.h b/include/clang/Sema/Scope.h index 97e447d..dfc6f9c 100644 --- a/include/clang/Sema/Scope.h +++ b/include/clang/Sema/Scope.h @@ -115,8 +115,14 @@ public: /// This scope corresponds to an enum. EnumScope = 0x40000, - /// This scope corresponds to a SEH try. + /// This scope corresponds to an SEH try. SEHTryScope = 0x80000, + + /// This scope corresponds to an SEH except. + SEHExceptScope = 0x100000, + + /// We are currently in the filter expression of an SEH except block. + SEHFilterScope = 0x200000, }; private: /// The parent scope for this scope. This is null for the translation-unit @@ -133,7 +139,9 @@ private: /// \brief Declarations with static linkage are mangled with the number of /// scopes seen as a component. - unsigned short MSLocalManglingNumber; + unsigned short MSLastManglingNumber; + + unsigned short MSCurManglingNumber; /// PrototypeDepth - This is the number of function prototype scopes /// enclosing this scope, including this scope. @@ -146,7 +154,7 @@ private: /// FnParent - If this scope has a parent scope that is a function body, this /// pointer is non-null and points to it. This is used for label processing. Scope *FnParent; - Scope *MSLocalManglingParent; + Scope *MSLastManglingParent; /// BreakParent/ContinueParent - This is a direct link to the innermost /// BreakScope/ContinueScope which contains the contents of this scope @@ -212,10 +220,10 @@ public: const Scope *getFnParent() const { return FnParent; } Scope *getFnParent() { return FnParent; } - const Scope *getMSLocalManglingParent() const { - return MSLocalManglingParent; + const Scope *getMSLastManglingParent() const { + return MSLastManglingParent; } - Scope *getMSLocalManglingParent() { return MSLocalManglingParent; } + Scope *getMSLastManglingParent() { return MSLastManglingParent; } /// getContinueParent - Return the closest scope that a continue statement /// would be affected by. @@ -269,22 +277,30 @@ public: DeclsInScope.erase(D); } - void incrementMSLocalManglingNumber() { - if (Scope *MSLMP = getMSLocalManglingParent()) - MSLMP->MSLocalManglingNumber += 1; + void incrementMSManglingNumber() { + if (Scope *MSLMP = getMSLastManglingParent()) { + MSLMP->MSLastManglingNumber += 1; + MSCurManglingNumber += 1; + } } - void decrementMSLocalManglingNumber() { - if (Scope *MSLMP = getMSLocalManglingParent()) - MSLMP->MSLocalManglingNumber -= 1; + void decrementMSManglingNumber() { + if (Scope *MSLMP = getMSLastManglingParent()) { + MSLMP->MSLastManglingNumber -= 1; + MSCurManglingNumber -= 1; + } } - unsigned getMSLocalManglingNumber() const { - if (const Scope *MSLMP = getMSLocalManglingParent()) - return MSLMP->MSLocalManglingNumber; + unsigned getMSLastManglingNumber() const { + if (const Scope *MSLMP = getMSLastManglingParent()) + return MSLMP->MSLastManglingNumber; return 1; } + unsigned getMSCurManglingNumber() const { + return MSCurManglingNumber; + } + /// isDeclScope - Return true if this is the scope that the specified decl is /// declared in. bool isDeclScope(Decl *D) { @@ -407,6 +423,15 @@ public: /// \brief Determine whether this scope is a SEH '__try' block. bool isSEHTryScope() const { return getFlags() & Scope::SEHTryScope; } + /// \brief Determine whether this scope is a SEH '__except' block. + bool isSEHExceptScope() const { return getFlags() & Scope::SEHExceptScope; } + + /// \brief Returns if rhs has a higher scope depth than this. + /// + /// The caller is responsible for calling this only if one of the two scopes + /// is an ancestor of the other. + bool Contains(const Scope& rhs) const { return Depth < rhs.Depth; } + /// containedInPrototypeScope - Return true if this or a parent scope /// is a FunctionPrototypeScope. bool containedInPrototypeScope() const; diff --git a/include/clang/Sema/ScopeInfo.h b/include/clang/Sema/ScopeInfo.h index d63b734..15ee8a4 100644 --- a/include/clang/Sema/ScopeInfo.h +++ b/include/clang/Sema/ScopeInfo.h @@ -124,6 +124,12 @@ public: /// false if there is an invocation of an initializer on 'self'. bool ObjCWarnForNoInitDelegation; + /// First C++ 'try' statement in the current function. + SourceLocation FirstCXXTryLoc; + + /// First SEH '__try' statement in the current function. + SourceLocation FirstSEHTryLoc; + /// \brief Used to determine if errors occurred in this function or block. DiagnosticErrorTrap ErrorTrap; @@ -321,6 +327,16 @@ public: HasDroppedStmt = true; } + void setHasCXXTry(SourceLocation TryLoc) { + setHasBranchProtectedScope(); + FirstCXXTryLoc = TryLoc; + } + + void setHasSEHTry(SourceLocation TryLoc) { + setHasBranchProtectedScope(); + FirstSEHTryLoc = TryLoc; + } + bool NeedsScopeChecking() const { return !HasDroppedStmt && (HasIndirectGoto || @@ -552,7 +568,7 @@ public: Kind = SK_Block; } - virtual ~BlockScopeInfo(); + ~BlockScopeInfo() override; static bool classof(const FunctionScopeInfo *FSI) { return FSI->Kind == SK_Block; @@ -583,7 +599,7 @@ public: Kind = SK_CapturedRegion; } - virtual ~CapturedRegionScopeInfo(); + ~CapturedRegionScopeInfo() override; /// \brief A descriptive name for the kind of captured region this is. StringRef getRegionName() const { @@ -632,13 +648,6 @@ public: /// \brief Whether the lambda contains an unexpanded parameter pack. bool ContainsUnexpandedParameterPack; - /// \brief Variables used to index into by-copy array captures. - SmallVector<VarDecl *, 4> ArrayIndexVars; - - /// \brief Offsets into the ArrayIndexVars array at which each capture starts - /// its list of array index variables. - SmallVector<unsigned, 4> ArrayIndexStarts; - /// \brief If this is a generic lambda, use this as the depth of /// each 'auto' parameter, during initial AST construction. unsigned AutoTemplateParameterDepth; @@ -682,13 +691,13 @@ public: LambdaScopeInfo(DiagnosticsEngine &Diag) : CapturingScopeInfo(Diag, ImpCap_None), Lambda(nullptr), CallOperator(nullptr), NumExplicitCaptures(0), Mutable(false), - ExprNeedsCleanups(false), ContainsUnexpandedParameterPack(false), - AutoTemplateParameterDepth(0), GLTemplateParameterList(nullptr) - { + ExplicitParams(false), ExprNeedsCleanups(false), + ContainsUnexpandedParameterPack(false), AutoTemplateParameterDepth(0), + GLTemplateParameterList(nullptr) { Kind = SK_Lambda; } - virtual ~LambdaScopeInfo(); + ~LambdaScopeInfo() override; /// \brief Note when all explicit captures have been added. void finishedExplicitCaptures() { @@ -826,9 +835,6 @@ CapturingScopeInfo::addThisCapture(bool isNested, SourceLocation Loc, Captures.push_back(Capture(Capture::ThisCapture, isNested, Loc, CaptureType, Cpy)); CXXThisCaptureIndex = Captures.size(); - - if (LambdaScopeInfo *LSI = dyn_cast<LambdaScopeInfo>(this)) - LSI->ArrayIndexStarts.push_back(LSI->ArrayIndexVars.size()); } } // end namespace sema diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index a364214..39ea3c6 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -78,6 +78,7 @@ namespace clang { typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; class CXXConstructorDecl; class CXXConversionDecl; + class CXXDeleteExpr; class CXXDestructorDecl; class CXXFieldCollector; class CXXMemberCallExpr; @@ -199,6 +200,11 @@ namespace sema { class TemplateDeductionInfo; } +namespace threadSafety { + class BeforeSet; + void threadSafetyCleanup(BeforeSet* Cache); +} + // FIXME: No way to easily map from TemplateTypeParmTypes to // TemplateTypeParmDecls, so we have this horrible PointerUnion. typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>, @@ -206,8 +212,8 @@ typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>, /// Sema - This implements semantic analysis and AST building for C. class Sema { - Sema(const Sema &) LLVM_DELETED_FUNCTION; - void operator=(const Sema &) LLVM_DELETED_FUNCTION; + Sema(const Sema &) = delete; + void operator=(const Sema &) = delete; ///\brief Source of additional semantic information. ExternalSemaSource *ExternalSource; @@ -217,15 +223,17 @@ class Sema { static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD); - static bool - shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, const NamedDecl *New) { + bool isVisibleSlow(const NamedDecl *D); + + bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, + const NamedDecl *New) { // We are about to link these. It is now safe to compute the linkage of // the new decl. If the new decl has external linkage, we will // link it with the hidden decl (which also has external linkage) and // it will keep having external linkage. If it has internal linkage, we // will not link it. Since it has no previous decls, it will remain // with internal linkage. - return !Old->isHidden() || New->isExternallyVisible(); + return isVisible(Old) || New->isExternallyVisible(); } public: @@ -298,6 +306,9 @@ public: /// The stack always has at least one element in it. SmallVector<MSVtorDispAttr::Mode, 2> VtorDispModeStack; + /// Stack of active SEH __finally scopes. Can be empty. + SmallVector<Scope*, 2> CurrentSEHFinally; + /// \brief Source location for newly created implicit MSInheritanceAttrs SourceLocation ImplicitMSInheritanceAttrLoc; @@ -394,6 +405,15 @@ public: llvm::SmallSetVector<const TypedefNameDecl *, 4> UnusedLocalTypedefNameCandidates; + /// \brief Delete-expressions to be analyzed at the end of translation unit + /// + /// This list contains class members, and locations of delete-expressions + /// that could not be proven as to whether they mismatch with new-expression + /// used in initializer of the field. + typedef std::pair<SourceLocation, bool> DeleteExprLoc; + typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs; + llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs; + typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; /// PureVirtualClassDiagSet - a set of class declarations which we have @@ -405,33 +425,6 @@ public: /// we are currently parsing the initializer. llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; - /// \brief A mapping from external names to the most recent - /// locally-scoped extern "C" declaration with that name. - /// - /// This map contains external declarations introduced in local - /// scopes, e.g., - /// - /// \code - /// extern "C" void f() { - /// void foo(int, int); - /// } - /// \endcode - /// - /// Here, the name "foo" will be associated with the declaration of - /// "foo" within f. This name is not visible outside of - /// "f". However, we still find it in two cases: - /// - /// - If we are declaring another global or extern "C" entity with - /// the name "foo", we can find "foo" as a previous declaration, - /// so that the types of this external declaration can be checked - /// for compatibility. - /// - /// - If we would implicitly declare "foo" (e.g., due to a call to - /// "foo" in C when no prototype or definition is visible), then - /// we find this declaration of "foo" and complain that it is - /// not visible. - llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternCDecls; - /// \brief Look for a locally scoped extern "C" declaration by the given name. NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name); @@ -474,8 +467,8 @@ public: SmallVector<std::pair<CXXMethodDecl*, const FunctionProtoType*>, 2> DelayedDefaultedMemberExceptionSpecs; - typedef llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> - LateParsedTemplateMapT; + typedef llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> + LateParsedTemplateMapT; LateParsedTemplateMapT LateParsedTemplateMap; /// \brief Callback to the parser to parse templated functions when needed. @@ -611,7 +604,7 @@ public: /// WeakUndeclaredIdentifiers - Identifiers contained in /// \#pragma weak before declared. rare. may alias another /// identifier, declared or undeclared - llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers; + llvm::MapVector<IdentifierInfo *, WeakInfo> WeakUndeclaredIdentifiers; /// ExtnameUndeclaredIdentifiers - Identifiers contained in /// \#pragma redefine_extname before declared. Used in Solaris system headers @@ -678,12 +671,27 @@ public: /// \brief The declaration of the Objective-C NSArray class. ObjCInterfaceDecl *NSArrayDecl; + /// \brief Pointer to NSMutableArray type (NSMutableArray *). + QualType NSMutableArrayPointer; + /// \brief The declaration of the arrayWithObjects:count: method. ObjCMethodDecl *ArrayWithObjectsMethod; /// \brief The declaration of the Objective-C NSDictionary class. ObjCInterfaceDecl *NSDictionaryDecl; + /// \brief Pointer to NSMutableDictionary type (NSMutableDictionary *). + QualType NSMutableDictionaryPointer; + + /// \brief Pointer to NSMutableSet type (NSMutableSet *). + QualType NSMutableSetPointer; + + /// \brief Pointer to NSCountedSet type (NSCountedSet *). + QualType NSCountedSetPointer; + + /// \brief Pointer to NSMutableOrderedSet type (NSMutableOrderedSet *). + QualType NSMutableOrderedSetPointer; + /// \brief The declaration of the dictionaryWithObjects:forKeys:count: method. ObjCMethodDecl *DictionaryWithObjectsMethod; @@ -890,6 +898,11 @@ public: void getUndefinedButUsed( SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined); + /// Retrieves list of suspicious delete-expressions that will be checked at + /// the end of translation unit. + const llvm::MapVector<FieldDecl *, DeleteLocs> & + getMismatchingDeleteExpressions() const; + typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods; typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool; @@ -903,7 +916,7 @@ public: /// Method selectors used in a \@selector expression. Used for implementation /// of -Wselector. - llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors; + llvm::MapVector<Selector, SourceLocation> ReferencedSelectors; /// Kinds of C++ special members. enum CXXSpecialMember { @@ -1254,117 +1267,82 @@ public: static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); } static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} - template<typename T1> - class BoundTypeDiagnoser1 : public TypeDiagnoser { + template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser { unsigned DiagID; - const T1 &Arg1; + std::tuple<const Ts &...> Args; + + template <std::size_t... Is> + void emit(const SemaDiagnosticBuilder &DB, + llvm::index_sequence<Is...>) const { + // Apply all tuple elements to the builder in order. + bool Dummy[] = {(DB << getPrintable(std::get<Is>(Args)))...}; + (void)Dummy; + } public: - BoundTypeDiagnoser1(unsigned DiagID, const T1 &Arg1) - : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1) { } + BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args) + : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Args(Args...) {} + void diagnose(Sema &S, SourceLocation Loc, QualType T) override { - if (Suppressed) return; - S.Diag(Loc, DiagID) << getPrintable(Arg1) << T; + if (Suppressed) + return; + const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID); + emit(DB, llvm::index_sequence_for<Ts...>()); + DB << T; } - - virtual ~BoundTypeDiagnoser1() { } }; - template<typename T1, typename T2> - class BoundTypeDiagnoser2 : public TypeDiagnoser { - unsigned DiagID; - const T1 &Arg1; - const T2 &Arg2; - - public: - BoundTypeDiagnoser2(unsigned DiagID, const T1 &Arg1, - const T2 &Arg2) - : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1), - Arg2(Arg2) { } +private: + bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, + TypeDiagnoser &Diagnoser); - void diagnose(Sema &S, SourceLocation Loc, QualType T) override { - if (Suppressed) return; - S.Diag(Loc, DiagID) << getPrintable(Arg1) << getPrintable(Arg2) << T; - } + VisibleModuleSet VisibleModules; + llvm::SmallVector<VisibleModuleSet, 16> VisibleModulesStack; - virtual ~BoundTypeDiagnoser2() { } - }; + Module *CachedFakeTopLevelModule; - template<typename T1, typename T2, typename T3> - class BoundTypeDiagnoser3 : public TypeDiagnoser { - unsigned DiagID; - const T1 &Arg1; - const T2 &Arg2; - const T3 &Arg3; +public: + /// \brief Get the module owning an entity. + Module *getOwningModule(Decl *Entity); - public: - BoundTypeDiagnoser3(unsigned DiagID, const T1 &Arg1, - const T2 &Arg2, const T3 &Arg3) - : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1), - Arg2(Arg2), Arg3(Arg3) { } + /// \brief Make a merged definition of an existing hidden definition \p ND + /// visible at the specified location. + void makeMergedDefinitionVisible(NamedDecl *ND, SourceLocation Loc); - void diagnose(Sema &S, SourceLocation Loc, QualType T) override { - if (Suppressed) return; - S.Diag(Loc, DiagID) - << getPrintable(Arg1) << getPrintable(Arg2) << getPrintable(Arg3) << T; - } + bool isModuleVisible(Module *M) { return VisibleModules.isVisible(M); } - virtual ~BoundTypeDiagnoser3() { } - }; + /// Determine whether a declaration is visible to name lookup. + bool isVisible(const NamedDecl *D) { + return !D->isHidden() || isVisibleSlow(D); + } + bool hasVisibleMergedDefinition(NamedDecl *Def); + + /// Determine if \p D has a visible definition. If not, suggest a declaration + /// that should be made visible to expose the definition. + bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested); + bool hasVisibleDefinition(const NamedDecl *D) { + NamedDecl *Hidden; + return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden); + } -private: - bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, - TypeDiagnoser &Diagnoser); -public: bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser); bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID); - template<typename T1> - bool RequireCompleteType(SourceLocation Loc, QualType T, - unsigned DiagID, const T1 &Arg1) { - BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); - return RequireCompleteType(Loc, T, Diagnoser); - } - - template<typename T1, typename T2> - bool RequireCompleteType(SourceLocation Loc, QualType T, - unsigned DiagID, const T1 &Arg1, const T2 &Arg2) { - BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); - return RequireCompleteType(Loc, T, Diagnoser); - } - - template<typename T1, typename T2, typename T3> - bool RequireCompleteType(SourceLocation Loc, QualType T, - unsigned DiagID, const T1 &Arg1, const T2 &Arg2, - const T3 &Arg3) { - BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, - Arg3); + template <typename... Ts> + bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, + const Ts &...Args) { + BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); return RequireCompleteType(Loc, T, Diagnoser); } bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser); bool RequireCompleteExprType(Expr *E, unsigned DiagID); - template<typename T1> - bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1) { - BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); - return RequireCompleteExprType(E, Diagnoser); - } - - template<typename T1, typename T2> - bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1, - const T2 &Arg2) { - BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); - return RequireCompleteExprType(E, Diagnoser); - } - - template<typename T1, typename T2, typename T3> - bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1, - const T2 &Arg2, const T3 &Arg3) { - BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, - Arg3); + template <typename... Ts> + bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) { + BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); return RequireCompleteExprType(E, Diagnoser); } @@ -1372,26 +1350,10 @@ public: TypeDiagnoser &Diagnoser); bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); - template<typename T1> - bool RequireLiteralType(SourceLocation Loc, QualType T, - unsigned DiagID, const T1 &Arg1) { - BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); - return RequireLiteralType(Loc, T, Diagnoser); - } - - template<typename T1, typename T2> - bool RequireLiteralType(SourceLocation Loc, QualType T, - unsigned DiagID, const T1 &Arg1, const T2 &Arg2) { - BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); - return RequireLiteralType(Loc, T, Diagnoser); - } - - template<typename T1, typename T2, typename T3> - bool RequireLiteralType(SourceLocation Loc, QualType T, - unsigned DiagID, const T1 &Arg1, const T2 &Arg2, - const T3 &Arg3) { - BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, - Arg3); + template <typename... Ts> + bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID, + const Ts &...Args) { + BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); return RequireLiteralType(Loc, T, Diagnoser); } @@ -1592,6 +1554,9 @@ public: void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R); void CheckShadow(Scope *S, VarDecl *D); void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); + void handleTagNumbering(const TagDecl *Tag, Scope *TagScope); + void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, + TypedefNameDecl *NewTD); void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, TypeSourceInfo *TInfo, @@ -1748,6 +1713,11 @@ public: /// #include or similar preprocessing directive. void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod); + /// \brief The parsed has entered a submodule. + void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod); + /// \brief The parser has left a submodule. + void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod); + /// \brief Create an implicit import of the given module at the given /// source location, for error recovery, if possible. /// @@ -1797,6 +1767,12 @@ public: TUK_Friend // Friend declaration: 'friend struct foo;' }; + struct SkipBodyInfo { + SkipBodyInfo() : ShouldSkip(false), Previous(nullptr) {} + bool ShouldSkip; + NamedDecl *Previous; + }; + Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, @@ -1806,7 +1782,7 @@ public: bool &OwnedDecl, bool &IsDependent, SourceLocation ScopedEnumKWLoc, bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, - bool IsTypeSpecifier); + bool IsTypeSpecifier, SkipBodyInfo *SkipBody = nullptr); Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, unsigned TagSpec, SourceLocation TagLoc, @@ -1871,6 +1847,11 @@ public: /// struct, or union). void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); + /// \brief Invoked when we enter a tag definition that we're skipping. + void ActOnTagStartSkippedDefinition(Scope *S, Decl *TD) { + PushDeclContext(S, cast<DeclContext>(TD)); + } + Decl *ActOnObjCContainerStartDefinition(Decl *IDecl); /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a @@ -1886,6 +1867,10 @@ public: void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, SourceLocation RBraceLoc); + void ActOnTagFinishSkippedDefinition() { + PopDeclContext(); + } + void ActOnObjCContainerFinishDefinition(); /// \brief Invoked when we must temporarily exit the objective-c container @@ -1908,6 +1893,11 @@ public: bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, QualType EnumUnderlyingTy, const EnumDecl *Prev); + /// Determine whether the body of an anonymous enumeration should be skipped. + /// \param II The name of the first enumerator. + SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, + SourceLocation IILoc); + Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, SourceLocation IdLoc, IdentifierInfo *Id, AttributeList *Attrs, @@ -2279,8 +2269,9 @@ public: void AddFunctionCandidates(const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, + TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, bool SuppressUserConversions = false, - TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); + bool PartialOverloading = false); void AddMethodCandidate(DeclAccessPair FoundDecl, QualType ObjectType, Expr::Classification ObjectClassification, @@ -2293,7 +2284,8 @@ public: Expr::Classification ObjectClassification, ArrayRef<Expr *> Args, OverloadCandidateSet& CandidateSet, - bool SuppressUserConversions = false); + bool SuppressUserConversions = false, + bool PartialOverloading = false); void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, @@ -2302,13 +2294,15 @@ public: Expr::Classification ObjectClassification, ArrayRef<Expr *> Args, OverloadCandidateSet& CandidateSet, - bool SuppressUserConversions = false); + bool SuppressUserConversions = false, + bool PartialOverloading = false); void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, OverloadCandidateSet& CandidateSet, - bool SuppressUserConversions = false); + bool SuppressUserConversions = false, + bool PartialOverloading = false); void AddConversionCandidate(CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, @@ -2731,18 +2725,44 @@ public: bool EnteringContext = false, const ObjCObjectPointerType *OPT = nullptr); + /// \brief Process any TypoExprs in the given Expr and its children, + /// generating diagnostics as appropriate and returning a new Expr if there + /// were typos that were all successfully corrected and ExprError if one or + /// more typos could not be corrected. + /// + /// \param E The Expr to check for TypoExprs. + /// + /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its + /// initializer. + /// + /// \param Filter A function applied to a newly rebuilt Expr to determine if + /// it is an acceptable/usable result from a single combination of typo + /// corrections. As long as the filter returns ExprError, different + /// combinations of corrections will be tried until all are exhausted. ExprResult - CorrectDelayedTyposInExpr(Expr *E, + CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl = nullptr, llvm::function_ref<ExprResult(Expr *)> Filter = [](Expr *E) -> ExprResult { return E; }); ExprResult - CorrectDelayedTyposInExpr(ExprResult ER, + CorrectDelayedTyposInExpr(Expr *E, + llvm::function_ref<ExprResult(Expr *)> Filter) { + return CorrectDelayedTyposInExpr(E, nullptr, Filter); + } + + ExprResult + CorrectDelayedTyposInExpr(ExprResult ER, VarDecl *InitDecl = nullptr, llvm::function_ref<ExprResult(Expr *)> Filter = [](Expr *E) -> ExprResult { return E; }) { return ER.isInvalid() ? ER : CorrectDelayedTyposInExpr(ER.get(), Filter); } + ExprResult + CorrectDelayedTyposInExpr(ExprResult ER, + llvm::function_ref<ExprResult(Expr *)> Filter) { + return CorrectDelayedTyposInExpr(ER, nullptr, Filter); + } + void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery = true); @@ -2798,6 +2818,7 @@ public: bool checkStringLiteralArgumentAttr(const AttributeList &Attr, unsigned ArgNum, StringRef &Str, SourceLocation *ArgLocation = nullptr); + bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); bool checkMSInheritanceAttrOnDefinition( CXXRecordDecl *RD, SourceRange Range, bool BestCase, MSInheritanceAttr::Spelling SemanticSpelling); @@ -2967,7 +2988,7 @@ private: /// optionally warns if there are multiple signatures. ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, bool receiverIdOrClass, - bool warn, bool instance); + bool instance); public: /// \brief - Returns instance or factory methods in global method pool for @@ -2977,8 +2998,13 @@ public: SmallVectorImpl<ObjCMethodDecl*>& Methods, bool instance); - bool AreMultipleMethodsInGlobalPool(Selector Sel, - bool instance); + bool AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod, + SourceRange R, + bool receiverIdOrClass); + + void DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods, + Selector Sel, SourceRange R, + bool receiverIdOrClass); private: /// \brief - Returns a selector which best matches given argument list or @@ -3016,19 +3042,17 @@ public: /// LookupInstanceMethodInGlobalPool - Returns the method and warns if /// there are multiple signatures. ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, - bool receiverIdOrClass=false, - bool warn=true) { + bool receiverIdOrClass=false) { return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, - warn, /*instance*/true); + /*instance*/true); } /// LookupFactoryMethodInGlobalPool - Returns the method and warns if /// there are multiple signatures. ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, - bool receiverIdOrClass=false, - bool warn=true) { + bool receiverIdOrClass=false) { return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, - warn, /*instance*/false); + /*instance*/false); } const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel, @@ -3295,7 +3319,9 @@ public: StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block); - StmtResult ActOnSEHFinallyBlock(SourceLocation Loc, Stmt *Block); + void ActOnStartSEHFinallyBlock(); + void ActOnAbortSEHFinallyBlock(); + StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); @@ -3346,7 +3372,7 @@ public: void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); - enum AvailabilityDiagnostic { AD_Deprecation, AD_Unavailable }; + enum AvailabilityDiagnostic { AD_Deprecation, AD_Unavailable, AD_Partial }; void EmitAvailabilityWarning(AvailabilityDiagnostic AD, NamedDecl *D, StringRef Message, @@ -3656,7 +3682,6 @@ public: Scope *S; UnqualifiedId &Id; Decl *ObjCImpDecl; - bool HasTrailingLParen; }; ExprResult BuildMemberReferenceExpr( @@ -3695,8 +3720,7 @@ public: CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Member, - Decl *ObjCImpDecl, - bool HasTrailingLParen); + Decl *ObjCImpDecl); void ActOnDefaultCtorInitializers(Decl *CDtorDecl); bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, @@ -3989,7 +4013,8 @@ public: SourceLocation UsingLoc, UnqualifiedId &Name, AttributeList *AttrList, - TypeResult Type); + TypeResult Type, + Decl *DeclFromDeclSpec); /// BuildCXXConstructExpr - Creates a complete call to a constructor, /// including handling of its default argument expressions. @@ -4437,8 +4462,7 @@ public: ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, bool IsThrownVarInScope); - ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E, - bool IsThrownVarInScope); + bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E); /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. /// Can be interpreted either as function-style casting ("int(x)") @@ -4489,7 +4513,7 @@ public: void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, QualType Param1, QualType Param2 = QualType(), - bool addMallocAttr = false); + bool addRestrictAttr = false); bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, DeclarationName Name, FunctionDecl* &Operator, @@ -4554,8 +4578,6 @@ public: ParsedType &ObjectType, bool &MayBePseudoDestructor); - ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr); - ExprResult BuildPseudoDestructorExpr(Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, @@ -4563,8 +4585,7 @@ public: TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, - PseudoDestructorTypeStorage DestroyedType, - bool HasTrailingLParen); + PseudoDestructorTypeStorage DestroyedType); ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, SourceLocation OpLoc, @@ -4573,15 +4594,13 @@ public: UnqualifiedId &FirstTypeName, SourceLocation CCLoc, SourceLocation TildeLoc, - UnqualifiedId &SecondTypeName, - bool HasTrailingLParen); + UnqualifiedId &SecondTypeName); ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, SourceLocation TildeLoc, - const DeclSpec& DS, - bool HasTrailingLParen); + const DeclSpec& DS); /// MaybeCreateExprWithCleanups - If the current full-expression /// requires any cleanups, surround it with a ExprWithCleanups node. @@ -4632,7 +4651,8 @@ public: bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, SourceLocation ColonColonLoc, CXXScopeSpec &SS); - bool isAcceptableNestedNameSpecifier(const NamedDecl *SD); + bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, + bool *CanCorrect = nullptr); NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, @@ -4854,8 +4874,12 @@ public: /// ActOnLambdaExpr - This is called when the body of a lambda expression /// was successfully completed. ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, - Scope *CurScope, - bool IsInstantiation = false); + Scope *CurScope); + + /// \brief Complete a lambda-expression having processed and attached the + /// lambda body. + ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, + sema::LambdaScopeInfo *LSI); /// \brief Define the "body" of the conversion from a lambda object to a /// function pointer. @@ -5056,14 +5080,6 @@ public: /// \brief Load any externally-stored vtable uses. void LoadExternalVTableUses(); - typedef LazyVector<CXXRecordDecl *, ExternalSemaSource, - &ExternalSemaSource::ReadDynamicClasses, 2, 2> - DynamicClassesType; - - /// \brief A list of all of the dynamic classes in this translation - /// unit. - DynamicClassesType DynamicClasses; - /// \brief Note that the vtable for the given class was used at the /// given location. void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, @@ -5093,6 +5109,7 @@ public: ArrayRef<CXXCtorInitializer*> MemInits, bool AnyErrors); + void checkClassLevelDLLAttribute(CXXRecordDecl *Class); void CheckCompletedCXXClass(CXXRecordDecl *Record); void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, Decl *TagDecl, @@ -5100,6 +5117,7 @@ public: SourceLocation RBrac, AttributeList *AttrList); void ActOnFinishCXXMemberDecls(); + void ActOnFinishCXXMemberDefaultArgs(Decl *D); void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param); unsigned ActOnReenterTemplateScope(Scope *S, Decl *Template); @@ -5177,8 +5195,6 @@ public: // FIXME: I don't like this name. void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); - bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); - bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, SourceLocation Loc, SourceRange Range, CXXCastPath *BasePath = nullptr, @@ -5305,27 +5321,10 @@ public: bool RequireNonAbstractType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser); - template<typename T1> - bool RequireNonAbstractType(SourceLocation Loc, QualType T, - unsigned DiagID, - const T1 &Arg1) { - BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); - return RequireNonAbstractType(Loc, T, Diagnoser); - } - - template<typename T1, typename T2> - bool RequireNonAbstractType(SourceLocation Loc, QualType T, - unsigned DiagID, - const T1 &Arg1, const T2 &Arg2) { - BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); - return RequireNonAbstractType(Loc, T, Diagnoser); - } - - template<typename T1, typename T2, typename T3> - bool RequireNonAbstractType(SourceLocation Loc, QualType T, - unsigned DiagID, - const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) { - BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, Arg3); + template <typename... Ts> + bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, + const Ts &...Args) { + BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); return RequireNonAbstractType(Loc, T, Diagnoser); } @@ -5437,7 +5436,8 @@ public: SourceLocation ModulePrivateLoc, SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists, - TemplateParameterList **OuterTemplateParamLists); + TemplateParameterList **OuterTemplateParamLists, + SkipBodyInfo *SkipBody = nullptr); void translateTemplateArguments(const ASTTemplateArgsPtr &In, TemplateArgumentListInfo &Out); @@ -5510,7 +5510,8 @@ public: SourceLocation ModulePrivateLoc, TemplateIdAnnotation &TemplateId, AttributeList *Attr, - MultiTemplateParamsArg TemplateParameterLists); + MultiTemplateParamsArg TemplateParameterLists, + SkipBodyInfo *SkipBody = nullptr); Decl *ActOnTemplateDeclarator(Scope *S, MultiTemplateParamsArg TemplateParameterLists, @@ -6181,14 +6182,16 @@ public: unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, - SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr); + SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr, + bool PartialOverloading = false); TemplateDeductionResult DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, FunctionDecl *&Specialization, - sema::TemplateDeductionInfo &Info); + sema::TemplateDeductionInfo &Info, + bool PartialOverloading = false); TemplateDeductionResult DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, @@ -6593,19 +6596,17 @@ public: bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, SourceRange InstantiationRange); - // FIXME: Replace this with a constructor once we can use delegating - // constructors in llvm. - void Initialize( - ActiveTemplateInstantiation::InstantiationKind Kind, + InstantiatingTemplate( + Sema &SemaRef, ActiveTemplateInstantiation::InstantiationKind Kind, SourceLocation PointOfInstantiation, SourceRange InstantiationRange, Decl *Entity, NamedDecl *Template = nullptr, ArrayRef<TemplateArgument> TemplateArgs = ArrayRef<TemplateArgument>(), sema::TemplateDeductionInfo *DeductionInfo = nullptr); - InstantiatingTemplate(const InstantiatingTemplate&) LLVM_DELETED_FUNCTION; + InstantiatingTemplate(const InstantiatingTemplate&) = delete; InstantiatingTemplate& - operator=(const InstantiatingTemplate&) LLVM_DELETED_FUNCTION; + operator=(const InstantiatingTemplate&) = delete; }; void PrintInstantiationStack(); @@ -6703,6 +6704,7 @@ public: /// \brief Worker object for performing CFG-based warnings. sema::AnalysisBasedWarnings AnalysisWarnings; + threadSafety::BeforeSet *ThreadSafetyDeclCache; /// \brief An entity for which implicit template instantiation is required. /// @@ -6720,12 +6722,17 @@ public: class SavePendingInstantiationsAndVTableUsesRAII { public: - SavePendingInstantiationsAndVTableUsesRAII(Sema &S): S(S) { + SavePendingInstantiationsAndVTableUsesRAII(Sema &S, bool Enabled) + : S(S), Enabled(Enabled) { + if (!Enabled) return; + SavedPendingInstantiations.swap(S.PendingInstantiations); SavedVTableUses.swap(S.VTableUses); } ~SavePendingInstantiationsAndVTableUsesRAII() { + if (!Enabled) return; + // Restore the set of pending vtables. assert(S.VTableUses.empty() && "VTableUses should be empty before it is discarded."); @@ -6741,6 +6748,7 @@ public: Sema &S; SmallVector<VTableUse, 16> SavedVTableUses; std::deque<PendingImplicitInstantiation> SavedPendingInstantiations; + bool Enabled; }; /// \brief The queue of implicit template instantiations that are required @@ -7030,7 +7038,7 @@ public: unsigned NumElts, AttributeList *attrList); - void FindProtocolDeclaration(bool WarnOnDeclarations, + void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, const IdentifierLocPair *ProtocolId, unsigned NumProtocols, SmallVectorImpl<Decl *> &Protocols); @@ -7471,6 +7479,11 @@ public: void AddAlignValueAttr(SourceRange AttrRange, Decl *D, Expr *E, unsigned SpellingListIndex); + /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular + /// declaration. + void AddLaunchBoundsAttr(SourceRange AttrRange, Decl *D, Expr *MaxThreads, + Expr *MinBlocks, unsigned SpellingListIndex); + // OpenMP directives and clauses. private: void *VarDataSharingAttributesStack; @@ -7490,9 +7503,19 @@ public: void StartOpenMPDSABlock(OpenMPDirectiveKind K, const DeclarationNameInfo &DirName, Scope *CurScope, SourceLocation Loc); + /// \brief Start analysis of clauses. + void StartOpenMPClauses(); + /// \brief End analysis of clauses. + void EndOpenMPClauses(); /// \brief Called on end of data sharing attribute block. void EndOpenMPDSABlock(Stmt *CurDirective); + /// \brief Check if the current region is an OpenMP loop region and if it is, + /// mark loop control variable, used in \p Init for loop initialization, as + /// private by default. + /// \param Init First part of the for loop. + void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init); + // OpenMP directives and clauses. /// \brief Called on correct id-expression from the '#pragma omp /// threadprivate'. @@ -7510,6 +7533,13 @@ public: /// \brief Initialization of captured region for OpenMP region. void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope); + /// \brief End of OpenMP region. + /// + /// \param S Statement associated with the current OpenMP region. + /// \param Clauses List of clauses for the current OpenMP region. + /// + /// \returns Statement for finished OpenMP region. + StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses); StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, @@ -7971,6 +8001,12 @@ public: Expr *SrcExpr, AssignmentAction Action, bool *Complained = nullptr); + /// IsValueInFlagEnum - Determine if a value is allowed as part of a flag + /// enum. If AllowMask is true, then we also allow the complement of a valid + /// value, to be used as a mask. + bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, + bool AllowMask) const; + /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant /// integer not in the range of enum values. void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, @@ -8398,6 +8434,8 @@ public: void CodeCompleteTypeQualifiers(DeclSpec &DS); void CodeCompleteCase(Scope *S); void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef<Expr *> Args); + void CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc, + ArrayRef<Expr *> Args); void CodeCompleteInitializer(Scope *S, Decl *D); void CodeCompleteReturn(Scope *S); void CodeCompleteAfterIf(Scope *S); @@ -8531,8 +8569,10 @@ private: bool CheckAArch64BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); bool CheckMipsBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); + bool CheckSystemZBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); bool CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); - + bool CheckPPCBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); + bool SemaBuiltinVAStart(CallExpr *TheCall); bool SemaBuiltinVAStartARM(CallExpr *Call); bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); @@ -8567,6 +8607,8 @@ public: FST_Strftime, FST_Strfmon, FST_Kprintf, + FST_FreeBSDKPrintf, + FST_OSTrace, FST_Unknown }; static FormatStringType GetFormatStringType(const FormatAttr *Format); @@ -8634,6 +8676,13 @@ private: /// statement that produces control flow different from GCC. void CheckBreakContinueBinding(Expr *E); + /// \brief Check whether receiver is mutable ObjC container which + /// attempts to add itself into the container + void CheckObjCCircularContainer(ObjCMessageExpr *Message); + + void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE); + void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc, + bool DeleteWasArrayForm); public: /// \brief Register a magic integral constant to be used as a type tag. void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, @@ -8682,6 +8731,7 @@ protected: friend class Parser; friend class InitializationSequence; friend class ASTReader; + friend class ASTDeclReader; friend class ASTWriter; public: @@ -8695,8 +8745,8 @@ public: /// template substitution or instantiation. Scope *getCurScope() const { return CurScope; } - void incrementMSLocalManglingNumber() const { - return CurScope->incrementMSLocalManglingNumber(); + void incrementMSManglingNumber() const { + return CurScope->incrementMSManglingNumber(); } IdentifierInfo *getSuperIdentifier() const; @@ -8717,6 +8767,16 @@ public: DC = CatD->getClassInterface(); return DC; } + + /// \brief To be used for checking whether the arguments being passed to + /// function exceeds the number of parameters expected for it. + static bool TooManyArguments(size_t NumParams, size_t NumArgs, + bool PartialOverloading = false) { + // We check whether we're just after a comma in code-completion. + if (NumArgs > 0 && PartialOverloading) + return NumArgs + 1 > NumParams; // If so, we view as an extra argument. + return NumArgs > NumParams; + } }; /// \brief RAII object that enters a new expression evaluation context. diff --git a/include/clang/Sema/SemaInternal.h b/include/clang/Sema/SemaInternal.h index 005d882..60c6598 100644 --- a/include/clang/Sema/SemaInternal.h +++ b/include/clang/Sema/SemaInternal.h @@ -48,6 +48,18 @@ inline bool IsVariableAConstantExpression(VarDecl *Var, ASTContext &Context) { Var->getAnyInitializer(DefVD) && DefVD->checkInitIsICE(); } +// Helper function to check whether D's attributes match current CUDA mode. +// Decls with mismatched attributes and related diagnostics may have to be +// ignored during this CUDA compilation pass. +inline bool DeclAttrsMatchCUDAMode(const LangOptions &LangOpts, Decl *D) { + if (!LangOpts.CUDA || !D) + return true; + bool isDeviceSideDecl = D->hasAttr<CUDADeviceAttr>() || + D->hasAttr<CUDASharedAttr>() || + D->hasAttr<CUDAGlobalAttr>(); + return isDeviceSideDecl == LangOpts.CUDAIsDevice; +} + // Directly mark a variable odr-used. Given a choice, prefer to use // MarkVariableReferenced since it does additional checks and then // calls MarkVarDeclODRUsed. @@ -221,18 +233,13 @@ private: std::string CurNameSpecifier; SmallVector<const IdentifierInfo*, 4> CurContextIdentifiers; SmallVector<const IdentifierInfo*, 4> CurNameSpecifierIdentifiers; - bool isSorted; - SpecifierInfoList Specifiers; - llvm::SmallSetVector<unsigned, 4> Distances; - llvm::DenseMap<unsigned, SpecifierInfoList> DistanceMap; + std::map<unsigned, SpecifierInfoList> DistanceMap; /// \brief Helper for building the list of DeclContexts between the current /// context and the top of the translation unit static DeclContextList buildContextChain(DeclContext *Start); - void sortNamespaces(); - unsigned buildNestedNameSpecifier(DeclContextList &DeclChain, NestedNameSpecifier *&NNS); @@ -244,12 +251,40 @@ private: /// the corresponding NestedNameSpecifier and its distance in the process. void addNameSpecifier(DeclContext *Ctx); - typedef SpecifierInfoList::iterator iterator; - iterator begin() { - if (!isSorted) sortNamespaces(); - return Specifiers.begin(); - } - iterator end() { return Specifiers.end(); } + /// \brief Provides flat iteration over specifiers, sorted by distance. + class iterator + : public llvm::iterator_facade_base<iterator, std::forward_iterator_tag, + SpecifierInfo> { + /// Always points to the last element in the distance map. + const std::map<unsigned, SpecifierInfoList>::iterator OuterBack; + /// Iterator on the distance map. + std::map<unsigned, SpecifierInfoList>::iterator Outer; + /// Iterator on an element in the distance map. + SpecifierInfoList::iterator Inner; + + public: + iterator(NamespaceSpecifierSet &Set, bool IsAtEnd) + : OuterBack(std::prev(Set.DistanceMap.end())), + Outer(Set.DistanceMap.begin()), + Inner(!IsAtEnd ? Outer->second.begin() : OuterBack->second.end()) { + assert(!Set.DistanceMap.empty()); + } + + iterator &operator++() { + ++Inner; + if (Inner == Outer->second.end() && Outer != OuterBack) { + ++Outer; + Inner = Outer->second.begin(); + } + return *this; + } + + SpecifierInfo &operator*() { return *Inner; } + bool operator==(const iterator &RHS) const { return Inner == RHS.Inner; } + }; + + iterator begin() { return iterator(*this, /*IsAtEnd=*/false); } + iterator end() { return iterator(*this, /*IsAtEnd=*/true); } }; void addName(StringRef Name, NamedDecl *ND, diff --git a/include/clang/Sema/Template.h b/include/clang/Sema/Template.h index 8f0d9da..b822b11 100644 --- a/include/clang/Sema/Template.h +++ b/include/clang/Sema/Template.h @@ -239,8 +239,8 @@ namespace clang { // This class is non-copyable LocalInstantiationScope( - const LocalInstantiationScope &) LLVM_DELETED_FUNCTION; - void operator=(const LocalInstantiationScope &) LLVM_DELETED_FUNCTION; + const LocalInstantiationScope &) = delete; + void operator=(const LocalInstantiationScope &) = delete; public: LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope = false) diff --git a/include/clang/Sema/TemplateDeduction.h b/include/clang/Sema/TemplateDeduction.h index 8338d97..229eb71 100644 --- a/include/clang/Sema/TemplateDeduction.h +++ b/include/clang/Sema/TemplateDeduction.h @@ -44,8 +44,8 @@ class TemplateDeductionInfo { /// SFINAE while performing template argument deduction. SmallVector<PartialDiagnosticAt, 4> SuppressedDiagnostics; - TemplateDeductionInfo(const TemplateDeductionInfo &) LLVM_DELETED_FUNCTION; - void operator=(const TemplateDeductionInfo &) LLVM_DELETED_FUNCTION; + TemplateDeductionInfo(const TemplateDeductionInfo &) = delete; + void operator=(const TemplateDeductionInfo &) = delete; public: TemplateDeductionInfo(SourceLocation Loc) @@ -91,9 +91,7 @@ public: if (HasSFINAEDiagnostic) return; SuppressedDiagnostics.clear(); - SuppressedDiagnostics.push_back( - std::make_pair(Loc, PartialDiagnostic::NullDiagnostic())); - SuppressedDiagnostics.back().second.swap(PD); + SuppressedDiagnostics.emplace_back(Loc, std::move(PD)); HasSFINAEDiagnostic = true; } @@ -102,9 +100,7 @@ public: PartialDiagnostic PD) { if (HasSFINAEDiagnostic) return; - SuppressedDiagnostics.push_back( - std::make_pair(Loc, PartialDiagnostic::NullDiagnostic())); - SuppressedDiagnostics.back().second.swap(PD); + SuppressedDiagnostics.emplace_back(Loc, std::move(PD)); } /// \brief Iterator over the set of suppressed diagnostics. @@ -252,8 +248,8 @@ class TemplateSpecCandidateSet { SourceLocation Loc; TemplateSpecCandidateSet( - const TemplateSpecCandidateSet &) LLVM_DELETED_FUNCTION; - void operator=(const TemplateSpecCandidateSet &) LLVM_DELETED_FUNCTION; + const TemplateSpecCandidateSet &) = delete; + void operator=(const TemplateSpecCandidateSet &) = delete; void destroyCandidates(); @@ -277,7 +273,7 @@ public: /// \brief Add a new candidate with NumConversions conversion sequence slots /// to the overload set. TemplateSpecCandidate &addCandidate() { - Candidates.push_back(TemplateSpecCandidate()); + Candidates.emplace_back(); return Candidates.back(); } diff --git a/include/clang/Sema/TypoCorrection.h b/include/clang/Sema/TypoCorrection.h index 922d0ff..958aab0 100644 --- a/include/clang/Sema/TypoCorrection.h +++ b/include/clang/Sema/TypoCorrection.h @@ -165,7 +165,7 @@ public: } /// \brief Returns whether this TypoCorrection has a non-empty DeclarationName - LLVM_EXPLICIT operator bool() const { return bool(CorrectionName); } + explicit operator bool() const { return bool(CorrectionName); } /// \brief Mark this TypoCorrection as being a keyword. /// Since addCorrectionDeclsand setCorrectionDecl don't allow NULL to be |