Move the static DeclAttrs map into ASTContext. Fixes <rdar://problem/6983177>.

llvm-svn: 73702
This commit is contained in:
Douglas Gregor 2009-06-18 16:11:24 +00:00
parent 0fd4eaef30
commit 78bd61f661
34 changed files with 266 additions and 249 deletions

View File

@ -126,6 +126,12 @@ class ASTContext {
RecordDecl *ObjCFastEnumerationStateTypeDecl; 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; TranslationUnitDecl *TUDecl;
/// SourceMgr - The associated SourceManager object. /// SourceMgr - The associated SourceManager object.
@ -164,6 +170,12 @@ public:
return FullSourceLoc(Loc,SourceMgr); 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; } TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }

View File

@ -832,12 +832,12 @@ public:
/// The gnu_inline attribute only introduces GNU inline semantics /// The gnu_inline attribute only introduces GNU inline semantics
/// when all of the inline declarations of the function are marked /// when all of the inline declarations of the function are marked
/// gnu_inline. /// gnu_inline.
bool hasActiveGNUInlineAttribute() const; bool hasActiveGNUInlineAttribute(ASTContext &Context) const;
/// \brief Determines whether this function is a GNU "extern /// \brief Determines whether this function is a GNU "extern
/// inline", which is roughly the opposite of a C99 "extern inline" /// inline", which is roughly the opposite of a C99 "extern inline"
/// function. /// function.
bool isExternGNUInline() const; bool isExternGNUInline(ASTContext &Context) const;
/// isOverloadedOperator - Whether this function declaration /// isOverloadedOperator - Whether this function declaration
/// represents an C++ overloaded operator, e.g., "operator+". /// represents an C++ overloaded operator, e.g., "operator+".

View File

@ -211,23 +211,23 @@ public:
} }
bool hasAttrs() const { return HasAttrs; } bool hasAttrs() const { return HasAttrs; }
void addAttr(Attr *attr); void addAttr(ASTContext &Context, Attr *attr);
const Attr *getAttrs() const { const Attr *getAttrs(ASTContext &Context) const {
if (!HasAttrs) return 0; // common case, no attributes. 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 swapAttrs(ASTContext &Context, Decl *D);
void invalidateAttrs(); void invalidateAttrs(ASTContext &Context);
template<typename T> const T *getAttr() const { template<typename T> const T *getAttr(ASTContext &Context) const {
for (const Attr *attr = getAttrs(); attr; attr = attr->getNext()) for (const Attr *attr = getAttrs(Context); attr; attr = attr->getNext())
if (const T *V = dyn_cast<T>(attr)) if (const T *V = dyn_cast<T>(attr))
return V; return V;
return 0; return 0;
} }
template<typename T> bool hasAttr() const { template<typename T> bool hasAttr(ASTContext &Context) const {
return getAttr<T>() != 0; return getAttr<T>(Context) != 0;
} }
/// setInvalidDecl - Indicates the Decl had a semantic error. This /// setInvalidDecl - Indicates the Decl had a semantic error. This
@ -329,7 +329,7 @@ public:
void dump(ASTContext &Context); void dump(ASTContext &Context);
private: private:
const Attr *getAttrsImpl() const; const Attr *getAttrsImpl(ASTContext &Context) const;
}; };

View File

@ -124,7 +124,7 @@ public:
/// with location to warn on and the source range[s] to report with the /// with location to warn on and the source range[s] to report with the
/// warning. /// warning.
bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 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 /// 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: /// incomplete type other than void. Nonarray expressions that can be lvalues:

View File

@ -222,7 +222,7 @@ const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const {
unsigned ASTContext::getDeclAlignInBytes(const Decl *D) { unsigned ASTContext::getDeclAlignInBytes(const Decl *D) {
unsigned Align = Target.getCharWidth(); 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()); Align = std::max(Align, AA->getAlignment());
if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
@ -445,7 +445,7 @@ ASTContext::getTypeInfo(const Type *T) {
case Type::Typedef: { case Type::Typedef: {
const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl(); 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(); Align = Aligned->getAlignment();
Width = getTypeSize(Typedef->getUnderlyingType().getTypePtr()); Width = getTypeSize(Typedef->getUnderlyingType().getTypePtr());
} else } else
@ -505,7 +505,7 @@ void ASTRecordLayout::LayoutField(const FieldDecl *FD, unsigned FieldNo,
// FIXME: Should this override struct packing? Probably we want to // FIXME: Should this override struct packing? Probably we want to
// take the minimum? // take the minimum?
if (const PackedAttr *PA = FD->getAttr<PackedAttr>()) if (const PackedAttr *PA = FD->getAttr<PackedAttr>(Context))
FieldPacking = PA->getAlignment(); FieldPacking = PA->getAlignment();
if (const Expr *BitWidthExpr = FD->getBitWidth()) { if (const Expr *BitWidthExpr = FD->getBitWidth()) {
@ -525,7 +525,7 @@ void ASTRecordLayout::LayoutField(const FieldDecl *FD, unsigned FieldNo,
FieldAlign = FieldInfo.second; FieldAlign = FieldInfo.second;
if (FieldPacking) if (FieldPacking)
FieldAlign = std::min(FieldAlign, 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()); FieldAlign = std::max(FieldAlign, AA->getAlignment());
// Check if we need to add padding to give the field the correct // 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? // is smaller than the specified packing?
if (FieldPacking) if (FieldPacking)
FieldAlign = std::min(FieldAlign, std::max(8U, 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()); FieldAlign = std::max(FieldAlign, AA->getAlignment());
// Round up the current record size to the field's alignment boundary. // Round up the current record size to the field's alignment boundary.
@ -731,10 +731,10 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
} }
unsigned StructPacking = 0; unsigned StructPacking = 0;
if (const PackedAttr *PA = D->getAttr<PackedAttr>()) if (const PackedAttr *PA = D->getAttr<PackedAttr>(*this))
StructPacking = PA->getAlignment(); StructPacking = PA->getAlignment();
if (const AlignedAttr *AA = D->getAttr<AlignedAttr>()) if (const AlignedAttr *AA = D->getAttr<AlignedAttr>(*this))
NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), NewEntry->SetAlignment(std::max(NewEntry->getAlignment(),
AA->getAlignment())); AA->getAlignment()));
@ -783,10 +783,10 @@ const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D) {
bool IsUnion = D->isUnion(); bool IsUnion = D->isUnion();
unsigned StructPacking = 0; unsigned StructPacking = 0;
if (const PackedAttr *PA = D->getAttr<PackedAttr>()) if (const PackedAttr *PA = D->getAttr<PackedAttr>(*this))
StructPacking = PA->getAlignment(); StructPacking = PA->getAlignment();
if (const AlignedAttr *AA = D->getAttr<AlignedAttr>()) if (const AlignedAttr *AA = D->getAttr<AlignedAttr>(*this))
NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), NewEntry->SetAlignment(std::max(NewEntry->getAlignment(),
AA->getAlignment())); AA->getAlignment()));
@ -2782,7 +2782,7 @@ QualType ASTContext::getFromTargetType(unsigned Type) const {
bool ASTContext::isObjCNSObjectType(QualType Ty) const { bool ASTContext::isObjCNSObjectType(QualType Ty) const {
if (TypedefType *TDT = dyn_cast<TypedefType>(Ty)) { if (TypedefType *TDT = dyn_cast<TypedefType>(Ty)) {
if (TypedefDecl *TD = TDT->getDecl()) if (TypedefDecl *TD = TDT->getDecl())
if (TD->getAttr<ObjCNSObjectAttr>()) if (TD->getAttr<ObjCNSObjectAttr>(*const_cast<ASTContext*>(this)))
return true; return true;
} }
return false; return false;

View File

@ -380,13 +380,14 @@ bool FunctionDecl::isExternC(ASTContext &Context) const {
// In C, any non-static, non-overloadable function has external // In C, any non-static, non-overloadable function has external
// linkage. // linkage.
if (!Context.getLangOptions().CPlusPlus) if (!Context.getLangOptions().CPlusPlus)
return getStorageClass() != Static && !getAttr<OverloadableAttr>(); return getStorageClass() != Static && !getAttr<OverloadableAttr>(Context);
for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit(); for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit();
DC = DC->getParent()) { DC = DC->getParent()) {
if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) { if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) {
if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) if (Linkage->getLanguage() == LinkageSpecDecl::lang_c)
return getStorageClass() != Static && !getAttr<OverloadableAttr>(); return getStorageClass() != Static &&
!getAttr<OverloadableAttr>(Context);
break; break;
} }
@ -451,7 +452,7 @@ unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const {
if (isa<LinkageSpecDecl>(getDeclContext()) && if (isa<LinkageSpecDecl>(getDeclContext()) &&
cast<LinkageSpecDecl>(getDeclContext())->getLanguage() cast<LinkageSpecDecl>(getDeclContext())->getLanguage()
== LinkageSpecDecl::lang_c && == LinkageSpecDecl::lang_c &&
!getAttr<OverloadableAttr>()) !getAttr<OverloadableAttr>(Context))
return BuiltinID; return BuiltinID;
// Not a builtin // Not a builtin
@ -496,25 +497,25 @@ unsigned FunctionDecl::getMinRequiredArguments() const {
return NumRequiredArgs; return NumRequiredArgs;
} }
bool FunctionDecl::hasActiveGNUInlineAttribute() const { bool FunctionDecl::hasActiveGNUInlineAttribute(ASTContext &Context) const {
if (!isInline() || !hasAttr<GNUInlineAttr>()) if (!isInline() || !hasAttr<GNUInlineAttr>(Context))
return false; return false;
for (const FunctionDecl *FD = getPreviousDeclaration(); FD; for (const FunctionDecl *FD = getPreviousDeclaration(); FD;
FD = FD->getPreviousDeclaration()) { FD = FD->getPreviousDeclaration()) {
if (FD->isInline() && !FD->hasAttr<GNUInlineAttr>()) if (FD->isInline() && !FD->hasAttr<GNUInlineAttr>(Context))
return false; return false;
} }
return true; return true;
} }
bool FunctionDecl::isExternGNUInline() const { bool FunctionDecl::isExternGNUInline(ASTContext &Context) const {
if (!hasActiveGNUInlineAttribute()) if (!hasActiveGNUInlineAttribute(Context))
return false; return false;
for (const FunctionDecl *FD = this; FD; FD = FD->getPreviousDeclaration()) 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 true;
return false; return false;

View File

@ -38,12 +38,6 @@ using namespace clang;
static bool StatSwitch = false; 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 { const char *Decl::getDeclKindName() const {
switch (DeclKind) { switch (DeclKind) {
default: assert(0 && "Declaration not in DeclNodes.def!"); default: assert(0 && "Declaration not in DeclNodes.def!");
@ -224,11 +218,8 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
} }
} }
void Decl::addAttr(Attr *NewAttr) { void Decl::addAttr(ASTContext &Context, Attr *NewAttr) {
if (!DeclAttrs) Attr *&ExistingAttr = Context.getDeclAttrs(this);
DeclAttrs = new DeclAttrMapTy();
Attr *&ExistingAttr = (*DeclAttrs)[this];
NewAttr->setNext(ExistingAttr); NewAttr->setNext(ExistingAttr);
ExistingAttr = NewAttr; ExistingAttr = NewAttr;
@ -236,25 +227,19 @@ void Decl::addAttr(Attr *NewAttr) {
HasAttrs = true; HasAttrs = true;
} }
void Decl::invalidateAttrs() { void Decl::invalidateAttrs(ASTContext &Context) {
if (!HasAttrs) return; if (!HasAttrs) return;
HasAttrs = false; HasAttrs = false;
(*DeclAttrs)[this] = 0; Context.eraseDeclAttrs(this);
DeclAttrs->erase(this);
if (DeclAttrs->empty()) {
delete DeclAttrs;
DeclAttrs = 0;
}
} }
const Attr *Decl::getAttrsImpl() const { const Attr *Decl::getAttrsImpl(ASTContext &Context) const {
assert(HasAttrs && "getAttrs() should verify this!"); 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 HasLHSAttr = this->HasAttrs;
bool HasRHSAttr = RHS->HasAttrs; bool HasRHSAttr = RHS->HasAttrs;
@ -263,17 +248,17 @@ void Decl::swapAttrs(Decl *RHS) {
// If 'this' has no attrs, swap the other way. // If 'this' has no attrs, swap the other way.
if (!HasLHSAttr) if (!HasLHSAttr)
return RHS->swapAttrs(this); return RHS->swapAttrs(Context, this);
// Handle the case when both decls have attrs. // Handle the case when both decls have attrs.
if (HasRHSAttr) { if (HasRHSAttr) {
std::swap((*DeclAttrs)[this], (*DeclAttrs)[RHS]); std::swap(Context.getDeclAttrs(this), Context.getDeclAttrs(RHS));
return; return;
} }
// Otherwise, LHS has an attr and RHS doesn't. // Otherwise, LHS has an attr and RHS doesn't.
(*DeclAttrs)[RHS] = (*DeclAttrs)[this]; Context.getDeclAttrs(RHS) = Context.getDeclAttrs(this);
(*DeclAttrs).erase(this); Context.eraseDeclAttrs(this);
this->HasAttrs = false; this->HasAttrs = false;
RHS->HasAttrs = true; RHS->HasAttrs = true;
} }
@ -282,12 +267,8 @@ void Decl::swapAttrs(Decl *RHS) {
void Decl::Destroy(ASTContext &C) { void Decl::Destroy(ASTContext &C) {
// Free attributes for this decl. // Free attributes for this decl.
if (HasAttrs) { if (HasAttrs) {
DeclAttrMapTy::iterator it = DeclAttrs->find(this); C.getDeclAttrs(this)->Destroy(C);
assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!"); invalidateAttrs(C);
// release attributes.
it->second->Destroy(C);
invalidateAttrs();
HasAttrs = false; HasAttrs = false;
} }

View File

@ -456,7 +456,7 @@ Stmt *BlockExpr::getBody() {
/// with location to warn on and the source range[s] to report with the /// with location to warn on and the source range[s] to report with the
/// warning. /// warning.
bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 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 // Don't warn if the expr is type dependent. The type could end up
// instantiating to void. // instantiating to void.
if (isTypeDependent()) if (isTypeDependent())
@ -469,7 +469,7 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
return true; return true;
case ParenExprClass: case ParenExprClass:
return cast<ParenExpr>(this)->getSubExpr()-> return cast<ParenExpr>(this)->getSubExpr()->
isUnusedResultAWarning(Loc, R1, R2); isUnusedResultAWarning(Loc, R1, R2, Context);
case UnaryOperatorClass: { case UnaryOperatorClass: {
const UnaryOperator *UO = cast<UnaryOperator>(this); const UnaryOperator *UO = cast<UnaryOperator>(this);
@ -492,7 +492,7 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
return false; return false;
break; break;
case UnaryOperator::Extension: case UnaryOperator::Extension:
return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2); return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Context);
} }
Loc = UO->getOperatorLoc(); Loc = UO->getOperatorLoc();
R1 = UO->getSubExpr()->getSourceRange(); R1 = UO->getSubExpr()->getSourceRange();
@ -502,8 +502,8 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
const BinaryOperator *BO = cast<BinaryOperator>(this); const BinaryOperator *BO = cast<BinaryOperator>(this);
// Consider comma to have side effects if the LHS or RHS does. // Consider comma to have side effects if the LHS or RHS does.
if (BO->getOpcode() == BinaryOperator::Comma) if (BO->getOpcode() == BinaryOperator::Comma)
return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2) || return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Context) ||
BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2); BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Context);
if (BO->isAssignmentOp()) if (BO->isAssignmentOp())
return false; 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 // The condition must be evaluated, but if either the LHS or RHS is a
// warning, warn about them. // warning, warn about them.
const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 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 true;
return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2); return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Context);
} }
case MemberExprClass: 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 // If the callee has attribute pure, const, or warn_unused_result, warn
// about it. void foo() { strlen("bar"); } should warn. // about it. void foo() { strlen("bar"); } should warn.
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CalleeDRE->getDecl())) if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CalleeDRE->getDecl()))
if (FD->getAttr<WarnUnusedResultAttr>() || if (FD->getAttr<WarnUnusedResultAttr>(Context) ||
FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { FD->getAttr<PureAttr>(Context) || FD->getAttr<ConstAttr>(Context)) {
Loc = CE->getCallee()->getLocStart(); Loc = CE->getCallee()->getLocStart();
R1 = CE->getCallee()->getSourceRange(); R1 = CE->getCallee()->getSourceRange();
@ -578,7 +579,7 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
if (!CS->body_empty()) if (!CS->body_empty())
if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 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(); Loc = cast<StmtExpr>(this)->getLParenLoc();
R1 = getSourceRange(); 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 // If this is a cast to void, check the operand. Otherwise, the result of
// the cast is unused. // the cast is unused.
if (getType()->isVoidType()) if (getType()->isVoidType())
return cast<CastExpr>(this)->getSubExpr()->isUnusedResultAWarning(Loc, return cast<CastExpr>(this)->getSubExpr()
R1, R2); ->isUnusedResultAWarning(Loc, R1, R2, Context);
Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); Loc = cast<CStyleCastExpr>(this)->getLParenLoc();
R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange();
return true; 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 // If this is a cast to void, check the operand. Otherwise, the result of
// the cast is unused. // the cast is unused.
if (getType()->isVoidType()) if (getType()->isVoidType())
return cast<CastExpr>(this)->getSubExpr()->isUnusedResultAWarning(Loc, return cast<CastExpr>(this)->getSubExpr()
R1, R2); ->isUnusedResultAWarning(Loc, R1, R2, Context);
Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc();
R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange();
return true; return true;
@ -606,11 +607,11 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
case ImplicitCastExprClass: case ImplicitCastExprClass:
// Check the operand, since implicit casts are inserted by Sema // Check the operand, since implicit casts are inserted by Sema
return cast<ImplicitCastExpr>(this) return cast<ImplicitCastExpr>(this)
->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2); ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Context);
case CXXDefaultArgExprClass: case CXXDefaultArgExprClass:
return cast<CXXDefaultArgExpr>(this) return cast<CXXDefaultArgExpr>(this)
->getExpr()->isUnusedResultAWarning(Loc, R1, R2); ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Context);
case CXXNewExprClass: case CXXNewExprClass:
// FIXME: In theory, there might be new expressions that don't have side // 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; return false;
case CXXExprWithTemporariesClass: case CXXExprWithTemporariesClass:
return cast<CXXExprWithTemporaries>(this) return cast<CXXExprWithTemporaries>(this)
->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2); ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Context);
} }
} }

View File

@ -1249,15 +1249,15 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ,
// Determine if there is a special return effect for this method. // Determine if there is a special return effect for this method.
if (isTrackedObjCObjectType(RetTy)) { if (isTrackedObjCObjectType(RetTy)) {
if (FD->getAttr<NSReturnsRetainedAttr>()) { if (FD->getAttr<NSReturnsRetainedAttr>(Ctx)) {
Summ.setRetEffect(ObjCAllocRetE); Summ.setRetEffect(ObjCAllocRetE);
} }
else if (FD->getAttr<CFReturnsRetainedAttr>()) { else if (FD->getAttr<CFReturnsRetainedAttr>(Ctx)) {
Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true));
} }
} }
else if (RetTy->getAsPointerType()) { else if (RetTy->getAsPointerType()) {
if (FD->getAttr<CFReturnsRetainedAttr>()) { if (FD->getAttr<CFReturnsRetainedAttr>(Ctx)) {
Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); 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. // Determine if there is a special return effect for this method.
if (isTrackedObjCObjectType(MD->getResultType())) { if (isTrackedObjCObjectType(MD->getResultType())) {
if (MD->getAttr<NSReturnsRetainedAttr>()) { if (MD->getAttr<NSReturnsRetainedAttr>(Ctx)) {
Summ.setRetEffect(ObjCAllocRetE); Summ.setRetEffect(ObjCAllocRetE);
} }
else if (MD->getAttr<CFReturnsRetainedAttr>()) { else if (MD->getAttr<CFReturnsRetainedAttr>(Ctx)) {
Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true));
} }
} }

View File

@ -85,7 +85,7 @@ public:
const LiveVariables::AnalysisDataTy& AD, const LiveVariables::AnalysisDataTy& AD,
const LiveVariables::ValTy& Live) { 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(), Report(VD, dsk, Ex->getSourceRange().getBegin(),
Val->getSourceRange()); Val->getSourceRange());
} }
@ -190,7 +190,7 @@ public:
// A dead initialization is a variable that is dead after it // A dead initialization is a variable that is dead after it
// is initialized. We don't flag warnings for those variables // is initialized. We don't flag warnings for those variables
// marked 'unused'. // 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. // Special case: check for initializations with constants.
// //
// e.g. : int x = 0; // e.g. : int x = 0;

View File

@ -109,7 +109,7 @@ void clang::CheckObjCDealloc(ObjCImplementationDecl* D,
QualType T = ID->getType(); QualType T = ID->getType();
if (!Ctx.isObjCObjectPointerType(T) || if (!Ctx.isObjCObjectPointerType(T) ||
ID->getAttr<IBOutletAttr>()) // Skip IBOutlets. ID->getAttr<IBOutletAttr>(Ctx)) // Skip IBOutlets.
continue; continue;
containsPointerIvar = true; containsPointerIvar = true;

View File

@ -74,7 +74,7 @@ void clang::CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR) {
continue; continue;
// Skip IB Outlets. // Skip IB Outlets.
if (ID->getAttr<IBOutletAttr>()) if (ID->getAttr<IBOutletAttr>(Ctx))
continue; continue;
M[ID] = Unused; M[ID] = Unused;

View File

@ -1482,7 +1482,8 @@ void GRExprEngine::VisitCallRec(CallExpr* CE, NodeTy* Pred,
SaveAndRestore<bool> OldSink(Builder->BuildSinks); SaveAndRestore<bool> OldSink(Builder->BuildSinks);
const FunctionDecl* FD = L.getAsFunctionDecl(); const FunctionDecl* FD = L.getAsFunctionDecl();
if (FD) { if (FD) {
if (FD->getAttr<NoReturnAttr>() || FD->getAttr<AnalyzerNoReturnAttr>()) if (FD->getAttr<NoReturnAttr>(getContext()) ||
FD->getAttr<AnalyzerNoReturnAttr>(getContext()))
Builder->BuildSinks = true; Builder->BuildSinks = true;
else { else {
// HACK: Some functions are not marked noreturn, and don't return. // HACK: Some functions are not marked noreturn, and don't return.

View File

@ -569,7 +569,7 @@ public:
if (!FD) if (!FD)
return false; return false;
const NonNullAttr* Att = FD->getAttr<NonNullAttr>(); const NonNullAttr* Att = FD->getAttr<NonNullAttr>(BR.getContext());
if (!Att) if (!Att)
return false; return false;

View File

@ -522,7 +522,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
case Builtin::BIsqrtf: case Builtin::BIsqrtf:
case Builtin::BIsqrtl: { case Builtin::BIsqrtl: {
// Rewrite sqrt to intrinsic if allowed. // Rewrite sqrt to intrinsic if allowed.
if (!FD->hasAttr<ConstAttr>()) if (!FD->hasAttr<ConstAttr>(getContext()))
break; break;
Value *Arg0 = EmitScalarExpr(E->getArg(0)); Value *Arg0 = EmitScalarExpr(E->getArg(0));
const llvm::Type *ArgType = Arg0->getType(); const llvm::Type *ArgType = Arg0->getType();
@ -534,7 +534,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
case Builtin::BIpowf: case Builtin::BIpowf:
case Builtin::BIpowl: { case Builtin::BIpowl: {
// Rewrite sqrt to intrinsic if allowed. // Rewrite sqrt to intrinsic if allowed.
if (!FD->hasAttr<ConstAttr>()) if (!FD->hasAttr<ConstAttr>(getContext()))
break; break;
Value *Base = EmitScalarExpr(E->getArg(0)); Value *Base = EmitScalarExpr(E->getArg(0));
Value *Exponent = EmitScalarExpr(E->getArg(1)); Value *Exponent = EmitScalarExpr(E->getArg(1));

View File

@ -377,13 +377,13 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
// FIXME: handle sseregparm someday... // FIXME: handle sseregparm someday...
if (TargetDecl) { if (TargetDecl) {
if (TargetDecl->hasAttr<NoThrowAttr>()) if (TargetDecl->hasAttr<NoThrowAttr>(getContext()))
FuncAttrs |= llvm::Attribute::NoUnwind; FuncAttrs |= llvm::Attribute::NoUnwind;
if (TargetDecl->hasAttr<NoReturnAttr>()) if (TargetDecl->hasAttr<NoReturnAttr>(getContext()))
FuncAttrs |= llvm::Attribute::NoReturn; FuncAttrs |= llvm::Attribute::NoReturn;
if (TargetDecl->hasAttr<ConstAttr>()) if (TargetDecl->hasAttr<ConstAttr>(getContext()))
FuncAttrs |= llvm::Attribute::ReadNone; FuncAttrs |= llvm::Attribute::ReadNone;
else if (TargetDecl->hasAttr<PureAttr>()) else if (TargetDecl->hasAttr<PureAttr>(getContext()))
FuncAttrs |= llvm::Attribute::ReadOnly; FuncAttrs |= llvm::Attribute::ReadOnly;
} }
@ -432,7 +432,8 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
// register variable. // register variable.
signed RegParm = 0; signed RegParm = 0;
if (TargetDecl) if (TargetDecl)
if (const RegparmAttr *RegParmAttr = TargetDecl->getAttr<RegparmAttr>()) if (const RegparmAttr *RegParmAttr
= TargetDecl->getAttr<RegparmAttr>(getContext()))
RegParm = RegParmAttr->getNumParams(); RegParm = RegParmAttr->getNumParams();
unsigned PointerWidth = getContext().Target.getPointerWidth(0); unsigned PointerWidth = getContext().Target.getPointerWidth(0);

View File

@ -60,7 +60,7 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
/// EmitBlockVarDecl - This method handles emission of any variable declaration /// EmitBlockVarDecl - This method handles emission of any variable declaration
/// inside a function, including static vars etc. /// inside a function, including static vars etc.
void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) { void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) {
if (D.hasAttr<AsmLabelAttr>()) if (D.hasAttr<AsmLabelAttr>(getContext()))
CGM.ErrorUnsupported(&D, "__asm__"); CGM.ErrorUnsupported(&D, "__asm__");
switch (D.getStorageClass()) { switch (D.getStorageClass()) {
@ -171,7 +171,7 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
} }
// FIXME: Merge attribute handling. // FIXME: Merge attribute handling.
if (const AnnotateAttr *AA = D.getAttr<AnnotateAttr>()) { if (const AnnotateAttr *AA = D.getAttr<AnnotateAttr>(getContext())) {
SourceManager &SM = CGM.getContext().getSourceManager(); SourceManager &SM = CGM.getContext().getSourceManager();
llvm::Constant *Ann = llvm::Constant *Ann =
CGM.EmitAnnotateAttr(GV, AA, CGM.EmitAnnotateAttr(GV, AA,
@ -179,10 +179,10 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
CGM.AddAnnotation(Ann); CGM.AddAnnotation(Ann);
} }
if (const SectionAttr *SA = D.getAttr<SectionAttr>()) if (const SectionAttr *SA = D.getAttr<SectionAttr>(getContext()))
GV->setSection(SA->getName()); GV->setSection(SA->getName());
if (D.hasAttr<UsedAttr>()) if (D.hasAttr<UsedAttr>(getContext()))
CGM.AddUsedGlobal(GV); CGM.AddUsedGlobal(GV);
// We may have to cast the constant because of the initializer // We may have to cast the constant because of the initializer
@ -244,7 +244,7 @@ const llvm::Type *CodeGenFunction::BuildByRefType(QualType Ty,
/// These turn into simple stack objects, or GlobalValues depending on target. /// These turn into simple stack objects, or GlobalValues depending on target.
void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) { void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
QualType Ty = D.getType(); QualType Ty = D.getType();
bool isByRef = D.hasAttr<BlocksAttr>(); bool isByRef = D.hasAttr<BlocksAttr>(getContext());
bool needsDispose = false; bool needsDispose = false;
unsigned Align = 0; unsigned Align = 0;
@ -414,7 +414,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
} }
// Handle the cleanup attribute // Handle the cleanup attribute
if (const CleanupAttr *CA = D.getAttr<CleanupAttr>()) { if (const CleanupAttr *CA = D.getAttr<CleanupAttr>(getContext())) {
const FunctionDecl *FD = CA->getFunctionDecl(); const FunctionDecl *FD = CA->getFunctionDecl();
llvm::Constant* F = CGM.GetAddrOfFunction(GlobalDecl(FD)); llvm::Constant* F = CGM.GetAddrOfFunction(GlobalDecl(FD));

View File

@ -668,7 +668,8 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
if (VD && (VD->isBlockVarDecl() || isa<ParmVarDecl>(VD) || if (VD && (VD->isBlockVarDecl() || isa<ParmVarDecl>(VD) ||
isa<ImplicitParamDecl>(VD))) { isa<ImplicitParamDecl>(VD))) {
LValue LV; LValue LV;
bool NonGCable = VD->hasLocalStorage() && !VD->hasAttr<BlocksAttr>(); bool NonGCable = VD->hasLocalStorage() &&
!VD->hasAttr<BlocksAttr>(getContext());
if (VD->hasExternalStorage()) { if (VD->hasExternalStorage()) {
llvm::Value *V = CGM.GetAddrOfGlobalVar(VD); llvm::Value *V = CGM.GetAddrOfGlobalVar(VD);
if (VD->getType()->isReferenceType()) if (VD->getType()->isReferenceType())
@ -684,7 +685,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
// local static? // local static?
if (!NonGCable) if (!NonGCable)
attr = getContext().getObjCGCAttrKind(E->getType()); attr = getContext().getObjCGCAttrKind(E->getType());
if (VD->hasAttr<BlocksAttr>()) { if (VD->hasAttr<BlocksAttr>(getContext())) {
bool needsCopyDispose = BlockRequiresCopying(VD->getType()); bool needsCopyDispose = BlockRequiresCopying(VD->getType());
const llvm::Type *PtrStructTy = V->getType(); const llvm::Type *PtrStructTy = V->getType();
const llvm::Type *Ty = PtrStructTy; const llvm::Type *Ty = PtrStructTy;

View File

@ -126,7 +126,7 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD,
/// its pointer, name, and types registered in the class struture. /// its pointer, name, and types registered in the class struture.
void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) { void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) {
// Check if we should generate debug info for this method. // Check if we should generate debug info for this method.
if (CGM.getDebugInfo() && !OMD->hasAttr<NodebugAttr>()) if (CGM.getDebugInfo() && !OMD->hasAttr<NodebugAttr>(getContext()))
DebugInfo = CGM.getDebugInfo(); DebugInfo = CGM.getDebugInfo();
StartObjCMethod(OMD, OMD->getClassInterface()); StartObjCMethod(OMD, OMD->getClassInterface());
EmitStmt(OMD->getBody(getContext())); EmitStmt(OMD->getBody(getContext()));

View File

@ -1356,11 +1356,12 @@ static llvm::Constant *getConstantGEP(llvm::Constant *C,
/// hasObjCExceptionAttribute - Return true if this class or any super /// hasObjCExceptionAttribute - Return true if this class or any super
/// class has the __objc_exception__ attribute. /// class has the __objc_exception__ attribute.
static bool hasObjCExceptionAttribute(const ObjCInterfaceDecl *OID) { static bool hasObjCExceptionAttribute(ASTContext &Context,
if (OID->hasAttr<ObjCExceptionAttr>()) const ObjCInterfaceDecl *OID) {
if (OID->hasAttr<ObjCExceptionAttr>(Context))
return true; return true;
if (const ObjCInterfaceDecl *Super = OID->getSuperClass()) if (const ObjCInterfaceDecl *Super = OID->getSuperClass())
return hasObjCExceptionAttribute(Super); return hasObjCExceptionAttribute(Context, Super);
return false; return false;
} }
@ -4402,7 +4403,7 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) {
if (classIsHidden) if (classIsHidden)
flags |= OBJC2_CLS_HIDDEN; flags |= OBJC2_CLS_HIDDEN;
if (hasObjCExceptionAttribute(ID->getClassInterface())) if (hasObjCExceptionAttribute(CGM.getContext(), ID->getClassInterface()))
flags |= CLS_EXCEPTION; flags |= CLS_EXCEPTION;
if (!ID->getClassInterface()->getSuperClass()) { if (!ID->getClassInterface()->getSuperClass()) {
@ -5686,7 +5687,7 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID,
// If this type (or a super class) has the __objc_exception__ // If this type (or a super class) has the __objc_exception__
// attribute, emit an external reference. // attribute, emit an external reference.
if (hasObjCExceptionAttribute(ID)) if (hasObjCExceptionAttribute(CGM.getContext(), ID))
return Entry = return Entry =
new llvm::GlobalVariable(ObjCTypes.EHTypeTy, false, new llvm::GlobalVariable(ObjCTypes.EHTypeTy, false,
llvm::GlobalValue::ExternalLinkage, llvm::GlobalValue::ExternalLinkage,

View File

@ -199,7 +199,7 @@ void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy,
void CodeGenFunction::GenerateCode(const FunctionDecl *FD, void CodeGenFunction::GenerateCode(const FunctionDecl *FD,
llvm::Function *Fn) { llvm::Function *Fn) {
// Check if we should generate debug info for this function. // Check if we should generate debug info for this function.
if (CGM.getDebugInfo() && !FD->hasAttr<NodebugAttr>()) if (CGM.getDebugInfo() && !FD->hasAttr<NodebugAttr>(getContext()))
DebugInfo = CGM.getDebugInfo(); DebugInfo = CGM.getDebugInfo();
FunctionArgList Args; FunctionArgList Args;

View File

@ -102,7 +102,7 @@ CodeGenModule::getDeclVisibilityMode(const Decl *D) const {
if (VD->getStorageClass() == VarDecl::PrivateExtern) if (VD->getStorageClass() == VarDecl::PrivateExtern)
return LangOptions::Hidden; return LangOptions::Hidden;
if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>()) { if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>(getContext())) {
switch (attr->getVisibility()) { switch (attr->getVisibility()) {
default: assert(0 && "Unknown visibility!"); default: assert(0 && "Unknown visibility!");
case VisibilityAttr::DefaultVisibility: case VisibilityAttr::DefaultVisibility:
@ -241,7 +241,8 @@ void CodeGenModule::EmitAnnotations() {
} }
static CodeGenModule::GVALinkage static CodeGenModule::GVALinkage
GetLinkageForFunction(const FunctionDecl *FD, const LangOptions &Features) { GetLinkageForFunction(ASTContext &Context, const FunctionDecl *FD,
const LangOptions &Features) {
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
// C++ member functions defined inside the class are always inline. // C++ member functions defined inside the class are always inline.
if (MD->isInline() || !MD->isOutOfLine()) if (MD->isInline() || !MD->isOutOfLine())
@ -265,11 +266,11 @@ GetLinkageForFunction(const FunctionDecl *FD, const LangOptions &Features) {
return CodeGenModule::GVA_C99Inline; return CodeGenModule::GVA_C99Inline;
// Normal inline is a strong symbol. // Normal inline is a strong symbol.
return CodeGenModule::GVA_StrongExternal; return CodeGenModule::GVA_StrongExternal;
} else if (FD->hasActiveGNUInlineAttribute()) { } else if (FD->hasActiveGNUInlineAttribute(Context)) {
// GCC in C99 mode seems to use a different decision-making // GCC in C99 mode seems to use a different decision-making
// process for extern inline, which factors in previous // process for extern inline, which factors in previous
// declarations. // declarations.
if (FD->isExternGNUInline()) if (FD->isExternGNUInline(Context))
return CodeGenModule::GVA_C99Inline; return CodeGenModule::GVA_C99Inline;
// Normal inline is a strong symbol. // Normal inline is a strong symbol.
return CodeGenModule::GVA_StrongExternal; return CodeGenModule::GVA_StrongExternal;
@ -293,13 +294,13 @@ GetLinkageForFunction(const FunctionDecl *FD, const LangOptions &Features) {
/// variables (these details are set in EmitGlobalVarDefinition for variables). /// variables (these details are set in EmitGlobalVarDefinition for variables).
void CodeGenModule::SetFunctionDefinitionAttributes(const FunctionDecl *D, void CodeGenModule::SetFunctionDefinitionAttributes(const FunctionDecl *D,
llvm::GlobalValue *GV) { llvm::GlobalValue *GV) {
GVALinkage Linkage = GetLinkageForFunction(D, Features); GVALinkage Linkage = GetLinkageForFunction(getContext(), D, Features);
if (Linkage == GVA_Internal) { if (Linkage == GVA_Internal) {
GV->setLinkage(llvm::Function::InternalLinkage); GV->setLinkage(llvm::Function::InternalLinkage);
} else if (D->hasAttr<DLLExportAttr>()) { } else if (D->hasAttr<DLLExportAttr>(getContext())) {
GV->setLinkage(llvm::Function::DLLExportLinkage); GV->setLinkage(llvm::Function::DLLExportLinkage);
} else if (D->hasAttr<WeakAttr>()) { } else if (D->hasAttr<WeakAttr>(getContext())) {
GV->setLinkage(llvm::Function::WeakAnyLinkage); GV->setLinkage(llvm::Function::WeakAnyLinkage);
} else if (Linkage == GVA_C99Inline) { } else if (Linkage == GVA_C99Inline) {
// In C99 mode, 'inline' functions are guaranteed to have a strong // In C99 mode, 'inline' functions are guaranteed to have a strong
@ -332,10 +333,10 @@ void CodeGenModule::SetLLVMFunctionAttributes(const Decl *D,
AttributeList.size())); AttributeList.size()));
// Set the appropriate calling convention for the Function. // Set the appropriate calling convention for the Function.
if (D->hasAttr<FastCallAttr>()) if (D->hasAttr<FastCallAttr>(getContext()))
F->setCallingConv(llvm::CallingConv::X86_FastCall); F->setCallingConv(llvm::CallingConv::X86_FastCall);
if (D->hasAttr<StdCallAttr>()) if (D->hasAttr<StdCallAttr>(getContext()))
F->setCallingConv(llvm::CallingConv::X86_StdCall); F->setCallingConv(llvm::CallingConv::X86_StdCall);
} }
@ -344,10 +345,10 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
if (!Features.Exceptions && !Features.ObjCNonFragileABI) if (!Features.Exceptions && !Features.ObjCNonFragileABI)
F->addFnAttr(llvm::Attribute::NoUnwind); F->addFnAttr(llvm::Attribute::NoUnwind);
if (D->hasAttr<AlwaysInlineAttr>()) if (D->hasAttr<AlwaysInlineAttr>(getContext()))
F->addFnAttr(llvm::Attribute::AlwaysInline); F->addFnAttr(llvm::Attribute::AlwaysInline);
if (D->hasAttr<NoinlineAttr>()) if (D->hasAttr<NoinlineAttr>(getContext()))
F->addFnAttr(llvm::Attribute::NoInline); F->addFnAttr(llvm::Attribute::NoInline);
} }
@ -355,10 +356,10 @@ void CodeGenModule::SetCommonAttributes(const Decl *D,
llvm::GlobalValue *GV) { llvm::GlobalValue *GV) {
setGlobalVisibility(GV, D); setGlobalVisibility(GV, D);
if (D->hasAttr<UsedAttr>()) if (D->hasAttr<UsedAttr>(getContext()))
AddUsedGlobal(GV); AddUsedGlobal(GV);
if (const SectionAttr *SA = D->getAttr<SectionAttr>()) if (const SectionAttr *SA = D->getAttr<SectionAttr>(getContext()))
GV->setSection(SA->getName()); GV->setSection(SA->getName());
} }
@ -382,9 +383,10 @@ void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD,
// Only a few attributes are set on declarations; these may later be // Only a few attributes are set on declarations; these may later be
// overridden by a definition. // overridden by a definition.
if (FD->hasAttr<DLLImportAttr>()) { if (FD->hasAttr<DLLImportAttr>(getContext())) {
F->setLinkage(llvm::Function::DLLImportLinkage); F->setLinkage(llvm::Function::DLLImportLinkage);
} else if (FD->hasAttr<WeakAttr>() || FD->hasAttr<WeakImportAttr>()) { } else if (FD->hasAttr<WeakAttr>(getContext()) ||
FD->hasAttr<WeakImportAttr>(getContext())) {
// "extern_weak" is overloaded in LLVM; we probably should have // "extern_weak" is overloaded in LLVM; we probably should have
// separate linkage types for this. // separate linkage types for this.
F->setLinkage(llvm::Function::ExternalWeakLinkage); F->setLinkage(llvm::Function::ExternalWeakLinkage);
@ -392,7 +394,7 @@ void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD,
F->setLinkage(llvm::Function::ExternalLinkage); F->setLinkage(llvm::Function::ExternalLinkage);
} }
if (const SectionAttr *SA = FD->getAttr<SectionAttr>()) if (const SectionAttr *SA = FD->getAttr<SectionAttr>(getContext()))
F->setSection(SA->getName()); F->setSection(SA->getName());
} }
@ -499,15 +501,16 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) { bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) {
// Never defer when EmitAllDecls is specified or the decl has // Never defer when EmitAllDecls is specified or the decl has
// attribute used. // attribute used.
if (Features.EmitAllDecls || Global->hasAttr<UsedAttr>()) if (Features.EmitAllDecls || Global->hasAttr<UsedAttr>(getContext()))
return false; return false;
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Global)) { if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Global)) {
// Constructors and destructors should never be deferred. // Constructors and destructors should never be deferred.
if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>()) if (FD->hasAttr<ConstructorAttr>(getContext()) ||
FD->hasAttr<DestructorAttr>(getContext()))
return false; return false;
GVALinkage Linkage = GetLinkageForFunction(FD, Features); GVALinkage Linkage = GetLinkageForFunction(getContext(), FD, Features);
// static, static inline, always_inline, and extern inline functions can // static, static inline, always_inline, and extern inline functions can
// always be deferred. Normal inline functions can be deferred in C99/C++. // always be deferred. Normal inline functions can be deferred in C99/C++.
@ -528,7 +531,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
// If this is an alias definition (which otherwise looks like a declaration) // If this is an alias definition (which otherwise looks like a declaration)
// emit it now. // emit it now.
if (Global->hasAttr<AliasAttr>()) if (Global->hasAttr<AliasAttr>(getContext()))
return EmitAliasDefinition(Global); return EmitAliasDefinition(Global);
// Ignore declarations, they will be emitted on their first use. // Ignore declarations, they will be emitted on their first use.
@ -717,7 +720,8 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMGlobal(const char *MangledName,
if (D->getStorageClass() == VarDecl::PrivateExtern) if (D->getStorageClass() == VarDecl::PrivateExtern)
GV->setVisibility(llvm::GlobalValue::HiddenVisibility); GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
if (D->hasAttr<WeakAttr>() || D->hasAttr<WeakImportAttr>()) if (D->hasAttr<WeakAttr>(getContext()) ||
D->hasAttr<WeakImportAttr>(getContext()))
GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
GV->setThreadLocal(D->isThreadSpecified()); GV->setThreadLocal(D->isThreadSpecified());
@ -837,7 +841,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
cast<llvm::GlobalValue>(Entry)->eraseFromParent(); cast<llvm::GlobalValue>(Entry)->eraseFromParent();
} }
if (const AnnotateAttr *AA = D->getAttr<AnnotateAttr>()) { if (const AnnotateAttr *AA = D->getAttr<AnnotateAttr>(getContext())) {
SourceManager &SM = Context.getSourceManager(); SourceManager &SM = Context.getSourceManager();
AddAnnotation(EmitAnnotateAttr(GV, AA, AddAnnotation(EmitAnnotateAttr(GV, AA,
SM.getInstantiationLineNumber(D->getLocation()))); SM.getInstantiationLineNumber(D->getLocation())));
@ -850,11 +854,11 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
// Set the llvm linkage type as appropriate. // Set the llvm linkage type as appropriate.
if (D->getStorageClass() == VarDecl::Static) if (D->getStorageClass() == VarDecl::Static)
GV->setLinkage(llvm::Function::InternalLinkage); GV->setLinkage(llvm::Function::InternalLinkage);
else if (D->hasAttr<DLLImportAttr>()) else if (D->hasAttr<DLLImportAttr>(getContext()))
GV->setLinkage(llvm::Function::DLLImportLinkage); GV->setLinkage(llvm::Function::DLLImportLinkage);
else if (D->hasAttr<DLLExportAttr>()) else if (D->hasAttr<DLLExportAttr>(getContext()))
GV->setLinkage(llvm::Function::DLLExportLinkage); GV->setLinkage(llvm::Function::DLLExportLinkage);
else if (D->hasAttr<WeakAttr>()) else if (D->hasAttr<WeakAttr>(getContext()))
GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage); GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage);
else if (!CompileOpts.NoCommon && else if (!CompileOpts.NoCommon &&
(!D->hasExternalStorage() && !D->getInit())) (!D->hasExternalStorage() && !D->getInit()))
@ -1017,14 +1021,14 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD) {
SetFunctionDefinitionAttributes(D, Fn); SetFunctionDefinitionAttributes(D, Fn);
SetLLVMFunctionAttributesForDefinition(D, Fn); SetLLVMFunctionAttributesForDefinition(D, Fn);
if (const ConstructorAttr *CA = D->getAttr<ConstructorAttr>()) if (const ConstructorAttr *CA = D->getAttr<ConstructorAttr>(getContext()))
AddGlobalCtor(Fn, CA->getPriority()); AddGlobalCtor(Fn, CA->getPriority());
if (const DestructorAttr *DA = D->getAttr<DestructorAttr>()) if (const DestructorAttr *DA = D->getAttr<DestructorAttr>(getContext()))
AddGlobalDtor(Fn, DA->getPriority()); AddGlobalDtor(Fn, DA->getPriority());
} }
void CodeGenModule::EmitAliasDefinition(const ValueDecl *D) { void CodeGenModule::EmitAliasDefinition(const ValueDecl *D) {
const AliasAttr *AA = D->getAttr<AliasAttr>(); const AliasAttr *AA = D->getAttr<AliasAttr>(getContext());
assert(AA && "Not an alias?"); assert(AA && "Not an alias?");
const llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType()); const llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType());
@ -1080,7 +1084,7 @@ void CodeGenModule::EmitAliasDefinition(const ValueDecl *D) {
// Set attributes which are particular to an alias; this is a // Set attributes which are particular to an alias; this is a
// specialization of the attributes which may be set on a global // specialization of the attributes which may be set on a global
// variable/function. // variable/function.
if (D->hasAttr<DLLExportAttr>()) { if (D->hasAttr<DLLExportAttr>(getContext())) {
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
// The dllexport attribute is ignored for undefined symbols. // The dllexport attribute is ignored for undefined symbols.
if (FD->getBody(getContext())) if (FD->getBody(getContext()))
@ -1088,7 +1092,8 @@ void CodeGenModule::EmitAliasDefinition(const ValueDecl *D) {
} else { } else {
GA->setLinkage(llvm::Function::DLLExportLinkage); GA->setLinkage(llvm::Function::DLLExportLinkage);
} }
} else if (D->hasAttr<WeakAttr>() || D->hasAttr<WeakImportAttr>()) { } else if (D->hasAttr<WeakAttr>(getContext()) ||
D->hasAttr<WeakImportAttr>(getContext())) {
GA->setLinkage(llvm::Function::WeakAnyLinkage); GA->setLinkage(llvm::Function::WeakAnyLinkage);
} }

View File

@ -87,7 +87,7 @@ static bool isInCLinkageSpecification(const Decl *D) {
bool CXXNameMangler::mangleFunctionDecl(const FunctionDecl *FD) { bool CXXNameMangler::mangleFunctionDecl(const FunctionDecl *FD) {
// Clang's "overloadable" attribute extension to C/C++ implies // Clang's "overloadable" attribute extension to C/C++ implies
// name mangling (always). // name mangling (always).
if (!FD->hasAttr<OverloadableAttr>()) { if (!FD->hasAttr<OverloadableAttr>(Context)) {
// C functions are not mangled, and "main" is never mangled. // C functions are not mangled, and "main" is never mangled.
if (!Context.getLangOptions().CPlusPlus || FD->isMain()) if (!Context.getLangOptions().CPlusPlus || FD->isMain())
return false; return false;
@ -111,7 +111,7 @@ bool CXXNameMangler::mangleFunctionDecl(const FunctionDecl *FD) {
bool CXXNameMangler::mangle(const NamedDecl *D) { bool CXXNameMangler::mangle(const NamedDecl *D) {
// Any decl can be declared with __asm("foo") on it, and this takes // Any decl can be declared with __asm("foo") on it, and this takes
// precedence over all other naming in the .o file. // precedence over all other naming in the .o file.
if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) { if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>(Context)) {
// If we have an asm name, then we use it as the mangling. // If we have an asm name, then we use it as the mangling.
Out << '\01'; // LLVM IR Marker for __asm("foo") Out << '\01'; // LLVM IR Marker for __asm("foo")
Out << ALA->getLabel(); Out << ALA->getLabel();

View File

@ -80,7 +80,7 @@ void PCHDeclReader::VisitDecl(Decl *D) {
D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
D->setInvalidDecl(Record[Idx++]); D->setInvalidDecl(Record[Idx++]);
if (Record[Idx++]) if (Record[Idx++])
D->addAttr(Reader.ReadAttributes()); D->addAttr(*Reader.getContext(), Reader.ReadAttributes());
D->setImplicit(Record[Idx++]); D->setImplicit(Record[Idx++]);
D->setAccess((AccessSpecifier)Record[Idx++]); D->setAccess((AccessSpecifier)Record[Idx++]);
} }

View File

@ -516,7 +516,7 @@ void PCHWriter::WriteDeclsBlock(ASTContext &Context) {
// If the declaration had any attributes, write them now. // If the declaration had any attributes, write them now.
if (D->hasAttrs()) if (D->hasAttrs())
WriteAttributeRecord(D->getAttrs()); WriteAttributeRecord(D->getAttrs(Context));
// Flush any expressions that were written as part of this declaration. // Flush any expressions that were written as part of this declaration.
FlushStmts(); FlushStmts();

View File

@ -77,11 +77,11 @@ JumpScopeChecker::JumpScopeChecker(Stmt *Body, Sema &s) : S(s) {
/// GetDiagForGotoScopeDecl - If this decl induces a new goto scope, return a /// GetDiagForGotoScopeDecl - If this decl induces a new goto scope, return a
/// diagnostic that should be emitted if control goes over it. If not, return 0. /// diagnostic that should be emitted if control goes over it. If not, return 0.
static unsigned GetDiagForGotoScopeDecl(const Decl *D) { static unsigned GetDiagForGotoScopeDecl(ASTContext &Context, const Decl *D) {
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
if (VD->getType()->isVariablyModifiedType()) if (VD->getType()->isVariablyModifiedType())
return diag::note_protected_by_vla; return diag::note_protected_by_vla;
if (VD->hasAttr<CleanupAttr>()) if (VD->hasAttr<CleanupAttr>(Context))
return diag::note_protected_by_cleanup; return diag::note_protected_by_cleanup;
} else if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) { } else if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
if (TD->getUnderlyingType()->isVariablyModifiedType()) if (TD->getUnderlyingType()->isVariablyModifiedType())
@ -125,7 +125,7 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) {
for (DeclStmt::decl_iterator I = DS->decl_begin(), E = DS->decl_end(); for (DeclStmt::decl_iterator I = DS->decl_begin(), E = DS->decl_end();
I != E; ++I) { I != E; ++I) {
// If this decl causes a new scope, push and switch to it. // If this decl causes a new scope, push and switch to it.
if (unsigned Diag = GetDiagForGotoScopeDecl(*I)) { if (unsigned Diag = GetDiagForGotoScopeDecl(this->S.Context, *I)) {
Scopes.push_back(GotoScope(ParentScope, Diag, (*I)->getLocation())); Scopes.push_back(GotoScope(ParentScope, Diag, (*I)->getLocation()));
ParentScope = Scopes.size()-1; ParentScope = Scopes.size()-1;
} }

View File

@ -205,7 +205,7 @@ void Sema::ActOnPragmaUnused(ExprTy **Exprs, unsigned NumExprs,
// Otherwise, add the 'unused' attribute to each referenced declaration. // Otherwise, add the 'unused' attribute to each referenced declaration.
for (unsigned i = 0; i < NumExprs; ++i) { for (unsigned i = 0; i < NumExprs; ++i) {
DeclRefExpr *DR = (DeclRefExpr*) Exprs[i]; DeclRefExpr *DR = (DeclRefExpr*) Exprs[i];
DR->getDecl()->addAttr(::new (Context) UnusedAttr()); DR->getDecl()->addAttr(Context, ::new (Context) UnusedAttr());
DR->Destroy(Context); DR->Destroy(Context);
} }
} }

View File

@ -166,7 +166,7 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) {
// handlers. // handlers.
// Printf checking. // Printf checking.
if (const FormatAttr *Format = FDecl->getAttr<FormatAttr>()) { if (const FormatAttr *Format = FDecl->getAttr<FormatAttr>(Context)) {
if (Format->getType() == "printf") { if (Format->getType() == "printf") {
bool HasVAListArg = Format->getFirstArg() == 0; bool HasVAListArg = Format->getFirstArg() == 0;
if (!HasVAListArg) { if (!HasVAListArg) {
@ -178,7 +178,8 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) {
HasVAListArg ? 0 : Format->getFirstArg() - 1); HasVAListArg ? 0 : Format->getFirstArg() - 1);
} }
} }
for (const Attr *attr = FDecl->getAttrs(); attr; attr = attr->getNext()) { for (const Attr *attr = FDecl->getAttrs(Context);
attr; attr = attr->getNext()) {
if (const NonNullAttr *NonNull = dyn_cast<NonNullAttr>(attr)) if (const NonNullAttr *NonNull = dyn_cast<NonNullAttr>(attr))
CheckNonNullArguments(NonNull, TheCall); CheckNonNullArguments(NonNull, TheCall);
} }
@ -191,7 +192,7 @@ Sema::CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall) {
OwningExprResult TheCallResult(Owned(TheCall)); OwningExprResult TheCallResult(Owned(TheCall));
// Printf checking. // Printf checking.
const FormatAttr *Format = NDecl->getAttr<FormatAttr>(); const FormatAttr *Format = NDecl->getAttr<FormatAttr>(Context);
if (!Format) if (!Format)
return move(TheCallResult); return move(TheCallResult);
const VarDecl *V = dyn_cast<VarDecl>(NDecl); const VarDecl *V = dyn_cast<VarDecl>(NDecl);

View File

@ -256,7 +256,7 @@ static bool AllowOverloadingOfFunction(Decl *PrevDecl, ASTContext &Context) {
if (isa<OverloadedFunctionDecl>(PrevDecl)) if (isa<OverloadedFunctionDecl>(PrevDecl))
return true; return true;
return PrevDecl->getAttr<OverloadableAttr>() != 0; return PrevDecl->getAttr<OverloadableAttr>(Context) != 0;
} }
/// Add this decl to the scope shadowed decl chains. /// Add this decl to the scope shadowed decl chains.
@ -611,8 +611,9 @@ void Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) {
/// DeclhasAttr - returns true if decl Declaration already has the target /// DeclhasAttr - returns true if decl Declaration already has the target
/// attribute. /// attribute.
static bool DeclHasAttr(const Decl *decl, const Attr *target) { static bool
for (const Attr *attr = decl->getAttrs(); attr; attr = attr->getNext()) DeclHasAttr(ASTContext &Context, const Decl *decl, const Attr *target) {
for (const Attr *attr = decl->getAttrs(Context); attr; attr = attr->getNext())
if (attr->getKind() == target->getKind()) if (attr->getKind() == target->getKind())
return true; return true;
@ -621,11 +622,11 @@ static bool DeclHasAttr(const Decl *decl, const Attr *target) {
/// MergeAttributes - append attributes from the Old decl to the New one. /// MergeAttributes - append attributes from the Old decl to the New one.
static void MergeAttributes(Decl *New, Decl *Old, ASTContext &C) { static void MergeAttributes(Decl *New, Decl *Old, ASTContext &C) {
for (const Attr *attr = Old->getAttrs(); attr; attr = attr->getNext()) { for (const Attr *attr = Old->getAttrs(C); attr; attr = attr->getNext()) {
if (!DeclHasAttr(New, attr) && attr->isMerged()) { if (!DeclHasAttr(C, New, attr) && attr->isMerged()) {
Attr *NewAttr = attr->clone(C); Attr *NewAttr = attr->clone(C);
NewAttr->setInherited(true); NewAttr->setInherited(true);
New->addAttr(NewAttr); New->addAttr(C, NewAttr);
} }
} }
} }
@ -1828,7 +1829,8 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
if (Expr *E = (Expr*) D.getAsmLabel()) { if (Expr *E = (Expr*) D.getAsmLabel()) {
// The parser guarantees this is a string. // The parser guarantees this is a string.
StringLiteral *SE = cast<StringLiteral>(E); StringLiteral *SE = cast<StringLiteral>(E);
NewVD->addAttr(::new (Context) AsmLabelAttr(std::string(SE->getStrData(), NewVD->addAttr(Context,
::new (Context) AsmLabelAttr(std::string(SE->getStrData(),
SE->getByteLength()))); SE->getByteLength())));
} }
@ -1907,11 +1909,11 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl,
} }
if (NewVD->hasLocalStorage() && T.isObjCGCWeak() if (NewVD->hasLocalStorage() && T.isObjCGCWeak()
&& !NewVD->hasAttr<BlocksAttr>()) && !NewVD->hasAttr<BlocksAttr>(Context))
Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local); Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local);
bool isVM = T->isVariablyModifiedType(); bool isVM = T->isVariablyModifiedType();
if (isVM || NewVD->hasAttr<CleanupAttr>()) if (isVM || NewVD->hasAttr<CleanupAttr>(Context))
CurFunctionNeedsScopeChecking = true; CurFunctionNeedsScopeChecking = true;
if ((isVM && NewVD->hasLinkage()) || if ((isVM && NewVD->hasLinkage()) ||
@ -1966,12 +1968,12 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl,
return NewVD->setInvalidDecl(); return NewVD->setInvalidDecl();
} }
if (!NewVD->hasLocalStorage() && NewVD->hasAttr<BlocksAttr>()) { if (!NewVD->hasLocalStorage() && NewVD->hasAttr<BlocksAttr>(Context)) {
Diag(NewVD->getLocation(), diag::err_block_on_nonlocal); Diag(NewVD->getLocation(), diag::err_block_on_nonlocal);
return NewVD->setInvalidDecl(); return NewVD->setInvalidDecl();
} }
if (isVM && NewVD->hasAttr<BlocksAttr>()) { if (isVM && NewVD->hasAttr<BlocksAttr>(Context)) {
Diag(NewVD->getLocation(), diag::err_block_on_vm); Diag(NewVD->getLocation(), diag::err_block_on_vm);
return NewVD->setInvalidDecl(); return NewVD->setInvalidDecl();
} }
@ -2201,7 +2203,8 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
if (Expr *E = (Expr*) D.getAsmLabel()) { if (Expr *E = (Expr*) D.getAsmLabel()) {
// The parser guarantees this is a string. // The parser guarantees this is a string.
StringLiteral *SE = cast<StringLiteral>(E); StringLiteral *SE = cast<StringLiteral>(E);
NewFD->addAttr(::new (Context) AsmLabelAttr(std::string(SE->getStrData(), NewFD->addAttr(Context,
::new (Context) AsmLabelAttr(std::string(SE->getStrData(),
SE->getByteLength()))); SE->getByteLength())));
} }
@ -2322,7 +2325,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
ProcessDeclAttributes(S, NewFD, D); ProcessDeclAttributes(S, NewFD, D);
AddKnownFunctionAttributes(NewFD); AddKnownFunctionAttributes(NewFD);
if (OverloadableAttrRequired && !NewFD->getAttr<OverloadableAttr>()) { if (OverloadableAttrRequired && !NewFD->getAttr<OverloadableAttr>(Context)) {
// If a function name is overloadable in C, then every function // If a function name is overloadable in C, then every function
// with that name must be marked "overloadable". // with that name must be marked "overloadable".
Diag(NewFD->getLocation(), diag::err_attribute_overloadable_missing) Diag(NewFD->getLocation(), diag::err_attribute_overloadable_missing)
@ -2330,7 +2333,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
if (PrevDecl) if (PrevDecl)
Diag(PrevDecl->getLocation(), Diag(PrevDecl->getLocation(),
diag::note_attribute_overloadable_prev_overload); diag::note_attribute_overloadable_prev_overload);
NewFD->addAttr(::new (Context) OverloadableAttr()); NewFD->addAttr(Context, ::new (Context) OverloadableAttr());
} }
// If this is a locally-scoped extern C function, update the // If this is a locally-scoped extern C function, update the
@ -2930,7 +2933,7 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
ProcessDeclAttributes(S, New, D); ProcessDeclAttributes(S, New, D);
if (New->hasAttr<BlocksAttr>()) { if (New->hasAttr<BlocksAttr>(Context)) {
Diag(New->getLocation(), diag::err_block_on_nonlocal); Diag(New->getLocation(), diag::err_block_on_nonlocal);
} }
return DeclPtrTy::make(New); return DeclPtrTy::make(New);
@ -3056,9 +3059,10 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) {
// Checking attributes of current function definition // Checking attributes of current function definition
// dllimport attribute. // dllimport attribute.
if (FD->getAttr<DLLImportAttr>() && (!FD->getAttr<DLLExportAttr>())) { if (FD->getAttr<DLLImportAttr>(Context) &&
(!FD->getAttr<DLLExportAttr>(Context))) {
// dllimport attribute cannot be applied to definition. // dllimport attribute cannot be applied to definition.
if (!(FD->getAttr<DLLImportAttr>())->isInherited()) { if (!(FD->getAttr<DLLImportAttr>(Context))->isInherited()) {
Diag(FD->getLocation(), Diag(FD->getLocation(),
diag::err_attribute_can_be_applied_only_to_symbol_declaration) diag::err_attribute_can_be_applied_only_to_symbol_declaration)
<< "dllimport"; << "dllimport";
@ -3227,8 +3231,9 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
unsigned FormatIdx; unsigned FormatIdx;
bool HasVAListArg; bool HasVAListArg;
if (Context.BuiltinInfo.isPrintfLike(BuiltinID, FormatIdx, HasVAListArg)) { if (Context.BuiltinInfo.isPrintfLike(BuiltinID, FormatIdx, HasVAListArg)) {
if (!FD->getAttr<FormatAttr>()) if (!FD->getAttr<FormatAttr>(Context))
FD->addAttr(::new (Context) FormatAttr("printf", FormatIdx + 1, FD->addAttr(Context,
::new (Context) FormatAttr("printf", FormatIdx + 1,
HasVAListArg ? 0 : FormatIdx + 2)); HasVAListArg ? 0 : FormatIdx + 2));
} }
@ -3237,8 +3242,8 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
// IRgen to use LLVM intrinsics for such functions. // IRgen to use LLVM intrinsics for such functions.
if (!getLangOptions().MathErrno && if (!getLangOptions().MathErrno &&
Context.BuiltinInfo.isConstWithoutErrno(BuiltinID)) { Context.BuiltinInfo.isConstWithoutErrno(BuiltinID)) {
if (!FD->getAttr<ConstAttr>()) if (!FD->getAttr<ConstAttr>(Context))
FD->addAttr(::new (Context) ConstAttr()); FD->addAttr(Context, ::new (Context) ConstAttr());
} }
} }
@ -3256,15 +3261,17 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
return; return;
if (Name->isStr("NSLog") || Name->isStr("NSLogv")) { if (Name->isStr("NSLog") || Name->isStr("NSLogv")) {
if (const FormatAttr *Format = FD->getAttr<FormatAttr>()) { if (const FormatAttr *Format = FD->getAttr<FormatAttr>(Context)) {
// FIXME: We known better than our headers. // FIXME: We known better than our headers.
const_cast<FormatAttr *>(Format)->setType("printf"); const_cast<FormatAttr *>(Format)->setType("printf");
} else } else
FD->addAttr(::new (Context) FormatAttr("printf", 1, FD->addAttr(Context,
::new (Context) FormatAttr("printf", 1,
Name->isStr("NSLogv") ? 0 : 2)); Name->isStr("NSLogv") ? 0 : 2));
} else if (Name->isStr("asprintf") || Name->isStr("vasprintf")) { } else if (Name->isStr("asprintf") || Name->isStr("vasprintf")) {
if (!FD->getAttr<FormatAttr>()) if (!FD->getAttr<FormatAttr>(Context))
FD->addAttr(::new (Context) FormatAttr("printf", 2, FD->addAttr(Context,
::new (Context) FormatAttr("printf", 2,
Name->isStr("vasprintf") ? 0 : 3)); Name->isStr("vasprintf") ? 0 : 3));
} }
} }
@ -3620,7 +3627,7 @@ CreateNewDecl:
// the #pragma tokens are effectively skipped over during the // the #pragma tokens are effectively skipped over during the
// parsing of the struct). // parsing of the struct).
if (unsigned Alignment = getPragmaPackAlignment()) if (unsigned Alignment = getPragmaPackAlignment())
New->addAttr(::new (Context) PackedAttr(Alignment * 8)); New->addAttr(Context, ::new (Context) PackedAttr(Alignment * 8));
} }
if (getLangOptions().CPlusPlus && SS.isEmpty() && Name && !Invalid) { if (getLangOptions().CPlusPlus && SS.isEmpty() && Name && !Invalid) {
@ -4471,7 +4478,7 @@ void Sema::ActOnPragmaWeakID(IdentifierInfo* Name,
// FIXME: This implementation is an ugly hack! // FIXME: This implementation is an ugly hack!
if (PrevDecl) { if (PrevDecl) {
PrevDecl->addAttr(::new (Context) WeakAttr()); PrevDecl->addAttr(Context, ::new (Context) WeakAttr());
return; return;
} }
Diag(PragmaLoc, diag::err_unsupported_pragma_weak); Diag(PragmaLoc, diag::err_unsupported_pragma_weak);
@ -4487,8 +4494,8 @@ void Sema::ActOnPragmaWeakAlias(IdentifierInfo* Name,
// FIXME: This implementation is an ugly hack! // FIXME: This implementation is an ugly hack!
if (PrevDecl) { if (PrevDecl) {
PrevDecl->addAttr(::new (Context) AliasAttr(AliasName->getName())); PrevDecl->addAttr(Context, ::new (Context) AliasAttr(AliasName->getName()));
PrevDecl->addAttr(::new (Context) WeakAttr()); PrevDecl->addAttr(Context, ::new (Context) WeakAttr());
return; return;
} }
Diag(PragmaLoc, diag::err_unsupported_pragma_weak); Diag(PragmaLoc, diag::err_unsupported_pragma_weak);

View File

@ -284,7 +284,7 @@ static void HandlePackedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
} }
if (TagDecl *TD = dyn_cast<TagDecl>(d)) if (TagDecl *TD = dyn_cast<TagDecl>(d))
TD->addAttr(::new (S.Context) PackedAttr(1)); TD->addAttr(S.Context, ::new (S.Context) PackedAttr(1));
else if (FieldDecl *FD = dyn_cast<FieldDecl>(d)) { else if (FieldDecl *FD = dyn_cast<FieldDecl>(d)) {
// If the alignment is less than or equal to 8 bits, the packed attribute // If the alignment is less than or equal to 8 bits, the packed attribute
// has no effect. // has no effect.
@ -293,7 +293,7 @@ static void HandlePackedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored_for_field_of_type) S.Diag(Attr.getLoc(), diag::warn_attribute_ignored_for_field_of_type)
<< Attr.getName() << FD->getType(); << Attr.getName() << FD->getType();
else else
FD->addAttr(::new (S.Context) PackedAttr(1)); FD->addAttr(S.Context, ::new (S.Context) PackedAttr(1));
} else } else
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName(); S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
} }
@ -308,7 +308,7 @@ static void HandleIBOutletAttr(Decl *d, const AttributeList &Attr, Sema &S) {
// The IBOutlet attribute only applies to instance variables of Objective-C // The IBOutlet attribute only applies to instance variables of Objective-C
// classes. // classes.
if (isa<ObjCIvarDecl>(d) || isa<ObjCPropertyDecl>(d)) if (isa<ObjCIvarDecl>(d) || isa<ObjCPropertyDecl>(d))
d->addAttr(::new (S.Context) IBOutletAttr()); d->addAttr(S.Context, ::new (S.Context) IBOutletAttr());
else else
S.Diag(Attr.getLoc(), diag::err_attribute_iboutlet); S.Diag(Attr.getLoc(), diag::err_attribute_iboutlet);
} }
@ -380,7 +380,7 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
unsigned* start = &NonNullArgs[0]; unsigned* start = &NonNullArgs[0];
unsigned size = NonNullArgs.size(); unsigned size = NonNullArgs.size();
std::sort(start, start + size); std::sort(start, start + size);
d->addAttr(::new (S.Context) NonNullAttr(start, size)); d->addAttr(S.Context, ::new (S.Context) NonNullAttr(start, size));
} }
static void HandleAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -405,7 +405,7 @@ static void HandleAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) {
// FIXME: check if target symbol exists in current file // FIXME: check if target symbol exists in current file
d->addAttr(::new (S.Context) AliasAttr(std::string(Alias, AliasLen))); d->addAttr(S.Context, ::new (S.Context) AliasAttr(std::string(Alias, AliasLen)));
} }
static void HandleAlwaysInlineAttr(Decl *d, const AttributeList &Attr, static void HandleAlwaysInlineAttr(Decl *d, const AttributeList &Attr,
@ -422,7 +422,7 @@ static void HandleAlwaysInlineAttr(Decl *d, const AttributeList &Attr,
return; return;
} }
d->addAttr(::new (S.Context) AlwaysInlineAttr()); d->addAttr(S.Context, ::new (S.Context) AlwaysInlineAttr());
} }
static bool HandleCommonNoReturnAttr(Decl *d, const AttributeList &Attr, static bool HandleCommonNoReturnAttr(Decl *d, const AttributeList &Attr,
@ -447,13 +447,13 @@ static bool HandleCommonNoReturnAttr(Decl *d, const AttributeList &Attr,
static void HandleNoReturnAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleNoReturnAttr(Decl *d, const AttributeList &Attr, Sema &S) {
if (HandleCommonNoReturnAttr(d, Attr, S)) if (HandleCommonNoReturnAttr(d, Attr, S))
d->addAttr(::new (S.Context) NoReturnAttr()); d->addAttr(S.Context, ::new (S.Context) NoReturnAttr());
} }
static void HandleAnalyzerNoReturnAttr(Decl *d, const AttributeList &Attr, static void HandleAnalyzerNoReturnAttr(Decl *d, const AttributeList &Attr,
Sema &S) { Sema &S) {
if (HandleCommonNoReturnAttr(d, Attr, S)) if (HandleCommonNoReturnAttr(d, Attr, S))
d->addAttr(::new (S.Context) AnalyzerNoReturnAttr()); d->addAttr(S.Context, ::new (S.Context) AnalyzerNoReturnAttr());
} }
static void HandleUnusedAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleUnusedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -469,7 +469,7 @@ static void HandleUnusedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) UnusedAttr()); d->addAttr(S.Context, ::new (S.Context) UnusedAttr());
} }
static void HandleUsedAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleUsedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -490,7 +490,7 @@ static void HandleUsedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) UsedAttr()); d->addAttr(S.Context, ::new (S.Context) UsedAttr());
} }
static void HandleConstructorAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleConstructorAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -519,7 +519,7 @@ static void HandleConstructorAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) ConstructorAttr(priority)); d->addAttr(S.Context, ::new (S.Context) ConstructorAttr(priority));
} }
static void HandleDestructorAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleDestructorAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -548,7 +548,7 @@ static void HandleDestructorAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) DestructorAttr(priority)); d->addAttr(S.Context, ::new (S.Context) DestructorAttr(priority));
} }
static void HandleDeprecatedAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleDeprecatedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -558,7 +558,7 @@ static void HandleDeprecatedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) DeprecatedAttr()); d->addAttr(S.Context, ::new (S.Context) DeprecatedAttr());
} }
static void HandleUnavailableAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleUnavailableAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -568,7 +568,7 @@ static void HandleUnavailableAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) UnavailableAttr()); d->addAttr(S.Context, ::new (S.Context) UnavailableAttr());
} }
static void HandleVisibilityAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleVisibilityAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -605,7 +605,7 @@ static void HandleVisibilityAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) VisibilityAttr(type)); d->addAttr(S.Context, ::new (S.Context) VisibilityAttr(type));
} }
static void HandleObjCExceptionAttr(Decl *D, const AttributeList &Attr, static void HandleObjCExceptionAttr(Decl *D, const AttributeList &Attr,
@ -621,7 +621,7 @@ static void HandleObjCExceptionAttr(Decl *D, const AttributeList &Attr,
return; return;
} }
D->addAttr(::new (S.Context) ObjCExceptionAttr()); D->addAttr(S.Context, ::new (S.Context) ObjCExceptionAttr());
} }
static void HandleObjCNSObject(Decl *D, const AttributeList &Attr, Sema &S) { static void HandleObjCNSObject(Decl *D, const AttributeList &Attr, Sema &S) {
@ -637,7 +637,7 @@ static void HandleObjCNSObject(Decl *D, const AttributeList &Attr, Sema &S) {
return; return;
} }
} }
D->addAttr(::new (S.Context) ObjCNSObjectAttr()); D->addAttr(S.Context, ::new (S.Context) ObjCNSObjectAttr());
} }
static void static void
@ -652,7 +652,7 @@ HandleOverloadableAttr(Decl *D, const AttributeList &Attr, Sema &S) {
return; return;
} }
D->addAttr(::new (S.Context) OverloadableAttr()); D->addAttr(S.Context, ::new (S.Context) OverloadableAttr());
} }
static void HandleBlocksAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleBlocksAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -676,7 +676,7 @@ static void HandleBlocksAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) BlocksAttr(type)); d->addAttr(S.Context, ::new (S.Context) BlocksAttr(type));
} }
static void HandleSentinelAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleSentinelAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -768,7 +768,7 @@ static void HandleSentinelAttr(Decl *d, const AttributeList &Attr, Sema &S) {
<< Attr.getName() << 6 /*function, method or block */; << Attr.getName() << 6 /*function, method or block */;
return; return;
} }
d->addAttr(::new (S.Context) SentinelAttr(sentinel, nullPos)); d->addAttr(S.Context, ::new (S.Context) SentinelAttr(sentinel, nullPos));
} }
static void HandleWarnUnusedResult(Decl *D, const AttributeList &Attr, Sema &S) { static void HandleWarnUnusedResult(Decl *D, const AttributeList &Attr, Sema &S) {
@ -786,7 +786,7 @@ static void HandleWarnUnusedResult(Decl *D, const AttributeList &Attr, Sema &S)
return; return;
} }
Fn->addAttr(::new (S.Context) WarnUnusedResultAttr()); Fn->addAttr(S.Context, ::new (S.Context) WarnUnusedResultAttr());
} }
static void HandleWeakAttr(Decl *D, const AttributeList &Attr, Sema &S) { static void HandleWeakAttr(Decl *D, const AttributeList &Attr, Sema &S) {
@ -803,7 +803,7 @@ static void HandleWeakAttr(Decl *D, const AttributeList &Attr, Sema &S) {
return; return;
} }
D->addAttr(::new (S.Context) WeakAttr()); D->addAttr(S.Context, ::new (S.Context) WeakAttr());
} }
static void HandleWeakImportAttr(Decl *D, const AttributeList &Attr, Sema &S) { static void HandleWeakImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
@ -836,7 +836,7 @@ static void HandleWeakImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
return; return;
} }
D->addAttr(::new (S.Context) WeakImportAttr()); D->addAttr(S.Context, ::new (S.Context) WeakImportAttr());
} }
static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) { static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
@ -848,7 +848,7 @@ static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
// Attribute can be applied only to functions or variables. // Attribute can be applied only to functions or variables.
if (isa<VarDecl>(D)) { if (isa<VarDecl>(D)) {
D->addAttr(::new (S.Context) DLLImportAttr()); D->addAttr(S.Context, ::new (S.Context) DLLImportAttr());
return; return;
} }
@ -876,12 +876,12 @@ static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
} }
} }
if (D->getAttr<DLLExportAttr>()) { if (D->getAttr<DLLExportAttr>(S.Context)) {
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllimport"; S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllimport";
return; return;
} }
D->addAttr(::new (S.Context) DLLImportAttr()); D->addAttr(S.Context, ::new (S.Context) DLLImportAttr());
} }
static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) { static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
@ -893,7 +893,7 @@ static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
// Attribute can be applied only to functions or variables. // Attribute can be applied only to functions or variables.
if (isa<VarDecl>(D)) { if (isa<VarDecl>(D)) {
D->addAttr(::new (S.Context) DLLExportAttr()); D->addAttr(S.Context, ::new (S.Context) DLLExportAttr());
return; return;
} }
@ -912,7 +912,7 @@ static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
return; return;
} }
D->addAttr(::new (S.Context) DLLExportAttr()); D->addAttr(S.Context, ::new (S.Context) DLLExportAttr());
} }
static void HandleSectionAttr(Decl *D, const AttributeList &Attr, Sema &S) { static void HandleSectionAttr(Decl *D, const AttributeList &Attr, Sema &S) {
@ -931,7 +931,8 @@ static void HandleSectionAttr(Decl *D, const AttributeList &Attr, Sema &S) {
S.Diag(Attr.getLoc(), diag::err_attribute_annotate_no_string); S.Diag(Attr.getLoc(), diag::err_attribute_annotate_no_string);
return; return;
} }
D->addAttr(::new (S.Context) SectionAttr(std::string(SE->getStrData(), D->addAttr(S.Context,
::new (S.Context) SectionAttr(std::string(SE->getStrData(),
SE->getByteLength()))); SE->getByteLength())));
} }
@ -950,13 +951,13 @@ static void HandleStdCallAttr(Decl *d, const AttributeList &Attr, Sema &S) {
} }
// stdcall and fastcall attributes are mutually incompatible. // stdcall and fastcall attributes are mutually incompatible.
if (d->getAttr<FastCallAttr>()) { if (d->getAttr<FastCallAttr>(S.Context)) {
S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible) S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
<< "stdcall" << "fastcall"; << "stdcall" << "fastcall";
return; return;
} }
d->addAttr(::new (S.Context) StdCallAttr()); d->addAttr(S.Context, ::new (S.Context) StdCallAttr());
} }
static void HandleFastCallAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleFastCallAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -973,13 +974,13 @@ static void HandleFastCallAttr(Decl *d, const AttributeList &Attr, Sema &S) {
} }
// stdcall and fastcall attributes are mutually incompatible. // stdcall and fastcall attributes are mutually incompatible.
if (d->getAttr<StdCallAttr>()) { if (d->getAttr<StdCallAttr>(S.Context)) {
S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible) S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
<< "fastcall" << "stdcall"; << "fastcall" << "stdcall";
return; return;
} }
d->addAttr(::new (S.Context) FastCallAttr()); d->addAttr(S.Context, ::new (S.Context) FastCallAttr());
} }
static void HandleNothrowAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleNothrowAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -989,7 +990,7 @@ static void HandleNothrowAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) NoThrowAttr()); d->addAttr(S.Context, ::new (S.Context) NoThrowAttr());
} }
static void HandleConstAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleConstAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -999,7 +1000,7 @@ static void HandleConstAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) ConstAttr()); d->addAttr(S.Context, ::new (S.Context) ConstAttr());
} }
static void HandlePureAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandlePureAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -1009,7 +1010,7 @@ static void HandlePureAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) PureAttr()); d->addAttr(S.Context, ::new (S.Context) PureAttr());
} }
static void HandleCleanupAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleCleanupAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -1067,7 +1068,7 @@ static void HandleCleanupAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) CleanupAttr(FD)); d->addAttr(S.Context, ::new (S.Context) CleanupAttr(FD));
} }
/// Handle __attribute__((format_arg((idx)))) attribute /// Handle __attribute__((format_arg((idx)))) attribute
@ -1130,7 +1131,7 @@ static void HandleFormatArgAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) FormatArgAttr(Idx.getZExtValue())); d->addAttr(S.Context, ::new (S.Context) FormatArgAttr(Idx.getZExtValue()));
} }
/// Handle __attribute__((format(type,idx,firstarg))) attributes /// Handle __attribute__((format(type,idx,firstarg))) attributes
@ -1271,7 +1272,8 @@ static void HandleFormatAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) FormatAttr(std::string(Format, FormatLen), d->addAttr(S.Context,
::new (S.Context) FormatAttr(std::string(Format, FormatLen),
Idx.getZExtValue(), FirstArg.getZExtValue())); Idx.getZExtValue(), FirstArg.getZExtValue()));
} }
@ -1339,7 +1341,7 @@ static void HandleTransparentUnionAttr(Decl *d, const AttributeList &Attr,
} }
} }
RD->addAttr(::new (S.Context) TransparentUnionAttr()); RD->addAttr(S.Context, ::new (S.Context) TransparentUnionAttr());
} }
static void HandleAnnotateAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleAnnotateAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -1357,7 +1359,8 @@ static void HandleAnnotateAttr(Decl *d, const AttributeList &Attr, Sema &S) {
S.Diag(Attr.getLoc(), diag::err_attribute_annotate_no_string); S.Diag(Attr.getLoc(), diag::err_attribute_annotate_no_string);
return; return;
} }
d->addAttr(::new (S.Context) AnnotateAttr(std::string(SE->getStrData(), d->addAttr(S.Context,
::new (S.Context) AnnotateAttr(std::string(SE->getStrData(),
SE->getByteLength()))); SE->getByteLength())));
} }
@ -1373,7 +1376,7 @@ static void HandleAlignedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
// FIXME: This should be the target specific maximum alignment. // FIXME: This should be the target specific maximum alignment.
// (For now we just use 128 bits which is the maximum on X86). // (For now we just use 128 bits which is the maximum on X86).
Align = 128; Align = 128;
d->addAttr(::new (S.Context) AlignedAttr(Align)); d->addAttr(S.Context, ::new (S.Context) AlignedAttr(Align));
return; return;
} }
@ -1390,7 +1393,7 @@ static void HandleAlignedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) AlignedAttr(Alignment.getZExtValue() * 8)); d->addAttr(S.Context, ::new (S.Context) AlignedAttr(Alignment.getZExtValue() * 8));
} }
/// HandleModeAttr - This attribute modifies the width of a decl with /// HandleModeAttr - This attribute modifies the width of a decl with
@ -1571,7 +1574,7 @@ static void HandleNodebugAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) NodebugAttr()); d->addAttr(S.Context, ::new (S.Context) NodebugAttr());
} }
static void HandleNoinlineAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleNoinlineAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -1587,7 +1590,7 @@ static void HandleNoinlineAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) NoinlineAttr()); d->addAttr(S.Context, ::new (S.Context) NoinlineAttr());
} }
static void HandleGNUInlineAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleGNUInlineAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -1609,7 +1612,7 @@ static void HandleGNUInlineAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) GNUInlineAttr()); d->addAttr(S.Context, ::new (S.Context) GNUInlineAttr());
} }
static void HandleRegparmAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleRegparmAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@ -1645,7 +1648,8 @@ static void HandleRegparmAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return; return;
} }
d->addAttr(::new (S.Context) RegparmAttr(NumParams.getZExtValue())); d->addAttr(S.Context,
::new (S.Context) RegparmAttr(NumParams.getZExtValue()));
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -1678,10 +1682,10 @@ static void HandleNSReturnsRetainedAttr(Decl *d, const AttributeList &Attr,
assert(0 && "invalid ownership attribute"); assert(0 && "invalid ownership attribute");
return; return;
case AttributeList::AT_cf_returns_retained: case AttributeList::AT_cf_returns_retained:
d->addAttr(::new (S.Context) CFReturnsRetainedAttr()); d->addAttr(S.Context, ::new (S.Context) CFReturnsRetainedAttr());
return; return;
case AttributeList::AT_ns_returns_retained: case AttributeList::AT_ns_returns_retained:
d->addAttr(::new (S.Context) NSReturnsRetainedAttr()); d->addAttr(S.Context, ::new (S.Context) NSReturnsRetainedAttr());
return; return;
}; };
} }

View File

@ -39,7 +39,7 @@ using namespace clang;
/// referenced), false otherwise. /// referenced), false otherwise.
bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) { bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
// See if the decl is deprecated. // See if the decl is deprecated.
if (D->getAttr<DeprecatedAttr>()) { if (D->getAttr<DeprecatedAttr>(Context)) {
// Implementing deprecated stuff requires referencing deprecated // Implementing deprecated stuff requires referencing deprecated
// stuff. Don't warn if we are implementing a deprecated // stuff. Don't warn if we are implementing a deprecated
// construct. // construct.
@ -48,7 +48,7 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
if (NamedDecl *ND = getCurFunctionOrMethodDecl()) { if (NamedDecl *ND = getCurFunctionOrMethodDecl()) {
// If this reference happens *in* a deprecated function or method, don't // If this reference happens *in* a deprecated function or method, don't
// warn. // warn.
isSilenced = ND->getAttr<DeprecatedAttr>(); isSilenced = ND->getAttr<DeprecatedAttr>(Context);
// If this is an Objective-C method implementation, check to see if the // If this is an Objective-C method implementation, check to see if the
// method was deprecated on the declaration, not the definition. // method was deprecated on the declaration, not the definition.
@ -61,7 +61,7 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
MD = Impl->getClassInterface()->getMethod(Context, MD = Impl->getClassInterface()->getMethod(Context,
MD->getSelector(), MD->getSelector(),
MD->isInstanceMethod()); MD->isInstanceMethod());
isSilenced |= MD && MD->getAttr<DeprecatedAttr>(); isSilenced |= MD && MD->getAttr<DeprecatedAttr>(Context);
} }
} }
} }
@ -80,7 +80,7 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
} }
// See if the decl is unavailable // See if the decl is unavailable
if (D->getAttr<UnavailableAttr>()) { if (D->getAttr<UnavailableAttr>(Context)) {
Diag(Loc, diag::warn_unavailable) << D->getDeclName(); Diag(Loc, diag::warn_unavailable) << D->getDeclName();
Diag(D->getLocation(), diag::note_unavailable_here) << 0; Diag(D->getLocation(), diag::note_unavailable_here) << 0;
} }
@ -95,7 +95,7 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
Expr **Args, unsigned NumArgs) Expr **Args, unsigned NumArgs)
{ {
const SentinelAttr *attr = D->getAttr<SentinelAttr>(); const SentinelAttr *attr = D->getAttr<SentinelAttr>(Context);
if (!attr) if (!attr)
return; return;
int sentinelPos = attr->getSentinel(); int sentinelPos = attr->getSentinel();
@ -1127,7 +1127,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
if (CurBlock && ShouldSnapshotBlockValueReference(CurBlock, VD)) { if (CurBlock && ShouldSnapshotBlockValueReference(CurBlock, VD)) {
QualType ExprTy = VD->getType().getNonReferenceType(); QualType ExprTy = VD->getType().getNonReferenceType();
// The BlocksAttr indicates the variable is bound by-reference. // The BlocksAttr indicates the variable is bound by-reference.
if (VD->getAttr<BlocksAttr>()) if (VD->getAttr<BlocksAttr>(Context))
return Owned(new (Context) BlockDeclRefExpr(VD, ExprTy, Loc, true)); return Owned(new (Context) BlockDeclRefExpr(VD, ExprTy, Loc, true));
// Variable will be bound by-copy, make it const within the closure. // Variable will be bound by-copy, make it const within the closure.
@ -3408,7 +3408,7 @@ Sema::CheckTransparentUnionArgumentConstraints(QualType ArgType, Expr *&rExpr) {
// If the ArgType is a Union type, we want to handle a potential // If the ArgType is a Union type, we want to handle a potential
// transparent_union GCC extension. // transparent_union GCC extension.
const RecordType *UT = ArgType->getAsUnionType(); const RecordType *UT = ArgType->getAsUnionType();
if (!UT || !UT->getDecl()->hasAttr<TransparentUnionAttr>()) if (!UT || !UT->getDecl()->hasAttr<TransparentUnionAttr>(Context))
return Incompatible; return Incompatible;
// The field to initialize within the transparent union. // The field to initialize within the transparent union.
@ -5142,7 +5142,7 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) {
CurBlock->hasPrototype = true; CurBlock->hasPrototype = true;
CurBlock->isVariadic = false; CurBlock->isVariadic = false;
// Check for a valid sentinel attribute on this block. // Check for a valid sentinel attribute on this block.
if (CurBlock->TheDecl->getAttr<SentinelAttr>()) { if (CurBlock->TheDecl->getAttr<SentinelAttr>(Context)) {
Diag(ParamInfo.getAttributes()->getLoc(), Diag(ParamInfo.getAttributes()->getLoc(),
diag::warn_attribute_sentinel_not_variadic) << 1; diag::warn_attribute_sentinel_not_variadic) << 1;
// FIXME: remove the attribute. // FIXME: remove the attribute.
@ -5190,7 +5190,8 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) {
PushOnScopeChains(*AI, CurBlock->TheScope); PushOnScopeChains(*AI, CurBlock->TheScope);
// Check for a valid sentinel attribute on this block. // Check for a valid sentinel attribute on this block.
if (!CurBlock->isVariadic && CurBlock->TheDecl->getAttr<SentinelAttr>()) { if (!CurBlock->isVariadic &&
CurBlock->TheDecl->getAttr<SentinelAttr>(Context)) {
Diag(ParamInfo.getAttributes()->getLoc(), Diag(ParamInfo.getAttributes()->getLoc(),
diag::warn_attribute_sentinel_not_variadic) << 1; diag::warn_attribute_sentinel_not_variadic) << 1;
// FIXME: remove the attribute. // FIXME: remove the attribute.

View File

@ -894,7 +894,7 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind,
continue; continue;
} }
if ((*I)->getAttr<OverloadableAttr>()) { if ((*I)->getAttr<OverloadableAttr>(Context)) {
// If this declaration has the "overloadable" attribute, we // If this declaration has the "overloadable" attribute, we
// might have a set of overloaded functions. // might have a set of overloaded functions.

View File

@ -3484,7 +3484,7 @@ Sema::BestViableFunction(OverloadCandidateSet& CandidateSet,
// Best is the best viable function. // Best is the best viable function.
if (Best->Function && if (Best->Function &&
(Best->Function->isDeleted() || (Best->Function->isDeleted() ||
Best->Function->getAttr<UnavailableAttr>())) Best->Function->getAttr<UnavailableAttr>(Context)))
return OR_Deleted; return OR_Deleted;
// If Best refers to a function that is either deleted (C++0x) or // If Best refers to a function that is either deleted (C++0x) or
@ -3506,7 +3506,7 @@ Sema::PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
if (Cand->Viable || !OnlyViable) { if (Cand->Viable || !OnlyViable) {
if (Cand->Function) { if (Cand->Function) {
if (Cand->Function->isDeleted() || if (Cand->Function->isDeleted() ||
Cand->Function->getAttr<UnavailableAttr>()) { Cand->Function->getAttr<UnavailableAttr>(Context)) {
// Deleted or "unavailable" function. // Deleted or "unavailable" function.
Diag(Cand->Function->getLocation(), diag::err_ovl_candidate_deleted) Diag(Cand->Function->getLocation(), diag::err_ovl_candidate_deleted)
<< Cand->Function->isDeleted(); << Cand->Function->isDeleted();

View File

@ -84,7 +84,7 @@ Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R,
SourceLocation Loc; SourceLocation Loc;
SourceRange R1, R2; SourceRange R1, R2;
if (!E->isUnusedResultAWarning(Loc, R1, R2)) if (!E->isUnusedResultAWarning(Loc, R1, R2, Context))
continue; continue;
Diag(Loc, diag::warn_unused_expr) << R1 << R2; Diag(Loc, diag::warn_unused_expr) << R1 << R2;
@ -759,7 +759,7 @@ Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
} }
QualType FnRetType = QualType(CurBlock->ReturnType, 0); QualType FnRetType = QualType(CurBlock->ReturnType, 0);
if (CurBlock->TheDecl->hasAttr<NoReturnAttr>()) { if (CurBlock->TheDecl->hasAttr<NoReturnAttr>(Context)) {
Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr) Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr)
<< getCurFunctionOrMethodDecl()->getDeclName(); << getCurFunctionOrMethodDecl()->getDeclName();
return StmtError(); return StmtError();
@ -835,7 +835,7 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, FullExprArg rex) {
QualType FnRetType; QualType FnRetType;
if (const FunctionDecl *FD = getCurFunctionDecl()) { if (const FunctionDecl *FD = getCurFunctionDecl()) {
FnRetType = FD->getResultType(); FnRetType = FD->getResultType();
if (FD->hasAttr<NoReturnAttr>()) if (FD->hasAttr<NoReturnAttr>(Context))
Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr) Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
<< getCurFunctionOrMethodDecl()->getDeclName(); << getCurFunctionOrMethodDecl()->getDeclName();
} else if (ObjCMethodDecl *MD = getCurMethodDecl()) } else if (ObjCMethodDecl *MD = getCurMethodDecl())