diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-06-18 16:11:24 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-06-18 16:11:24 +0000 |
commit | 68584ed35ad819a1668e3f527ba7f5dd4ae6a333 (patch) | |
tree | f92e4dc8a0ad0128f011a81e4ef954ff1ea7311c | |
parent | 0adea828ec9db09bf54ca4efa54b2a2f688726b5 (diff) |
Move the static DeclAttrs map into ASTContext. Fixes <rdar://problem/6983177>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73702 91177308-0d34-0410-b5e6-96231b3b80d8
34 files changed, 266 insertions, 249 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index f6a3479d10..b686b0edd3 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -126,6 +126,12 @@ class ASTContext { RecordDecl *ObjCFastEnumerationStateTypeDecl; + /// \brief Keeps track of all declaration attributes. + /// + /// Since so few decls have attrs, we keep them in a hash map instead of + /// wasting space in the Decl class. + llvm::DenseMap<const Decl*, Attr*> DeclAttrs; + TranslationUnitDecl *TUDecl; /// SourceMgr - The associated SourceManager object. @@ -164,6 +170,12 @@ public: return FullSourceLoc(Loc,SourceMgr); } + /// \brief Retrieve the attributes for the given declaration. + Attr*& getDeclAttrs(const Decl *D) { return DeclAttrs[D]; } + + /// \brief Erase the attributes corresponding to the given declaration. + void eraseDeclAttrs(const Decl *D) { DeclAttrs.erase(D); } + TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; } diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 7440e7b5f1..1f3e88fb16 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -832,12 +832,12 @@ public: /// The gnu_inline attribute only introduces GNU inline semantics /// when all of the inline declarations of the function are marked /// gnu_inline. - bool hasActiveGNUInlineAttribute() const; + bool hasActiveGNUInlineAttribute(ASTContext &Context) const; /// \brief Determines whether this function is a GNU "extern /// inline", which is roughly the opposite of a C99 "extern inline" /// function. - bool isExternGNUInline() const; + bool isExternGNUInline(ASTContext &Context) const; /// isOverloadedOperator - Whether this function declaration /// represents an C++ overloaded operator, e.g., "operator+". diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 291034e100..811e966172 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -211,23 +211,23 @@ public: } bool hasAttrs() const { return HasAttrs; } - void addAttr(Attr *attr); - const Attr *getAttrs() const { + void addAttr(ASTContext &Context, Attr *attr); + const Attr *getAttrs(ASTContext &Context) const { if (!HasAttrs) return 0; // common case, no attributes. - return getAttrsImpl(); // Uncommon case, out of line hash lookup. + return getAttrsImpl(Context); // Uncommon case, out of line hash lookup. } - void swapAttrs(Decl *D); - void invalidateAttrs(); + void swapAttrs(ASTContext &Context, Decl *D); + void invalidateAttrs(ASTContext &Context); - template<typename T> const T *getAttr() const { - for (const Attr *attr = getAttrs(); attr; attr = attr->getNext()) + template<typename T> const T *getAttr(ASTContext &Context) const { + for (const Attr *attr = getAttrs(Context); attr; attr = attr->getNext()) if (const T *V = dyn_cast<T>(attr)) return V; return 0; } - template<typename T> bool hasAttr() const { - return getAttr<T>() != 0; + template<typename T> bool hasAttr(ASTContext &Context) const { + return getAttr<T>(Context) != 0; } /// setInvalidDecl - Indicates the Decl had a semantic error. This @@ -329,7 +329,7 @@ public: void dump(ASTContext &Context); private: - const Attr *getAttrsImpl() const; + const Attr *getAttrsImpl(ASTContext &Context) const; }; diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 98de5f9d38..f1e25ce918 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -124,7 +124,7 @@ public: /// with location to warn on and the source range[s] to report with the /// warning. bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, - SourceRange &R2) const; + SourceRange &R2, ASTContext &Context) const; /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or /// incomplete type other than void. Nonarray expressions that can be lvalues: diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 4af1599b94..b80142fef3 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -222,7 +222,7 @@ const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { unsigned ASTContext::getDeclAlignInBytes(const Decl *D) { unsigned Align = Target.getCharWidth(); - if (const AlignedAttr* AA = D->getAttr<AlignedAttr>()) + if (const AlignedAttr* AA = D->getAttr<AlignedAttr>(*this)) Align = std::max(Align, AA->getAlignment()); if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { @@ -445,7 +445,7 @@ ASTContext::getTypeInfo(const Type *T) { case Type::Typedef: { const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl(); - if (const AlignedAttr *Aligned = Typedef->getAttr<AlignedAttr>()) { + if (const AlignedAttr *Aligned = Typedef->getAttr<AlignedAttr>(*this)) { Align = Aligned->getAlignment(); Width = getTypeSize(Typedef->getUnderlyingType().getTypePtr()); } else @@ -505,7 +505,7 @@ void ASTRecordLayout::LayoutField(const FieldDecl *FD, unsigned FieldNo, // FIXME: Should this override struct packing? Probably we want to // take the minimum? - if (const PackedAttr *PA = FD->getAttr<PackedAttr>()) + if (const PackedAttr *PA = FD->getAttr<PackedAttr>(Context)) FieldPacking = PA->getAlignment(); if (const Expr *BitWidthExpr = FD->getBitWidth()) { @@ -525,7 +525,7 @@ void ASTRecordLayout::LayoutField(const FieldDecl *FD, unsigned FieldNo, FieldAlign = FieldInfo.second; if (FieldPacking) FieldAlign = std::min(FieldAlign, FieldPacking); - if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>()) + if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>(Context)) FieldAlign = std::max(FieldAlign, AA->getAlignment()); // Check if we need to add padding to give the field the correct @@ -565,7 +565,7 @@ void ASTRecordLayout::LayoutField(const FieldDecl *FD, unsigned FieldNo, // is smaller than the specified packing? if (FieldPacking) FieldAlign = std::min(FieldAlign, std::max(8U, FieldPacking)); - if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>()) + if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>(Context)) FieldAlign = std::max(FieldAlign, AA->getAlignment()); // Round up the current record size to the field's alignment boundary. @@ -731,10 +731,10 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D, } unsigned StructPacking = 0; - if (const PackedAttr *PA = D->getAttr<PackedAttr>()) + if (const PackedAttr *PA = D->getAttr<PackedAttr>(*this)) StructPacking = PA->getAlignment(); - if (const AlignedAttr *AA = D->getAttr<AlignedAttr>()) + if (const AlignedAttr *AA = D->getAttr<AlignedAttr>(*this)) NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), AA->getAlignment())); @@ -783,10 +783,10 @@ const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D) { bool IsUnion = D->isUnion(); unsigned StructPacking = 0; - if (const PackedAttr *PA = D->getAttr<PackedAttr>()) + if (const PackedAttr *PA = D->getAttr<PackedAttr>(*this)) StructPacking = PA->getAlignment(); - if (const AlignedAttr *AA = D->getAttr<AlignedAttr>()) + if (const AlignedAttr *AA = D->getAttr<AlignedAttr>(*this)) NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), AA->getAlignment())); @@ -2782,7 +2782,7 @@ QualType ASTContext::getFromTargetType(unsigned Type) const { bool ASTContext::isObjCNSObjectType(QualType Ty) const { if (TypedefType *TDT = dyn_cast<TypedefType>(Ty)) { if (TypedefDecl *TD = TDT->getDecl()) - if (TD->getAttr<ObjCNSObjectAttr>()) + if (TD->getAttr<ObjCNSObjectAttr>(*const_cast<ASTContext*>(this))) return true; } return false; diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index a3e406b245..b2b643a64f 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -380,13 +380,14 @@ bool FunctionDecl::isExternC(ASTContext &Context) const { // In C, any non-static, non-overloadable function has external // linkage. if (!Context.getLangOptions().CPlusPlus) - return getStorageClass() != Static && !getAttr<OverloadableAttr>(); + return getStorageClass() != Static && !getAttr<OverloadableAttr>(Context); for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit(); DC = DC->getParent()) { if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) { if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) - return getStorageClass() != Static && !getAttr<OverloadableAttr>(); + return getStorageClass() != Static && + !getAttr<OverloadableAttr>(Context); break; } @@ -451,7 +452,7 @@ unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const { if (isa<LinkageSpecDecl>(getDeclContext()) && cast<LinkageSpecDecl>(getDeclContext())->getLanguage() == LinkageSpecDecl::lang_c && - !getAttr<OverloadableAttr>()) + !getAttr<OverloadableAttr>(Context)) return BuiltinID; // Not a builtin @@ -496,25 +497,25 @@ unsigned FunctionDecl::getMinRequiredArguments() const { return NumRequiredArgs; } -bool FunctionDecl::hasActiveGNUInlineAttribute() const { - if (!isInline() || !hasAttr<GNUInlineAttr>()) +bool FunctionDecl::hasActiveGNUInlineAttribute(ASTContext &Context) const { + if (!isInline() || !hasAttr<GNUInlineAttr>(Context)) return false; for (const FunctionDecl *FD = getPreviousDeclaration(); FD; FD = FD->getPreviousDeclaration()) { - if (FD->isInline() && !FD->hasAttr<GNUInlineAttr>()) + if (FD->isInline() && !FD->hasAttr<GNUInlineAttr>(Context)) return false; } return true; } -bool FunctionDecl::isExternGNUInline() const { - if (!hasActiveGNUInlineAttribute()) +bool FunctionDecl::isExternGNUInline(ASTContext &Context) const { + if (!hasActiveGNUInlineAttribute(Context)) return false; for (const FunctionDecl *FD = this; FD; FD = FD->getPreviousDeclaration()) - if (FD->getStorageClass() == Extern && FD->hasAttr<GNUInlineAttr>()) + if (FD->getStorageClass() == Extern && FD->hasAttr<GNUInlineAttr>(Context)) return true; return false; diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index a39a506de0..b83a503dbb 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -38,12 +38,6 @@ using namespace clang; static bool StatSwitch = false; -// This keeps track of all decl attributes. Since so few decls have attrs, we -// keep them in a hash map instead of wasting space in the Decl class. -typedef llvm::DenseMap<const Decl*, Attr*> DeclAttrMapTy; - -static DeclAttrMapTy *DeclAttrs = 0; - const char *Decl::getDeclKindName() const { switch (DeclKind) { default: assert(0 && "Declaration not in DeclNodes.def!"); @@ -224,11 +218,8 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) { } } -void Decl::addAttr(Attr *NewAttr) { - if (!DeclAttrs) - DeclAttrs = new DeclAttrMapTy(); - - Attr *&ExistingAttr = (*DeclAttrs)[this]; +void Decl::addAttr(ASTContext &Context, Attr *NewAttr) { + Attr *&ExistingAttr = Context.getDeclAttrs(this); NewAttr->setNext(ExistingAttr); ExistingAttr = NewAttr; @@ -236,25 +227,19 @@ void Decl::addAttr(Attr *NewAttr) { HasAttrs = true; } -void Decl::invalidateAttrs() { +void Decl::invalidateAttrs(ASTContext &Context) { if (!HasAttrs) return; - + HasAttrs = false; - (*DeclAttrs)[this] = 0; - DeclAttrs->erase(this); - - if (DeclAttrs->empty()) { - delete DeclAttrs; - DeclAttrs = 0; - } + Context.eraseDeclAttrs(this); } -const Attr *Decl::getAttrsImpl() const { +const Attr *Decl::getAttrsImpl(ASTContext &Context) const { assert(HasAttrs && "getAttrs() should verify this!"); - return (*DeclAttrs)[this]; + return Context.getDeclAttrs(this); } -void Decl::swapAttrs(Decl *RHS) { +void Decl::swapAttrs(ASTContext &Context, Decl *RHS) { bool HasLHSAttr = this->HasAttrs; bool HasRHSAttr = RHS->HasAttrs; @@ -263,17 +248,17 @@ void Decl::swapAttrs(Decl *RHS) { // If 'this' has no attrs, swap the other way. if (!HasLHSAttr) - return RHS->swapAttrs(this); + return RHS->swapAttrs(Context, this); // Handle the case when both decls have attrs. if (HasRHSAttr) { - std::swap((*DeclAttrs)[this], (*DeclAttrs)[RHS]); + std::swap(Context.getDeclAttrs(this), Context.getDeclAttrs(RHS)); return; } // Otherwise, LHS has an attr and RHS doesn't. - (*DeclAttrs)[RHS] = (*DeclAttrs)[this]; - (*DeclAttrs).erase(this); + Context.getDeclAttrs(RHS) = Context.getDeclAttrs(this); + Context.eraseDeclAttrs(this); this->HasAttrs = false; RHS->HasAttrs = true; } @@ -282,12 +267,8 @@ void Decl::swapAttrs(Decl *RHS) { void Decl::Destroy(ASTContext &C) { // Free attributes for this decl. if (HasAttrs) { - DeclAttrMapTy::iterator it = DeclAttrs->find(this); - assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!"); - - // release attributes. - it->second->Destroy(C); - invalidateAttrs(); + C.getDeclAttrs(this)->Destroy(C); + invalidateAttrs(C); HasAttrs = false; } diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 309be4175f..eb4136c2e2 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -456,7 +456,7 @@ Stmt *BlockExpr::getBody() { /// with location to warn on and the source range[s] to report with the /// warning. bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, - SourceRange &R2) const { + SourceRange &R2, ASTContext &Context) const { // Don't warn if the expr is type dependent. The type could end up // instantiating to void. if (isTypeDependent()) @@ -469,7 +469,7 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, return true; case ParenExprClass: return cast<ParenExpr>(this)->getSubExpr()-> - isUnusedResultAWarning(Loc, R1, R2); + isUnusedResultAWarning(Loc, R1, R2, Context); case UnaryOperatorClass: { const UnaryOperator *UO = cast<UnaryOperator>(this); @@ -492,7 +492,7 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, return false; break; case UnaryOperator::Extension: - return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2); + return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Context); } Loc = UO->getOperatorLoc(); R1 = UO->getSubExpr()->getSourceRange(); @@ -502,8 +502,8 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, const BinaryOperator *BO = cast<BinaryOperator>(this); // Consider comma to have side effects if the LHS or RHS does. if (BO->getOpcode() == BinaryOperator::Comma) - return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2) || - BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2); + return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Context) || + BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Context); if (BO->isAssignmentOp()) return false; @@ -519,9 +519,10 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, // The condition must be evaluated, but if either the LHS or RHS is a // warning, warn about them. const ConditionalOperator *Exp = cast<ConditionalOperator>(this); - if (Exp->getLHS() && Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2)) + if (Exp->getLHS() && + Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Context)) return true; - return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2); + return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Context); } case MemberExprClass: @@ -554,8 +555,8 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, // If the callee has attribute pure, const, or warn_unused_result, warn // about it. void foo() { strlen("bar"); } should warn. if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CalleeDRE->getDecl())) - if (FD->getAttr<WarnUnusedResultAttr>() || - FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { + if (FD->getAttr<WarnUnusedResultAttr>(Context) || + FD->getAttr<PureAttr>(Context) || FD->getAttr<ConstAttr>(Context)) { Loc = CE->getCallee()->getLocStart(); R1 = CE->getCallee()->getSourceRange(); @@ -578,7 +579,7 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); if (!CS->body_empty()) if (const Expr *E = dyn_cast<Expr>(CS->body_back())) - return E->isUnusedResultAWarning(Loc, R1, R2); + return E->isUnusedResultAWarning(Loc, R1, R2, Context); Loc = cast<StmtExpr>(this)->getLParenLoc(); R1 = getSourceRange(); @@ -588,8 +589,8 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, // If this is a cast to void, check the operand. Otherwise, the result of // the cast is unused. if (getType()->isVoidType()) - return cast<CastExpr>(this)->getSubExpr()->isUnusedResultAWarning(Loc, - R1, R2); + return cast<CastExpr>(this)->getSubExpr() + ->isUnusedResultAWarning(Loc, R1, R2, Context); Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); return true; @@ -597,8 +598,8 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, // If this is a cast to void, check the operand. Otherwise, the result of // the cast is unused. if (getType()->isVoidType()) - return cast<CastExpr>(this)->getSubExpr()->isUnusedResultAWarning(Loc, - R1, R2); + return cast<CastExpr>(this)->getSubExpr() + ->isUnusedResultAWarning(Loc, R1, R2, Context); Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); return true; @@ -606,11 +607,11 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, case ImplicitCastExprClass: // Check the operand, since implicit casts are inserted by Sema return cast<ImplicitCastExpr>(this) - ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2); + ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Context); case CXXDefaultArgExprClass: return cast<CXXDefaultArgExpr>(this) - ->getExpr()->isUnusedResultAWarning(Loc, R1, R2); + ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Context); case CXXNewExprClass: // FIXME: In theory, there might be new expressions that don't have side @@ -619,7 +620,7 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, return false; case CXXExprWithTemporariesClass: return cast<CXXExprWithTemporaries>(this) - ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2); + ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Context); } } diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 1a89f3d784..6603ba72b7 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -1249,15 +1249,15 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ, // Determine if there is a special return effect for this method. if (isTrackedObjCObjectType(RetTy)) { - if (FD->getAttr<NSReturnsRetainedAttr>()) { + if (FD->getAttr<NSReturnsRetainedAttr>(Ctx)) { Summ.setRetEffect(ObjCAllocRetE); } - else if (FD->getAttr<CFReturnsRetainedAttr>()) { + else if (FD->getAttr<CFReturnsRetainedAttr>(Ctx)) { Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); } } else if (RetTy->getAsPointerType()) { - if (FD->getAttr<CFReturnsRetainedAttr>()) { + if (FD->getAttr<CFReturnsRetainedAttr>(Ctx)) { Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); } } @@ -1271,10 +1271,10 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ, // Determine if there is a special return effect for this method. if (isTrackedObjCObjectType(MD->getResultType())) { - if (MD->getAttr<NSReturnsRetainedAttr>()) { + if (MD->getAttr<NSReturnsRetainedAttr>(Ctx)) { Summ.setRetEffect(ObjCAllocRetE); } - else if (MD->getAttr<CFReturnsRetainedAttr>()) { + else if (MD->getAttr<CFReturnsRetainedAttr>(Ctx)) { Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); } } diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp index 69433d6396..0f61a5ee91 100644 --- a/lib/Analysis/CheckDeadStores.cpp +++ b/lib/Analysis/CheckDeadStores.cpp @@ -85,7 +85,7 @@ public: const LiveVariables::AnalysisDataTy& AD, const LiveVariables::ValTy& Live) { - if (VD->hasLocalStorage() && !Live(VD, AD) && !VD->getAttr<UnusedAttr>()) + if (VD->hasLocalStorage() && !Live(VD, AD) && !VD->getAttr<UnusedAttr>(Ctx)) Report(VD, dsk, Ex->getSourceRange().getBegin(), Val->getSourceRange()); } @@ -190,7 +190,7 @@ public: // A dead initialization is a variable that is dead after it // is initialized. We don't flag warnings for those variables // marked 'unused'. - if (!Live(V, AD) && V->getAttr<UnusedAttr>() == 0) { + if (!Live(V, AD) && V->getAttr<UnusedAttr>(Ctx) == 0) { // Special case: check for initializations with constants. // // e.g. : int x = 0; diff --git a/lib/Analysis/CheckObjCDealloc.cpp b/lib/Analysis/CheckObjCDealloc.cpp index f50d7a19c4..2ba7d868e9 100644 --- a/lib/Analysis/CheckObjCDealloc.cpp +++ b/lib/Analysis/CheckObjCDealloc.cpp @@ -109,7 +109,7 @@ void clang::CheckObjCDealloc(ObjCImplementationDecl* D, QualType T = ID->getType(); if (!Ctx.isObjCObjectPointerType(T) || - ID->getAttr<IBOutletAttr>()) // Skip IBOutlets. + ID->getAttr<IBOutletAttr>(Ctx)) // Skip IBOutlets. continue; containsPointerIvar = true; diff --git a/lib/Analysis/CheckObjCUnusedIVars.cpp b/lib/Analysis/CheckObjCUnusedIVars.cpp index 7979f9c942..92c50e2a91 100644 --- a/lib/Analysis/CheckObjCUnusedIVars.cpp +++ b/lib/Analysis/CheckObjCUnusedIVars.cpp @@ -74,7 +74,7 @@ void clang::CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR) { continue; // Skip IB Outlets. - if (ID->getAttr<IBOutletAttr>()) + if (ID->getAttr<IBOutletAttr>(Ctx)) continue; M[ID] = Unused; diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index b740bf029b..e392de6aab 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -1482,7 +1482,8 @@ void GRExprEngine::VisitCallRec(CallExpr* CE, NodeTy* Pred, SaveAndRestore<bool> OldSink(Builder->BuildSinks); const FunctionDecl* FD = L.getAsFunctionDecl(); if (FD) { - if (FD->getAttr<NoReturnAttr>() || FD->getAttr<AnalyzerNoReturnAttr>()) + if (FD->getAttr<NoReturnAttr>(getContext()) || + FD->getAttr<AnalyzerNoReturnAttr>(getContext())) Builder->BuildSinks = true; else { // HACK: Some functions are not marked noreturn, and don't return. diff --git a/lib/Analysis/GRExprEngineInternalChecks.cpp b/lib/Analysis/GRExprEngineInternalChecks.cpp index 9aea12447d..a0de13f702 100644 --- a/lib/Analysis/GRExprEngineInternalChecks.cpp +++ b/lib/Analysis/GRExprEngineInternalChecks.cpp @@ -569,7 +569,7 @@ public: if (!FD) return false; - const NonNullAttr* Att = FD->getAttr<NonNullAttr>(); + const NonNullAttr* Att = FD->getAttr<NonNullAttr>(BR.getContext()); if (!Att) return false; diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index a919dfa2e3..66b1f17368 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -522,7 +522,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, case Builtin::BIsqrtf: case Builtin::BIsqrtl: { // Rewrite sqrt to intrinsic if allowed. - if (!FD->hasAttr<ConstAttr>()) + if (!FD->hasAttr<ConstAttr>(getContext())) break; Value *Arg0 = EmitScalarExpr(E->getArg(0)); const llvm::Type *ArgType = Arg0->getType(); @@ -534,7 +534,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, case Builtin::BIpowf: case Builtin::BIpowl: { // Rewrite sqrt to intrinsic if allowed. - if (!FD->hasAttr<ConstAttr>()) + if (!FD->hasAttr<ConstAttr>(getContext())) break; Value *Base = EmitScalarExpr(E->getArg(0)); Value *Exponent = EmitScalarExpr(E->getArg(1)); diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 4037f32ac1..ec6058afd9 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -377,13 +377,13 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, // FIXME: handle sseregparm someday... if (TargetDecl) { - if (TargetDecl->hasAttr<NoThrowAttr>()) + if (TargetDecl->hasAttr<NoThrowAttr>(getContext())) FuncAttrs |= llvm::Attribute::NoUnwind; - if (TargetDecl->hasAttr<NoReturnAttr>()) + if (TargetDecl->hasAttr<NoReturnAttr>(getContext())) FuncAttrs |= llvm::Attribute::NoReturn; - if (TargetDecl->hasAttr<ConstAttr>()) + if (TargetDecl->hasAttr<ConstAttr>(getContext())) FuncAttrs |= llvm::Attribute::ReadNone; - else if (TargetDecl->has |