From e4865d28364da404013c49f4518cd7ba051a6b08 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 23 Oct 2013 16:46:34 +0000 Subject: [PATCH] A decl never becomes unused. Make that explicit in the API. llvm-svn: 193248 --- clang/include/clang/AST/DeclBase.h | 2 +- clang/lib/Sema/SemaDecl.cpp | 6 ++++-- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 3 ++- clang/lib/Serialization/ASTReaderDecl.cpp | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index 716b88532730..f8c69f99297d 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -508,7 +508,7 @@ public: /// \brief Set whether the declaration is used, in the sense of odr-use. /// /// This should only be used immediately after creating a declaration. - void setIsUsed(bool U) { Used = U; } + void setIsUsed() { Used = true; } /// \brief Mark the declaration used, in the sense of odr-use. /// diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index bc7be6d4593e..ba7892840608 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2801,7 +2801,8 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, New->setPure(); // Merge "used" flag. - New->setIsUsed(Old->getMostRecentDecl()->isUsed(false)); + if (Old->getMostRecentDecl()->isUsed(false)) + New->setIsUsed(); // Merge attributes from the parameters. These can mismatch with K&R // declarations. @@ -3114,7 +3115,8 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) { } // Merge "used" flag. - New->setIsUsed(Old->getMostRecentDecl()->isUsed(false)); + if (Old->getMostRecentDecl()->isUsed(false)) + New->setIsUsed(); // Keep a chain of previous declarations. New->setPreviousDecl(Old); diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 3989c56ccd8d..f5c4c72cb349 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3378,7 +3378,8 @@ void Sema::BuildVariableInstantiation( NewVar->setAccess(OldVar->getAccess()); if (!OldVar->isStaticDataMember()) { - NewVar->setIsUsed(OldVar->isUsed(false)); + if (OldVar->isUsed(false)) + NewVar->setIsUsed(); NewVar->setReferenced(OldVar->isReferenced()); } diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 0c885bc57921..d3937fcff05d 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -386,7 +386,7 @@ void ASTDeclReader::VisitDecl(Decl *D) { D->setAttrsImpl(Attrs, Reader.getContext()); } D->setImplicit(Record[Idx++]); - D->setIsUsed(Record[Idx++]); + D->Used = Record[Idx++]; D->setReferenced(Record[Idx++]); D->setTopLevelDeclInObjCContainer(Record[Idx++]); D->setAccess((AccessSpecifier)Record[Idx++]); @@ -2989,7 +2989,7 @@ void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile, case UPD_DECL_MARKED_USED: { // FIXME: This doesn't send the right notifications if there are // ASTMutationListeners other than an ASTWriter. - D->setIsUsed(true); + D->Used = true; break; } }