2008-06-27 02:38:35 +08:00
|
|
|
//===--- SemaDeclAttr.cpp - Declaration Attribute Handling ----------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements decl-related attribute processing.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-08-26 06:03:47 +08:00
|
|
|
#include "clang/Sema/SemaInternal.h"
|
2010-01-10 20:58:08 +08:00
|
|
|
#include "TargetAttributesSema.h"
|
2008-06-27 02:38:35 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2012-05-05 00:28:38 +08:00
|
|
|
#include "clang/AST/CXXInheritance.h"
|
2010-08-25 15:42:41 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2008-08-11 14:23:49 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2008-08-11 14:23:49 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2013-02-27 03:13:56 +08:00
|
|
|
#include "clang/AST/Mangle.h"
|
2013-02-09 06:30:41 +08:00
|
|
|
#include "clang/Basic/CharInfo.h"
|
2011-06-16 07:02:42 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2008-06-28 06:18:37 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2013-09-13 23:35:43 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2010-08-21 02:27:03 +08:00
|
|
|
#include "clang/Sema/DeclSpec.h"
|
2010-08-26 10:13:20 +08:00
|
|
|
#include "clang/Sema/DelayedDiagnostic.h"
|
2011-09-29 15:17:38 +08:00
|
|
|
#include "clang/Sema/Lookup.h"
|
2013-01-29 06:42:45 +08:00
|
|
|
#include "clang/Sema/Scope.h"
|
2009-08-11 03:03:04 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2008-06-27 02:38:35 +08:00
|
|
|
using namespace clang;
|
2010-08-26 10:13:20 +08:00
|
|
|
using namespace sema;
|
2008-06-27 02:38:35 +08:00
|
|
|
|
2013-11-25 05:35:16 +08:00
|
|
|
namespace AttributeLangSupport {
|
2013-11-25 08:52:29 +08:00
|
|
|
enum LANG {
|
2013-11-25 05:35:16 +08:00
|
|
|
C,
|
|
|
|
Cpp,
|
|
|
|
ObjC
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2008-06-29 08:16:31 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Helper functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
static const FunctionType *getFunctionType(const Decl *D,
|
2009-08-15 04:49:40 +08:00
|
|
|
bool blocksToo = true) {
|
2008-06-27 02:38:35 +08:00
|
|
|
QualType Ty;
|
2011-07-02 07:49:12 +08:00
|
|
|
if (const ValueDecl *decl = dyn_cast<ValueDecl>(D))
|
2008-06-27 02:38:35 +08:00
|
|
|
Ty = decl->getType();
|
2011-07-02 07:49:12 +08:00
|
|
|
else if (const TypedefNameDecl* decl = dyn_cast<TypedefNameDecl>(D))
|
2008-06-27 02:38:35 +08:00
|
|
|
Ty = decl->getUnderlyingType();
|
|
|
|
else
|
|
|
|
return 0;
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2008-06-27 02:38:35 +08:00
|
|
|
if (Ty->isFunctionPointerType())
|
2009-07-30 05:53:49 +08:00
|
|
|
Ty = Ty->getAs<PointerType>()->getPointeeType();
|
2009-05-19 01:39:25 +08:00
|
|
|
else if (blocksToo && Ty->isBlockPointerType())
|
2009-07-30 05:53:49 +08:00
|
|
|
Ty = Ty->getAs<BlockPointerType>()->getPointeeType();
|
2008-10-19 10:04:16 +08:00
|
|
|
|
2009-09-22 07:43:11 +08:00
|
|
|
return Ty->getAs<FunctionType>();
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
|
|
|
|
2008-09-26 12:12:28 +08:00
|
|
|
// FIXME: We should provide an abstraction around a method or function
|
|
|
|
// to provide the following bits of information.
|
|
|
|
|
2009-12-21 07:11:08 +08:00
|
|
|
/// isFunction - Return true if the given decl has function
|
2009-08-15 04:49:40 +08:00
|
|
|
/// type (function or function-typed variable).
|
2011-07-02 07:49:12 +08:00
|
|
|
static bool isFunction(const Decl *D) {
|
|
|
|
return getFunctionType(D, false) != NULL;
|
2009-08-15 04:49:40 +08:00
|
|
|
}
|
|
|
|
|
2008-10-19 10:04:16 +08:00
|
|
|
/// isFunctionOrMethod - Return true if the given decl has function
|
|
|
|
/// type (function or function-typed variable) or an Objective-C
|
|
|
|
/// method.
|
2011-07-02 07:49:12 +08:00
|
|
|
static bool isFunctionOrMethod(const Decl *D) {
|
2012-07-24 09:31:55 +08:00
|
|
|
return isFunction(D) || isa<ObjCMethodDecl>(D);
|
2008-10-19 10:04:16 +08:00
|
|
|
}
|
2008-09-26 12:12:28 +08:00
|
|
|
|
2009-05-16 07:15:03 +08:00
|
|
|
/// isFunctionOrMethodOrBlock - Return true if the given decl has function
|
|
|
|
/// type (function or function-typed variable) or an Objective-C
|
|
|
|
/// method or a block.
|
2011-07-02 07:49:12 +08:00
|
|
|
static bool isFunctionOrMethodOrBlock(const Decl *D) {
|
|
|
|
if (isFunctionOrMethod(D))
|
2009-05-16 07:15:03 +08:00
|
|
|
return true;
|
|
|
|
// check for block is more involved.
|
2011-07-02 07:49:12 +08:00
|
|
|
if (const VarDecl *V = dyn_cast<VarDecl>(D)) {
|
2009-05-16 07:15:03 +08:00
|
|
|
QualType Ty = V->getType();
|
|
|
|
return Ty->isBlockPointerType();
|
|
|
|
}
|
2011-07-02 07:49:12 +08:00
|
|
|
return isa<BlockDecl>(D);
|
2009-05-16 07:15:03 +08:00
|
|
|
}
|
|
|
|
|
2011-01-05 20:14:39 +08:00
|
|
|
/// Return true if the given decl has a declarator that should have
|
|
|
|
/// been processed by Sema::GetTypeForDeclarator.
|
2011-07-02 07:49:12 +08:00
|
|
|
static bool hasDeclarator(const Decl *D) {
|
2011-06-16 07:02:42 +08:00
|
|
|
// In some sense, TypedefDecl really *ought* to be a DeclaratorDecl.
|
2011-07-02 07:49:12 +08:00
|
|
|
return isa<DeclaratorDecl>(D) || isa<BlockDecl>(D) || isa<TypedefNameDecl>(D) ||
|
|
|
|
isa<ObjCPropertyDecl>(D);
|
2011-01-05 20:14:39 +08:00
|
|
|
}
|
|
|
|
|
2008-10-19 10:04:16 +08:00
|
|
|
/// hasFunctionProto - Return true if the given decl has a argument
|
|
|
|
/// information. This decl should have already passed
|
2009-05-16 07:15:03 +08:00
|
|
|
/// isFunctionOrMethod or isFunctionOrMethodOrBlock.
|
2011-07-02 07:49:12 +08:00
|
|
|
static bool hasFunctionProto(const Decl *D) {
|
|
|
|
if (const FunctionType *FnTy = getFunctionType(D))
|
2009-02-27 07:50:07 +08:00
|
|
|
return isa<FunctionProtoType>(FnTy);
|
2009-05-16 07:15:03 +08:00
|
|
|
else {
|
2011-07-02 07:49:12 +08:00
|
|
|
assert(isa<ObjCMethodDecl>(D) || isa<BlockDecl>(D));
|
2008-10-19 10:04:16 +08:00
|
|
|
return true;
|
|
|
|
}
|
2008-09-26 12:12:28 +08:00
|
|
|
}
|
|
|
|
|
2008-10-19 10:04:16 +08:00
|
|
|
/// getFunctionOrMethodNumArgs - Return number of function or method
|
|
|
|
/// arguments. It is an error to call this on a K&R function (use
|
|
|
|
/// hasFunctionProto first).
|
2011-07-02 07:49:12 +08:00
|
|
|
static unsigned getFunctionOrMethodNumArgs(const Decl *D) {
|
|
|
|
if (const FunctionType *FnTy = getFunctionType(D))
|
2009-02-27 07:50:07 +08:00
|
|
|
return cast<FunctionProtoType>(FnTy)->getNumArgs();
|
2011-07-02 07:49:12 +08:00
|
|
|
if (const BlockDecl *BD = dyn_cast<BlockDecl>(D))
|
2009-05-20 01:08:59 +08:00
|
|
|
return BD->getNumParams();
|
2011-07-02 07:49:12 +08:00
|
|
|
return cast<ObjCMethodDecl>(D)->param_size();
|
2008-09-26 12:12:28 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
static QualType getFunctionOrMethodArgType(const Decl *D, unsigned Idx) {
|
|
|
|
if (const FunctionType *FnTy = getFunctionType(D))
|
2009-02-27 07:50:07 +08:00
|
|
|
return cast<FunctionProtoType>(FnTy)->getArgType(Idx);
|
2011-07-02 07:49:12 +08:00
|
|
|
if (const BlockDecl *BD = dyn_cast<BlockDecl>(D))
|
2009-05-20 01:08:59 +08:00
|
|
|
return BD->getParamDecl(Idx)->getType();
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
return cast<ObjCMethodDecl>(D)->param_begin()[Idx]->getType();
|
2008-09-26 12:12:28 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
static QualType getFunctionOrMethodResultType(const Decl *D) {
|
|
|
|
if (const FunctionType *FnTy = getFunctionType(D))
|
2009-05-21 01:41:43 +08:00
|
|
|
return cast<FunctionProtoType>(FnTy)->getResultType();
|
2011-07-02 07:49:12 +08:00
|
|
|
return cast<ObjCMethodDecl>(D)->getResultType();
|
2009-05-21 01:41:43 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
static bool isFunctionOrMethodVariadic(const Decl *D) {
|
|
|
|
if (const FunctionType *FnTy = getFunctionType(D)) {
|
2009-02-27 07:50:07 +08:00
|
|
|
const FunctionProtoType *proto = cast<FunctionProtoType>(FnTy);
|
2008-09-26 12:12:28 +08:00
|
|
|
return proto->isVariadic();
|
2011-07-02 07:49:12 +08:00
|
|
|
} else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D))
|
2010-04-30 00:48:58 +08:00
|
|
|
return BD->isVariadic();
|
2009-05-20 01:08:59 +08:00
|
|
|
else {
|
2011-07-02 07:49:12 +08:00
|
|
|
return cast<ObjCMethodDecl>(D)->isVariadic();
|
2008-09-26 12:12:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
static bool isInstanceMethod(const Decl *D) {
|
|
|
|
if (const CXXMethodDecl *MethodDecl = dyn_cast<CXXMethodDecl>(D))
|
2010-11-16 16:35:43 +08:00
|
|
|
return MethodDecl->isInstance();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-27 02:38:35 +08:00
|
|
|
static inline bool isNSStringType(QualType T, ASTContext &Ctx) {
|
2009-09-22 07:43:11 +08:00
|
|
|
const ObjCObjectPointerType *PT = T->getAs<ObjCObjectPointerType>();
|
2008-07-27 06:17:49 +08:00
|
|
|
if (!PT)
|
2008-06-27 02:38:35 +08:00
|
|
|
return false;
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2010-05-18 05:00:27 +08:00
|
|
|
ObjCInterfaceDecl *Cls = PT->getObjectType()->getInterface();
|
|
|
|
if (!Cls)
|
2008-06-27 02:38:35 +08:00
|
|
|
return false;
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2010-05-18 05:00:27 +08:00
|
|
|
IdentifierInfo* ClsName = Cls->getIdentifier();
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2008-06-27 02:38:35 +08:00
|
|
|
// FIXME: Should we walk the chain of classes?
|
|
|
|
return ClsName == &Ctx.Idents.get("NSString") ||
|
|
|
|
ClsName == &Ctx.Idents.get("NSMutableString");
|
|
|
|
}
|
|
|
|
|
2008-09-26 11:32:58 +08:00
|
|
|
static inline bool isCFStringType(QualType T, ASTContext &Ctx) {
|
2009-07-30 05:53:49 +08:00
|
|
|
const PointerType *PT = T->getAs<PointerType>();
|
2008-09-26 11:32:58 +08:00
|
|
|
if (!PT)
|
|
|
|
return false;
|
|
|
|
|
2009-07-30 05:53:49 +08:00
|
|
|
const RecordType *RT = PT->getPointeeType()->getAs<RecordType>();
|
2008-09-26 11:32:58 +08:00
|
|
|
if (!RT)
|
|
|
|
return false;
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2008-09-26 11:32:58 +08:00
|
|
|
const RecordDecl *RD = RT->getDecl();
|
2010-05-12 05:36:43 +08:00
|
|
|
if (RD->getTagKind() != TTK_Struct)
|
2008-09-26 11:32:58 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return RD->getIdentifier() == &Ctx.Idents.get("__CFString");
|
|
|
|
}
|
|
|
|
|
2013-11-01 05:23:20 +08:00
|
|
|
static unsigned getNumAttributeArgs(const AttributeList &Attr) {
|
|
|
|
// FIXME: Include the type in the argument list.
|
|
|
|
return Attr.getNumArgs() + Attr.hasParsedType();
|
|
|
|
}
|
|
|
|
|
2011-08-10 01:59:31 +08:00
|
|
|
/// \brief Check if the attribute has exactly as many args as Num. May
|
|
|
|
/// output an error.
|
2011-07-12 07:30:35 +08:00
|
|
|
static bool checkAttributeNumArgs(Sema &S, const AttributeList &Attr,
|
2013-11-01 05:23:20 +08:00
|
|
|
unsigned Num) {
|
|
|
|
if (getNumAttributeArgs(Attr) != Num) {
|
2013-07-24 03:30:11 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
|
|
|
|
<< Attr.getName() << Num;
|
2011-07-12 07:30:35 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-29 04:12:35 +08:00
|
|
|
|
2011-08-10 01:59:31 +08:00
|
|
|
/// \brief Check if the attribute has at least as many args as Num. May
|
|
|
|
/// output an error.
|
|
|
|
static bool checkAttributeAtLeastNumArgs(Sema &S, const AttributeList &Attr,
|
2013-11-01 05:23:20 +08:00
|
|
|
unsigned Num) {
|
|
|
|
if (getNumAttributeArgs(Attr) < Num) {
|
2011-07-29 04:12:35 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_too_few_arguments) << Num;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-21 09:50:40 +08:00
|
|
|
/// \brief If Expr is a valid integer constant, get the value of the integer
|
|
|
|
/// expression and return success or failure. May output an error.
|
|
|
|
static bool checkUInt32Argument(Sema &S, const AttributeList &Attr,
|
|
|
|
const Expr *Expr, uint32_t &Val,
|
|
|
|
unsigned Idx = UINT_MAX) {
|
|
|
|
llvm::APSInt I(32);
|
|
|
|
if (Expr->isTypeDependent() || Expr->isValueDependent() ||
|
|
|
|
!Expr->isIntegerConstantExpr(I, S.Context)) {
|
|
|
|
if (Idx != UINT_MAX)
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_type)
|
|
|
|
<< Attr.getName() << Idx << AANT_ArgumentIntegerConstant
|
|
|
|
<< Expr->getSourceRange();
|
|
|
|
else
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
|
|
|
|
<< Attr.getName() << AANT_ArgumentIntegerConstant
|
|
|
|
<< Expr->getSourceRange();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Val = (uint32_t)I.getZExtValue();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-03 02:05:46 +08:00
|
|
|
/// \brief Diagnose mutually exclusive attributes when present on a given
|
|
|
|
/// declaration. Returns true if diagnosed.
|
|
|
|
template <typename AttrTy>
|
|
|
|
static bool checkAttrMutualExclusion(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr,
|
|
|
|
const char *OtherName) {
|
|
|
|
// FIXME: it would be nice if OtherName did not have to be passed in, but was
|
|
|
|
// instead determined based on the AttrTy template parameter.
|
|
|
|
if (D->hasAttr<AttrTy>()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
|
|
|
|
<< Attr.getName() << OtherName;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-17 08:08:38 +08:00
|
|
|
/// \brief Check if IdxExpr is a valid argument index for a function or
|
|
|
|
/// instance method D. May output an error.
|
|
|
|
///
|
|
|
|
/// \returns true if IdxExpr is a valid index.
|
|
|
|
static bool checkFunctionOrMethodArgumentIndex(Sema &S, const Decl *D,
|
|
|
|
StringRef AttrName,
|
|
|
|
SourceLocation AttrLoc,
|
|
|
|
unsigned AttrArgNum,
|
|
|
|
const Expr *IdxExpr,
|
|
|
|
uint64_t &Idx)
|
|
|
|
{
|
2013-07-30 08:48:57 +08:00
|
|
|
assert(isFunctionOrMethod(D));
|
2012-08-17 08:08:38 +08:00
|
|
|
|
|
|
|
// In C++ the implicit 'this' function parameter also counts.
|
|
|
|
// Parameters are counted from one.
|
2013-07-30 08:48:57 +08:00
|
|
|
bool HP = hasFunctionProto(D);
|
|
|
|
bool HasImplicitThisParam = isInstanceMethod(D);
|
|
|
|
bool IV = HP && isFunctionOrMethodVariadic(D);
|
|
|
|
unsigned NumArgs = (HP ? getFunctionOrMethodNumArgs(D) : 0) +
|
|
|
|
HasImplicitThisParam;
|
2012-08-17 08:08:38 +08:00
|
|
|
|
|
|
|
llvm::APSInt IdxInt;
|
|
|
|
if (IdxExpr->isTypeDependent() || IdxExpr->isValueDependent() ||
|
|
|
|
!IdxExpr->isIntegerConstantExpr(IdxInt, S.Context)) {
|
2013-07-23 22:03:57 +08:00
|
|
|
std::string Name = std::string("'") + AttrName.str() + std::string("'");
|
|
|
|
S.Diag(AttrLoc, diag::err_attribute_argument_n_type) << Name.c_str()
|
2013-07-30 09:31:03 +08:00
|
|
|
<< AttrArgNum << AANT_ArgumentIntegerConstant << IdxExpr->getSourceRange();
|
2012-08-17 08:08:38 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Idx = IdxInt.getLimitedValue();
|
2013-07-30 08:48:57 +08:00
|
|
|
if (Idx < 1 || (!IV && Idx > NumArgs)) {
|
2012-08-17 08:08:38 +08:00
|
|
|
S.Diag(AttrLoc, diag::err_attribute_argument_out_of_bounds)
|
|
|
|
<< AttrName << AttrArgNum << IdxExpr->getSourceRange();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Idx--; // Convert to zero-based.
|
|
|
|
if (HasImplicitThisParam) {
|
|
|
|
if (Idx == 0) {
|
|
|
|
S.Diag(AttrLoc,
|
|
|
|
diag::err_attribute_invalid_implicit_this_argument)
|
|
|
|
<< AttrName << IdxExpr->getSourceRange();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
--Idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-14 03:35:18 +08:00
|
|
|
/// \brief Check if the argument \p ArgNum of \p Attr is a ASCII string literal.
|
|
|
|
/// If not emit an error and return false. If the argument is an identifier it
|
|
|
|
/// will emit an error with a fixit hint and treat it as if it was a string
|
|
|
|
/// literal.
|
2013-10-01 22:34:18 +08:00
|
|
|
bool Sema::checkStringLiteralArgumentAttr(const AttributeList &Attr,
|
|
|
|
unsigned ArgNum, StringRef &Str,
|
2013-10-01 22:34:25 +08:00
|
|
|
SourceLocation *ArgLocation) {
|
2013-09-14 03:35:18 +08:00
|
|
|
// Look for identifiers. If we have one emit a hint to fix it to a literal.
|
|
|
|
if (Attr.isArgIdent(ArgNum)) {
|
|
|
|
IdentifierLoc *Loc = Attr.getArgAsIdent(ArgNum);
|
2013-10-01 22:34:18 +08:00
|
|
|
Diag(Loc->Loc, diag::err_attribute_argument_type)
|
2013-09-14 03:35:18 +08:00
|
|
|
<< Attr.getName() << AANT_ArgumentString
|
|
|
|
<< FixItHint::CreateInsertion(Loc->Loc, "\"")
|
2013-10-01 22:34:18 +08:00
|
|
|
<< FixItHint::CreateInsertion(PP.getLocForEndOfToken(Loc->Loc), "\"");
|
2013-09-14 03:35:18 +08:00
|
|
|
Str = Loc->Ident->getName();
|
|
|
|
if (ArgLocation)
|
|
|
|
*ArgLocation = Loc->Loc;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check for an actual string literal.
|
|
|
|
Expr *ArgExpr = Attr.getArgAsExpr(ArgNum);
|
|
|
|
StringLiteral *Literal = dyn_cast<StringLiteral>(ArgExpr->IgnoreParenCasts());
|
|
|
|
if (ArgLocation)
|
|
|
|
*ArgLocation = ArgExpr->getLocStart();
|
|
|
|
|
|
|
|
if (!Literal || !Literal->isAscii()) {
|
2013-10-01 22:34:18 +08:00
|
|
|
Diag(ArgExpr->getLocStart(), diag::err_attribute_argument_type)
|
2013-09-14 03:35:18 +08:00
|
|
|
<< Attr.getName() << AANT_ArgumentString;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Str = Literal->getString();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-27 23:24:06 +08:00
|
|
|
/// \brief Applies the given attribute to the Decl without performing any
|
|
|
|
/// additional semantic checking.
|
|
|
|
template <typename AttrType>
|
|
|
|
static void handleSimpleAttribute(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
D->addAttr(::new (S.Context) AttrType(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
2011-08-10 01:59:31 +08:00
|
|
|
/// \brief Check if the passed-in expression is of type int or bool.
|
|
|
|
static bool isIntOrBool(Expr *Exp) {
|
|
|
|
QualType QT = Exp->getType();
|
|
|
|
return QT->isBooleanType() || QT->isIntegerType();
|
|
|
|
}
|
|
|
|
|
2012-04-24 02:39:55 +08:00
|
|
|
|
|
|
|
// Check to see if the type is a smart pointer of some kind. We assume
|
|
|
|
// it's a smart pointer if it defines both operator-> and operator*.
|
2012-05-03 06:18:42 +08:00
|
|
|
static bool threadSafetyCheckIsSmartPointer(Sema &S, const RecordType* RT) {
|
|
|
|
DeclContextLookupConstResult Res1 = RT->getDecl()->lookup(
|
|
|
|
S.Context.DeclarationNames.getCXXOperatorName(OO_Star));
|
2012-12-19 08:45:41 +08:00
|
|
|
if (Res1.empty())
|
2012-05-03 06:18:42 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
DeclContextLookupConstResult Res2 = RT->getDecl()->lookup(
|
|
|
|
S.Context.DeclarationNames.getCXXOperatorName(OO_Arrow));
|
2012-12-19 08:45:41 +08:00
|
|
|
if (Res2.empty())
|
2012-05-03 06:18:42 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2012-04-24 02:39:55 +08:00
|
|
|
}
|
|
|
|
|
2011-07-29 01:21:07 +08:00
|
|
|
/// \brief Check if passed in Decl is a pointer type.
|
|
|
|
/// Note that this function may produce an error message.
|
|
|
|
/// \return true if the Decl is a pointer type; false otherwise
|
2012-04-20 00:10:44 +08:00
|
|
|
static bool threadSafetyCheckIsPointer(Sema &S, const Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2011-08-02 12:50:49 +08:00
|
|
|
if (const ValueDecl *vd = dyn_cast<ValueDecl>(D)) {
|
2011-07-29 01:21:07 +08:00
|
|
|
QualType QT = vd->getType();
|
2011-08-02 12:50:49 +08:00
|
|
|
if (QT->isAnyPointerType())
|
2011-07-29 01:21:07 +08:00
|
|
|
return true;
|
2012-04-24 02:39:55 +08:00
|
|
|
|
2012-05-03 06:18:42 +08:00
|
|
|
if (const RecordType *RT = QT->getAs<RecordType>()) {
|
|
|
|
// If it's an incomplete type, it could be a smart pointer; skip it.
|
|
|
|
// (We don't want to force template instantiation if we can avoid it,
|
|
|
|
// since that would alter the order in which templates are instantiated.)
|
|
|
|
if (RT->isIncompleteType())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (threadSafetyCheckIsSmartPointer(S, RT))
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-24 02:39:55 +08:00
|
|
|
|
2012-04-20 00:10:44 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_thread_attribute_decl_not_pointer)
|
2011-07-29 01:21:07 +08:00
|
|
|
<< Attr.getName()->getName() << QT;
|
|
|
|
} else {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_can_be_applied_only_to_value_decl)
|
|
|
|
<< Attr.getName();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-10 01:59:31 +08:00
|
|
|
/// \brief Checks that the passed in QualType either is of RecordType or points
|
|
|
|
/// to RecordType. Returns the relevant RecordType, null if it does not exit.
|
2011-08-19 12:18:11 +08:00
|
|
|
static const RecordType *getRecordType(QualType QT) {
|
|
|
|
if (const RecordType *RT = QT->getAs<RecordType>())
|
2011-08-10 01:59:31 +08:00
|
|
|
return RT;
|
2011-08-19 12:18:11 +08:00
|
|
|
|
|
|
|
// Now check if we point to record type.
|
|
|
|
if (const PointerType *PT = QT->getAs<PointerType>())
|
|
|
|
return PT->getPointeeType()->getAs<RecordType>();
|
|
|
|
|
|
|
|
return 0;
|
2011-08-10 01:59:31 +08:00
|
|
|
}
|
|
|
|
|
2012-05-05 00:28:38 +08:00
|
|
|
|
2012-05-08 11:27:22 +08:00
|
|
|
static bool checkBaseClassIsLockableCallback(const CXXBaseSpecifier *Specifier,
|
|
|
|
CXXBasePath &Path, void *Unused) {
|
2012-05-05 00:28:38 +08:00
|
|
|
const RecordType *RT = Specifier->getType()->getAs<RecordType>();
|
2013-12-19 10:39:40 +08:00
|
|
|
return RT->getDecl()->hasAttr<LockableAttr>();
|
2012-05-05 00:28:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-24 02:46:34 +08:00
|
|
|
/// \brief Thread Safety Analysis: Checks that the passed in RecordType
|
2012-04-20 00:10:44 +08:00
|
|
|
/// resolves to a lockable object.
|
2012-04-07 04:02:30 +08:00
|
|
|
static void checkForLockableRecord(Sema &S, Decl *D, const AttributeList &Attr,
|
|
|
|
QualType Ty) {
|
|
|
|
const RecordType *RT = getRecordType(Ty);
|
2012-08-04 01:40:43 +08:00
|
|
|
|
2012-04-07 04:02:30 +08:00
|
|
|
// Warn if could not get record type for this argument.
|
2011-09-03 11:30:59 +08:00
|
|
|
if (!RT) {
|
2012-04-20 00:10:44 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_thread_attribute_argument_not_class)
|
2012-04-07 04:02:30 +08:00
|
|
|
<< Attr.getName() << Ty.getAsString();
|
|
|
|
return;
|
2011-08-24 02:46:34 +08:00
|
|
|
}
|
2012-05-03 06:18:42 +08:00
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
// Don't check for lockable if the class hasn't been defined yet.
|
2012-02-17 01:15:51 +08:00
|
|
|
if (RT->isIncompleteType())
|
2012-04-07 04:02:30 +08:00
|
|
|
return;
|
2012-05-03 06:18:42 +08:00
|
|
|
|
|
|
|
// Allow smart pointers to be used as lockable objects.
|
|
|
|
// FIXME -- Check the type that the smart pointer points to.
|
|
|
|
if (threadSafetyCheckIsSmartPointer(S, RT))
|
|
|
|
return;
|
|
|
|
|
2012-05-05 00:28:38 +08:00
|
|
|
// Check if the type is lockable.
|
|
|
|
RecordDecl *RD = RT->getDecl();
|
2013-12-19 10:39:40 +08:00
|
|
|
if (RD->hasAttr<LockableAttr>())
|
2012-04-07 04:02:30 +08:00
|
|
|
return;
|
2012-05-05 00:28:38 +08:00
|
|
|
|
|
|
|
// Else check if any base classes are lockable.
|
|
|
|
if (CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) {
|
|
|
|
CXXBasePaths BPaths(false, false);
|
|
|
|
if (CRD->lookupInBases(checkBaseClassIsLockableCallback, 0, BPaths))
|
|
|
|
return;
|
2011-08-24 02:46:34 +08:00
|
|
|
}
|
2012-05-05 00:28:38 +08:00
|
|
|
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_thread_attribute_argument_not_lockable)
|
|
|
|
<< Attr.getName() << Ty.getAsString();
|
2011-08-24 02:46:34 +08:00
|
|
|
}
|
|
|
|
|
2011-08-10 01:59:31 +08:00
|
|
|
/// \brief Thread Safety Analysis: Checks that all attribute arguments, starting
|
2012-04-20 00:10:44 +08:00
|
|
|
/// from Sidx, resolve to a lockable object.
|
2011-08-24 02:46:34 +08:00
|
|
|
/// \param Sidx The attribute argument index to start checking with.
|
|
|
|
/// \param ParamIdxOk Whether an argument can be indexing into a function
|
|
|
|
/// parameter list.
|
2012-04-20 00:10:44 +08:00
|
|
|
static void checkAttrArgsAreLockableObjs(Sema &S, Decl *D,
|
2011-08-24 02:46:34 +08:00
|
|
|
const AttributeList &Attr,
|
|
|
|
SmallVectorImpl<Expr*> &Args,
|
2011-08-10 01:59:31 +08:00
|
|
|
int Sidx = 0,
|
|
|
|
bool ParamIdxOk = false) {
|
2011-08-24 02:46:34 +08:00
|
|
|
for(unsigned Idx = Sidx; Idx < Attr.getNumArgs(); ++Idx) {
|
2013-08-31 09:11:41 +08:00
|
|
|
Expr *ArgExp = Attr.getArgAsExpr(Idx);
|
2011-08-24 02:46:34 +08:00
|
|
|
|
2011-09-09 01:42:31 +08:00
|
|
|
if (ArgExp->isTypeDependent()) {
|
2012-04-20 00:10:44 +08:00
|
|
|
// FIXME -- need to check this again on template instantiation
|
2011-09-09 01:42:31 +08:00
|
|
|
Args.push_back(ArgExp);
|
|
|
|
continue;
|
|
|
|
}
|
2011-08-10 01:59:31 +08:00
|
|
|
|
2012-04-24 00:45:01 +08:00
|
|
|
if (StringLiteral *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
|
2012-09-08 01:34:53 +08:00
|
|
|
if (StrLit->getLength() == 0 ||
|
2013-09-14 00:30:12 +08:00
|
|
|
(StrLit->isAscii() && StrLit->getString() == StringRef("*"))) {
|
2012-09-01 05:57:32 +08:00
|
|
|
// Pass empty strings to the analyzer without warnings.
|
2012-09-08 01:34:53 +08:00
|
|
|
// Treat "*" as the universal lock.
|
2012-09-01 05:57:32 +08:00
|
|
|
Args.push_back(ArgExp);
|
2012-04-24 00:45:01 +08:00
|
|
|
continue;
|
2012-09-01 05:57:32 +08:00
|
|
|
}
|
2012-04-24 00:45:01 +08:00
|
|
|
|
2012-04-20 00:10:44 +08:00
|
|
|
// We allow constant strings to be used as a placeholder for expressions
|
|
|
|
// that are not valid C++ syntax, but warn that they are ignored.
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_thread_attribute_ignored) <<
|
|
|
|
Attr.getName();
|
2012-09-01 05:57:32 +08:00
|
|
|
Args.push_back(ArgExp);
|
2012-04-20 00:10:44 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-08-24 02:46:34 +08:00
|
|
|
QualType ArgTy = ArgExp->getType();
|
2011-08-10 01:59:31 +08:00
|
|
|
|
2012-04-24 00:45:01 +08:00
|
|
|
// A pointer to member expression of the form &MyClass::mu is treated
|
|
|
|
// specially -- we need to look at the type of the member.
|
|
|
|
if (UnaryOperator *UOp = dyn_cast<UnaryOperator>(ArgExp))
|
|
|
|
if (UOp->getOpcode() == UO_AddrOf)
|
|
|
|
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
|
|
|
|
if (DRE->getDecl()->isCXXInstanceMember())
|
|
|
|
ArgTy = DRE->getDecl()->getType();
|
|
|
|
|
2011-08-24 02:46:34 +08:00
|
|
|
// First see if we can just cast to record type, or point to record type.
|
|
|
|
const RecordType *RT = getRecordType(ArgTy);
|
2011-08-10 01:59:31 +08:00
|
|
|
|
2011-08-24 02:46:34 +08:00
|
|
|
// Now check if we index into a record type function param.
|
|
|
|
if(!RT && ParamIdxOk) {
|
|
|
|
FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
|
2011-08-10 01:59:31 +08:00
|
|
|
IntegerLiteral *IL = dyn_cast<IntegerLiteral>(ArgExp);
|
|
|
|
if(FD && IL) {
|
|
|
|
unsigned int NumParams = FD->getNumParams();
|
|
|
|
llvm::APInt ArgValue = IL->getValue();
|
2011-08-24 02:46:34 +08:00
|
|
|
uint64_t ParamIdxFromOne = ArgValue.getZExtValue();
|
|
|
|
uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
|
|
|
|
if(!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) {
|
2011-08-10 01:59:31 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_range)
|
|
|
|
<< Attr.getName() << Idx + 1 << NumParams;
|
2012-04-20 00:10:44 +08:00
|
|
|
continue;
|
2011-08-10 01:59:31 +08:00
|
|
|
}
|
2011-08-24 02:46:34 +08:00
|
|
|
ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType();
|
2011-08-10 01:59:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-07 04:02:30 +08:00
|
|
|
checkForLockableRecord(S, D, Attr, ArgTy);
|
2011-08-10 01:59:31 +08:00
|
|
|
|
2011-08-24 02:46:34 +08:00
|
|
|
Args.push_back(ArgExp);
|
2011-08-10 01:59:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-29 08:16:31 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Attribute Implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-08-01 06:40:48 +08:00
|
|
|
// FIXME: All this manual attribute parsing code is gross. At the
|
|
|
|
// least add some helper functions to check most argument patterns (#
|
|
|
|
// and types of args).
|
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static void handlePtGuardedVarAttr(Sema &S, Decl *D,
|
2013-01-25 00:46:58 +08:00
|
|
|
const AttributeList &Attr) {
|
2012-07-24 02:48:41 +08:00
|
|
|
if (!threadSafetyCheckIsPointer(S, D, Attr))
|
|
|
|
return;
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
PtGuardedVarAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-07-29 01:21:07 +08:00
|
|
|
}
|
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static bool checkGuardedByAttrCommon(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr,
|
2012-07-24 02:48:41 +08:00
|
|
|
Expr* &Arg) {
|
2012-04-20 00:10:44 +08:00
|
|
|
SmallVector<Expr*, 1> Args;
|
|
|
|
// check that all arguments are lockable objects
|
|
|
|
checkAttrArgsAreLockableObjs(S, D, Attr, Args);
|
|
|
|
unsigned Size = Args.size();
|
|
|
|
if (Size != 1)
|
2012-07-24 02:48:41 +08:00
|
|
|
return false;
|
2012-08-04 01:40:43 +08:00
|
|
|
|
2012-07-24 02:48:41 +08:00
|
|
|
Arg = Args[0];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handleGuardedByAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
|
|
|
Expr *Arg = 0;
|
|
|
|
if (!checkGuardedByAttrCommon(S, D, Attr, Arg))
|
2012-04-20 00:10:44 +08:00
|
|
|
return;
|
2011-08-10 01:59:31 +08:00
|
|
|
|
2012-07-24 02:48:41 +08:00
|
|
|
D->addAttr(::new (S.Context) GuardedByAttr(Attr.getRange(), S.Context, Arg));
|
2011-07-29 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static void handlePtGuardedByAttr(Sema &S, Decl *D,
|
2012-07-24 02:48:41 +08:00
|
|
|
const AttributeList &Attr) {
|
|
|
|
Expr *Arg = 0;
|
|
|
|
if (!checkGuardedByAttrCommon(S, D, Attr, Arg))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!threadSafetyCheckIsPointer(S, D, Attr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
D->addAttr(::new (S.Context) PtGuardedByAttr(Attr.getRange(),
|
|
|
|
S.Context, Arg));
|
|
|
|
}
|
2011-07-29 04:12:35 +08:00
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static bool checkAcquireOrderAttrCommon(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr,
|
2013-07-06 03:34:19 +08:00
|
|
|
SmallVectorImpl<Expr *> &Args) {
|
2011-08-10 01:59:31 +08:00
|
|
|
if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
|
2012-07-24 02:48:41 +08:00
|
|
|
return false;
|
2011-07-29 04:12:35 +08:00
|
|
|
|
2012-04-20 00:10:44 +08:00
|
|
|
// Check that this attribute only applies to lockable types.
|
2013-12-02 23:02:49 +08:00
|
|
|
QualType QT = cast<ValueDecl>(D)->getType();
|
2011-08-10 01:59:31 +08:00
|
|
|
if (!QT->isDependentType()) {
|
|
|
|
const RecordType *RT = getRecordType(QT);
|
2013-12-19 10:39:40 +08:00
|
|
|
if (!RT || !RT->getDecl()->hasAttr<LockableAttr>()) {
|
2012-04-20 00:10:44 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_thread_attribute_decl_not_lockable)
|
2012-07-24 02:48:41 +08:00
|
|
|
<< Attr.getName();
|
|
|
|
return false;
|
2011-08-10 01:59:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-20 00:10:44 +08:00
|
|
|
// Check that all arguments are lockable objects.
|
|
|
|
checkAttrArgsAreLockableObjs(S, D, Attr, Args);
|
2013-05-03 23:05:50 +08:00
|
|
|
if (Args.empty())
|
2012-07-24 02:48:41 +08:00
|
|
|
return false;
|
2012-08-04 01:40:43 +08:00
|
|
|
|
2012-07-24 02:48:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static void handleAcquiredAfterAttr(Sema &S, Decl *D,
|
2012-07-24 02:48:41 +08:00
|
|
|
const AttributeList &Attr) {
|
|
|
|
SmallVector<Expr*, 1> Args;
|
|
|
|
if (!checkAcquireOrderAttrCommon(S, D, Attr, Args))
|
2012-04-20 00:10:44 +08:00
|
|
|
return;
|
2012-07-24 02:48:41 +08:00
|
|
|
|
2012-04-20 00:10:44 +08:00
|
|
|
Expr **StartArg = &Args[0];
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
AcquiredAfterAttr(Attr.getRange(), S.Context,
|
|
|
|
StartArg, Args.size(),
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-07-24 02:48:41 +08:00
|
|
|
}
|
2011-08-24 02:46:34 +08:00
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static void handleAcquiredBeforeAttr(Sema &S, Decl *D,
|
2012-07-24 02:48:41 +08:00
|
|
|
const AttributeList &Attr) {
|
|
|
|
SmallVector<Expr*, 1> Args;
|
|
|
|
if (!checkAcquireOrderAttrCommon(S, D, Attr, Args))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Expr **StartArg = &Args[0];
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
AcquiredBeforeAttr(Attr.getRange(), S.Context,
|
|
|
|
StartArg, Args.size(),
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-07-29 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static bool checkLockFunAttrCommon(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr,
|
2013-07-06 03:34:19 +08:00
|
|
|
SmallVectorImpl<Expr *> &Args) {
|
2011-07-29 04:12:35 +08:00
|
|
|
// zero or more arguments ok
|
2011-08-10 01:59:31 +08:00
|
|
|
// check that all arguments are lockable objects
|
2012-04-20 00:10:44 +08:00
|
|
|
checkAttrArgsAreLockableObjs(S, D, Attr, Args, 0, /*ParamIdxOk=*/true);
|
2012-07-24 02:48:41 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static void handleSharedLockFunctionAttr(Sema &S, Decl *D,
|
2012-07-24 02:48:41 +08:00
|
|
|
const AttributeList &Attr) {
|
|
|
|
SmallVector<Expr*, 1> Args;
|
|
|
|
if (!checkLockFunAttrCommon(S, D, Attr, Args))
|
|
|
|
return;
|
|
|
|
|
2011-08-24 02:46:34 +08:00
|
|
|
unsigned Size = Args.size();
|
|
|
|
Expr **StartArg = Size == 0 ? 0 : &Args[0];
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
SharedLockFunctionAttr(Attr.getRange(), S.Context, StartArg, Size,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-07-24 02:48:41 +08:00
|
|
|
}
|
2011-08-24 02:46:34 +08:00
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static void handleExclusiveLockFunctionAttr(Sema &S, Decl *D,
|
2012-07-24 02:48:41 +08:00
|
|
|
const AttributeList &Attr) {
|
|
|
|
SmallVector<Expr*, 1> Args;
|
|
|
|
if (!checkLockFunAttrCommon(S, D, Attr, Args))
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned Size = Args.size();
|
|
|
|
Expr **StartArg = Size == 0 ? 0 : &Args[0];
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ExclusiveLockFunctionAttr(Attr.getRange(), S.Context,
|
|
|
|
StartArg, Size,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-07-29 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
2013-05-18 07:02:59 +08:00
|
|
|
static void handleAssertSharedLockAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
SmallVector<Expr*, 1> Args;
|
|
|
|
if (!checkLockFunAttrCommon(S, D, Attr, Args))
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned Size = Args.size();
|
|
|
|
Expr **StartArg = Size == 0 ? 0 : &Args[0];
|
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
AssertSharedLockAttr(Attr.getRange(), S.Context, StartArg, Size,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handleAssertExclusiveLockAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
SmallVector<Expr*, 1> Args;
|
|
|
|
if (!checkLockFunAttrCommon(S, D, Attr, Args))
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned Size = Args.size();
|
|
|
|
Expr **StartArg = Size == 0 ? 0 : &Args[0];
|
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
AssertExclusiveLockAttr(Attr.getRange(), S.Context,
|
|
|
|
StartArg, Size,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static bool checkTryLockFunAttrCommon(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr,
|
2013-07-06 03:34:19 +08:00
|
|
|
SmallVectorImpl<Expr *> &Args) {
|
2011-08-10 01:59:31 +08:00
|
|
|
if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
|
2012-07-24 02:48:41 +08:00
|
|
|
return false;
|
2011-07-29 04:12:35 +08:00
|
|
|
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!isIntOrBool(Attr.getArgAsExpr(0))) {
|
2013-07-23 22:03:57 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_type)
|
2013-07-30 09:31:03 +08:00
|
|
|
<< Attr.getName() << 1 << AANT_ArgumentIntOrBool;
|
2012-07-24 02:48:41 +08:00
|
|
|
return false;
|
2011-08-10 01:59:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// check that all arguments are lockable objects
|
2012-04-20 00:10:44 +08:00
|
|
|
checkAttrArgsAreLockableObjs(S, D, Attr, Args, 1);
|
2012-07-24 02:48:41 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static void handleSharedTrylockFunctionAttr(Sema &S, Decl *D,
|
2012-07-24 02:48:41 +08:00
|
|
|
const AttributeList &Attr) {
|
|
|
|
SmallVector<Expr*, 2> Args;
|
|
|
|
if (!checkTryLockFunAttrCommon(S, D, Attr, Args))
|
|
|
|
return;
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
SharedTrylockFunctionAttr(Attr.getRange(), S.Context,
|
2013-08-31 09:11:41 +08:00
|
|
|
Attr.getArgAsExpr(0),
|
|
|
|
Args.data(), Args.size(),
|
2013-01-25 00:46:58 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-07-24 02:48:41 +08:00
|
|
|
}
|
2011-08-24 02:46:34 +08:00
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static void handleExclusiveTrylockFunctionAttr(Sema &S, Decl *D,
|
2012-07-24 02:48:41 +08:00
|
|
|
const AttributeList &Attr) {
|
|
|
|
SmallVector<Expr*, 2> Args;
|
|
|
|
if (!checkTryLockFunAttrCommon(S, D, Attr, Args))
|
|
|
|
return;
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ExclusiveTrylockFunctionAttr(Attr.getRange(), S.Context,
|
2013-08-31 09:11:41 +08:00
|
|
|
Attr.getArgAsExpr(0),
|
|
|
|
Args.data(), Args.size(),
|
2013-01-25 00:46:58 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-07-29 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static bool checkLocksRequiredCommon(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr,
|
2013-07-06 03:34:19 +08:00
|
|
|
SmallVectorImpl<Expr *> &Args) {
|
2011-08-10 01:59:31 +08:00
|
|
|
if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
|
2012-07-24 02:48:41 +08:00
|
|
|
return false;
|
2011-07-29 04:12:35 +08:00
|
|
|
|
2011-08-10 01:59:31 +08:00
|
|
|
// check that all arguments are lockable objects
|
2012-04-20 00:10:44 +08:00
|
|
|
checkAttrArgsAreLockableObjs(S, D, Attr, Args);
|
2013-05-03 23:05:50 +08:00
|
|
|
if (Args.empty())
|
2012-07-24 02:48:41 +08:00
|
|
|
return false;
|
2012-08-04 01:40:43 +08:00
|
|
|
|
2012-07-24 02:48:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static void handleExclusiveLocksRequiredAttr(Sema &S, Decl *D,
|
2012-07-24 02:48:41 +08:00
|
|
|
const AttributeList &Attr) {
|
|
|
|
SmallVector<Expr*, 1> Args;
|
|
|
|
if (!checkLocksRequiredCommon(S, D, Attr, Args))
|
2012-04-20 00:10:44 +08:00
|
|
|
return;
|
2012-07-24 02:48:41 +08:00
|
|
|
|
2012-04-20 00:10:44 +08:00
|
|
|
Expr **StartArg = &Args[0];
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ExclusiveLocksRequiredAttr(Attr.getRange(), S.Context,
|
|
|
|
StartArg, Args.size(),
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-07-24 02:48:41 +08:00
|
|
|
}
|
2011-08-24 02:46:34 +08:00
|
|
|
|
2012-08-04 01:40:43 +08:00
|
|
|
static void handleSharedLocksRequiredAttr(Sema &S, Decl *D,
|
2012-07-24 02:48:41 +08:00
|
|
|
const AttributeList &Attr) {
|
|
|
|
SmallVector<Expr*, 1> Args;
|
|
|
|
if (!checkLocksRequiredCommon(S, D, Attr, Args))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Expr **StartArg = &Args[0];
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
SharedLocksRequiredAttr(Attr.getRange(), S.Context,
|
|
|
|
StartArg, Args.size(),
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-07-29 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handleUnlockFunAttr(Sema &S, Decl *D,
|
2011-08-10 01:59:31 +08:00
|
|
|
const AttributeList &Attr) {
|
2011-07-29 04:12:35 +08:00
|
|
|
// zero or more arguments ok
|
2011-08-10 01:59:31 +08:00
|
|
|
// check that all arguments are lockable objects
|
2011-08-24 02:46:34 +08:00
|
|
|
SmallVector<Expr*, 1> Args;
|
2012-04-20 00:10:44 +08:00
|
|
|
checkAttrArgsAreLockableObjs(S, D, Attr, Args, 0, /*ParamIdxOk=*/true);
|
2011-08-24 02:46:34 +08:00
|
|
|
unsigned Size = Args.size();
|
|
|
|
Expr **StartArg = Size == 0 ? 0 : &Args[0];
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
UnlockFunctionAttr(Attr.getRange(), S.Context, StartArg, Size,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-07-29 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handleLockReturnedAttr(Sema &S, Decl *D,
|
2011-08-10 01:59:31 +08:00
|
|
|
const AttributeList &Attr) {
|
2011-08-24 02:46:34 +08:00
|
|
|
// check that the argument is lockable object
|
2012-05-03 01:38:37 +08:00
|
|
|
SmallVector<Expr*, 1> Args;
|
|
|
|
checkAttrArgsAreLockableObjs(S, D, Attr, Args);
|
|
|
|
unsigned Size = Args.size();
|
|
|
|
if (Size == 0)
|
|
|
|
return;
|
2011-08-24 02:46:34 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
LockReturnedAttr(Attr.getRange(), S.Context, Args[0],
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-07-29 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handleLocksExcludedAttr(Sema &S, Decl *D,
|
2011-08-10 01:59:31 +08:00
|
|
|
const AttributeList &Attr) {
|
|
|
|
if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
|
2011-07-29 04:12:35 +08:00
|
|
|
return;
|
|
|
|
|
2011-08-10 01:59:31 +08:00
|
|
|
// check that all arguments are lockable objects
|
2011-08-24 02:46:34 +08:00
|
|
|
SmallVector<Expr*, 1> Args;
|
2012-04-20 00:10:44 +08:00
|
|
|
checkAttrArgsAreLockableObjs(S, D, Attr, Args);
|
2011-08-24 02:46:34 +08:00
|
|
|
unsigned Size = Args.size();
|
2012-04-20 00:10:44 +08:00
|
|
|
if (Size == 0)
|
|
|
|
return;
|
|
|
|
Expr **StartArg = &Args[0];
|
2011-08-24 02:46:34 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
LocksExcludedAttr(Attr.getRange(), S.Context, StartArg, Size,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-07-29 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
2013-08-31 06:56:34 +08:00
|
|
|
static void handleConsumableAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-09-06 09:28:43 +08:00
|
|
|
ConsumableAttr::ConsumedState DefaultState;
|
|
|
|
|
|
|
|
if (Attr.isArgIdent(0)) {
|
2013-09-12 03:47:58 +08:00
|
|
|
IdentifierLoc *IL = Attr.getArgAsIdent(0);
|
|
|
|
if (!ConsumableAttr::ConvertStrToConsumedState(IL->Ident->getName(),
|
|
|
|
DefaultState)) {
|
|
|
|
S.Diag(IL->Loc, diag::warn_attribute_type_not_supported)
|
|
|
|
<< Attr.getName() << IL->Ident;
|
2013-09-06 09:28:43 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
|
|
|
|
<< Attr.getName() << AANT_ArgumentIdentifier;
|
|
|
|
return;
|
|
|
|
}
|
2013-08-13 05:20:55 +08:00
|
|
|
|
2013-08-31 06:56:34 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
2013-09-06 09:28:43 +08:00
|
|
|
ConsumableAttr(Attr.getRange(), S.Context, DefaultState,
|
2013-08-31 06:56:34 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool checkForConsumableClass(Sema &S, const CXXMethodDecl *MD,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
ASTContext &CurrContext = S.getASTContext();
|
|
|
|
QualType ThisType = MD->getThisType(CurrContext)->getPointeeType();
|
|
|
|
|
|
|
|
if (const CXXRecordDecl *RD = ThisType->getAsCXXRecordDecl()) {
|
|
|
|
if (!RD->hasAttr<ConsumableAttr>()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attr_on_unconsumable_class) <<
|
|
|
|
RD->getNameAsString();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-13 05:20:55 +08:00
|
|
|
|
2013-10-05 05:28:06 +08:00
|
|
|
static void handleCallableWhenAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-10-15 07:26:04 +08:00
|
|
|
if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
|
|
|
|
return;
|
2013-08-13 05:20:55 +08:00
|
|
|
|
2013-08-31 06:56:34 +08:00
|
|
|
if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), Attr))
|
|
|
|
return;
|
|
|
|
|
2013-10-05 05:28:06 +08:00
|
|
|
SmallVector<CallableWhenAttr::ConsumedState, 3> States;
|
|
|
|
for (unsigned ArgIndex = 0; ArgIndex < Attr.getNumArgs(); ++ArgIndex) {
|
|
|
|
CallableWhenAttr::ConsumedState CallableState;
|
|
|
|
|
2013-10-06 06:45:34 +08:00
|
|
|
StringRef StateString;
|
|
|
|
SourceLocation Loc;
|
|
|
|
if (!S.checkStringLiteralArgumentAttr(Attr, ArgIndex, StateString, &Loc))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
|
2013-10-18 07:23:53 +08:00
|
|
|
CallableState)) {
|
2013-10-06 06:45:34 +08:00
|
|
|
S.Diag(Loc, diag::warn_attribute_type_not_supported)
|
|
|
|
<< Attr.getName() << StateString;
|
2013-10-05 05:28:06 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-10-06 06:45:34 +08:00
|
|
|
|
|
|
|
States.push_back(CallableState);
|
2013-10-05 05:28:06 +08:00
|
|
|
}
|
|
|
|
|
2013-08-13 05:20:55 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
2013-10-05 05:28:06 +08:00
|
|
|
CallableWhenAttr(Attr.getRange(), S.Context, States.data(),
|
|
|
|
States.size(), Attr.getAttributeSpellingListIndex()));
|
2013-08-13 05:20:55 +08:00
|
|
|
}
|
|
|
|
|
2013-10-12 06:30:48 +08:00
|
|
|
|
2013-10-18 07:23:53 +08:00
|
|
|
static void handleParamTypestateAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
if (!checkAttributeNumArgs(S, Attr, 1)) return;
|
2013-11-27 21:27:02 +08:00
|
|
|
|
2013-10-18 07:23:53 +08:00
|
|
|
ParamTypestateAttr::ConsumedState ParamState;
|
|
|
|
|
|
|
|
if (Attr.isArgIdent(0)) {
|
|
|
|
IdentifierLoc *Ident = Attr.getArgAsIdent(0);
|
|
|
|
StringRef StateString = Ident->Ident->getName();
|
|
|
|
|
|
|
|
if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
|
|
|
|
ParamState)) {
|
|
|
|
S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported)
|
|
|
|
<< Attr.getName() << StateString;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type) <<
|
|
|
|
Attr.getName() << AANT_ArgumentIdentifier;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This check is currently being done in the analysis. It can be
|
|
|
|
// enabled here only after the parser propagates attributes at
|
|
|
|
// template specialization definition, not declaration.
|
|
|
|
//QualType ReturnType = cast<ParmVarDecl>(D)->getType();
|
|
|
|
//const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
|
|
|
|
//
|
|
|
|
//if (!RD || !RD->hasAttr<ConsumableAttr>()) {
|
|
|
|
// S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
|
|
|
|
// ReturnType.getAsString();
|
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
|
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ParamTypestateAttr(Attr.getRange(), S.Context, ParamState,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-04 04:11:38 +08:00
|
|
|
static void handleReturnTypestateAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-10-18 06:53:04 +08:00
|
|
|
if (!checkAttributeNumArgs(S, Attr, 1)) return;
|
|
|
|
|
2013-09-04 04:11:38 +08:00
|
|
|
ReturnTypestateAttr::ConsumedState ReturnState;
|
|
|
|
|
|
|
|
if (Attr.isArgIdent(0)) {
|
2013-09-12 03:47:58 +08:00
|
|
|
IdentifierLoc *IL = Attr.getArgAsIdent(0);
|
|
|
|
if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->Ident->getName(),
|
|
|
|
ReturnState)) {
|
|
|
|
S.Diag(IL->Loc, diag::warn_attribute_type_not_supported)
|
|
|
|
<< Attr.getName() << IL->Ident;
|
2013-09-04 04:11:38 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type) <<
|
|
|
|
Attr.getName() << AANT_ArgumentIdentifier;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This check is currently being done in the analysis. It can be
|
|
|
|
// enabled here only after the parser propagates attributes at
|
|
|
|
// template specialization definition, not declaration.
|
|
|
|
//QualType ReturnType;
|
|
|
|
//
|
2013-10-18 06:53:04 +08:00
|
|
|
//if (const ParmVarDecl *Param = dyn_cast<ParmVarDecl>(D)) {
|
|
|
|
// ReturnType = Param->getType();
|
|
|
|
//
|
|
|
|
//} else if (const CXXConstructorDecl *Constructor =
|
|
|
|
// dyn_cast<CXXConstructorDecl>(D)) {
|
2013-09-04 04:11:38 +08:00
|
|
|
// ReturnType = Constructor->getThisType(S.getASTContext())->getPointeeType();
|
|
|
|
//
|
|
|
|
//} else {
|
|
|
|
//
|
|
|
|
// ReturnType = cast<FunctionDecl>(D)->getCallResultType();
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
|
|
|
|
//
|
|
|
|
//if (!RD || !RD->hasAttr<ConsumableAttr>()) {
|
|
|
|
// S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
|
|
|
|
// ReturnType.getAsString();
|
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
|
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ReturnTypestateAttr(Attr.getRange(), S.Context, ReturnState,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
2013-10-12 07:03:26 +08:00
|
|
|
|
|
|
|
static void handleSetTypestateAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-10-15 07:26:04 +08:00
|
|
|
if (!checkAttributeNumArgs(S, Attr, 1))
|
|
|
|
return;
|
2013-10-12 07:03:26 +08:00
|
|
|
|
|
|
|
if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), Attr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
SetTypestateAttr::ConsumedState NewState;
|
|
|
|
if (Attr.isArgIdent(0)) {
|
2013-10-15 07:22:37 +08:00
|
|
|
IdentifierLoc *Ident = Attr.getArgAsIdent(0);
|
|
|
|
StringRef Param = Ident->Ident->getName();
|
|
|
|
if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
|
|
|
|
S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported)
|
|
|
|
<< Attr.getName() << Param;
|
2013-10-12 07:03:26 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type) <<
|
|
|
|
Attr.getName() << AANT_ArgumentIdentifier;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
SetTypestateAttr(Attr.getRange(), S.Context, NewState,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
2013-10-30 04:28:41 +08:00
|
|
|
static void handleTestTypestateAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-10-15 07:26:04 +08:00
|
|
|
if (!checkAttributeNumArgs(S, Attr, 1))
|
|
|
|
return;
|
2013-10-12 07:03:26 +08:00
|
|
|
|
|
|
|
if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), Attr))
|
|
|
|
return;
|
|
|
|
|
2013-10-30 04:28:41 +08:00
|
|
|
TestTypestateAttr::ConsumedState TestState;
|
2013-10-12 07:03:26 +08:00
|
|
|
if (Attr.isArgIdent(0)) {
|
2013-10-15 07:22:37 +08:00
|
|
|
IdentifierLoc *Ident = Attr.getArgAsIdent(0);
|
|
|
|
StringRef Param = Ident->Ident->getName();
|
2013-10-30 04:28:41 +08:00
|
|
|
if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
|
2013-10-15 07:22:37 +08:00
|
|
|
S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported)
|
|
|
|
<< Attr.getName() << Param;
|
2013-10-12 07:03:26 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type) <<
|
|
|
|
Attr.getName() << AANT_ArgumentIdentifier;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
D->addAttr(::new (S.Context)
|
2013-10-30 04:28:41 +08:00
|
|
|
TestTypestateAttr(Attr.getRange(), S.Context, TestState,
|
2013-10-12 07:03:26 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleExtVectorTypeAttr(Sema &S, Scope *scope, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-01-13 10:11:23 +08:00
|
|
|
// Remember this typedef decl, we will need it later for diagnostics.
|
2013-11-27 21:27:02 +08:00
|
|
|
S.ExtVectorDecls.push_back(cast<TypedefNameDecl>(D));
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handlePackedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2011-07-02 07:49:12 +08:00
|
|
|
if (TagDecl *TD = dyn_cast<TagDecl>(D))
|
2011-09-14 00:05:58 +08:00
|
|
|
TD->addAttr(::new (S.Context) PackedAttr(Attr.getRange(), S.Context));
|
2011-07-02 07:49:12 +08:00
|
|
|
else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
|
2008-06-27 02:38:35 +08:00
|
|
|
// If the alignment is less than or equal to 8 bits, the packed attribute
|
|
|
|
// has no effect.
|
2012-11-07 08:35:20 +08:00
|
|
|
if (!FD->getType()->isDependentType() &&
|
|
|
|
!FD->getType()->isIncompleteType() &&
|
2008-06-29 08:43:07 +08:00
|
|
|
S.Context.getTypeAlign(FD->getType()) <= 8)
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored_for_field_of_type)
|
2008-11-24 05:45:46 +08:00
|
|
|
<< Attr.getName() << FD->getType();
|
2008-06-27 02:38:35 +08:00
|
|
|
else
|
2013-01-25 00:46:58 +08:00
|
|
|
FD->addAttr(::new (S.Context)
|
|
|
|
PackedAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-06-27 02:38:35 +08:00
|
|
|
} else
|
2008-11-19 16:23:25 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
|
|
|
|
2011-09-29 15:02:25 +08:00
|
|
|
static bool checkIBOutletCommon(Sema &S, Decl *D, const AttributeList &Attr) {
|
|
|
|
// The IBOutlet/IBOutletCollection attributes only apply to instance
|
|
|
|
// variables or properties of Objective-C classes. The outlet must also
|
|
|
|
// have an object reference type.
|
|
|
|
if (const ObjCIvarDecl *VD = dyn_cast<ObjCIvarDecl>(D)) {
|
|
|
|
if (!VD->getType()->getAs<ObjCObjectPointerType>()) {
|
2011-11-02 02:08:35 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_iboutlet_object_type)
|
2011-09-29 15:02:25 +08:00
|
|
|
<< Attr.getName() << VD->getType() << 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D)) {
|
|
|
|
if (!PD->getType()->getAs<ObjCObjectPointerType>()) {
|
2012-03-15 00:55:17 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_iboutlet_object_type)
|
2011-09-29 15:02:25 +08:00
|
|
|
<< Attr.getName() << PD->getType() << 1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_iboutlet) << Attr.getName();
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-15 00:55:17 +08:00
|
|
|
|
2011-09-29 15:02:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleIBOutlet(Sema &S, Decl *D, const AttributeList &Attr) {
|
2011-09-29 15:02:25 +08:00
|
|
|
if (!checkIBOutletCommon(S, D, Attr))
|
2010-02-18 11:08:58 +08:00
|
|
|
return;
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
IBOutletAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-07-16 06:26:48 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleIBOutletCollection(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2010-05-20 01:38:06 +08:00
|
|
|
|
|
|
|
// The iboutletcollection attribute can have zero or one arguments.
|
2013-08-31 09:11:41 +08:00
|
|
|
if (Attr.getNumArgs() > 1) {
|
2013-07-24 03:30:11 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
|
|
|
|
<< Attr.getName() << 1;
|
2010-05-20 01:38:06 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-29 15:02:25 +08:00
|
|
|
if (!checkIBOutletCommon(S, D, Attr))
|
2010-05-20 01:38:06 +08:00
|
|
|
return;
|
2011-09-29 15:02:25 +08:00
|
|
|
|
2013-10-31 09:56:18 +08:00
|
|
|
ParsedType PT;
|
|
|
|
|
|
|
|
if (Attr.hasParsedType())
|
|
|
|
PT = Attr.getTypeArg();
|
|
|
|
else {
|
|
|
|
PT = S.getTypeName(S.Context.Idents.get("NSObject"), Attr.getLoc(),
|
|
|
|
S.getScopeForContext(D->getDeclContext()->getParent()));
|
|
|
|
if (!PT) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_iboutletcollection_type) << "NSObject";
|
|
|
|
return;
|
|
|
|
}
|
2010-08-18 04:23:12 +08:00
|
|
|
}
|
2013-10-31 09:56:18 +08:00
|
|
|
|
2013-11-01 05:23:20 +08:00
|
|
|
TypeSourceInfo *QTLoc = 0;
|
|
|
|
QualType QT = S.GetTypeFromParser(PT, &QTLoc);
|
|
|
|
if (!QTLoc)
|
|
|
|
QTLoc = S.Context.getTrivialTypeSourceInfo(QT, Attr.getLoc());
|
2013-10-31 09:56:18 +08:00
|
|
|
|
2010-08-18 04:23:12 +08:00
|
|
|
// Diagnose use of non-object type in iboutletcollection attribute.
|
|
|
|
// FIXME. Gnu attribute extension ignores use of builtin types in
|
|
|
|
// attributes. So, __attribute__((iboutletcollection(char))) will be
|
|
|
|
// treated as __attribute__((iboutletcollection())).
|
2011-10-19 03:54:31 +08:00
|
|
|
if (!QT->isObjCIdType() && !QT->isObjCObjectType()) {
|
2013-10-31 09:56:18 +08:00
|
|
|
S.Diag(Attr.getLoc(),
|
|
|
|
QT->isBuiltinType() ? diag::err_iboutletcollection_builtintype
|
|
|
|
: diag::err_iboutletcollection_type) << QT;
|
2010-08-18 04:23:12 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-10-31 09:56:18 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
2013-11-01 05:23:20 +08:00
|
|
|
IBOutletCollectionAttr(Attr.getRange(), S.Context, QTLoc,
|
2013-01-25 00:46:58 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-05-20 01:38:06 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:16 +08:00
|
|
|
static void possibleTransparentUnionPointerType(QualType &T) {
|
2011-06-28 05:12:03 +08:00
|
|
|
if (const RecordType *UT = T->getAsUnionType())
|
|
|
|
if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
|
|
|
|
RecordDecl *UD = UT->getDecl();
|
|
|
|
for (RecordDecl::field_iterator it = UD->field_begin(),
|
|
|
|
itend = UD->field_end(); it != itend; ++it) {
|
|
|
|
QualType QT = it->getType();
|
|
|
|
if (QT->isAnyPointerType() || QT->isBlockPointerType()) {
|
|
|
|
T = QT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleNonNullAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2009-07-25 03:02:52 +08:00
|
|
|
// GCC ignores the nonnull attribute on K&R style function prototypes, so we
|
|
|
|
// ignore it as well
|
2011-07-02 07:49:12 +08:00
|
|
|
if (!isFunctionOrMethod(D) || !hasFunctionProto(D)) {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< Attr.getName() << ExpectedFunction;
|
2008-07-22 05:53:04 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-07-30 08:48:57 +08:00
|
|
|
SmallVector<unsigned, 8> NonNullArgs;
|
|
|
|
for (unsigned i = 0; i < Attr.getNumArgs(); ++i) {
|
2013-08-31 09:11:41 +08:00
|
|
|
Expr *Ex = Attr.getArgAsExpr(i);
|
2013-07-30 08:48:57 +08:00
|
|
|
uint64_t Idx;
|
|
|
|
if (!checkFunctionOrMethodArgumentIndex(S, D, Attr.getName()->getName(),
|
|
|
|
Attr.getLoc(), i + 1, Ex, Idx))
|
2008-07-22 05:53:04 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Is the function argument a pointer type?
|
2013-07-30 08:48:57 +08:00
|
|
|
QualType T = getFunctionOrMethodArgType(D, Idx).getNonReferenceType();
|
2011-07-02 07:49:16 +08:00
|
|
|
possibleTransparentUnionPointerType(T);
|
2011-06-28 05:12:03 +08:00
|
|
|
|
2009-07-16 07:23:54 +08:00
|
|
|
if (!T->isAnyPointerType() && !T->isBlockPointerType()) {
|
2008-07-22 05:53:04 +08:00
|
|
|
// FIXME: Should also highlight argument in decl.
|
2010-08-13 02:48:43 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_nonnull_pointers_only)
|
2008-11-19 13:08:23 +08:00
|
|
|
<< "nonnull" << Ex->getSourceRange();
|
2008-09-02 03:57:52 +08:00
|
|
|
continue;
|
2008-07-22 05:53:04 +08:00
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-07-30 08:48:57 +08:00
|
|
|
NonNullArgs.push_back(Idx);
|
2008-07-22 05:53:04 +08:00
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
|
|
|
// If no arguments were specified to __attribute__((nonnull)) then all pointer
|
|
|
|
// arguments have a nonnull attribute.
|
2008-09-02 03:57:52 +08:00
|
|
|
if (NonNullArgs.empty()) {
|
2013-01-24 09:12:16 +08:00
|
|
|
for (unsigned i = 0, e = getFunctionOrMethodNumArgs(D); i != e; ++i) {
|
|
|
|
QualType T = getFunctionOrMethodArgType(D, i).getNonReferenceType();
|
2011-07-02 07:49:16 +08:00
|
|
|
possibleTransparentUnionPointerType(T);
|
2009-07-16 07:23:54 +08:00
|
|
|
if (T->isAnyPointerType() || T->isBlockPointerType())
|
2013-01-24 09:12:16 +08:00
|
|
|
NonNullArgs.push_back(i);
|
2008-11-18 14:52:58 +08:00
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2010-10-22 02:49:36 +08:00
|
|
|
// No pointer arguments?
|
2010-09-28 03:05:51 +08:00
|
|
|
if (NonNullArgs.empty()) {
|
|
|
|
// Warn the trivial case only if attribute is not coming from a
|
|
|
|
// macro instantiation.
|
|
|
|
if (Attr.getLoc().isFileID())
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_nonnull_no_pointers);
|
2008-09-02 03:57:52 +08:00
|
|
|
return;
|
2010-09-28 03:05:51 +08:00
|
|
|
}
|
2008-07-22 05:53:04 +08:00
|
|
|
}
|
2008-09-02 03:57:52 +08:00
|
|
|
|
2013-01-24 09:12:16 +08:00
|
|
|
unsigned *start = &NonNullArgs[0];
|
2008-09-02 03:57:52 +08:00
|
|
|
unsigned size = NonNullArgs.size();
|
2010-07-31 09:52:11 +08:00
|
|
|
llvm::array_pod_sort(start, start + size);
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
NonNullAttr(Attr.getRange(), S.Context, start, size,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-07-22 05:53:04 +08:00
|
|
|
}
|
|
|
|
|
2013-09-17 02:11:41 +08:00
|
|
|
static const char *ownershipKindToDiagName(OwnershipAttr::OwnershipKind K) {
|
|
|
|
switch (K) {
|
|
|
|
case OwnershipAttr::Holds: return "'ownership_holds'";
|
|
|
|
case OwnershipAttr::Takes: return "'ownership_takes'";
|
|
|
|
case OwnershipAttr::Returns: return "'ownership_returns'";
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown ownership");
|
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleOwnershipAttr(Sema &S, Decl *D, const AttributeList &AL) {
|
2013-09-17 02:11:41 +08:00
|
|
|
// This attribute must be applied to a function declaration. The first
|
|
|
|
// argument to the attribute must be an identifier, the name of the resource,
|
|
|
|
// for example: malloc. The following arguments must be argument indexes, the
|
|
|
|
// arguments must be of integer type for Returns, otherwise of pointer type.
|
2010-07-31 09:52:11 +08:00
|
|
|
// The difference between Holds and Takes is that a pointer may still be used
|
2013-09-17 02:11:41 +08:00
|
|
|
// after being held. free() should be __attribute((ownership_takes)), whereas
|
2010-08-12 16:54:03 +08:00
|
|
|
// a list append function may well be __attribute((ownership_holds)).
|
2010-07-31 09:52:11 +08:00
|
|
|
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!AL.isArgIdent(0)) {
|
2013-07-23 22:03:57 +08:00
|
|
|
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
|
2013-09-17 02:11:41 +08:00
|
|
|
<< AL.getName() << 1 << AANT_ArgumentIdentifier;
|
2010-07-31 09:52:11 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-09-17 02:11:41 +08:00
|
|
|
|
2013-11-27 09:46:48 +08:00
|
|
|
// Figure out our Kind.
|
|
|
|
OwnershipAttr::OwnershipKind K =
|
|
|
|
OwnershipAttr(AL.getLoc(), S.Context, 0, 0, 0,
|
|
|
|
AL.getAttributeSpellingListIndex()).getOwnKind();
|
|
|
|
|
|
|
|
// Check arguments.
|
|
|
|
switch (K) {
|
|
|
|
case OwnershipAttr::Takes:
|
|
|
|
case OwnershipAttr::Holds:
|
2013-08-31 09:11:41 +08:00
|
|
|
if (AL.getNumArgs() < 2) {
|
2013-09-17 02:11:41 +08:00
|
|
|
S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << 2;
|
2010-07-31 09:52:11 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-08-12 16:54:03 +08:00
|
|
|
break;
|
2013-11-27 09:46:48 +08:00
|
|
|
case OwnershipAttr::Returns:
|
2013-08-31 09:11:41 +08:00
|
|
|
if (AL.getNumArgs() > 2) {
|
2013-09-17 02:11:41 +08:00
|
|
|
S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << 1;
|
2010-07-31 09:52:11 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-08-12 16:54:03 +08:00
|
|
|
break;
|
2010-07-31 09:52:11 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
if (!isFunction(D) || !hasFunctionProto(D)) {
|
2011-03-02 20:29:23 +08:00
|
|
|
S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
|
|
|
|
<< AL.getName() << ExpectedFunction;
|
2010-07-31 09:52:11 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-27 09:46:48 +08:00
|
|
|
IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident;
|
2010-07-31 09:52:11 +08:00
|
|
|
|
|
|
|
// Normalize the argument, __foo__ becomes foo.
|
2013-11-27 09:46:48 +08:00
|
|
|
StringRef ModuleName = Module->getName();
|
|
|
|
if (ModuleName.startswith("__") && ModuleName.endswith("__") &&
|
|
|
|
ModuleName.size() > 4) {
|
|
|
|
ModuleName = ModuleName.drop_front(2).drop_back(2);
|
|
|
|
Module = &S.PP.getIdentifierTable().get(ModuleName);
|
|
|
|
}
|
2010-07-31 09:52:11 +08:00
|
|
|
|
2013-07-30 08:48:57 +08:00
|
|
|
SmallVector<unsigned, 8> OwnershipArgs;
|
2013-08-31 09:11:41 +08:00
|
|
|
for (unsigned i = 1; i < AL.getNumArgs(); ++i) {
|
|
|
|
Expr *Ex = AL.getArgAsExpr(i);
|
2013-07-30 08:48:57 +08:00
|
|
|
uint64_t Idx;
|
|
|
|
if (!checkFunctionOrMethodArgumentIndex(S, D, AL.getName()->getName(),
|
2013-08-31 09:11:41 +08:00
|
|
|
AL.getLoc(), i, Ex, Idx))
|
2013-07-30 08:48:57 +08:00
|
|
|
return;
|
2010-11-16 16:35:43 +08:00
|
|
|
|
2013-09-17 02:11:41 +08:00
|
|
|
// Is the function argument a pointer type?
|
|
|
|
QualType T = getFunctionOrMethodArgType(D, Idx);
|
|
|
|
int Err = -1; // No error
|
2010-07-31 09:52:11 +08:00
|
|
|
switch (K) {
|
2013-09-17 02:11:41 +08:00
|
|
|
case OwnershipAttr::Takes:
|
|
|
|
case OwnershipAttr::Holds:
|
|
|
|
if (!T->isAnyPointerType() && !T->isBlockPointerType())
|
|
|
|
Err = 0;
|
|
|
|
break;
|
|
|
|
case OwnershipAttr::Returns:
|
|
|
|
if (!T->isIntegerType())
|
|
|
|
Err = 1;
|
|
|
|
break;
|
2010-07-31 09:52:11 +08:00
|
|
|
}
|
2013-09-17 02:11:41 +08:00
|
|
|
if (-1 != Err) {
|
2013-09-20 00:37:20 +08:00
|
|
|
S.Diag(AL.getLoc(), diag::err_ownership_type) << AL.getName() << Err
|
2013-09-17 02:11:41 +08:00
|
|
|
<< Ex->getSourceRange();
|
|
|
|
return;
|
2010-07-31 09:52:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check we don't have a conflict with another ownership attribute.
|
2010-08-19 07:23:40 +08:00
|
|
|
for (specific_attr_iterator<OwnershipAttr>
|
2013-09-17 02:11:41 +08:00
|
|
|
i = D->specific_attr_begin<OwnershipAttr>(),
|
|
|
|
e = D->specific_attr_end<OwnershipAttr>(); i != e; ++i) {
|
2013-11-27 09:46:48 +08:00
|
|
|
// FIXME: A returns attribute should conflict with any returns attribute
|
|
|
|
// with a different index too.
|
2013-09-17 02:11:41 +08:00
|
|
|
if ((*i)->getOwnKind() != K && (*i)->args_end() !=
|
|
|
|
std::find((*i)->args_begin(), (*i)->args_end(), Idx)) {
|
|
|
|
S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
|
|
|
|
<< AL.getName() << ownershipKindToDiagName((*i)->getOwnKind());
|
|
|
|
return;
|
2010-07-31 09:52:11 +08:00
|
|
|
}
|
|
|
|
}
|
2013-07-30 08:48:57 +08:00
|
|
|
OwnershipArgs.push_back(Idx);
|
2010-07-31 09:52:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned* start = OwnershipArgs.data();
|
|
|
|
unsigned size = OwnershipArgs.size();
|
|
|
|
llvm::array_pod_sort(start, start + size);
|
2010-08-19 07:23:40 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
2013-11-27 09:46:48 +08:00
|
|
|
OwnershipAttr(AL.getLoc(), S.Context, Module, start, size,
|
2013-01-25 00:46:58 +08:00
|
|
|
AL.getAttributeSpellingListIndex()));
|
2010-07-31 09:52:11 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleWeakRefAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2010-02-24 06:00:30 +08:00
|
|
|
// Check the attribute arguments.
|
|
|
|
if (Attr.getNumArgs() > 1) {
|
2013-07-24 03:30:11 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
|
|
|
|
<< Attr.getName() << 1;
|
2010-02-24 06:00:30 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
NamedDecl *nd = cast<NamedDecl>(D);
|
2011-02-09 06:35:49 +08:00
|
|
|
|
2010-02-24 06:00:30 +08:00
|
|
|
// gcc rejects
|
|
|
|
// class c {
|
|
|
|
// static int a __attribute__((weakref ("v2")));
|
|
|
|
// static int b() __attribute__((weakref ("f3")));
|
|
|
|
// };
|
|
|
|
// and ignores the attributes of
|
|
|
|
// void f(void) {
|
|
|
|
// static int a __attribute__((weakref ("v2")));
|
|
|
|
// }
|
|
|
|
// we reject them
|
2011-07-02 07:49:12 +08:00
|
|
|
const DeclContext *Ctx = D->getDeclContext()->getRedeclContext();
|
2010-08-31 08:36:30 +08:00
|
|
|
if (!Ctx->isFileContext()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_weakref_not_global_context) <<
|
2011-02-09 06:35:49 +08:00
|
|
|
nd->getNameAsString();
|
2010-08-31 08:36:30 +08:00
|
|
|
return;
|
2010-02-24 06:00:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// The GCC manual says
|
|
|
|
//
|
|
|
|
// At present, a declaration to which `weakref' is attached can only
|
|
|
|
// be `static'.
|
|
|
|
//
|
|
|
|
// It also says
|
|
|
|
//
|
|
|
|
// Without a TARGET,
|
|
|
|
// given as an argument to `weakref' or to `alias', `weakref' is
|
|
|
|
// equivalent to `weak'.
|
|
|
|
//
|
|
|
|
// gcc 4.4.1 will accept
|
|
|
|
// int a7 __attribute__((weakref));
|
|
|
|
// as
|
|
|
|
// int a7 __attribute__((weak));
|
|
|
|
// This looks like a bug in gcc. We reject that for now. We should revisit
|
|
|
|
// it if this behaviour is actually used.
|
|
|
|
|
|
|
|
// GCC rejects
|
|
|
|
// static ((alias ("y"), weakref)).
|
|
|
|
// Should we? How to check that weakref is before or after alias?
|
|
|
|
|
2013-09-10 07:40:31 +08:00
|
|
|
// FIXME: it would be good for us to keep the WeakRefAttr as-written instead
|
|
|
|
// of transforming it into an AliasAttr. The WeakRefAttr never uses the
|
|
|
|
// StringRef parameter it was given anyway.
|
2013-09-14 03:35:18 +08:00
|
|
|
StringRef Str;
|
2013-10-01 22:34:18 +08:00
|
|
|
if (Attr.getNumArgs() && S.checkStringLiteralArgumentAttr(Attr, 0, Str))
|
2010-02-24 06:00:30 +08:00
|
|
|
// GCC will accept anything as the argument of weakref. Should we
|
|
|
|
// check for an existing decl?
|
2013-09-14 03:35:18 +08:00
|
|
|
D->addAttr(::new (S.Context) AliasAttr(Attr.getRange(), S.Context, Str,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-02-24 06:00:30 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
WeakRefAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-02-24 06:00:30 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 23:35:43 +08:00
|
|
|
static void handleAliasAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
|
|
|
StringRef Str;
|
2013-10-01 22:34:18 +08:00
|
|
|
if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str))
|
2013-09-13 23:35:43 +08:00
|
|
|
return;
|
|
|
|
|
2011-09-02 08:18:52 +08:00
|
|
|
if (S.Context.getTargetInfo().getTriple().isOSDarwin()) {
|
2010-12-07 23:23:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_alias_not_supported_on_darwin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-27 02:38:35 +08:00
|
|
|
// FIXME: check if target symbol exists in current file
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-09-13 23:35:43 +08:00
|
|
|
D->addAttr(::new (S.Context) AliasAttr(Attr.getRange(), S.Context, Str,
|
2013-01-25 00:46:58 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
|
|
|
|
2012-05-13 05:10:52 +08:00
|
|
|
static void handleColdAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-12-03 02:05:46 +08:00
|
|
|
if (checkAttrMutualExclusion<HotAttr>(S, D, Attr, "hot"))
|
2012-05-13 05:10:52 +08:00
|
|
|
return;
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context) ColdAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-05-13 05:10:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handleHotAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-12-03 02:05:46 +08:00
|
|
|
if (checkAttrMutualExclusion<ColdAttr>(S, D, Attr, "cold"))
|
2012-05-13 05:10:52 +08:00
|
|
|
return;
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context) HotAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-05-13 05:10:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-23 19:51:46 +08:00
|
|
|
static void handleTLSModelAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-09-13 23:35:43 +08:00
|
|
|
StringRef Model;
|
|
|
|
SourceLocation LiteralLoc;
|
2012-06-23 19:51:46 +08:00
|
|
|
// Check that it is a string.
|
2013-10-01 22:34:18 +08:00
|
|
|
if (!S.checkStringLiteralArgumentAttr(Attr, 0, Model, &LiteralLoc))
|
2012-06-23 19:51:46 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Check that the value.
|
|
|
|
if (Model != "global-dynamic" && Model != "local-dynamic"
|
|
|
|
&& Model != "initial-exec" && Model != "local-exec") {
|
2013-09-13 23:35:43 +08:00
|
|
|
S.Diag(LiteralLoc, diag::err_attr_tlsmodel_arg);
|
2012-06-23 19:51:46 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
TLSModelAttr(Attr.getRange(), S.Context, Model,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-06-23 19:51:46 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleMallocAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2011-07-02 07:49:12 +08:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
2009-09-09 23:08:12 +08:00
|
|
|
QualType RetTy = FD->getResultType();
|
2009-08-15 08:51:46 +08:00
|
|
|
if (RetTy->isAnyPointerType() || RetTy->isBlockPointerType()) {
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
MallocAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-08-15 08:51:46 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-08-10 06:36:29 +08:00
|
|
|
}
|
|
|
|
|
2009-08-15 08:51:46 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_malloc_pointer_only);
|
2009-08-10 04:07:29 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleCommonAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-06-21 06:55:04 +08:00
|
|
|
if (S.LangOpts.CPlusPlus) {
|
2013-11-25 05:48:06 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_not_supported_in_lang)
|
|
|
|
<< Attr.getName() << AttributeLangSupport::Cpp;
|
2013-06-21 06:55:04 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-27 21:27:02 +08:00
|
|
|
D->addAttr(::new (S.Context) CommonAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-12-02 10:45:55 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleNoReturnAttr(Sema &S, Decl *D, const AttributeList &attr) {
|
2011-07-02 07:49:12 +08:00
|
|
|
if (hasDeclarator(D)) return;
|
2011-01-05 20:14:39 +08:00
|
|
|
|
|
|
|
if (S.CheckNoReturnAttr(attr)) return;
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
if (!isa<ObjCMethodDecl>(D)) {
|
2011-01-05 20:14:39 +08:00
|
|
|
S.Diag(attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< attr.getName() << ExpectedFunctionOrMethod;
|
2011-01-05 20:14:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
NoReturnAttr(attr.getRange(), S.Context,
|
|
|
|
attr.getAttributeSpellingListIndex()));
|
2011-01-05 20:14:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Sema::CheckNoReturnAttr(const AttributeList &attr) {
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!checkAttributeNumArgs(*this, attr, 0)) {
|
2011-01-05 20:14:39 +08:00
|
|
|
attr.setInvalid();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-08-19 08:51:58 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleAnalyzerNoReturnAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2010-08-19 08:51:58 +08:00
|
|
|
|
|
|
|
// The checking path for 'noreturn' and 'analyzer_noreturn' are different
|
|
|
|
// because 'analyzer_noreturn' does not impact the type.
|
2011-07-02 07:49:12 +08:00
|
|
|
if (!isFunctionOrMethod(D) && !isa<BlockDecl>(D)) {
|
|
|
|
ValueDecl *VD = dyn_cast<ValueDecl>(D);
|
2009-12-15 11:11:10 +08:00
|
|
|
if (VD == 0 || (!VD->getType()->isBlockPointerType()
|
|
|
|
&& !VD->getType()->isFunctionPointerType())) {
|
2010-04-30 21:10:51 +08:00
|
|
|
S.Diag(Attr.getLoc(),
|
2013-01-02 20:01:23 +08:00
|
|
|
Attr.isCXX11Attribute() ? diag::err_attribute_wrong_decl_type
|
2010-08-19 08:51:58 +08:00
|
|
|
: diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< Attr.getName() << ExpectedFunctionMethodOrBlock;
|
2010-08-19 08:51:58 +08:00
|
|
|
return;
|
2009-04-30 03:03:13 +08:00
|
|
|
}
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
2010-08-19 08:51:58 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
AnalyzerNoReturnAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
|
|
|
|
2010-08-10 05:53:52 +08:00
|
|
|
// PS3 PPU-specific.
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleVecReturnAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2010-08-10 05:53:52 +08:00
|
|
|
/*
|
|
|
|
Returning a Vector Class in Registers
|
|
|
|
|
2010-12-02 06:13:54 +08:00
|
|
|
According to the PPU ABI specifications, a class with a single member of
|
|
|
|
vector type is returned in memory when used as the return value of a function.
|
|
|
|
This results in inefficient code when implementing vector classes. To return
|
|
|
|
the value in a single vector register, add the vecreturn attribute to the
|
|
|
|
class definition. This attribute is also applicable to struct types.
|
2010-08-10 05:53:52 +08:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
struct Vector
|
|
|
|
{
|
|
|
|
__vector float xyzw;
|
|
|
|
} __attribute__((vecreturn));
|
|
|
|
|
|
|
|
Vector Add(Vector lhs, Vector rhs)
|
|
|
|
{
|
|
|
|
Vector result;
|
|
|
|
result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
|
|
|
|
return result; // This will be returned in a register
|
|
|
|
}
|
|
|
|
*/
|
2013-12-19 10:39:40 +08:00
|
|
|
if (D->hasAttr<VecReturnAttr>()) {
|
2010-08-10 05:53:52 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_repeat_attribute) << "vecreturn";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
RecordDecl *record = cast<RecordDecl>(D);
|
2010-09-18 09:12:07 +08:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (!isa<CXXRecordDecl>(record)) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_vecreturn_only_vector_member);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cast<CXXRecordDecl>(record)->isPOD()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_vecreturn_only_pod_record);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-02 06:13:54 +08:00
|
|
|
for (RecordDecl::field_iterator iter = record->field_begin();
|
|
|
|
iter != record->field_end(); iter++) {
|
2010-09-18 09:12:07 +08:00
|
|
|
if ((count == 1) || !iter->getType()->isVectorType()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_vecreturn_only_vector_member);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
VecReturnAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-08-10 05:53:52 +08:00
|
|
|
}
|
|
|
|
|
2013-01-29 06:42:45 +08:00
|
|
|
static void handleDependencyAttr(Sema &S, Scope *Scope, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
if (isa<ParmVarDecl>(D)) {
|
|
|
|
// [[carries_dependency]] can only be applied to a parameter if it is a
|
|
|
|
// parameter of a function declaration or lambda.
|
|
|
|
if (!(Scope->getFlags() & clang::Scope::FunctionDeclarationScope)) {
|
|
|
|
S.Diag(Attr.getLoc(),
|
|
|
|
diag::err_carries_dependency_param_not_function_decl);
|
|
|
|
return;
|
|
|
|
}
|
2009-11-21 16:43:09 +08:00
|
|
|
}
|
2013-01-29 06:42:45 +08:00
|
|
|
|
|
|
|
D->addAttr(::new (S.Context) CarriesDependencyAttr(
|
|
|
|
Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-11-21 16:43:09 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleUnusedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2011-07-02 07:49:12 +08:00
|
|
|
if (!isa<VarDecl>(D) && !isa<ObjCIvarDecl>(D) && !isFunctionOrMethod(D) &&
|
2012-06-14 02:31:09 +08:00
|
|
|
!isa<TypeDecl>(D) && !isa<LabelDecl>(D) && !isa<FieldDecl>(D)) {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< Attr.getName() << ExpectedVariableFunctionOrLabel;
|
2008-07-25 12:39:19 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
UnusedAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-07-25 12:39:19 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleUsedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2011-07-02 07:49:12 +08:00
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
2013-08-17 07:18:50 +08:00
|
|
|
if (VD->hasLocalStorage()) {
|
2009-02-14 03:23:53 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "used";
|
|
|
|
return;
|
|
|
|
}
|
2011-07-02 07:49:12 +08:00
|
|
|
} else if (!isFunctionOrMethod(D)) {
|
2009-02-14 03:23:53 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< Attr.getName() << ExpectedVariableOrFunction;
|
2009-02-14 03:23:53 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
UsedAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-02-14 03:23:53 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleConstructorAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2008-08-01 06:40:48 +08:00
|
|
|
// check the attribute arguments.
|
2011-03-02 20:15:05 +08:00
|
|
|
if (Attr.getNumArgs() > 1) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 1;
|
2008-08-01 06:40:48 +08:00
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
}
|
2008-08-01 06:40:48 +08:00
|
|
|
|
2013-11-21 09:50:40 +08:00
|
|
|
uint32_t priority = ConstructorAttr::DefaultPriority;
|
|
|
|
if (Attr.getNumArgs() > 0 &&
|
|
|
|
!checkUInt32Argument(S, Attr, Attr.getArgAsExpr(0), priority))
|
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ConstructorAttr(Attr.getRange(), S.Context, priority,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-08-01 06:40:48 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleDestructorAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2008-08-01 06:40:48 +08:00
|
|
|
// check the attribute arguments.
|
2011-03-02 20:15:05 +08:00
|
|
|
if (Attr.getNumArgs() > 1) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 1;
|
2008-08-01 06:40:48 +08:00
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
}
|
2008-08-01 06:40:48 +08:00
|
|
|
|
2013-11-21 09:50:40 +08:00
|
|
|
uint32_t priority = ConstructorAttr::DefaultPriority;
|
|
|
|
if (Attr.getNumArgs() > 0 &&
|
|
|
|
!checkUInt32Argument(S, Attr, Attr.getArgAsExpr(0), priority))
|
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
DestructorAttr(Attr.getRange(), S.Context, priority,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-08-01 06:40:48 +08:00
|
|
|
}
|
|
|
|
|
2012-05-16 20:19:08 +08:00
|
|
|
template <typename AttrTy>
|
2013-07-18 21:13:52 +08:00
|
|
|
static void handleAttrWithMessage(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2011-02-24 13:42:24 +08:00
|
|
|
unsigned NumArgs = Attr.getNumArgs();
|
|
|
|
if (NumArgs > 1) {
|
2011-03-02 20:15:05 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 1;
|
2010-10-07 05:18:44 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-05-16 20:19:08 +08:00
|
|
|
|
|
|
|
// Handle the case where the attribute has a text message.
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Str;
|
2013-10-01 22:34:18 +08:00
|
|
|
if (NumArgs == 1 && !S.checkStringLiteralArgumentAttr(Attr, 0, Str))
|
2013-09-13 23:35:43 +08:00
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context) AttrTy(Attr.getRange(), S.Context, Str,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-12-17 09:07:27 +08:00
|
|
|
}
|
|
|
|
|
2013-11-23 09:01:34 +08:00
|
|
|
static void handleObjCSuppresProtocolAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
D->addAttr(::new (S.Context)
|
2013-12-11 03:43:48 +08:00
|
|
|
ObjCExplicitProtocolImplAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2013-11-23 09:01:34 +08:00
|
|
|
}
|
|
|
|
|
2012-05-08 11:27:22 +08:00
|
|
|
static bool checkAvailabilityAttr(Sema &S, SourceRange Range,
|
|
|
|
IdentifierInfo *Platform,
|
|
|
|
VersionTuple Introduced,
|
|
|
|
VersionTuple Deprecated,
|
|
|
|
VersionTuple Obsoleted) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef PlatformName
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
= AvailabilityAttr::getPrettyPlatformName(Platform->getName());
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
if (PlatformName.empty())
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
PlatformName = Platform->getName();
|
|
|
|
|
2011-08-11 00:09:55 +08:00
|
|
|
// Ensure that Introduced <= Deprecated <= Obsoleted (although not all
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
// of these steps are needed).
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
if (!Introduced.empty() && !Deprecated.empty() &&
|
|
|
|
!(Introduced <= Deprecated)) {
|
|
|
|
S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
|
|
|
|
<< 1 << PlatformName << Deprecated.getAsString()
|
|
|
|
<< 0 << Introduced.getAsString();
|
|
|
|
return true;
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
}
|
|
|
|
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
if (!Introduced.empty() && !Obsoleted.empty() &&
|
|
|
|
!(Introduced <= Obsoleted)) {
|
|
|
|
S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
|
|
|
|
<< 2 << PlatformName << Obsoleted.getAsString()
|
|
|
|
<< 0 << Introduced.getAsString();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Deprecated.empty() && !Obsoleted.empty() &&
|
|
|
|
!(Deprecated <= Obsoleted)) {
|
|
|
|
S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
|
|
|
|
<< 2 << PlatformName << Obsoleted.getAsString()
|
|
|
|
<< 1 << Deprecated.getAsString();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-16 06:43:08 +08:00
|
|
|
/// \brief Check whether the two versions match.
|
|
|
|
///
|
|
|
|
/// If either version tuple is empty, then they are assumed to match. If
|
|
|
|
/// \p BeforeIsOkay is true, then \p X can be less than or equal to \p Y.
|
|
|
|
static bool versionsMatch(const VersionTuple &X, const VersionTuple &Y,
|
|
|
|
bool BeforeIsOkay) {
|
|
|
|
if (X.empty() || Y.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (X == Y)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (BeforeIsOkay && X < Y)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-09 06:04:34 +08:00
|
|
|
AvailabilityAttr *Sema::mergeAvailabilityAttr(NamedDecl *D, SourceRange Range,
|
2012-05-13 11:25:18 +08:00
|
|
|
IdentifierInfo *Platform,
|
|
|
|
VersionTuple Introduced,
|
|
|
|
VersionTuple Deprecated,
|
|
|
|
VersionTuple Obsoleted,
|
|
|
|
bool IsUnavailable,
|
2013-01-16 06:43:08 +08:00
|
|
|
StringRef Message,
|
2013-01-25 00:46:58 +08:00
|
|
|
bool Override,
|
|
|
|
unsigned AttrSpellingListIndex) {
|
2012-05-10 10:50:16 +08:00
|
|
|
VersionTuple MergedIntroduced = Introduced;
|
|
|
|
VersionTuple MergedDeprecated = Deprecated;
|
|
|
|
VersionTuple MergedObsoleted = Obsoleted;
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
bool FoundAny = false;
|
|
|
|
|
2012-05-10 10:50:16 +08:00
|
|
|
if (D->hasAttrs()) {
|
|
|
|
AttrVec &Attrs = D->getAttrs();
|
|
|
|
for (unsigned i = 0, e = Attrs.size(); i != e;) {
|
|
|
|
const AvailabilityAttr *OldAA = dyn_cast<AvailabilityAttr>(Attrs[i]);
|
|
|
|
if (!OldAA) {
|
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
IdentifierInfo *OldPlatform = OldAA->getPlatform();
|
|
|
|
if (OldPlatform != Platform) {
|
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
FoundAny = true;
|
|
|
|
VersionTuple OldIntroduced = OldAA->getIntroduced();
|
|
|
|
VersionTuple OldDeprecated = OldAA->getDeprecated();
|
|
|
|
VersionTuple OldObsoleted = OldAA->getObsoleted();
|
|
|
|
bool OldIsUnavailable = OldAA->getUnavailable();
|
2013-01-16 06:43:08 +08:00
|
|
|
|
|
|
|
if (!versionsMatch(OldIntroduced, Introduced, Override) ||
|
|
|
|
!versionsMatch(Deprecated, OldDeprecated, Override) ||
|
|
|
|
!versionsMatch(Obsoleted, OldObsoleted, Override) ||
|
|
|
|
!(OldIsUnavailable == IsUnavailable ||
|
2013-01-16 08:54:48 +08:00
|
|
|
(Override && !OldIsUnavailable && IsUnavailable))) {
|
2013-01-16 06:43:08 +08:00
|
|
|
if (Override) {
|
|
|
|
int Which = -1;
|
|
|
|
VersionTuple FirstVersion;
|
|
|
|
VersionTuple SecondVersion;
|
|
|
|
if (!versionsMatch(OldIntroduced, Introduced, Override)) {
|
|
|
|
Which = 0;
|
|
|
|
FirstVersion = OldIntroduced;
|
|
|
|
SecondVersion = Introduced;
|
|
|
|
} else if (!versionsMatch(Deprecated, OldDeprecated, Override)) {
|
|
|
|
Which = 1;
|
|
|
|
FirstVersion = Deprecated;
|
|
|
|
SecondVersion = OldDeprecated;
|
|
|
|
} else if (!versionsMatch(Obsoleted, OldObsoleted, Override)) {
|
|
|
|
Which = 2;
|
|
|
|
FirstVersion = Obsoleted;
|
|
|
|
SecondVersion = OldObsoleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Which == -1) {
|
|
|
|
Diag(OldAA->getLocation(),
|
|
|
|
diag::warn_mismatched_availability_override_unavail)
|
|
|
|
<< AvailabilityAttr::getPrettyPlatformName(Platform->getName());
|
|
|
|
} else {
|
|
|
|
Diag(OldAA->getLocation(),
|
|
|
|
diag::warn_mismatched_availability_override)
|
|
|
|
<< Which
|
|
|
|
<< AvailabilityAttr::getPrettyPlatformName(Platform->getName())
|
|
|
|
<< FirstVersion.getAsString() << SecondVersion.getAsString();
|
|
|
|
}
|
|
|
|
Diag(Range.getBegin(), diag::note_overridden_method);
|
|
|
|
} else {
|
|
|
|
Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
|
|
|
|
Diag(Range.getBegin(), diag::note_previous_attribute);
|
|
|
|
}
|
|
|
|
|
2012-05-10 10:50:16 +08:00
|
|
|
Attrs.erase(Attrs.begin() + i);
|
|
|
|
--e;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
VersionTuple MergedIntroduced2 = MergedIntroduced;
|
|
|
|
VersionTuple MergedDeprecated2 = MergedDeprecated;
|
|
|
|
VersionTuple MergedObsoleted2 = MergedObsoleted;
|
|
|
|
|
|
|
|
if (MergedIntroduced2.empty())
|
|
|
|
MergedIntroduced2 = OldIntroduced;
|
|
|
|
if (MergedDeprecated2.empty())
|
|
|
|
MergedDeprecated2 = OldDeprecated;
|
|
|
|
if (MergedObsoleted2.empty())
|
|
|
|
MergedObsoleted2 = OldObsoleted;
|
|
|
|
|
|
|
|
if (checkAvailabilityAttr(*this, OldAA->getRange(), Platform,
|
|
|
|
MergedIntroduced2, MergedDeprecated2,
|
|
|
|
MergedObsoleted2)) {
|
|
|
|
Attrs.erase(Attrs.begin() + i);
|
|
|
|
--e;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
MergedIntroduced = MergedIntroduced2;
|
|
|
|
MergedDeprecated = MergedDeprecated2;
|
|
|
|
MergedObsoleted = MergedObsoleted2;
|
|
|
|
++i;
|
|
|
|
}
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
}
|
|
|
|
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
if (FoundAny &&
|
|
|
|
MergedIntroduced == Introduced &&
|
|
|
|
MergedDeprecated == Deprecated &&
|
|
|
|
MergedObsoleted == Obsoleted)
|
2012-05-13 11:25:18 +08:00
|
|
|
return NULL;
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
|
2013-04-06 08:34:27 +08:00
|
|
|
// Only create a new attribute if !Override, but we want to do
|
|
|
|
// the checking.
|
2012-05-10 10:50:16 +08:00
|
|
|
if (!checkAvailabilityAttr(*this, Range, Platform, MergedIntroduced,
|
2013-04-06 08:34:27 +08:00
|
|
|
MergedDeprecated, MergedObsoleted) &&
|
|
|
|
!Override) {
|
2012-05-13 11:25:18 +08:00
|
|
|
return ::new (Context) AvailabilityAttr(Range, Context, Platform,
|
|
|
|
Introduced, Deprecated,
|
2013-01-25 00:46:58 +08:00
|
|
|
Obsoleted, IsUnavailable, Message,
|
|
|
|
AttrSpellingListIndex);
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
}
|
2012-05-13 11:25:18 +08:00
|
|
|
return NULL;
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
}
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
static void handleAvailabilityAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!checkAttributeNumArgs(S, Attr, 1))
|
|
|
|
return;
|
|
|
|
IdentifierLoc *Platform = Attr.getArgAsIdent(0);
|
2013-01-25 00:46:58 +08:00
|
|
|
unsigned Index = Attr.getAttributeSpellingListIndex();
|
|
|
|
|
2013-08-31 09:11:41 +08:00
|
|
|
IdentifierInfo *II = Platform->Ident;
|
|
|
|
if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty())
|
|
|
|
S.Diag(Platform->Loc, diag::warn_availability_unknown_platform)
|
|
|
|
<< Platform->Ident;
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
|
2013-01-09 05:30:32 +08:00
|
|
|
NamedDecl *ND = dyn_cast<NamedDecl>(D);
|
|
|
|
if (!ND) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
AvailabilityChange Introduced = Attr.getAvailabilityIntroduced();
|
|
|
|
AvailabilityChange Deprecated = Attr.getAvailabilityDeprecated();
|
|
|
|
AvailabilityChange Obsoleted = Attr.getAvailabilityObsoleted();
|
|
|
|
bool IsUnavailable = Attr.getUnavailableLoc().isValid();
|
2011-12-10 08:28:41 +08:00
|
|
|
StringRef Str;
|
2013-09-14 01:31:48 +08:00
|
|
|
if (const StringLiteral *SE =
|
|
|
|
dyn_cast_or_null<StringLiteral>(Attr.getMessageExpr()))
|
2011-12-10 08:28:41 +08:00
|
|
|
Str = SE->getString();
|
Split mergeAvailabilityAttr out of handleAvailabilityAttr. This is important
for having a uniform logic for adding attributes to a decl. This in turn
is needed to fix the FIXME:
// FIXME: This needs to happen before we merge declarations. Then,
// let attribute merging cope with attribute conflicts.
ProcessDeclAttributes(S, NewFD, D,
/*NonInheritable=*/false, /*Inheritable=*/true);
The idea is that mergeAvailabilityAttr will become a method. Once attributes
are processed before merging, it will be called from handleAvailabilityAttr to
handle multiple attributes in one decl:
void f(int) __attribute__((availability(ios,deprecated=3.0),
availability(ios,introduced=2.0)));
and from SemaDecl.cpp to handle multiple decls:
void f(int) __attribute__((availability(ios,deprecated=3.0)));
void f(int) __attribute__((availability(ios,introduced=2.0)));
As a bonus, use the new structure to diagnose incompatible availability
attributes added to different decls (see included testcases).
llvm-svn: 156269
2012-05-07 03:56:25 +08:00
|
|
|
|
2013-08-31 09:11:41 +08:00
|
|
|
AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(ND, Attr.getRange(), II,
|
2012-05-13 11:25:18 +08:00
|
|
|
Introduced.Version,
|
|
|
|
Deprecated.Version,
|
|
|
|
Obsoleted.Version,
|
2013-01-16 06:43:08 +08:00
|
|
|
IsUnavailable, Str,
|
2013-01-25 00:46:58 +08:00
|
|
|
/*Override=*/false,
|
|
|
|
Index);
|
2013-01-12 14:42:30 +08:00
|
|
|
if (NewAttr)
|
2012-05-13 11:25:18 +08:00
|
|
|
D->addAttr(NewAttr);
|
2012-05-10 10:50:16 +08:00
|
|
|
}
|
|
|
|
|
2013-02-20 09:54:26 +08:00
|
|
|
template <class T>
|
|
|
|
static T *mergeVisibilityAttr(Sema &S, Decl *D, SourceRange range,
|
|
|
|
typename T::VisibilityType value,
|
|
|
|
unsigned attrSpellingListIndex) {
|
|
|
|
T *existingAttr = D->getAttr<T>();
|
|
|
|
if (existingAttr) {
|
|
|
|
typename T::VisibilityType existingValue = existingAttr->getVisibility();
|
|
|
|
if (existingValue == value)
|
|
|
|
return NULL;
|
|
|
|
S.Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
|
|
|
|
S.Diag(range.getBegin(), diag::note_previous_attribute);
|
|
|
|
D->dropAttr<T>();
|
|
|
|
}
|
|
|
|
return ::new (S.Context) T(range, S.Context, value, attrSpellingListIndex);
|
|
|
|
}
|
|
|
|
|
2012-05-13 11:25:18 +08:00
|
|
|
VisibilityAttr *Sema::mergeVisibilityAttr(Decl *D, SourceRange Range,
|
2013-01-25 00:46:58 +08:00
|
|
|
VisibilityAttr::VisibilityType Vis,
|
|
|
|
unsigned AttrSpellingListIndex) {
|
2013-02-20 09:54:26 +08:00
|
|
|
return ::mergeVisibilityAttr<VisibilityAttr>(*this, D, Range, Vis,
|
|
|
|
AttrSpellingListIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeVisibilityAttr *Sema::mergeTypeVisibilityAttr(Decl *D, SourceRange Range,
|
|
|
|
TypeVisibilityAttr::VisibilityType Vis,
|
|
|
|
unsigned AttrSpellingListIndex) {
|
|
|
|
return ::mergeVisibilityAttr<TypeVisibilityAttr>(*this, D, Range, Vis,
|
|
|
|
AttrSpellingListIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr,
|
|
|
|
bool isTypeVisibility) {
|
|
|
|
// Visibility attributes don't mean anything on a typedef.
|
2012-05-10 11:01:34 +08:00
|
|
|
if (isa<TypedefNameDecl>(D)) {
|
2013-02-20 09:54:26 +08:00
|
|
|
S.Diag(Attr.getRange().getBegin(), diag::warn_attribute_ignored)
|
|
|
|
<< Attr.getName();
|
|
|
|
return;
|
2012-05-10 11:01:34 +08:00
|
|
|
}
|
2013-02-20 09:54:26 +08:00
|
|
|
|
|
|
|
// 'type_visibility' can only go on a type or namespace.
|
|
|
|
if (isTypeVisibility &&
|
|
|
|
!(isa<TagDecl>(D) ||
|
|
|
|
isa<ObjCInterfaceDecl>(D) ||
|
|
|
|
isa<NamespaceDecl>(D))) {
|
|
|
|
S.Diag(Attr.getRange().getBegin(), diag::err_attribute_wrong_decl_type)
|
|
|
|
<< Attr.getName() << ExpectedTypeOrNamespace;
|
|
|
|
return;
|
2012-05-10 10:50:16 +08:00
|
|
|
}
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
|
2013-09-09 23:08:57 +08:00
|
|
|
// Check that the argument is a string literal.
|
2013-09-13 23:35:43 +08:00
|
|
|
StringRef TypeStr;
|
|
|
|
SourceLocation LiteralLoc;
|
2013-10-01 22:34:18 +08:00
|
|
|
if (!S.checkStringLiteralArgumentAttr(Attr, 0, TypeStr, &LiteralLoc))
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2010-08-19 07:23:40 +08:00
|
|
|
VisibilityAttr::VisibilityType type;
|
2013-09-12 03:47:58 +08:00
|
|
|
if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr, type)) {
|
2013-09-13 23:35:43 +08:00
|
|
|
S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported)
|
2013-09-12 03:47:58 +08:00
|
|
|
<< Attr.getName() << TypeStr;
|
|
|
|
return;
|
|
|
|
}
|
2013-01-25 00:46:58 +08:00
|
|
|
|
2013-09-12 03:47:58 +08:00
|
|
|
// Complain about attempts to use protected visibility on targets
|
|
|
|
// (like Darwin) that don't support it.
|
|
|
|
if (type == VisibilityAttr::Protected &&
|
|
|
|
!S.Context.getTargetInfo().hasProtectedVisibility()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_protected_visibility);
|
2010-08-19 07:23:40 +08:00
|
|
|
type = VisibilityAttr::Default;
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
unsigned Index = Attr.getAttributeSpellingListIndex();
|
2013-02-20 09:54:26 +08:00
|
|
|
clang::Attr *newAttr;
|
|
|
|
if (isTypeVisibility) {
|
|
|
|
newAttr = S.mergeTypeVisibilityAttr(D, Attr.getRange(),
|
|
|
|
(TypeVisibilityAttr::VisibilityType) type,
|
|
|
|
Index);
|
|
|
|
} else {
|
|
|
|
newAttr = S.mergeVisibilityAttr(D, Attr.getRange(), type, Index);
|
|
|
|
}
|
|
|
|
if (newAttr)
|
|
|
|
D->addAttr(newAttr);
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleObjCMethodFamilyAttr(Sema &S, Decl *decl,
|
|
|
|
const AttributeList &Attr) {
|
2013-11-27 21:27:02 +08:00
|
|
|
ObjCMethodDecl *method = cast<ObjCMethodDecl>(decl);
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!Attr.isArgIdent(0)) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_type)
|
|
|
|
<< Attr.getName() << 1 << AANT_ArgumentIdentifier;
|
2011-03-02 19:33:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-12 03:47:58 +08:00
|
|
|
IdentifierLoc *IL = Attr.getArgAsIdent(0);
|
|
|
|
ObjCMethodFamilyAttr::FamilyKind F;
|
|
|
|
if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->Ident->getName(), F)) {
|
|
|
|
S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << Attr.getName()
|
|
|
|
<< IL->Ident;
|
2011-03-02 19:33:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-12 03:47:58 +08:00
|
|
|
if (F == ObjCMethodFamilyAttr::OMF_init &&
|
2011-06-16 07:02:42 +08:00
|
|
|
!method->getResultType()->isObjCObjectPointerType()) {
|
|
|
|
S.Diag(method->getLocation(), diag::err_init_method_bad_return_type)
|
|
|
|
<< method->getResultType();
|
|
|
|
// Ignore the attribute.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-14 00:05:58 +08:00
|
|
|
method->addAttr(new (S.Context) ObjCMethodFamilyAttr(Attr.getRange(),
|
2013-09-12 03:47:58 +08:00
|
|
|
S.Context, F));
|
2011-03-02 19:33:24 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleObjCNSObject(Sema &S, Decl *D, const AttributeList &Attr) {
|
2011-04-15 22:24:37 +08:00
|
|
|
if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
|
2009-01-14 07:34:40 +08:00
|
|
|
QualType T = TD->getUnderlyingType();
|
2012-08-30 06:54:47 +08:00
|
|
|
if (!T->isCARCBridgableType()) {
|
2009-01-14 07:34:40 +08:00
|
|
|
S.Diag(TD->getLocation(), diag::err_nsobject_attribute);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-01 07:18:32 +08:00
|
|
|
else if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D)) {
|
|
|
|
QualType T = PD->getType();
|
2012-08-30 06:54:47 +08:00
|
|
|
if (!T->isCARCBridgableType()) {
|
2012-06-01 07:18:32 +08:00
|
|
|
S.Diag(PD->getLocation(), diag::err_nsobject_attribute);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-01 09:40:32 +08:00
|
|
|
// It is okay to include this attribute on properties, e.g.:
|
|
|
|
//
|
|
|
|
// @property (retain, nonatomic) struct Bork *Q __attribute__((NSObject));
|
|
|
|
//
|
|
|
|
// In this case it follows tradition and suppresses an error in the above
|
|
|
|
// case.
|
2011-11-29 09:48:40 +08:00
|
|
|
S.Diag(D->getLocation(), diag::warn_nsobject_attribute);
|
2012-03-01 09:40:32 +08:00
|
|
|
}
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ObjCNSObjectAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-01-14 07:34:40 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleBlocksAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!Attr.isArgIdent(0)) {
|
2013-07-23 22:03:57 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_type)
|
2013-08-31 09:11:41 +08:00
|
|
|
<< Attr.getName() << 1 << AANT_ArgumentIdentifier;
|
2008-09-19 00:44:58 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-08-31 09:11:41 +08:00
|
|
|
IdentifierInfo *II = Attr.getArgAsIdent(0)->Ident;
|
2010-08-19 07:23:40 +08:00
|
|
|
BlocksAttr::BlockType type;
|
2013-09-12 03:47:58 +08:00
|
|
|
if (!BlocksAttr::ConvertStrToBlockType(II->getName(), type)) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported)
|
|
|
|
<< Attr.getName() << II;
|
2008-09-19 00:44:58 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
BlocksAttr(Attr.getRange(), S.Context, type,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-09-19 00:44:58 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleSentinelAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2008-10-06 02:05:59 +08:00
|
|
|
// check the attribute arguments.
|
|
|
|
if (Attr.getNumArgs() > 2) {
|
2011-03-02 20:15:05 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 2;
|
2008-10-06 02:05:59 +08:00
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
}
|
|
|
|
|
2013-11-21 08:28:23 +08:00
|
|
|
unsigned sentinel = (unsigned)SentinelAttr::DefaultSentinel;
|
2008-10-06 02:05:59 +08:00
|
|
|
if (Attr.getNumArgs() > 0) {
|
2013-08-31 09:11:41 +08:00
|
|
|
Expr *E = Attr.getArgAsExpr(0);
|
2008-10-06 02:05:59 +08:00
|
|
|
llvm::APSInt Idx(32);
|
2010-05-19 07:01:22 +08:00
|
|
|
if (E->isTypeDependent() || E->isValueDependent() ||
|
|
|
|
!E->isIntegerConstantExpr(Idx, S.Context)) {
|
2013-07-23 22:03:57 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_type)
|
2013-07-30 09:31:03 +08:00
|
|
|
<< Attr.getName() << 1 << AANT_ArgumentIntegerConstant
|
2013-07-23 22:03:57 +08:00
|
|
|
<< E->getSourceRange();
|
2008-10-06 02:05:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2011-09-09 15:56:05 +08:00
|
|
|
if (Idx.isSigned() && Idx.isNegative()) {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_sentinel_less_than_zero)
|
|
|
|
<< E->getSourceRange();
|
2008-10-06 02:05:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-09-09 15:56:05 +08:00
|
|
|
|
|
|
|
sentinel = Idx.getZExtValue();
|
2008-10-06 02:05:59 +08:00
|
|
|
}
|
|
|
|
|
2013-11-21 08:28:23 +08:00
|
|
|
unsigned nullPos = (unsigned)SentinelAttr::DefaultNullPos;
|
2008-10-06 02:05:59 +08:00
|
|
|
if (Attr.getNumArgs() > 1) {
|
2013-08-31 09:11:41 +08:00
|
|
|
Expr *E = Attr.getArgAsExpr(1);
|
2008-10-06 02:05:59 +08:00
|
|
|
llvm::APSInt Idx(32);
|
2010-05-19 07:01:22 +08:00
|
|
|
if (E->isTypeDependent() || E->isValueDependent() ||
|
|
|
|
!E->isIntegerConstantExpr(Idx, S.Context)) {
|
2013-07-23 22:03:57 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_type)
|
2013-07-30 09:31:03 +08:00
|
|
|
<< Attr.getName() << 2 << AANT_ArgumentIntegerConstant
|
2013-07-23 22:03:57 +08:00
|
|
|
<< E->getSourceRange();
|
2008-10-06 02:05:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
nullPos = Idx.getZExtValue();
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2011-09-09 15:56:05 +08:00
|
|
|
if ((Idx.isSigned() && Idx.isNegative()) || nullPos > 1) {
|
2008-10-06 02:05:59 +08:00
|
|
|
// FIXME: This error message could be improved, it would be nice
|
|
|
|
// to say what the bounds actually are.
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
|
|
|
|
<< E->getSourceRange();
|
2008-10-06 02:05:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
2011-09-09 15:56:05 +08:00
|
|
|
const FunctionType *FT = FD->getType()->castAs<FunctionType>();
|
2009-03-18 07:03:47 +08:00
|
|
|
if (isa<FunctionNoProtoType>(FT)) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_named_arguments);
|
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2009-03-18 07:03:47 +08:00
|
|
|
if (!cast<FunctionProtoType>(FT)->isVariadic()) {
|
2009-05-16 05:18:04 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
|
2008-10-06 02:05:59 +08:00
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
}
|
2011-07-02 07:49:12 +08:00
|
|
|
} else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
|
2008-10-06 02:05:59 +08:00
|
|
|
if (!MD->isVariadic()) {
|
2009-05-16 05:18:04 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
|
2008-10-06 02:05:59 +08:00
|
|
|
return;
|
2009-05-15 04:53:39 +08:00
|
|
|
}
|
2012-01-06 09:23:10 +08:00
|
|
|
} else if (BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
|
|
|
|
if (!BD->isVariadic()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
|
|
|
|
return;
|
|
|
|
}
|
2011-07-02 07:49:12 +08:00
|
|
|
} else if (const VarDecl *V = dyn_cast<VarDecl>(D)) {
|
2009-05-15 04:53:39 +08:00
|
|
|
QualType Ty = V->getType();
|
2009-05-16 04:33:25 +08:00
|
|
|
if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) {
|
2011-07-02 07:49:12 +08:00
|
|
|
const FunctionType *FT = Ty->isFunctionPointerType() ? getFunctionType(D)
|
2010-12-02 06:13:54 +08:00
|
|
|
: Ty->getAs<BlockPointerType>()->getPointeeType()->getAs<FunctionType>();
|
2009-05-15 04:53:39 +08:00
|
|
|
if (!cast<FunctionProtoType>(FT)->isVariadic()) {
|
2009-05-16 05:18:04 +08:00
|
|
|
int m = Ty->isFunctionPointerType() ? 0 : 1;
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
|
2009-05-15 04:53:39 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-08-05 05:02:39 +08:00
|
|
|
} else {
|
2009-05-15 04:53:39 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< Attr.getName() << ExpectedFunctionMethodOrBlock;
|
2009-05-15 04:53:39 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-10-06 02:05:59 +08:00
|
|
|
} else {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< Attr.getName() << ExpectedFunctionMethodOrBlock;
|
2008-10-06 02:05:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
SentinelAttr(Attr.getRange(), S.Context, sentinel, nullPos,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-10-06 02:05:59 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleWarnUnusedResult(Sema &S, Decl *D, const AttributeList &Attr) {
|
2012-11-13 07:48:05 +08:00
|
|
|
if (!isFunction(D) && !isa<ObjCMethodDecl>(D) && !isa<CXXRecordDecl>(D)) {
|
2009-02-14 15:37:35 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2012-11-13 08:18:47 +08:00
|
|
|
<< Attr.getName() << ExpectedFunctionMethodOrClass;
|
2009-02-14 15:37:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2010-03-31 02:22:15 +08:00
|
|
|
if (isFunction(D) && getFunctionType(D)->getResultType()->isVoidType()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_void_function_method)
|
|
|
|
<< Attr.getName() << 0;
|
2009-12-23 07:59:52 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-03-31 02:22:15 +08:00
|
|
|
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
|
|
|
|
if (MD->getResultType()->isVoidType()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_void_function_method)
|
|
|
|
<< Attr.getName() << 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
WarnUnusedResultAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-02-14 15:37:35 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleWeakImportAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2009-03-06 14:39:57 +08:00
|
|
|
// weak_import only applies to variable & function declarations.
|
|
|
|
bool isDef = false;
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
if (!D->canBeWeakImported(isDef)) {
|
|
|
|
if (isDef)
|
2013-05-21 05:53:29 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_invalid_on_definition)
|
|
|
|
<< "weak_import";
|
2011-03-23 21:27:51 +08:00
|
|
|
else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) ||
|
2011-09-02 08:18:52 +08:00
|
|
|
(S.Context.getTargetInfo().getTriple().isOSDarwin() &&
|
2011-10-27 07:59:12 +08:00
|
|
|
(isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) {
|
2011-03-23 21:27:51 +08:00
|
|
|
// Nothing to warn about here.
|
|
|
|
} else
|
2010-04-14 04:22:35 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< Attr.getName() << ExpectedVariableOrFunction;
|
2009-03-06 14:39:57 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
WeakImportAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-03-06 14:39:57 +08:00
|
|
|
}
|
|
|
|
|
2012-07-10 06:06:01 +08:00
|
|
|
// Handles reqd_work_group_size and work_group_size_hint.
|
2013-12-03 06:38:33 +08:00
|
|
|
template <typename WorkGroupAttr>
|
2012-07-10 06:06:01 +08:00
|
|
|
static void handleWorkGroupSize(Sema &S, Decl *D,
|
2012-07-24 09:31:55 +08:00
|
|
|
const AttributeList &Attr) {
|
2013-11-21 09:50:40 +08:00
|
|
|
uint32_t WGSize[3];
|
|
|
|
for (unsigned i = 0; i < 3; ++i)
|
|
|
|
if (!checkUInt32Argument(S, Attr, Attr.getArgAsExpr(i), WGSize[i], i))
|
2009-06-26 14:32:41 +08:00
|
|
|
return;
|
2012-07-10 06:06:01 +08:00
|
|
|
|
2013-12-03 06:38:33 +08:00
|
|
|
WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>();
|
|
|
|
if (Existing && !(Existing->getXDim() == WGSize[0] &&
|
|
|
|
Existing->getYDim() == WGSize[1] &&
|
|
|
|
Existing->getZDim() == WGSize[2]))
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_duplicate_attribute) << Attr.getName();
|
2012-07-10 06:06:01 +08:00
|
|
|
|
2013-12-03 06:38:33 +08:00
|
|
|
D->addAttr(::new (S.Context) WorkGroupAttr(Attr.getRange(), S.Context,
|
|
|
|
WGSize[0], WGSize[1], WGSize[2],
|
2013-01-25 00:46:58 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-06-26 14:32:41 +08:00
|
|
|
}
|
|
|
|
|
2013-03-08 17:42:32 +08:00
|
|
|
static void handleVecTypeHint(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!Attr.hasParsedType()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
|
|
|
|
<< Attr.getName() << 1;
|
2013-03-08 17:42:32 +08:00
|
|
|
return;
|
2013-08-31 09:11:41 +08:00
|
|
|
}
|
2013-03-08 17:42:32 +08:00
|
|
|
|
2013-11-01 05:23:20 +08:00
|
|
|
TypeSourceInfo *ParmTSI = 0;
|
|
|
|
QualType ParmType = S.GetTypeFromParser(Attr.getTypeArg(), &ParmTSI);
|
|
|
|
assert(ParmTSI && "no type source info for attribute argument");
|
2013-03-08 17:42:32 +08:00
|
|
|
|
|
|
|
if (!ParmType->isExtVectorType() && !ParmType->isFloatingType() &&
|
|
|
|
(ParmType->isBooleanType() ||
|
|
|
|
!ParmType->isIntegralType(S.getASTContext()))) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_vec_type_hint)
|
|
|
|
<< ParmType;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-03 06:16:55 +08:00
|
|
|
if (VecTypeHintAttr *A = D->getAttr<VecTypeHintAttr>()) {
|
2013-11-01 05:23:20 +08:00
|
|
|
if (!S.Context.hasSameType(A->getTypeHint(), ParmType)) {
|
2013-03-08 17:42:32 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_duplicate_attribute) << Attr.getName();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
D->addAttr(::new (S.Context) VecTypeHintAttr(Attr.getLoc(), S.Context,
|
2013-11-01 05:23:20 +08:00
|
|
|
ParmTSI));
|
2013-03-08 17:42:32 +08:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:25:18 +08:00
|
|
|
SectionAttr *Sema::mergeSectionAttr(Decl *D, SourceRange Range,
|
2013-01-25 00:46:58 +08:00
|
|
|
StringRef Name,
|
|
|
|
unsigned AttrSpellingListIndex) {
|
2012-05-13 10:42:42 +08:00
|
|
|
if (SectionAttr *ExistingAttr = D->getAttr<SectionAttr>()) {
|
|
|
|
if (ExistingAttr->getName() == Name)
|
2012-05-13 11:25:18 +08:00
|
|
|
return NULL;
|
2012-05-13 10:42:42 +08:00
|
|
|
Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section);
|
|
|
|
Diag(Range.getBegin(), diag::note_previous_attribute);
|
2012-05-13 11:25:18 +08:00
|
|
|
return NULL;
|
2012-05-13 10:42:42 +08:00
|
|
|
}
|
2013-01-25 00:46:58 +08:00
|
|
|
return ::new (Context) SectionAttr(Range, Context, Name,
|
|
|
|
AttrSpellingListIndex);
|
2012-05-13 10:42:42 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleSectionAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2009-02-13 01:28:23 +08:00
|
|
|
// Make sure that there is a string literal as the sections's single
|
|
|
|
// argument.
|
2013-09-13 23:35:43 +08:00
|
|
|
StringRef Str;
|
|
|
|
SourceLocation LiteralLoc;
|
2013-10-01 22:34:18 +08:00
|
|
|
if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str, &LiteralLoc))
|
2009-02-13 01:28:23 +08:00
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-11 03:03:04 +08:00
|
|
|
// If the target wants to validate the section specifier, make it happen.
|
2013-09-13 23:35:43 +08:00
|
|
|
std::string Error = S.Context.getTargetInfo().isValidSectionSpecifier(Str);
|
2010-01-13 04:58:53 +08:00
|
|
|
if (!Error.empty()) {
|
2013-09-13 23:35:43 +08:00
|
|
|
S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
|
2010-01-13 04:58:53 +08:00
|
|
|
<< Error;
|
2009-08-11 03:03:04 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
unsigned Index = Attr.getAttributeSpellingListIndex();
|
2013-09-13 23:35:43 +08:00
|
|
|
SectionAttr *NewAttr = S.mergeSectionAttr(D, Attr.getRange(), Str, Index);
|
2012-05-13 11:25:18 +08:00
|
|
|
if (NewAttr)
|
|
|
|
D->addAttr(NewAttr);
|
2009-02-13 01:28:23 +08:00
|
|
|
}
|
|
|
|
|
2008-06-27 02:38:35 +08:00
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleCleanupAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-11-27 21:27:02 +08:00
|
|
|
VarDecl *VD = cast<VarDecl>(D);
|
|
|
|
if (!VD->hasLocalStorage()) {
|
2013-09-11 09:37:41 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
|
2009-01-31 09:16:18 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-09-11 09:37:41 +08:00
|
|
|
Expr *E = Attr.getArgAsExpr(0);
|
|
|
|
SourceLocation Loc = E->getExprLoc();
|
|
|
|
FunctionDecl *FD = 0;
|
|
|
|
DeclarationNameInfo NI;
|
2013-08-31 09:11:41 +08:00
|
|
|
|
2013-09-11 09:37:41 +08:00
|
|
|
// gcc only allows for simple identifiers. Since we support more than gcc, we
|
|
|
|
// will warn the user.
|
|
|
|
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
|
|
|
|
if (DRE->hasQualifier())
|
|
|
|
S.Diag(Loc, diag::warn_cleanup_ext);
|
|
|
|
FD = dyn_cast<FunctionDecl>(DRE->getDecl());
|
|
|
|
NI = DRE->getNameInfo();
|
|
|
|
if (!FD) {
|
|
|
|
S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
|
|
|
|
<< NI.getName();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
|
|
|
|
if (ULE->hasExplicitTemplateArgs())
|
|
|
|
S.Diag(Loc, diag::warn_cleanup_ext);
|
|
|
|
FD = S.ResolveSingleFunctionTemplateSpecialization(ULE, true);
|
|
|
|
NI = ULE->getNameInfo();
|
2013-10-21 02:48:56 +08:00
|
|
|
if (!FD) {
|
|
|
|
S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
|
|
|
|
<< NI.getName();
|
|
|
|
if (ULE->getType() == S.Context.OverloadTy)
|
|
|
|
S.NoteAllOverloadCandidates(ULE);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-11 09:37:41 +08:00
|
|
|
} else {
|
|
|
|
S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
|
2009-01-31 09:16:18 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FD->getNumParams() != 1) {
|
2013-09-11 09:37:41 +08:00
|
|
|
S.Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
|
|
|
|
<< NI.getName();
|
2009-01-31 09:16:18 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2009-02-08 07:16:50 +08:00
|
|
|
// We're currently more strict than GCC about what function types we accept.
|
|
|
|
// If this ever proves to be a problem it should be easy to fix.
|
|
|
|
QualType Ty = S.Context.getPointerType(VD->getType());
|
|
|
|
QualType ParamTy = FD->getParamDecl(0)->getType();
|
2011-01-28 10:26:04 +08:00
|
|
|
if (S.CheckAssignmentConstraints(FD->getParamDecl(0)->getLocation(),
|
|
|
|
ParamTy, Ty) != Sema::Compatible) {
|
2013-09-11 09:37:41 +08:00
|
|
|
S.Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
|
|
|
|
<< NI.getName() << ParamTy << Ty;
|
2009-02-08 07:16:50 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
CleanupAttr(Attr.getRange(), S.Context, FD,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-01-31 09:16:18 +08:00
|
|
|
}
|
|
|
|
|
2009-07-25 03:02:52 +08:00
|
|
|
/// Handle __attribute__((format_arg((idx)))) attribute based on
|
2012-12-21 03:22:21 +08:00
|
|
|
/// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleFormatArgAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2011-07-02 07:49:12 +08:00
|
|
|
if (!isFunctionOrMethod(D) || !hasFunctionProto(D)) {
|
2009-05-21 01:41:43 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< Attr.getName() << ExpectedFunction;
|
2009-05-21 01:41:43 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-11-16 16:35:43 +08:00
|
|
|
|
2013-08-31 09:11:41 +08:00
|
|
|
Expr *IdxExpr = Attr.getArgAsExpr(0);
|
2013-07-30 08:48:57 +08:00
|
|
|
uint64_t ArgIdx;
|
|
|
|
if (!checkFunctionOrMethodArgumentIndex(S, D, Attr.getName()->getName(),
|
|
|
|
Attr.getLoc(), 1, IdxExpr, ArgIdx))
|
2009-05-21 01:41:43 +08:00
|
|
|
return;
|
2010-11-16 16:35:43 +08:00
|
|
|
|
2009-05-21 01:41:43 +08:00
|
|
|
// make sure the format string is really a string
|
2011-07-02 07:49:12 +08:00
|
|
|
QualType Ty = getFunctionOrMethodArgType(D, ArgIdx);
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2009-05-21 01:41:43 +08:00
|
|
|
bool not_nsstring_type = !isNSStringType(Ty, S.Context);
|
|
|
|
if (not_nsstring_type &&
|
|
|
|
!isCFStringType(Ty, S.Context) &&
|
|
|
|
(!Ty->isPointerType() ||
|
2009-07-30 05:53:49 +08:00
|
|
|
!Ty->getAs<PointerType>()->getPointeeType()->isCharType())) {
|
2009-05-21 01:41:43 +08:00
|
|
|
// FIXME: Should highlight the actual expression that has the wrong type.
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_format_attribute_not)
|
2009-07-25 03:02:52 +08:00
|
|
|
<< (not_nsstring_type ? "a string type" : "an NSString")
|
2009-05-21 01:41:43 +08:00
|
|
|
<< IdxExpr->getSourceRange();
|
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
}
|
2011-07-02 07:49:12 +08:00
|
|
|
Ty = getFunctionOrMethodResultType(D);
|
2009-05-21 01:41:43 +08:00
|
|
|
if (!isNSStringType(Ty, S.Context) &&
|
|
|
|
!isCFStringType(Ty, S.Context) &&
|
|
|
|
(!Ty->isPointerType() ||
|
2009-07-30 05:53:49 +08:00
|
|
|
!Ty->getAs<PointerType>()->getPointeeType()->isCharType())) {
|
2009-05-21 01:41:43 +08:00
|
|
|
// FIXME: Should highlight the actual expression that has the wrong type.
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_format_attribute_result_not)
|
2009-07-25 03:02:52 +08:00
|
|
|
<< (not_nsstring_type ? "string type" : "NSString")
|
2009-05-21 01:41:43 +08:00
|
|
|
<< IdxExpr->getSourceRange();
|
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-30 08:48:57 +08:00
|
|
|
// We cannot use the ArgIdx returned from checkFunctionOrMethodArgumentIndex
|
|
|
|
// because that has corrected for the implicit this parameter, and is zero-
|
|
|
|
// based. The attribute expects what the user wrote explicitly.
|
|
|
|
llvm::APSInt Val;
|
|
|
|
IdxExpr->EvaluateAsInt(Val, S.Context);
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
2013-07-30 08:48:57 +08:00
|
|
|
FormatArgAttr(Attr.getRange(), S.Context, Val.getZExtValue(),
|
2013-01-25 00:46:58 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-05-21 01:41:43 +08:00
|
|
|
}
|
|
|
|
|
2009-10-18 10:09:17 +08:00
|
|
|
enum FormatAttrKind {
|
|
|
|
CFStringFormat,
|
|
|
|
NSStringFormat,
|
|
|
|
StrftimeFormat,
|
|
|
|
SupportedFormat,
|
2010-03-23 05:08:50 +08:00
|
|
|
IgnoredFormat,
|
2009-10-18 10:09:17 +08:00
|
|
|
InvalidFormat
|
|
|
|
};
|
|
|
|
|
|
|
|
/// getFormatAttrKind - Map from format attribute names to supported format
|
|
|
|
/// types.
|
2011-07-23 18:55:15 +08:00
|
|
|
static FormatAttrKind getFormatAttrKind(StringRef Format) {
|
2012-05-16 20:44:25 +08:00
|
|
|
return llvm::StringSwitch<FormatAttrKind>(Format)
|
|
|
|
// Check for formats that get handled specially.
|
|
|
|
.Case("NSString", NSStringFormat)
|
|
|
|
.Case("CFString", CFStringFormat)
|
|
|
|
.Case("strftime", StrftimeFormat)
|
|
|
|
|
|
|
|
// Otherwise, check for supported formats.
|
|
|
|
.Cases("scanf", "printf", "printf0", "strfmon", SupportedFormat)
|
|
|
|
.Cases("cmn_err", "vcmn_err", "zcmn_err", SupportedFormat)
|
|
|
|
.Case("kprintf", SupportedFormat) // OpenBSD.
|
|
|
|
|
|
|
|
.Cases("gcc_diag", "gcc_cdiag", "gcc_cxxdiag", "gcc_tdiag", IgnoredFormat)
|
|
|
|
.Default(InvalidFormat);
|
2009-10-18 10:09:17 +08:00
|
|
|
}
|
|
|
|
|
2010-06-19 05:44:06 +08:00
|
|
|
/// Handle __attribute__((init_priority(priority))) attributes based on
|
2012-12-21 03:22:21 +08:00
|
|
|
/// http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleInitPriorityAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!S.getLangOpts().CPlusPlus) {
|
2010-06-19 05:44:06 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-28 00:34:09 +08:00
|
|
|
if (S.getCurFunctionOrMethodDecl()) {
|
2010-06-19 07:14:53 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_init_priority_object_attr);
|
|
|
|
Attr.setInvalid();
|
|
|
|
return;
|
|
|
|
}
|
2013-11-28 00:34:09 +08:00
|
|
|
QualType T = cast<VarDecl>(D)->getType();
|
2010-06-19 07:14:53 +08:00
|
|
|
if (S.Context.getAsArrayType(T))
|
|
|
|
T = S.Context.getBaseElementType(T);
|
|
|
|
if (!T->getAs<RecordType>()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_init_priority_object_attr);
|
|
|
|
Attr.setInvalid();
|
|
|
|
return;
|
|
|
|
}
|
2013-11-21 09:50:40 +08:00
|
|
|
|
|
|
|
Expr *E = Attr.getArgAsExpr(0);
|
|
|
|
uint32_t prioritynum;
|
|
|
|
if (!checkUInt32Argument(S, Attr, E, prioritynum)) {
|
2010-06-19 05:44:06 +08:00
|
|
|
Attr.setInvalid();
|
|
|
|
return;
|
|
|
|
}
|
2013-11-21 09:50:40 +08:00
|
|
|
|
2010-06-19 05:44:06 +08:00
|
|
|
if (prioritynum < 101 || prioritynum > 65535) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_outof_range)
|
2013-11-21 09:50:40 +08:00
|
|
|
<< E->getSourceRange();
|
2010-06-19 05:44:06 +08:00
|
|
|
Attr.setInvalid();
|
|
|
|
return;
|
|
|
|
}
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
InitPriorityAttr(Attr.getRange(), S.Context, prioritynum,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-06-19 05:44:06 +08:00
|
|
|
}
|
|
|
|
|
2013-09-04 05:02:22 +08:00
|
|
|
FormatAttr *Sema::mergeFormatAttr(Decl *D, SourceRange Range,
|
|
|
|
IdentifierInfo *Format, int FormatIdx,
|
|
|
|
int FirstArg,
|
2013-01-25 00:46:58 +08:00
|
|
|
unsigned AttrSpellingListIndex) {
|
2012-05-11 08:36:07 +08:00
|
|
|
// Check whether we already have an equivalent format attribute.
|
|
|
|
for (specific_attr_iterator<FormatAttr>
|
|
|
|
i = D->specific_attr_begin<FormatAttr>(),
|
|
|
|
e = D->specific_attr_end<FormatAttr>();
|
|
|
|
i != e ; ++i) {
|
|
|
|
FormatAttr *f = *i;
|
|
|
|
if (f->getType() == Format &&
|
|
|
|
f->getFormatIdx() == FormatIdx &&
|
|
|
|
f->getFirstArg() == FirstArg) {
|
|
|
|
// If we don't have a valid location for this attribute, adopt the
|
|
|
|
// location.
|
|
|
|
if (f->getLocation().isInvalid())
|
|
|
|
f->setRange(Range);
|
2012-05-13 11:25:18 +08:00
|
|
|
return NULL;
|
2012-05-11 08:36:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:02:22 +08:00
|
|
|
return ::new (Context) FormatAttr(Range, Context, Format, FormatIdx,
|
|
|
|
FirstArg, AttrSpellingListIndex);
|
2012-05-11 08:36:07 +08:00
|
|
|
}
|
|
|
|
|
2009-07-25 03:02:52 +08:00
|
|
|
/// Handle __attribute__((format(type,idx,firstarg))) attributes based on
|
2012-12-21 03:22:21 +08:00
|
|
|
/// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleFormatAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!Attr.isArgIdent(0)) {
|
2013-07-23 22:03:57 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_type)
|
2013-08-31 09:11:41 +08:00
|
|
|
<< Attr.getName() << 1 << AANT_ArgumentIdentifier;
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
if (!isFunctionOrMethodOrBlock(D) || !hasFunctionProto(D)) {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< Attr.getName() << ExpectedFunction;
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-16 16:35:43 +08:00
|
|
|
// In C++ the implicit 'this' function parameter also counts, and they are
|
|
|
|
// counted from one.
|
2011-07-02 07:49:12 +08:00
|
|
|
bool HasImplicitThisParam = isInstanceMethod(D);
|
|
|
|
unsigned NumArgs = getFunctionOrMethodNumArgs(D) + HasImplicitThisParam;
|
2008-06-27 02:38:35 +08:00
|
|
|
|
2013-08-31 09:11:41 +08:00
|
|
|
IdentifierInfo *II = Attr.getArgAsIdent(0)->Ident;
|
|
|
|
StringRef Format = II->getName();
|
2008-06-27 02:38:35 +08:00
|
|
|
|
|
|
|
// Normalize the argument, __foo__ becomes foo.
|
2013-09-04 05:02:22 +08:00
|
|
|
if (Format.startswith("__") && Format.endswith("__")) {
|
2009-10-18 10:09:17 +08:00
|
|
|
Format = Format.substr(2, Format.size() - 4);
|
2013-09-04 05:02:22 +08:00
|
|
|
// If we've modified the string name, we need a new identifier for it.
|
|
|
|
II = &S.Context.Idents.get(Format);
|
|
|
|
}
|
2009-10-18 10:09:17 +08:00
|
|
|
|
|
|
|
// Check for supported formats.
|
|
|
|
FormatAttrKind Kind = getFormatAttrKind(Format);
|
2010-03-23 05:08:50 +08:00
|
|
|
|
|
|
|
if (Kind == IgnoredFormat)
|
|
|
|
return;
|
|
|
|
|
2009-10-18 10:09:17 +08:00
|
|
|
if (Kind == InvalidFormat) {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported)
|
2013-08-31 09:11:41 +08:00
|
|
|
<< "format" << II->getName();
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// checks for the 2nd argument
|
2013-08-31 09:11:41 +08:00
|
|
|
Expr *IdxExpr = Attr.getArgAsExpr(1);
|
2013-11-21 09:50:40 +08:00
|
|
|
uint32_t Idx;
|
|
|
|
if (!checkUInt32Argument(S, Attr, IdxExpr, Idx, 2))
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
|
2013-11-21 09:50:40 +08:00
|
|
|
if (Idx < 1 || Idx > NumArgs) {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds)
|
2008-11-19 16:23:25 +08:00
|
|
|
<< "format" << 2 << IdxExpr->getSourceRange();
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Do we need to bounds check?
|
2013-11-21 09:50:40 +08:00
|
|
|
unsigned ArgIdx = Idx - 1;
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2009-11-18 02:02:24 +08:00
|
|
|
if (HasImplicitThisParam) {
|
|
|
|
if (ArgIdx == 0) {
|
2010-11-16 16:35:43 +08:00
|
|
|
S.Diag(Attr.getLoc(),
|
|
|
|
diag::err_format_attribute_implicit_this_format_string)
|
|
|
|
<< IdxExpr->getSourceRange();
|
2009-11-18 02:02:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ArgIdx--;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-06-27 02:38:35 +08:00
|
|
|
// make sure the format string is really a string
|
2011-07-02 07:49:12 +08:00
|
|
|
QualType Ty = getFunctionOrMethodArgType(D, ArgIdx);
|
2008-06-27 02:38:35 +08:00
|
|
|
|
2009-10-18 10:09:17 +08:00
|
|
|
if (Kind == CFStringFormat) {
|
2008-09-26 11:32:58 +08:00
|
|
|
if (!isCFStringType(Ty, S.Context)) {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_format_attribute_not)
|
|
|
|
<< "a CFString" << IdxExpr->getSourceRange();
|
2008-09-26 11:32:58 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-10-18 10:09:17 +08:00
|
|
|
} else if (Kind == NSStringFormat) {
|
2009-05-16 15:39:55 +08:00
|
|
|
// FIXME: do we need to check if the type is NSString*? What are the
|
|
|
|
// semantics?
|
2008-06-29 08:43:07 +08:00
|
|
|
if (!isNSStringType(Ty, S.Context)) {
|
2009-05-16 15:39:55 +08:00
|
|
|
// FIXME: Should highlight the actual expression that has the wrong type.
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_format_attribute_not)
|
|
|
|
<< "an NSString" << IdxExpr->getSourceRange();
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
2009-07-25 03:02:52 +08:00
|
|
|
}
|
2008-06-27 02:38:35 +08:00
|
|
|
} else if (!Ty->isPointerType() ||
|
2009-07-30 05:53:49 +08:00
|
|
|
!Ty->getAs<PointerType>()->getPointeeType()->isCharType()) {
|
2009-05-16 15:39:55 +08:00
|
|
|
// FIXME: Should highlight the actual expression that has the wrong type.
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_format_attribute_not)
|
|
|
|
<< "a string type" << IdxExpr->getSourceRange();
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the 3rd argument
|
2013-08-31 09:11:41 +08:00
|
|
|
Expr *FirstArgExpr = Attr.getArgAsExpr(2);
|
2013-11-21 09:50:40 +08:00
|
|
|
uint32_t FirstArg;
|
|
|
|
if (!checkUInt32Argument(S, Attr, FirstArgExpr, FirstArg, 3))
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// check if the function is variadic if the 3rd argument non-zero
|
|
|
|
if (FirstArg != 0) {
|
2011-07-02 07:49:12 +08:00
|
|
|
if (isFunctionOrMethodVariadic(D)) {
|
2008-06-27 02:38:35 +08:00
|
|
|
++NumArgs; // +1 for ...
|
|
|
|
} else {
|
2011-07-02 07:49:12 +08:00
|
|
|
S.Diag(D->getLocation(), diag::err_format_attribute_requires_variadic);
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-19 16:23:25 +08:00
|
|
|
// strftime requires FirstArg to be 0 because it doesn't read from any
|
|
|
|
// variable the input is just the current time + the format string.
|
2009-10-18 10:09:17 +08:00
|
|
|
if (Kind == StrftimeFormat) {
|
2008-06-27 02:38:35 +08:00
|
|
|
if (FirstArg != 0) {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_format_strftime_third_parameter)
|
|
|
|
<< FirstArgExpr->getSourceRange();
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// if 0 it disables parameter checking (to use with e.g. va_list)
|
|
|
|
} else if (FirstArg != 0 && FirstArg != NumArgs) {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds)
|
2008-11-19 16:23:25 +08:00
|
|
|
<< "format" << 3 << FirstArgExpr->getSourceRange();
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:02:22 +08:00
|
|
|
FormatAttr *NewAttr = S.mergeFormatAttr(D, Attr.getRange(), II,
|
2013-11-21 09:50:40 +08:00
|
|
|
Idx, FirstArg,
|
2013-01-25 00:46:58 +08:00
|
|
|
Attr.getAttributeSpellingListIndex());
|
2012-05-13 11:25:18 +08:00
|
|
|
if (NewAttr)
|
|
|
|
D->addAttr(NewAttr);
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleTransparentUnionAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2009-04-30 06:16:16 +08:00
|
|
|
// Try to find the underlying union declaration.
|
|
|
|
RecordDecl *RD = 0;
|
2011-07-02 07:49:12 +08:00
|
|
|
TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D);
|
2009-04-30 06:16:16 +08:00
|
|
|
if (TD && TD->getUnderlyingType()->isUnionType())
|
|
|
|
RD = TD->getUnderlyingType()->getAsUnionType()->getDecl();
|
|
|
|
else
|
2011-07-02 07:49:12 +08:00
|
|
|
RD = dyn_cast<RecordDecl>(D);
|
2009-04-30 06:16:16 +08:00
|
|
|
|
|
|
|
if (!RD || !RD->isUnion()) {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
2011-03-02 20:29:23 +08:00
|
|
|
<< Attr.getName() << ExpectedUnion;
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-07 14:10:15 +08:00
|
|
|
if (!RD->isCompleteDefinition()) {
|
2009-07-25 03:02:52 +08:00
|
|
|
S.Diag(Attr.getLoc(),
|
2009-04-30 06:16:16 +08:00
|
|
|
diag::warn_transparent_union_attribute_not_definition);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-30 10:36:12 +08:00
|
|
|
RecordDecl::field_iterator Field = RD->field_begin(),
|
|
|
|
FieldEnd = RD->field_end();
|
2009-04-30 06:16:16 +08:00
|
|
|
if (Field == FieldEnd) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_transparent_union_attribute_zero_fields);
|
|
|
|
return;
|
|
|
|
}
|
2008-09-02 13:19:23 +08:00
|
|
|
|
2012-06-07 04:45:41 +08:00
|
|
|
FieldDecl *FirstField = *Field;
|
2009-04-30 06:16:16 +08:00
|
|
|
QualType FirstType = FirstField->getType();
|
2010-07-01 01:24:13 +08:00
|
|
|
if (FirstType->hasFloatingRepresentation() || FirstType->isVectorType()) {
|
2009-07-25 03:02:52 +08:00
|
|
|
S.Diag(FirstField->getLocation(),
|
2010-07-01 01:24:13 +08:00
|
|
|
diag::warn_transparent_union_attribute_floating)
|
|
|
|
<< FirstType->isVectorType() << FirstType;
|
2009-04-30 06:16:16 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-09-02 13:19:23 +08:00
|
|
|
|
2009-04-30 06:16:16 +08:00
|
|
|
uint64_t FirstSize = S.Context.getTypeSize(FirstType);
|
|
|
|
uint64_t FirstAlign = S.Context.getTypeAlign(FirstType);
|
|
|
|
for (; Field != FieldEnd; ++Field) {
|
|
|
|
QualType FieldType = Field->getType();
|
|
|
|
if (S.Context.getTypeSize(FieldType) != FirstSize ||
|
|
|
|
S.Context.getTypeAlign(FieldType) != FirstAlign) {
|
|
|
|
// Warn if we drop the attribute.
|
|
|
|
bool isSize = S.Context.getTypeSize(FieldType) != FirstSize;
|
2009-07-25 03:02:52 +08:00
|
|
|
unsigned FieldBits = isSize? S.Context.getTypeSize(FieldType)
|
2009-04-30 06:16:16 +08:00
|
|
|
: S.Context.getTypeAlign(FieldType);
|
2009-07-25 03:02:52 +08:00
|
|
|
S.Diag(Field->getLocation(),
|
2009-04-30 06:16:16 +08:00
|
|
|
diag::warn_transparent_union_attribute_field_size_align)
|
|
|
|
<< isSize << Field->getDeclName() << FieldBits;
|
|
|
|
unsigned FirstBits = isSize? FirstSize : FirstAlign;
|
2009-07-25 03:02:52 +08:00
|
|
|
S.Diag(FirstField->getLocation(),
|
2009-04-30 06:16:16 +08:00
|
|
|
diag::note_transparent_union_first_field_size_align)
|
|
|
|
<< isSize << FirstBits;
|
2008-09-02 13:19:23 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-06-27 02:38:35 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
RD->addAttr(::new (S.Context)
|
|
|
|
TransparentUnionAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleAnnotateAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2008-06-27 02:38:35 +08:00
|
|
|
// Make sure that there is a string literal as the annotation's single
|
|
|
|
// argument.
|
2013-09-13 23:35:43 +08:00
|
|
|
StringRef Str;
|
2013-10-01 22:34:18 +08:00
|
|
|
if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str))
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
2011-09-10 06:41:49 +08:00
|
|
|
|
|
|
|
// Don't duplicate annotations that are already set.
|
|
|
|
for (specific_attr_iterator<AnnotateAttr>
|
|
|
|
i = D->specific_attr_begin<AnnotateAttr>(),
|
|
|
|
e = D->specific_attr_end<AnnotateAttr>(); i != e; ++i) {
|
2013-09-13 23:35:43 +08:00
|
|
|
if ((*i)->getAnnotation() == Str)
|
|
|
|
return;
|
2011-09-10 06:41:49 +08:00
|
|
|
}
|
2013-01-25 00:46:58 +08:00
|
|
|
|
|
|
|
D->addAttr(::new (S.Context)
|
2013-09-13 23:35:43 +08:00
|
|
|
AnnotateAttr(Attr.getRange(), S.Context, Str,
|
2013-01-25 00:46:58 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleAlignedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2008-06-27 02:38:35 +08:00
|
|
|
// check the attribute arguments.
|
2008-06-29 07:36:30 +08:00
|
|
|
if (Attr.getNumArgs() > 1) {
|
2013-07-24 03:30:11 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
|
|
|
|
<< Attr.getName() << 1;
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-06-20 06:09:27 +08:00
|
|
|
|
2013-02-01 16:12:08 +08:00
|
|
|
if (Attr.getNumArgs() == 0) {
|
|
|
|
D->addAttr(::new (S.Context) AlignedAttr(Attr.getRange(), S.Context,
|
|
|
|
true, 0, Attr.getAttributeSpellingListIndex()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-31 09:11:41 +08:00
|
|
|
Expr *E = Attr.getArgAsExpr(0);
|
2013-02-22 16:32:16 +08:00
|
|
|
if (Attr.isPackExpansion() && !E->containsUnexpandedParameterPack()) {
|
|
|
|
S.Diag(Attr.getEllipsisLoc(),
|
|
|
|
diag::err_pack_expansion_without_parameter_packs);
|
|
|
|
return;
|
|
|
|
}
|
2013-02-01 16:12:08 +08:00
|
|
|
|
2013-02-22 16:32:16 +08:00
|
|
|
if (!Attr.isPackExpansion() && S.DiagnoseUnexpandedParameterPack(E))
|
2013-02-01 16:12:08 +08:00
|
|
|
return;
|
|
|
|
|
2013-02-22 16:32:16 +08:00
|
|
|
S.AddAlignedAttr(Attr.getRange(), D, E, Attr.getAttributeSpellingListIndex(),
|
|
|
|
Attr.isPackExpansion());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
|
|
|
|
unsigned SpellingListIndex, bool IsPackExpansion) {
|
2013-02-01 16:12:08 +08:00
|
|
|
AlignedAttr TmpAttr(AttrRange, Context, true, E, SpellingListIndex);
|
|
|
|
SourceLocation AttrLoc = AttrRange.getBegin();
|
|
|
|
|
2013-01-29 17:02:09 +08:00
|
|
|
// C++11 alignas(...) and C11 _Alignas(...) have additional requirements.
|
2013-02-01 16:12:08 +08:00
|
|
|
if (TmpAttr.isAlignas()) {
|
2013-01-29 17:02:09 +08:00
|
|
|
// C++11 [dcl.align]p1:
|
|
|
|
// An alignment-specifier may be applied to a variable or to a class
|
|
|
|
// data member, but it shall not be applied to a bit-field, a function
|
|
|
|
// parameter, the formal parameter of a catch clause, or a variable
|
|
|
|
// declared with the register storage class specifier. An
|
|
|
|
// alignment-specifier may also be applied to the declaration of a class
|
|
|
|
// or enumeration type.
|
|
|
|
// C11 6.7.5/2:
|
|
|
|
// An alignment attribute shall not be specified in a declaration of
|
|
|
|
// a typedef, or a bit-field, or a function, or a parameter, or an
|
|
|
|
// object declared with the register storage-class specifier.
|
|
|
|
int DiagKind = -1;
|
|
|
|
if (isa<ParmVarDecl>(D)) {
|
|
|
|
DiagKind = 0;
|
|
|
|
} else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
|
|
|
if (VD->getStorageClass() == SC_Register)
|
|
|
|
DiagKind = 1;
|
|
|
|
if (VD->isExceptionVariable())
|
|
|
|
DiagKind = 2;
|
|
|
|
} else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
|
|
|
|
if (FD->isBitField())
|
|
|
|
DiagKind = 3;
|
|
|
|
} else if (!isa<TagDecl>(D)) {
|
2013-02-01 16:12:08 +08:00
|
|
|
Diag(AttrLoc, diag::err_attribute_wrong_decl_type)
|
|
|
|
<< (TmpAttr.isC11() ? "'_Alignas'" : "'alignas'")
|
2013-02-01 16:25:07 +08:00
|
|
|
<< (TmpAttr.isC11() ? ExpectedVariableOrField
|
|
|
|
: ExpectedVariableFieldOrTag);
|
2013-01-29 17:02:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (DiagKind != -1) {
|
2013-02-01 16:12:08 +08:00
|
|
|
Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type)
|
2013-02-22 12:55:39 +08:00
|
|
|
<< TmpAttr.isC11() << DiagKind;
|
2013-01-29 17:02:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-25 11:22:07 +08:00
|
|
|
if (E->isTypeDependent() || E->isValueDependent()) {
|
|
|
|
// Save dependent expressions in the AST to be instantiated.
|
2013-02-22 16:32:16 +08:00
|
|
|
AlignedAttr *AA = ::new (Context) AlignedAttr(TmpAttr);
|
|
|
|
AA->setPackExpansion(IsPackExpansion);
|
|
|
|
D->addAttr(AA);
|
2008-06-27 02:38:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-02-01 09:19:17 +08:00
|
|
|
|
2010-08-19 07:23:40 +08:00
|
|
|
// FIXME: Cache the number on the Attr object?
|
2008-06-29 07:50:44 +08:00
|
|
|
llvm::APSInt Alignment(32);
|
2012-05-05 06:38:52 +08:00
|
|
|
ExprResult ICE
|
|
|
|
= VerifyIntegerConstantExpression(E, &Alignment,
|
|
|
|
diag::err_aligned_attribute_argument_not_int,
|
|
|
|
/*AllowFold*/ false);
|
2012-02-04 17:53:13 +08:00
|
|
|
if (ICE.isInvalid())
|
2008-06-29 07:50:44 +08:00
|
|
|
return;
|
2013-02-01 16:12:08 +08:00
|
|
|
|
|
|
|
// C++11 [dcl.align]p2:
|
|
|
|
// -- if the constant expression evaluates to zero, the alignment
|
|
|
|
// specifier shall have no effect
|
|
|
|
// C11 6.7.5p6:
|
|
|
|
// An alignment specification of zero has no effect.
|
|
|
|
if (!(TmpAttr.isAlignas() && !Alignment) &&
|
|
|
|
!llvm::isPowerOf2_64(Alignment.getZExtValue())) {
|
2010-06-25 11:22:07 +08:00
|
|
|
Diag(AttrLoc, diag::err_attribute_aligned_not_power_of_two)
|
|
|
|
<< E->getSourceRange();
|
2009-02-17 07:37:57 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-02-01 09:19:17 +08:00
|
|
|
|
2013-02-01 16:12:08 +08:00
|
|
|
if (TmpAttr.isDeclspec()) {
|
2012-06-20 06:09:27 +08:00
|
|
|
// We've already verified it's a power of 2, now let's make sure it's
|
|
|
|
// 8192 or less.
|
|
|
|
if (Alignment.getZExtValue() > 8192) {
|
2013-02-01 09:19:17 +08:00
|
|
|
Diag(AttrLoc, diag::err_attribute_aligned_greater_than_8192)
|
2012-06-20 06:09:27 +08:00
|
|
|
<< E->getSourceRange();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 07:37:57 +08:00
|
|
|
|
2013-02-22 16:32:16 +08:00
|
|
|
AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context, true,
|
|
|
|
ICE.take(), SpellingListIndex);
|
|
|
|
AA->setPackExpansion(IsPackExpansion);
|
|
|
|
D->addAttr(AA);
|
2010-08-19 07:23:40 +08:00
|
|
|
}
|
|
|
|
|
2013-02-01 09:19:17 +08:00
|
|
|
void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *TS,
|
2013-02-22 16:32:16 +08:00
|
|
|
unsigned SpellingListIndex, bool IsPackExpansion) {
|
2010-08-19 07:23:40 +08:00
|
|
|
// FIXME: Cache the number on the Attr object if non-dependent?
|
|
|
|
// FIXME: Perform checking of type validity
|
2013-02-22 16:32:16 +08:00
|
|
|
AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context, false, TS,
|
|
|
|
SpellingListIndex);
|
|
|
|
AA->setPackExpansion(IsPackExpansion);
|
|
|
|
D->addAttr(AA);
|
2008-06-27 02:38:35 +08:00
|
|
|
}
|
2008-06-28 06:18:37 +08:00
|
|
|
|
2013-02-01 16:12:08 +08:00
|
|
|
void Sema::CheckAlignasUnderalignment(Decl *D) {
|
|
|
|
assert(D->hasAttrs() && "no attributes on decl");
|
|
|
|
|
|
|
|
QualType Ty;
|
|
|
|
if (ValueDecl *VD = dyn_cast<ValueDecl>(D))
|
|
|
|
Ty = VD->getType();
|
|
|
|
else
|
|
|
|
Ty = Context.getTagDeclType(cast<TagDecl>(D));
|
2013-02-22 17:21:42 +08:00
|
|
|
if (Ty->isDependentType() || Ty->isIncompleteType())
|
2013-02-01 16:12:08 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// C++11 [dcl.align]p5, C11 6.7.5/4:
|
|
|
|
// The combined effect of all alignment attributes in a declaration shall
|
|
|
|
// not specify an alignment that is less strict than the alignment that
|
|
|
|
// would otherwise be required for the entity being declared.
|
|
|
|
AlignedAttr *AlignasAttr = 0;
|
|
|
|
unsigned Align = 0;
|
|
|
|
for (specific_attr_iterator<AlignedAttr>
|
|
|
|
I = D->specific_attr_begin<AlignedAttr>(),
|
|
|
|
E = D->specific_attr_end<AlignedAttr>(); I != E; ++I) {
|
|
|
|
if (I->isAlignmentDependent())
|
|
|
|
return;
|
|
|
|
if (I->isAlignas())
|
|
|
|
AlignasAttr = *I;
|
|
|
|
Align = std::max(Align, I->getAlignment(Context));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AlignasAttr && Align) {
|
|
|
|
CharUnits RequestedAlign = Context.toCharUnitsFromBits(Align);
|
|
|
|
CharUnits NaturalAlign = Context.getTypeAlignInChars(Ty);
|
|
|
|
if (NaturalAlign > RequestedAlign)
|
|
|
|
Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned)
|
|
|
|
<< Ty << (unsigned)NaturalAlign.getQuantity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:16 +08:00
|
|
|
/// handleModeAttr - This attribute modifies the width of a decl with primitive
|
2009-07-25 03:02:52 +08:00
|
|
|
/// type.
|
2008-06-28 06:18:37 +08:00
|
|
|
///
|
2009-07-25 03:02:52 +08:00
|
|
|
/// Despite what would be logical, the mode attribute is a decl attribute, not a
|
|
|
|
/// type attribute: 'int ** __attribute((mode(HI))) *G;' tries to make 'G' be
|
|
|
|
/// HImode, not an intermediate pointer.
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleModeAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2008-06-28 06:18:37 +08:00
|
|
|
// This attribute isn't documented, but glibc uses it. It changes
|
|
|
|
// the width of an int or unsigned int to the specified size.
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!Attr.isArgIdent(0)) {
|
2013-07-30 22:29:12 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type) << Attr.getName()
|
|
|
|
<< AANT_ArgumentIdentifier;
|
2008-06-28 06:18:37 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-08-31 09:11:41 +08:00
|
|
|
|
|
|
|
IdentifierInfo *Name = Attr.getArgAsIdent(0)->Ident;
|
|
|
|
StringRef Str = Name->getName();
|
2008-06-28 06:18:37 +08:00
|
|
|
|
|
|
|
// Normalize the attribute name, __foo__ becomes foo.
|
2009-10-18 10:09:24 +08:00
|
|
|
if (Str.startswith("__") && Str.endswith("__"))
|
|
|
|
Str = Str.substr(2, Str.size() - 4);
|
2008-06-28 06:18:37 +08:00
|
|
|
|
|
|
|
unsigned DestWidth = 0;
|
|
|
|
bool IntegerMode = true;
|
2009-03-03 14:41:03 +08:00
|
|
|
bool ComplexMode = false;
|
2009-10-18 10:09:24 +08:00
|
|
|
switch (Str.size()) {
|
2008-06-28 06:18:37 +08:00
|
|
|
case 2:
|
2009-03-03 14:41:03 +08:00
|
|
|
switch (Str[0]) {
|
|
|
|
case 'Q': DestWidth = 8; break;
|
|
|
|
case 'H': DestWidth = 16; break;
|
|
|
|
case 'S': DestWidth = 32; break;
|
|
|
|
case 'D': DestWidth = 64; break;
|
|
|
|
case 'X': DestWidth = 96; break;
|
|
|
|
case 'T': DestWidth = 128; break;
|
|
|
|
}
|
|
|
|
if (Str[1] == 'F') {
|
|
|
|
IntegerMode = false;
|
|
|
|
} else if (Str[1] == 'C') {
|
|
|
|
IntegerMode = false;
|
|
|
|
ComplexMode = true;
|
|
|
|
} else if (Str[1] != 'I') {
|
|
|
|
DestWidth = 0;
|
|
|
|
}
|
2008-06-28 06:18:37 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
// FIXME: glibc uses 'word' to define register_t; this is narrower than a
|
|
|
|
// pointer on PIC16 and other embedded platforms.
|
2009-10-18 10:09:24 +08:00
|
|
|
if (Str == "word")
|
2011-09-02 08:18:52 +08:00
|
|
|
DestWidth = S.Context.getTargetInfo().getPointerWidth(0);
|
2009-10-18 10:09:24 +08:00
|
|
|
else if (Str == "byte")
|
2011-09-02 08:18:52 +08:00
|
|
|
DestWidth = S.Context.getTargetInfo().getCharWidth();
|
2008-06-28 06:18:37 +08:00
|
|
|
break;
|
|
|
|
case 7:
|
2009-10-18 10:09:24 +08:00
|
|
|
if (Str == "pointer")
|
2011-09-02 08:18:52 +08:00
|
|
|
DestWidth = S.Context.getTargetInfo().getPointerWidth(0);
|
2008-06-28 06:18:37 +08:00
|
|
|
break;
|
2013-01-08 03:58:54 +08:00
|
|
|
case 11:
|
|
|
|
if (Str == "unwind_word")
|
2013-01-08 04:01:57 +08:00
|
|
|
DestWidth = S.Context.getTargetInfo().getUnwindWordWidth();
|
2013-01-08 03:58:54 +08:00
|
|
|
break;
|
2008-06-28 06:18:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QualType OldTy;
|
2011-04-15 22:24:37 +08:00
|
|
|
if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
|
2008-06-28 06:18:37 +08:00
|
|
|
OldTy = TD->getUnderlyingType();
|
|
|
|
else if (ValueDecl *VD = dyn_cast<ValueDecl>(D))
|
|
|
|
OldTy = VD->getType();
|
|
|
|
else {
|
2008-11-19 13:08:23 +08:00
|
|
|
S.Diag(D->getLocation(), diag::err_attr_wrong_decl)
|
2011-09-14 00:05:58 +08:00
|
|
|
<< "mode" << Attr.getRange();
|
2008-06-28 06:18:37 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-03-03 14:41:03 +08:00
|
|
|
|
2009-09-22 07:43:11 +08:00
|
|
|
if (!OldTy->getAs<BuiltinType>() && !OldTy->isComplexType())
|
2009-03-03 14:41:03 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_mode_not_primitive);
|
|
|
|
else if (IntegerMode) {
|
2010-06-16 08:17:44 +08:00
|
|
|
if (!OldTy->isIntegralOrEnumerationType())
|
2009-03-03 14:41:03 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_mode_wrong_type);
|
|
|
|
} else if (ComplexMode) {
|
|
|
|
if (!OldTy->isComplexType())
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_mode_wrong_type);
|
|
|
|
} else {
|
|
|
|
if (!OldTy->isFloatingType())
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_mode_wrong_type);
|
|
|
|
}
|
|
|
|
|
2009-05-16 15:39:55 +08:00
|
|
|
// FIXME: Sync this with InitializePredefinedMacros; we need to match int8_t
|
|
|
|
// and friends, at least with glibc.
|
2009-02-13 10:31:07 +08:00
|
|
|
// FIXME: Make sure floating-point mappings are accurate
|
|
|
|
// FIXME: Support XF and TF types
|
2013-09-18 17:08:52 +08:00
|
|
|
if (!DestWidth) {
|
2008-11-19 16:23:25 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_unknown_machine_mode) << Name;
|
2008-06-28 06:18:37 +08:00
|
|
|
return;
|
2013-09-18 17:08:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QualType NewTy;
|
|
|
|
|
|
|
|
if (IntegerMode)
|
|
|
|
NewTy = S.Context.getIntTypeForBitwidth(DestWidth,
|
|
|
|
OldTy->isSignedIntegerType());
|
|
|
|
else
|
|
|
|
NewTy = S.Context.getRealTypeForBitwidth(DestWidth);
|
|
|
|
|
|
|
|
if (NewTy.isNull()) {
|
2008-11-19 16:23:25 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_unsupported_machine_mode) << Name;
|
2008-06-28 06:18:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-03 14:41:03 +08:00
|
|
|
if (ComplexMode) {
|
|
|
|
NewTy = S.Context.getComplexType(NewTy);
|
2008-06-28 06:18:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Install the new type.
|
2013-06-20 20:46:19 +08:00
|
|
|
if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
|
|
|
|
TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
|
|
|
|
else
|
2008-06-28 06:18:37 +08:00
|
|
|
cast<ValueDecl>(D)->setType(NewTy);
|
2013-06-20 20:46:19 +08:00
|
|
|
|
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ModeAttr(Attr.getRange(), S.Context, Name,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2008-06-28 06:18:37 +08:00
|
|
|
}
|
2008-06-29 08:23:49 +08:00
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleNoDebugAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2012-07-24 09:40:49 +08:00
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
|
|
|
if (!VD->hasGlobalStorage())
|
|
|
|
S.Diag(Attr.getLoc(),
|
|
|
|
diag::warn_attribute_requires_functions_or_static_globals)
|
|
|
|
<< Attr.getName();
|
|
|
|
} else if (!isFunctionOrMethod(D)) {
|
|
|
|
S.Diag(Attr.getLoc(),
|
|
|
|
diag::warn_attribute_requires_functions_or_static_globals)
|
|
|
|
<< Attr.getName();
|
2009-02-13 14:46:13 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
NoDebugAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-02-13 14:46:13 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleGlobalAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-12-03 03:30:36 +08:00
|
|
|
FunctionDecl *FD = cast<FunctionDecl>(D);
|
|
|
|
if (!FD->getResultType()->isVoidType()) {
|
|
|
|
TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc().IgnoreParens();
|
|
|
|
if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
|
|
|
|
S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return)
|
|
|
|
<< FD->getType()
|
|
|
|
<< FixItHint::CreateReplacement(FTL.getResultLoc().getSourceRange(),
|
|
|
|
"void");
|
|
|
|
} else {
|
|
|
|
S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return)
|
|
|
|
<< FD->getType();
|
2010-12-13 07:02:57 +08:00
|
|
|
}
|
2013-12-03 03:30:36 +08:00
|
|
|
return;
|
2010-12-01 11:15:31 +08:00
|
|
|
}
|
|
|
|
|
2013-12-03 03:30:36 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
CUDAGlobalAttr(Attr.getRange(), S.Context,
|
2013-01-25 00:46:58 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-12-01 11:15:31 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleGNUInlineAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-11-27 21:27:02 +08:00
|
|
|
FunctionDecl *Fn = cast<FunctionDecl>(D);
|
2009-10-28 05:01:01 +08:00
|
|
|
if (!Fn->isInlineSpecified()) {
|
2009-04-21 03:12:28 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
|
2009-04-15 01:02:11 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
GNUInlineAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-04-15 00:30:50 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleCallConvAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2011-07-02 07:49:12 +08:00
|
|
|
if (hasDeclarator(D)) return;
|
2011-01-05 20:14:39 +08:00
|
|
|
|
2012-12-10 01:45:41 +08:00
|
|
|
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
|
2011-07-02 07:49:12 +08:00
|
|
|
// Diagnostic is emitted elsewhere: here we store the (valid) Attr
|
2010-04-30 21:10:51 +08:00
|
|
|
// in the Decl node for syntactic reasoning, e.g., pretty-printing.
|
2011-01-05 20:14:39 +08:00
|
|
|
CallingConv CC;
|
2012-12-10 01:45:41 +08:00
|
|
|
if (S.CheckCallingConvAttr(Attr, CC, FD))
|
2011-01-05 20:14:39 +08:00
|
|
|
return;
|
2010-04-30 21:10:51 +08:00
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
if (!isa<ObjCMethodDecl>(D)) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
|
|
|
<< Attr.getName() << ExpectedFunctionOrMethod;
|
2011-01-05 20:14:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
switch (Attr.getKind()) {
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_FastCall:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
FastCallAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-04-30 21:10:51 +08:00
|
|
|
return;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_StdCall:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
StdCallAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-04-30 21:10:51 +08:00
|
|
|
return;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ThisCall:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ThisCallAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-08-31 07:30:49 +08:00
|
|
|
return;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_CDecl:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
CDeclAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-04-30 21:10:51 +08:00
|
|
|
return;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Pascal:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
PascalAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-09-03 09:29:35 +08:00
|
|
|
return;
|
2013-08-30 12:39:01 +08:00
|
|
|
case AttributeList::AT_MSABI:
|
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
MSABIAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
return;
|
|
|
|
case AttributeList::AT_SysVABI:
|
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
SysVABIAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
return;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Pcs: {
|
2011-04-15 04:06:49 +08:00
|
|
|
PcsAttr::PCSType PCS;
|
2012-08-14 21:24:39 +08:00
|
|
|
switch (CC) {
|
|
|
|
case CC_AAPCS:
|
2011-04-15 04:06:49 +08:00
|
|
|
PCS = PcsAttr::AAPCS;
|
2012-08-14 21:24:39 +08:00
|
|
|
break;
|
|
|
|
case CC_AAPCS_VFP:
|
2011-04-15 04:06:49 +08:00
|
|
|
PCS = PcsAttr::AAPCS_VFP;
|
2012-08-14 21:24:39 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("unexpected calling convention in pcs attribute");
|
2011-04-15 04:06:49 +08:00
|
|
|
}
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
PcsAttr(Attr.getRange(), S.Context, PCS,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-10-17 06:30:41 +08:00
|
|
|
return;
|
2011-04-15 04:06:49 +08:00
|
|
|
}
|
2012-10-17 06:30:41 +08:00
|
|
|
case AttributeList::AT_PnaclCall:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
PnaclCallAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-10-17 06:30:41 +08:00
|
|
|
return;
|
2012-12-25 16:53:55 +08:00
|
|
|
case AttributeList::AT_IntelOclBicc:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
IntelOclBiccAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-12-25 16:53:55 +08:00
|
|
|
return;
|
2012-10-17 06:30:41 +08:00
|
|
|
|
2010-04-30 21:10:51 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("unexpected attribute kind");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 09:50:40 +08:00
|
|
|
static void handleOpenCLImageAccessAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
uint32_t ArgNum;
|
|
|
|
if (!checkUInt32Argument(S, Attr, Attr.getArgAsExpr(0), ArgNum))
|
2013-03-24 21:58:12 +08:00
|
|
|
return;
|
|
|
|
|
2013-11-21 09:50:40 +08:00
|
|
|
D->addAttr(::new (S.Context) OpenCLImageAccessAttr(Attr.getRange(),
|
|
|
|
S.Context, ArgNum));
|
2013-03-24 21:58:12 +08:00
|
|
|
}
|
|
|
|
|
2012-12-10 01:45:41 +08:00
|
|
|
bool Sema::CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC,
|
|
|
|
const FunctionDecl *FD) {
|
2011-01-05 20:14:39 +08:00
|
|
|
if (attr.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
2012-08-14 21:13:47 +08:00
|
|
|
unsigned ReqArgs = attr.getKind() == AttributeList::AT_Pcs ? 1 : 0;
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!checkAttributeNumArgs(*this, attr, ReqArgs)) {
|
2011-01-05 20:14:39 +08:00
|
|
|
attr.setInvalid();
|
|
|
|
return true;
|
2009-03-28 02:38:55 +08:00
|
|
|
}
|
2009-03-28 05:06:47 +08:00
|
|
|
|
2011-04-15 04:06:49 +08:00
|
|
|
// TODO: diagnose uses of these conventions on the wrong target. Or, better
|
|
|
|
// move to TargetAttributesSema one day.
|
2011-01-05 20:14:39 +08:00
|
|
|
switch (attr.getKind()) {
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_CDecl: CC = CC_C; break;
|
|
|
|
case AttributeList::AT_FastCall: CC = CC_X86FastCall; break;
|
|
|
|
case AttributeList::AT_StdCall: CC = CC_X86StdCall; break;
|
|
|
|
case AttributeList::AT_ThisCall: CC = CC_X86ThisCall; break;
|
|
|
|
case AttributeList::AT_Pascal: CC = CC_X86Pascal; break;
|
2013-08-30 12:39:01 +08:00
|
|
|
case AttributeList::AT_MSABI:
|
|
|
|
CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_C :
|
|
|
|
CC_X86_64Win64;
|
|
|
|
break;
|
|
|
|
case AttributeList::AT_SysVABI:
|
|
|
|
CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_X86_64SysV :
|
|
|
|
CC_C;
|
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Pcs: {
|
2013-09-14 01:48:25 +08:00
|
|
|
StringRef StrRef;
|
2013-10-01 22:34:18 +08:00
|
|
|
if (!checkStringLiteralArgumentAttr(attr, 0, StrRef)) {
|
2011-04-15 04:06:49 +08:00
|
|
|
attr.setInvalid();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (StrRef == "aapcs") {
|
|
|
|
CC = CC_AAPCS;
|
|
|
|
break;
|
|
|
|
} else if (StrRef == "aapcs-vfp") {
|
|
|
|
CC = CC_AAPCS_VFP;
|
|
|
|
break;
|
|
|
|
}
|
2012-08-14 21:13:47 +08:00
|
|
|
|
|
|
|
attr.setInvalid();
|
|
|
|
Diag(attr.getLoc(), diag::err_invalid_pcs);
|
|
|
|
return true;
|
2011-04-15 04:06:49 +08:00
|
|
|
}
|
2012-10-17 06:30:41 +08:00
|
|
|
case AttributeList::AT_PnaclCall: CC = CC_PnaclCall; break;
|
2012-12-25 16:53:55 +08:00
|
|
|
case AttributeList::AT_IntelOclBicc: CC = CC_IntelOclBicc; break;
|
2012-01-17 14:56:22 +08:00
|
|
|
default: llvm_unreachable("unexpected attribute kind");
|
2011-01-05 20:14:39 +08:00
|
|
|
}
|
|
|
|
|
2012-10-02 22:26:08 +08:00
|
|
|
const TargetInfo &TI = Context.getTargetInfo();
|
|
|
|
TargetInfo::CallingConvCheckResult A = TI.checkCallingConvention(CC);
|
|
|
|
if (A == TargetInfo::CCCR_Warning) {
|
|
|
|
Diag(attr.getLoc(), diag::warn_cconv_ignored) << attr.getName();
|
2012-12-10 01:45:41 +08:00
|
|
|
|
|
|
|
TargetInfo::CallingConvMethodType MT = TargetInfo::CCMT_Unknown;
|
|
|
|
if (FD)
|
|
|
|
MT = FD->isCXXInstanceMember() ? TargetInfo::CCMT_Member :
|
|
|
|
TargetInfo::CCMT_NonMember;
|
|
|
|
CC = TI.getDefaultCallingConv(MT);
|
2012-10-02 22:26:08 +08:00
|
|
|
}
|
|
|
|
|
2011-01-05 20:14:39 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleRegparmAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2011-07-02 07:49:12 +08:00
|
|
|
if (hasDeclarator(D)) return;
|
2011-01-05 20:14:39 +08:00
|
|
|
|
|
|
|
unsigned numParams;
|
2011-07-02 07:49:12 +08:00
|
|
|
if (S.CheckRegparmAttr(Attr, numParams))
|
2011-01-05 20:14:39 +08:00
|
|
|
return;
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
if (!isa<ObjCMethodDecl>(D)) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
|
|
|
<< Attr.getName() << ExpectedFunctionOrMethod;
|
2009-03-28 02:38:55 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-03-28 05:06:47 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
RegparmAttr(Attr.getRange(), S.Context, numParams,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-01-05 20:14:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Checks a regparm attribute, returning true if it is ill-formed and
|
|
|
|
/// otherwise setting numParams to the appropriate value.
|
2011-07-02 07:49:12 +08:00
|
|
|
bool Sema::CheckRegparmAttr(const AttributeList &Attr, unsigned &numParams) {
|
|
|
|
if (Attr.isInvalid())
|
2011-01-05 20:14:39 +08:00
|
|
|
return true;
|
|
|
|
|
2013-07-19 02:01:48 +08:00
|
|
|
if (!checkAttributeNumArgs(*this, Attr, 1)) {
|
2011-07-02 07:49:12 +08:00
|
|
|
Attr.setInvalid();
|
2011-01-05 20:14:39 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-21 09:50:40 +08:00
|
|
|
uint32_t NP;
|
2013-08-31 09:11:41 +08:00
|
|
|
Expr *NumParamsExpr = Attr.getArgAsExpr(0);
|
2013-11-21 09:50:40 +08:00
|
|
|
if (!checkUInt32Argument(*this, Attr, NumParamsExpr, NP)) {
|
2011-07-02 07:49:12 +08:00
|
|
|
Attr.setInvalid();
|
2011-01-05 20:14:39 +08:00
|
|
|
return true;
|
2009-03-28 05:06:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-02 08:18:52 +08:00
|
|
|
if (Context.getTargetInfo().getRegParmMax() == 0) {
|
2011-07-02 07:49:12 +08:00
|
|
|
Diag(Attr.getLoc(), diag::err_attribute_regparm_wrong_platform)
|
2009-03-28 05:06:47 +08:00
|
|
|
<< NumParamsExpr->getSourceRange();
|
2011-07-02 07:49:12 +08:00
|
|
|
Attr.setInvalid();
|
2011-01-05 20:14:39 +08:00
|
|
|
return true;
|
2009-03-28 05:06:47 +08:00
|
|
|
}
|
|
|
|
|
2013-11-21 09:50:40 +08:00
|
|
|
numParams = NP;
|
2011-09-02 08:18:52 +08:00
|
|
|
if (numParams > Context.getTargetInfo().getRegParmMax()) {
|
2011-07-02 07:49:12 +08:00
|
|
|
Diag(Attr.getLoc(), diag::err_attribute_regparm_invalid_number)
|
2011-09-02 08:18:52 +08:00
|
|
|
<< Context.getTargetInfo().getRegParmMax() << NumParamsExpr->getSourceRange();
|
2011-07-02 07:49:12 +08:00
|
|
|
Attr.setInvalid();
|
2011-01-05 20:14:39 +08:00
|
|
|
return true;
|
2009-03-28 05:06:47 +08:00
|
|
|
}
|
|
|
|
|
2011-01-05 20:14:39 +08:00
|
|
|
return false;
|
2009-03-28 02:38:55 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 08:41:31 +08:00
|
|
|
static void handleLaunchBoundsAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-12-03 03:30:36 +08:00
|
|
|
// check the attribute arguments.
|
|
|
|
if (Attr.getNumArgs() != 1 && Attr.getNumArgs() != 2) {
|
|
|
|
// FIXME: 0 is not okay.
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 2;
|
|
|
|
return;
|
|
|
|
}
|
2010-12-13 07:03:07 +08:00
|
|
|
|
2013-12-03 03:30:36 +08:00
|
|
|
if (!isFunctionOrMethod(D)) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
|
|
|
<< Attr.getName() << ExpectedFunctionOrMethod;
|
|
|
|
return;
|
|
|
|
}
|
2010-12-13 07:03:07 +08:00
|
|
|
|
2013-12-19 08:41:31 +08:00
|
|
|
uint32_t MaxThreads, MinBlocks = 0;
|
|
|
|
if (!checkUInt32Argument(S, Attr, Attr.getArgAsExpr(0), MaxThreads, 1))
|
|
|
|
return;
|
|
|
|
if (Attr.getNumArgs() > 1 && !checkUInt32Argument(S, Attr,
|
|
|
|
Attr.getArgAsExpr(1),
|
|
|
|
MinBlocks, 2))
|
2013-12-03 03:30:36 +08:00
|
|
|
return;
|
2010-12-13 07:03:07 +08:00
|
|
|
|
2013-12-03 03:30:36 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
CUDALaunchBoundsAttr(Attr.getRange(), S.Context,
|
|
|
|
MaxThreads, MinBlocks,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-12-13 07:03:07 +08:00
|
|
|
}
|
|
|
|
|
2012-08-17 08:08:38 +08:00
|
|
|
static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!Attr.isArgIdent(0)) {
|
2013-07-23 22:03:57 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_type)
|
2013-07-30 09:31:03 +08:00
|
|
|
<< Attr.getName() << /* arg num = */ 1 << AANT_ArgumentIdentifier;
|
2012-08-17 08:08:38 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-08-31 09:11:41 +08:00
|
|
|
|
|
|
|
if (!checkAttributeNumArgs(S, Attr, 3))
|
2012-08-17 08:08:38 +08:00
|
|
|
return;
|
|
|
|
|
2013-08-31 09:11:41 +08:00
|
|
|
StringRef AttrName = Attr.getName()->getName();
|
|
|
|
IdentifierInfo *ArgumentKind = Attr.getArgAsIdent(0)->Ident;
|
2012-08-17 08:08:38 +08:00
|
|
|
|
|
|
|
if (!isFunctionOrMethod(D) || !hasFunctionProto(D)) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
|
|
|
|
<< Attr.getName() << ExpectedFunctionOrMethod;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ArgumentIdx;
|
|
|
|
if (!checkFunctionOrMethodArgumentIndex(S, D, AttrName,
|
|
|
|
Attr.getLoc(), 2,
|
2013-08-31 09:11:41 +08:00
|
|
|
Attr.getArgAsExpr(1), ArgumentIdx))
|
2012-08-17 08:08:38 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
uint64_t TypeTagIdx;
|
|
|
|
if (!checkFunctionOrMethodArgumentIndex(S, D, AttrName,
|
|
|
|
Attr.getLoc(), 3,
|
2013-08-31 09:11:41 +08:00
|
|
|
Attr.getArgAsExpr(2), TypeTagIdx))
|
2012-08-17 08:08:38 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
bool IsPointer = (AttrName == "pointer_with_type_tag");
|
|
|
|
if (IsPointer) {
|
|
|
|
// Ensure that buffer has a pointer type.
|
|
|
|
QualType BufferTy = getFunctionOrMethodArgType(D, ArgumentIdx);
|
|
|
|
if (!BufferTy->isPointerType()) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_pointers_only)
|
2013-05-23 07:25:32 +08:00
|
|
|
<< Attr.getName();
|
2012-08-17 08:08:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ArgumentWithTypeTagAttr(Attr.getRange(), S.Context, ArgumentKind,
|
|
|
|
ArgumentIdx, TypeTagIdx, IsPointer,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-08-17 08:08:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-08-31 09:11:41 +08:00
|
|
|
if (!Attr.isArgIdent(0)) {
|
2013-07-23 22:03:57 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_type)
|
2013-07-30 09:31:03 +08:00
|
|
|
<< Attr.getName() << 1 << AANT_ArgumentIdentifier;
|
2012-08-17 08:08:38 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-08-31 09:11:41 +08:00
|
|
|
|
|
|
|
if (!checkAttributeNumArgs(S, Attr, 1))
|
|
|
|
return;
|
2012-08-17 08:08:38 +08:00
|
|
|
|
2013-11-26 02:50:49 +08:00
|
|
|
if (!isa<VarDecl>(D)) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
|
|
|
|
<< Attr.getName() << ExpectedVariable;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-31 09:11:41 +08:00
|
|
|
IdentifierInfo *PointerKind = Attr.getArgAsIdent(0)->Ident;
|
2013-11-01 05:23:20 +08:00
|
|
|
TypeSourceInfo *MatchingCTypeLoc = 0;
|
|
|
|
S.GetTypeFromParser(Attr.getMatchingCType(), &MatchingCTypeLoc);
|
|
|
|
assert(MatchingCTypeLoc && "no type source info for attribute argument");
|
2012-08-17 08:08:38 +08:00
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
TypeTagForDatatypeAttr(Attr.getRange(), S.Context, PointerKind,
|
2013-11-01 05:23:20 +08:00
|
|
|
MatchingCTypeLoc,
|
2013-01-25 00:46:58 +08:00
|
|
|
Attr.getLayoutCompatible(),
|
|
|
|
Attr.getMustBeNull(),
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2012-08-17 08:08:38 +08:00
|
|
|
}
|
|
|
|
|
2009-05-09 10:44:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Checker-specific attribute handlers.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-25 11:31:58 +08:00
|
|
|
static bool isValidSubjectOfNSAttribute(Sema &S, QualType type) {
|
2011-10-10 06:26:49 +08:00
|
|
|
return type->isDependentType() ||
|
|
|
|
type->isObjCObjectPointerType() ||
|
|
|
|
S.Context.isObjCNSObjectType(type);
|
2011-01-25 11:31:58 +08:00
|
|
|
}
|
|
|
|
static bool isValidSubjectOfCFAttribute(Sema &S, QualType type) {
|
2011-10-10 06:26:49 +08:00
|
|
|
return type->isDependentType() ||
|
|
|
|
type->isPointerType() ||
|
|
|
|
isValidSubjectOfNSAttribute(S, type);
|
2011-01-25 11:31:58 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleNSConsumedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-11-27 21:27:02 +08:00
|
|
|
ParmVarDecl *param = cast<ParmVarDecl>(D);
|
2011-01-25 11:31:58 +08:00
|
|
|
bool typeOK, cf;
|
2013-11-27 21:27:02 +08:00
|
|
|
|
2012-06-20 07:57:03 +08:00
|
|
|
if (Attr.getKind() == AttributeList::AT_NSConsumed) {
|
2011-01-25 11:31:58 +08:00
|
|
|
typeOK = isValidSubjectOfNSAttribute(S, param->getType());
|
|
|
|
cf = false;
|
|
|
|
} else {
|
|
|
|
typeOK = isValidSubjectOfCFAttribute(S, param->getType());
|
|
|
|
cf = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!typeOK) {
|
2011-07-02 07:49:12 +08:00
|
|
|
S.Diag(D->getLocStart(), diag::warn_ns_attribute_wrong_parameter_type)
|
2011-09-14 00:05:58 +08:00
|
|
|
<< Attr.getRange() << Attr.getName() << cf;
|
2011-01-25 11:31:58 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cf)
|
2013-01-25 00:46:58 +08:00
|
|
|
param->addAttr(::new (S.Context)
|
|
|
|
CFConsumedAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-01-25 11:31:58 +08:00
|
|
|
else
|
2013-01-25 00:46:58 +08:00
|
|
|
param->addAttr(::new (S.Context)
|
|
|
|
NSConsumedAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-01-25 11:31:58 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleNSReturnsRetainedAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2009-05-09 10:44:38 +08:00
|
|
|
|
2011-01-25 11:31:58 +08:00
|
|
|
QualType returnType;
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
|
2011-01-25 11:31:58 +08:00
|
|
|
returnType = MD->getResultType();
|
2012-03-11 15:00:24 +08:00
|
|
|
else if (S.getLangOpts().ObjCAutoRefCount && hasDeclarator(D) &&
|
2012-06-20 07:57:03 +08:00
|
|
|
(Attr.getKind() == AttributeList::AT_NSReturnsRetained))
|
2011-06-16 07:02:42 +08:00
|
|
|
return; // ignore: was handled as a type attribute
|
2012-08-29 06:26:21 +08:00
|
|
|
else if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D))
|
|
|
|
returnType = PD->getType();
|
2011-07-02 07:49:12 +08:00
|
|
|
else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
2011-01-25 11:31:58 +08:00
|
|
|
returnType = FD->getResultType();
|
2009-05-14 05:07:32 +08:00
|
|
|
else {
|
2011-07-02 07:49:12 +08:00
|
|
|
S.Diag(D->getLocStart(), diag::warn_attribute_wrong_decl_type)
|
2011-09-14 00:05:58 +08:00
|
|
|
<< Attr.getRange() << Attr.getName()
|
2011-03-02 20:29:23 +08:00
|
|
|
<< ExpectedFunctionOrMethod;
|
2009-05-09 10:44:38 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2011-01-25 11:31:58 +08:00
|
|
|
bool typeOK;
|
|
|
|
bool cf;
|
2011-07-02 07:49:12 +08:00
|
|
|
switch (Attr.getKind()) {
|
2012-01-17 14:56:22 +08:00
|
|
|
default: llvm_unreachable("invalid ownership attribute");
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_NSReturnsAutoreleased:
|
|
|
|
case AttributeList::AT_NSReturnsRetained:
|
|
|
|
case AttributeList::AT_NSReturnsNotRetained:
|
2011-01-25 11:31:58 +08:00
|
|
|
typeOK = isValidSubjectOfNSAttribute(S, returnType);
|
|
|
|
cf = false;
|
|
|
|
break;
|
|
|
|
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_CFReturnsRetained:
|
|
|
|
case AttributeList::AT_CFReturnsNotRetained:
|
2011-01-25 11:31:58 +08:00
|
|
|
typeOK = isValidSubjectOfCFAttribute(S, returnType);
|
|
|
|
cf = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!typeOK) {
|
2011-07-02 07:49:12 +08:00
|
|
|
S.Diag(D->getLocStart(), diag::warn_ns_attribute_wrong_return_type)
|
2011-09-14 00:05:58 +08:00
|
|
|
<< Attr.getRange() << Attr.getName() << isa<ObjCMethodDecl>(D) << cf;
|
2009-07-25 03:02:52 +08:00
|
|
|
return;
|
2009-05-14 05:07:32 +08:00
|
|
|
}
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
switch (Attr.getKind()) {
|
2009-05-09 10:44:38 +08:00
|
|
|
default:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("invalid ownership attribute");
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_NSReturnsAutoreleased:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
NSReturnsAutoreleasedAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-01-25 11:31:58 +08:00
|
|
|
return;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_CFReturnsNotRetained:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
CFReturnsNotRetainedAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-02-18 08:05:45 +08:00
|
|
|
return;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_NSReturnsNotRetained:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
NSReturnsNotRetainedAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-02-18 08:05:45 +08:00
|
|
|
return;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_CFReturnsRetained:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
CFReturnsRetainedAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-05-09 10:44:38 +08:00
|
|
|
return;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_NSReturnsRetained:
|
2013-01-25 00:46:58 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
NSReturnsRetainedAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2009-05-09 10:44:38 +08:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-07-22 16:53:00 +08:00
|
|
|
static void handleObjCReturnsInnerPointerAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &attr) {
|
2013-09-20 01:52:50 +08:00
|
|
|
const int EP_ObjCMethod = 1;
|
|
|
|
const int EP_ObjCProperty = 2;
|
2013-09-20 01:18:55 +08:00
|
|
|
|
2011-07-22 16:53:00 +08:00
|
|
|
SourceLocation loc = attr.getLoc();
|
2013-09-20 00:37:20 +08:00
|
|
|
QualType resultType;
|
2013-11-27 21:27:02 +08:00
|
|
|
if (isa<ObjCMethodDecl>(D))
|
|
|
|
resultType = cast<ObjCMethodDecl>(D)->getResultType();
|
2013-09-20 00:37:20 +08:00
|
|
|
else
|
2013-11-27 21:27:02 +08:00
|
|
|
resultType = cast<ObjCPropertyDecl>(D)->getType();
|
2011-07-22 16:53:00 +08:00
|
|
|
|
2011-10-01 04:50:23 +08:00
|
|
|
if (!resultType->isReferenceType() &&
|
|
|
|
(!resultType->isPointerType() || resultType->isObjCRetainableType())) {
|
2013-09-20 00:37:20 +08:00
|
|
|
S.Diag(D->getLocStart(), diag::warn_ns_attribute_wrong_return_type)
|
2011-07-22 16:53:00 +08:00
|
|
|
<< SourceRange(loc)
|
2013-11-27 21:27:02 +08:00
|
|
|
<< attr.getName()
|
|
|
|
<< (isa<ObjCMethodDecl>(D) ? EP_ObjCMethod : EP_ObjCProperty)
|
2013-09-20 01:18:55 +08:00
|
|
|
<< /*non-retainable pointer*/ 2;
|
2011-07-22 16:53:00 +08:00
|
|
|
|
|
|
|
// Drop the attribute.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-20 00:37:20 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
2013-01-25 00:46:58 +08:00
|
|
|
ObjCReturnsInnerPointerAttr(attr.getRange(), S.Context,
|
|
|
|
attr.getAttributeSpellingListIndex()));
|
2011-07-22 16:53:00 +08:00
|
|
|
}
|
|
|
|
|
2012-09-08 07:46:23 +08:00
|
|
|
static void handleObjCRequiresSuperAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &attr) {
|
2013-11-27 21:27:02 +08:00
|
|
|
ObjCMethodDecl *method = cast<ObjCMethodDecl>(D);
|
2012-09-08 07:46:23 +08:00
|
|
|
|
|
|
|
DeclContext *DC = method->getDeclContext();
|
|
|
|
if (const ObjCProtocolDecl *PDecl = dyn_cast_or_null<ObjCProtocolDecl>(DC)) {
|
|
|
|
S.Diag(D->getLocStart(), diag::warn_objc_requires_super_protocol)
|
|
|
|
<< attr.getName() << 0;
|
|
|
|
S.Diag(PDecl->getLocation(), diag::note_protocol_decl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (method->getMethodFamily() == OMF_dealloc) {
|
|
|
|
S.Diag(D->getLocStart(), diag::warn_objc_requires_super_protocol)
|
|
|
|
<< attr.getName() << 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-25 00:46:58 +08:00
|
|
|
method->addAttr(::new (S.Context)
|
|
|
|
ObjCRequiresSuperAttr(attr.getRange(), S.Context,
|
|
|
|
attr.getAttributeSpellingListIndex()));
|
2012-09-08 07:46:23 +08:00
|
|
|
}
|
|
|
|
|
2013-12-03 02:05:46 +08:00
|
|
|
static void handleCFAuditedTransferAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
if (checkAttrMutualExclusion<CFUnknownTransferAttr>(S, D, Attr,
|
|
|
|
"cf_unknown_transfer"))
|
|
|
|
return;
|
2011-09-30 13:12:12 +08:00
|
|
|
|
2013-12-03 02:05:46 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
CFAuditedTransferAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handleCFUnknownTransferAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
if (checkAttrMutualExclusion<CFAuditedTransferAttr>(S, D, Attr,
|
|
|
|
"cf_audited_transfer"))
|
2011-09-30 13:12:12 +08:00
|
|
|
return;
|
|
|
|
|
2013-12-03 02:05:46 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
CFUnknownTransferAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-09-30 13:12:12 +08:00
|
|
|
}
|
|
|
|
|
2013-11-14 07:59:17 +08:00
|
|
|
static void handleObjCBridgeAttr(Sema &S, Scope *Sc, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-11-22 08:02:22 +08:00
|
|
|
IdentifierLoc * Parm = Attr.isArgIdent(0) ? Attr.getArgAsIdent(0) : 0;
|
2013-11-21 15:20:34 +08:00
|
|
|
|
2013-11-14 07:59:17 +08:00
|
|
|
if (!Parm) {
|
2013-11-21 15:20:34 +08:00
|
|
|
S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << Attr.getName() << 0;
|
2013-11-14 07:59:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
D->addAttr(::new (S.Context)
|
2013-11-21 15:20:34 +08:00
|
|
|
ObjCBridgeAttr(Attr.getRange(), S.Context, Parm->Ident,
|
2013-11-14 07:59:17 +08:00
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
2013-11-22 04:50:32 +08:00
|
|
|
static void handleObjCBridgeMutableAttr(Sema &S, Scope *Sc, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-11-22 08:02:22 +08:00
|
|
|
IdentifierLoc * Parm = Attr.isArgIdent(0) ? Attr.getArgAsIdent(0) : 0;
|
2013-11-22 04:50:32 +08:00
|
|
|
|
|
|
|
if (!Parm) {
|
|
|
|
S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << Attr.getName() << 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ObjCBridgeMutableAttr(Attr.getRange(), S.Context, Parm->Ident,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
2013-12-05 04:32:50 +08:00
|
|
|
static void handleObjCBridgeRelatedAttr(Sema &S, Scope *Sc, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
IdentifierInfo *RelatedClass =
|
|
|
|
Attr.isArgIdent(0) ? Attr.getArgAsIdent(0)->Ident : 0;
|
|
|
|
if (!RelatedClass) {
|
|
|
|
S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << Attr.getName() << 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IdentifierInfo *ClassMethod =
|
|
|
|
Attr.getArgAsIdent(1) ? Attr.getArgAsIdent(1)->Ident : 0;
|
|
|
|
IdentifierInfo *InstanceMethod =
|
|
|
|
Attr.getArgAsIdent(2) ? Attr.getArgAsIdent(2)->Ident : 0;
|
|
|
|
D->addAttr(::new (S.Context)
|
|
|
|
ObjCBridgeRelatedAttr(Attr.getRange(), S.Context, RelatedClass,
|
|
|
|
ClassMethod, InstanceMethod,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
2013-12-04 05:11:25 +08:00
|
|
|
static void handleObjCDesignatedInitializer(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2013-12-07 14:08:04 +08:00
|
|
|
ObjCInterfaceDecl *IFace = cast<ObjCInterfaceDecl>(D->getDeclContext());
|
2013-12-04 05:11:30 +08:00
|
|
|
IFace->setHasDesignatedInitializers();
|
2013-12-07 14:08:04 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
2013-12-04 05:11:25 +08:00
|
|
|
ObjCDesignatedInitializerAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleObjCOwnershipAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2011-07-02 07:49:12 +08:00
|
|
|
if (hasDeclarator(D)) return;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
S.Diag(D->getLocStart(), diag::err_attribute_wrong_decl_type)
|
2012-03-15 00:55:17 +08:00
|
|
|
<< Attr.getRange() << Attr.getName() << ExpectedVariable;
|
2011-06-16 07:02:42 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleObjCPreciseLifetimeAttr(Sema &S, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
2011-07-02 07:49:12 +08:00
|
|
|
ValueDecl *vd = cast<ValueDecl>(D);
|
2011-06-16 07:02:42 +08:00
|
|
|
QualType type = vd->getType();
|
|
|
|
|
|
|
|
if (!type->isDependentType() &&
|
|
|
|
!type->isObjCLifetimeType()) {
|
2011-07-02 07:49:12 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_objc_precise_lifetime_bad_type)
|
2011-06-16 07:02:42 +08:00
|
|
|
<< type;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qualifiers::ObjCLifetime lifetime = type.getObjCLifetime();
|
|
|
|
|
|
|
|
// If we have no lifetime yet, check the lifetime we're presumably
|
|
|
|
// going to infer.
|
|
|
|
if (lifetime == Qualifiers::OCL_None && !type->isDependentType())
|
|
|
|
lifetime = type->getObjCARCImplicitLifetime();
|
|
|
|
|
|
|
|
switch (lifetime) {
|
|
|
|
case Qualifiers::OCL_None:
|
|
|
|
assert(type->isDependentType() &&
|
|
|
|
"didn't infer lifetime for non-dependent type?");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qualifiers::OCL_Weak: // meaningful
|
|
|
|
case Qualifiers::OCL_Strong: // meaningful
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qualifiers::OCL_ExplicitNone:
|
|
|
|
case Qualifiers::OCL_Autoreleasing:
|
2011-07-02 07:49:12 +08:00
|
|
|
S.Diag(Attr.getLoc(), diag::warn_objc_precise_lifetime_meaningless)
|
2011-06-16 07:02:42 +08:00
|
|
|
<< (lifetime == Qualifiers::OCL_Autoreleasing);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-02 07:49:12 +08:00
|
|
|
D->addAttr(::new (S.Context)
|
2013-01-25 00:46:58 +08:00
|
|
|
ObjCPreciseLifetimeAttr(Attr.getRange(), S.Context,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2011-06-16 07:02:42 +08:00
|
|
|
}
|
|
|
|
|
2010-12-19 14:50:37 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Microsoft specific attribute handlers.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-02 08:01:44 +08:00
|
|
|
static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
2013-11-25 05:35:16 +08:00
|
|
|
if (!S.LangOpts.CPlusPlus) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_not_supported_in_lang)
|
|
|
|
<< Attr.getName() << AttributeLangSupport::C;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-25 04:58:02 +08:00
|
|
|
if (!isa<CXXRecordDecl>(D)) {
|
|
|
|
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
|
|
|
|
<< Attr.getName() << ExpectedClass;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-13 23:35:43 +08:00
|
|
|
StringRef StrRef;
|
|
|
|
SourceLocation LiteralLoc;
|
2013-10-01 22:34:18 +08:00
|
|
|
if (!S.checkStringLiteralArgumentAttr(Attr, 0, StrRef, &LiteralLoc))
|
2013-05-17 22:04:52 +08:00
|
|
|
return;
|
2010-12-20 09:41:49 +08:00
|
|
|
|
2013-08-09 16:56:20 +08:00
|
|
|
// GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or
|
|
|
|
// "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}", normalize to the former.
|
|
|
|
if (StrRef.size() == 38 && StrRef.front() == '{' && StrRef.back() == '}')
|
|
|
|
StrRef = StrRef.drop_front().drop_back();
|
2010-12-20 09:41:49 +08:00
|
|
|
|
2013-05-17 22:04:52 +08:00
|
|
|
// Validate GUID length.
|
2013-08-09 16:56:20 +08:00
|
|
|
if (StrRef.size() != 36) {
|
2013-09-13 23:35:43 +08:00
|
|
|
S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
|
2013-05-17 22:04:52 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-01-24 05:07:30 +08:00
|
|
|
|
2013-08-09 16:56:20 +08:00
|
|
|
for (unsigned i = 0; i < 36; ++i) {
|
2013-05-17 22:04:52 +08:00
|
|
|
if (i == 8 || i == 13 || i == 18 || i == 23) {
|
2013-08-09 16:56:20 +08:00
|
|
|
if (StrRef[i] != '-') {
|
2013-09-13 23:35:43 +08:00
|
|
|
S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
|
2010-12-20 09:41:49 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-08-09 16:56:20 +08:00
|
|
|
} else if (!isHexDigit(StrRef[i])) {
|
2013-09-13 23:35:43 +08:00
|
|
|
S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
|
2013-05-17 22:04:52 +08:00
|
|
|
return;
|
2010-12-20 09:41:49 +08:00
|
|
|
}
|
2013-05-17 22:04:52 +08:00
|
|
|
}
|
2010-12-19 14:50:37 +08:00
|
|
|
|
2013-08-09 16:56:20 +08:00
|
|
|
D->addAttr(::new (S.Context) UuidAttr(Attr.getRange(), S.Context, StrRef,
|
|
|
|
Attr.getAttributeSpellingListIndex()));
|
2010-02-17 02:27:26 +08:00
|
|
|
}
|
|
|
|
|
2013-09-10 07:33:17 +08:00
|
|
|
/// Handles semantic checking for features that are common to all attributes,
|
|
|
|
/// such as checking whether a parameter was properly specified, or the correct
|
|
|
|
/// number of arguments were passed, etc.
|
|
|
|
static bool handleCommonAttributeFeatures(Sema &S, Scope *scope, Decl *D,
|
|
|
|
const AttributeList &Attr) {
|
|
|
|
// Several attributes carry different semantics than the parsing requires, so
|
|
|
|
// those are opted out of the common handling.
|
|
|
|
//
|
|
|
|
// We also bail on unknown and ignored attributes because those are handled
|
|
|
|
// as part of the target-specific handling logic.
|
|
|
|
if (Attr.hasCustomParsing() ||
|
|
|
|
Attr.getKind() == AttributeList::UnknownAttribute ||
|
|
|
|
Attr.getKind() == AttributeList::IgnoredAttribute)
|
|
|
|
return false;
|
|
|
|
|
2013-12-03 03:30:36 +08:00
|
|
|
// Check whether the attribute requires specific language extensions to be
|
|
|
|
// enabled.
|
|
|
|
if (!Attr.diagnoseLangOpts(S))
|
|
|
|
return true;
|
|
|
|
|
2013-09-10 07:33:17 +08:00
|
|
|
// If there are no optional arguments, then checking for the argument count
|
|
|
|
// is trivial.
|
|
|
|
if (Attr.getMinArgs() == Attr.getMaxArgs() &&
|
|
|
|
!checkAttributeNumArgs(S, Attr, Attr.getMinArgs()))
|
|
|
|
return true;
|
2013-11-27 21:27:02 +08:00
|
|
|
|
|
|
|
// Check whether the attribute appertains to the given subject.
|
|
|
|
if (!Attr.diagnoseAppertainsTo(S, D))
|
|
|
|
return true;
|
|
|
|
|
2013-09-10 07:33:17 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-29 08:23:49 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Top Level Sema Entry Points
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-08-29 08:47:48 +08:00
|
|
|
/// ProcessDeclAttribute - Apply the specific attribute to the specified decl if
|
|
|
|
/// the attribute applies to decls. If the attribute is a type attribute, just
|
|
|
|
/// silently ignore it if a GNU attribute.
|
|
|
|
static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
|
|
|
|
const AttributeList &Attr,
|
|
|
|
bool IncludeCXX11Attributes) {
|
|
|
|
if (Attr.isInvalid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ignore C++11 attributes on declarator chunks: they appertain to the type
|
|
|
|
// instead.
|
|
|
|
if (Attr.isCXX11Attribute() && !IncludeCXX11Attributes)
|
|
|
|
return;
|
2010-04-30 21:10:51 +08:00
|
|
|
|
2013-09-10 07:33:17 +08:00
|
|
|
if (handleCommonAttributeFeatures(S, scope, D, Attr))
|
|
|
|
return;
|
|
|
|
|
2008-06-29 08:43:07 +08:00
|
|
|
switch (Attr.getKind()) {
|
2013-12-02 23:13:14 +08:00
|
|
|
case AttributeList::AT_IBAction:
|
|
|
|
handleSimpleAttribute<IBActionAttr>(S, D, Attr); break;
|
2013-01-17 09:30:42 +08:00
|
|
|
case AttributeList::AT_IBOutlet: handleIBOutlet(S, D, Attr); break;
|
|
|
|
case AttributeList::AT_IBOutletCollection:
|
|
|
|
handleIBOutletCollection(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_AddressSpace:
|
|
|
|
case AttributeList::AT_ObjCGC:
|
|
|
|
case AttributeList::AT_VectorSize:
|
|
|
|
case AttributeList::AT_NeonVectorType:
|
|
|
|
case AttributeList::AT_NeonPolyVectorType:
|
2013-05-23 07:25:32 +08:00
|
|
|
case AttributeList::AT_Ptr32:
|
|
|
|
case AttributeList::AT_Ptr64:
|
|
|
|
case AttributeList::AT_SPtr:
|
|
|
|
case AttributeList::AT_UPtr:
|
2009-07-25 03:02:52 +08:00
|
|
|
// Ignore these, these are type attributes, handled by
|
|
|
|
// ProcessTypeAttributes.
|
2008-06-29 08:43:07 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Alias: handleAliasAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_Aligned: handleAlignedAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_AlwaysInline:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<AlwaysInlineAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_AnalyzerNoReturn:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleAnalyzerNoReturnAttr (S, D, Attr); break;
|
2012-06-23 19:51:46 +08:00
|
|
|
case AttributeList::AT_TLSModel: handleTLSModelAttr (S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Annotate: handleAnnotateAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_Availability:handleAvailabilityAttr(S, D, Attr); break;
|
|
|
|
case AttributeList::AT_CarriesDependency:
|
2013-01-29 06:42:45 +08:00
|
|
|
handleDependencyAttr(S, scope, D, Attr);
|
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Common: handleCommonAttr (S, D, Attr); break;
|
2013-12-03 03:30:36 +08:00
|
|
|
case AttributeList::AT_CUDAConstant:
|
|
|
|
handleSimpleAttribute<CUDAConstantAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Constructor: handleConstructorAttr (S, D, Attr); break;
|
2013-01-17 09:30:42 +08:00
|
|
|
case AttributeList::AT_CXX11NoReturn:
|
2013-11-28 02:53:58 +08:00
|
|
|
handleSimpleAttribute<CXX11NoReturnAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Deprecated:
|
2013-07-18 21:13:52 +08:00
|
|
|
handleAttrWithMessage<DeprecatedAttr>(S, D, Attr);
|
2012-05-16 20:19:08 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Destructor: handleDestructorAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_ExtVectorType:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleExtVectorTypeAttr(S, scope, D, Attr);
|
2008-08-01 06:40:48 +08:00
|
|
|
break;
|
2012-11-02 07:55:47 +08:00
|
|
|
case AttributeList::AT_MinSize:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<MinSizeAttr>(S, D, Attr);
|
2012-11-02 07:55:47 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Format: handleFormatAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_FormatArg: handleFormatArgAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_CUDAGlobal: handleGlobalAttr (S, D, Attr); break;
|
2013-12-03 05:09:08 +08:00
|
|
|
case AttributeList::AT_CUDADevice:
|
|
|
|
handleSimpleAttribute<CUDADeviceAttr>(S, D, Attr); break;
|
2013-12-03 03:30:36 +08:00
|
|
|
case AttributeList::AT_CUDAHost:
|
|
|
|
handleSimpleAttribute<CUDAHostAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_GNUInline: handleGNUInlineAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_CUDALaunchBounds:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleLaunchBoundsAttr(S, D, Attr);
|
2010-12-13 07:03:07 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Malloc: handleMallocAttr (S, D, Attr); break;
|
2013-11-27 23:24:06 +08:00
|
|
|
case AttributeList::AT_MayAlias:
|
|
|
|
handleSimpleAttribute<MayAliasAttr>(S, D, Attr); break;
|
2013-08-29 08:47:48 +08:00
|
|
|
case AttributeList::AT_Mode: handleModeAttr (S, D, Attr); break;
|
2013-11-27 23:24:06 +08:00
|
|
|
case AttributeList::AT_NoCommon:
|
|
|
|
handleSimpleAttribute<NoCommonAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_NonNull: handleNonNullAttr (S, D, Attr); break;
|
2013-11-27 23:24:06 +08:00
|
|
|
case AttributeList::AT_Overloadable:
|
|
|
|
handleSimpleAttribute<OverloadableAttr>(S, D, Attr); break;
|
2013-11-27 09:46:48 +08:00
|
|
|
case AttributeList::AT_Ownership: handleOwnershipAttr (S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Cold: handleColdAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_Hot: handleHotAttr (S, D, Attr); break;
|
2013-11-27 23:24:06 +08:00
|
|
|
case AttributeList::AT_Naked:
|
|
|
|
handleSimpleAttribute<NakedAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_NoReturn: handleNoReturnAttr (S, D, Attr); break;
|
2013-12-22 00:49:29 +08:00
|
|
|
case AttributeList::AT_NoThrow:
|
|
|
|
handleSimpleAttribute<NoThrowAttr>(S, D, Attr); break;
|
2013-12-03 03:30:36 +08:00
|
|
|
case AttributeList::AT_CUDAShared:
|
|
|
|
handleSimpleAttribute<CUDASharedAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_VecReturn: handleVecReturnAttr (S, D, Attr); break;
|
|
|
|
|
|
|
|
case AttributeList::AT_ObjCOwnership:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleObjCOwnershipAttr(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ObjCPreciseLifetime:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleObjCPreciseLifetimeAttr(S, D, Attr); break;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ObjCReturnsInnerPointer:
|
2011-07-22 16:53:00 +08:00
|
|
|
handleObjCReturnsInnerPointerAttr(S, D, Attr); break;
|
|
|
|
|
2012-09-08 07:46:23 +08:00
|
|
|
case AttributeList::AT_ObjCRequiresSuper:
|
|
|
|
handleObjCRequiresSuperAttr(S, D, Attr); break;
|
|
|
|
|
2013-11-14 07:59:17 +08:00
|
|
|
case AttributeList::AT_ObjCBridge:
|
|
|
|
handleObjCBridgeAttr(S, scope, D, Attr); break;
|
2013-11-22 04:50:32 +08:00
|
|
|
|
|
|
|
case AttributeList::AT_ObjCBridgeMutable:
|
|
|
|
handleObjCBridgeMutableAttr(S, scope, D, Attr); break;
|
2013-12-05 04:32:50 +08:00
|
|
|
|
|
|
|
case AttributeList::AT_ObjCBridgeRelated:
|
|
|
|
handleObjCBridgeRelatedAttr(S, scope, D, Attr); break;
|
2011-09-29 15:17:38 +08:00
|
|
|
|
2013-12-04 05:11:25 +08:00
|
|
|
case AttributeList::AT_ObjCDesignatedInitializer:
|
|
|
|
handleObjCDesignatedInitializer(S, D, Attr); break;
|
|
|
|
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_CFAuditedTransfer:
|
2013-12-03 02:05:46 +08:00
|
|
|
handleCFAuditedTransferAttr(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_CFUnknownTransfer:
|
2013-12-03 02:05:46 +08:00
|
|
|
handleCFUnknownTransferAttr(S, D, Attr); break;
|
2011-09-30 13:12:12 +08:00
|
|
|
|
2009-05-09 10:44:38 +08:00
|
|
|
// Checker-specific.
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_CFConsumed:
|
|
|
|
case AttributeList::AT_NSConsumed: handleNSConsumedAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_NSConsumesSelf:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<NSConsumesSelfAttr>(S, D, Attr); break;
|
2011-01-25 11:31:58 +08:00
|
|
|
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_NSReturnsAutoreleased:
|
|
|
|
case AttributeList::AT_NSReturnsNotRetained:
|
|
|
|
case AttributeList::AT_CFReturnsNotRetained:
|
|
|
|
case AttributeList::AT_NSReturnsRetained:
|
|
|
|
case AttributeList::AT_CFReturnsRetained:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleNSReturnsRetainedAttr(S, D, Attr); break;
|
2012-07-10 06:06:01 +08:00
|
|
|
case AttributeList::AT_WorkGroupSizeHint:
|
2013-12-03 06:38:33 +08:00
|
|
|
handleWorkGroupSize<WorkGroupSizeHintAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ReqdWorkGroupSize:
|
2013-12-03 06:38:33 +08:00
|
|
|
handleWorkGroupSize<ReqdWorkGroupSizeAttr>(S, D, Attr); break;
|
2013-03-08 17:42:32 +08:00
|
|
|
case AttributeList::AT_VecTypeHint:
|
|
|
|
handleVecTypeHint(S, D, Attr); break;
|
|
|
|
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_InitPriority:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleInitPriorityAttr(S, D, Attr); break;
|
2010-06-19 05:44:06 +08:00
|
|
|
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Packed: handlePackedAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_Section: handleSectionAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_Unavailable:
|
2013-07-18 21:13:52 +08:00
|
|
|
handleAttrWithMessage<UnavailableAttr>(S, D, Attr);
|
2012-05-16 20:19:08 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ArcWeakrefUnavailable:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<ArcWeakrefUnavailableAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ObjCRootClass:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<ObjCRootClassAttr>(S, D, Attr); break;
|
2013-12-11 03:43:48 +08:00
|
|
|
case AttributeList::AT_ObjCExplicitProtocolImpl:
|
2013-11-23 09:01:34 +08:00
|
|
|
handleObjCSuppresProtocolAttr(S, D, Attr);
|
|
|
|
break;
|
|
|
|
case AttributeList::AT_ObjCRequiresPropertyDefs:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<ObjCRequiresPropertyDefsAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Unused: handleUnusedAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_ReturnsTwice:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<ReturnsTwiceAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Used: handleUsedAttr (S, D, Attr); break;
|
2013-02-20 09:54:26 +08:00
|
|
|
case AttributeList::AT_Visibility:
|
|
|
|
handleVisibilityAttr(S, D, Attr, false);
|
|
|
|
break;
|
|
|
|
case AttributeList::AT_TypeVisibility:
|
|
|
|
handleVisibilityAttr(S, D, Attr, true);
|
|
|
|
break;
|
2013-07-20 23:05:36 +08:00
|
|
|
case AttributeList::AT_WarnUnused:
|
2013-11-28 00:59:17 +08:00
|
|
|
handleSimpleAttribute<WarnUnusedAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_WarnUnusedResult: handleWarnUnusedResult(S, D, Attr);
|
2009-02-14 15:37:35 +08:00
|
|
|
break;
|
2013-12-03 01:07:07 +08:00
|
|
|
case AttributeList::AT_Weak:
|
|
|
|
handleSimpleAttribute<WeakAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_WeakRef: handleWeakRefAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_WeakImport: handleWeakImportAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_TransparentUnion:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleTransparentUnionAttr(S, D, Attr);
|
2008-06-29 08:43:07 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ObjCException:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<ObjCExceptionAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ObjCMethodFamily:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleObjCMethodFamilyAttr(S, D, Attr);
|
2011-03-02 19:33:24 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ObjCNSObject:handleObjCNSObject (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_Blocks: handleBlocksAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_Sentinel: handleSentinelAttr (S, D, Attr); break;
|
2013-12-22 00:49:29 +08:00
|
|
|
case AttributeList::AT_Const:
|
|
|
|
handleSimpleAttribute<ConstAttr>(S, D, Attr); break;
|
2013-11-27 23:24:06 +08:00
|
|
|
case AttributeList::AT_Pure:
|
|
|
|
handleSimpleAttribute<PureAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Cleanup: handleCleanupAttr (S, D, Attr); break;
|
|
|
|
case AttributeList::AT_NoDebug: handleNoDebugAttr (S, D, Attr); break;
|
2013-11-27 23:24:06 +08:00
|
|
|
case AttributeList::AT_NoInline:
|
|
|
|
handleSimpleAttribute<NoInlineAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Regparm: handleRegparmAttr (S, D, Attr); break;
|
2009-07-25 03:02:52 +08:00
|
|
|
case AttributeList::IgnoredAttribute:
|
2009-02-13 16:16:43 +08:00
|
|
|
// Just ignore
|
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_NoInstrumentFunction: // Interacts with -pg.
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<NoInstrumentFunctionAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_StdCall:
|
|
|
|
case AttributeList::AT_CDecl:
|
|
|
|
case AttributeList::AT_FastCall:
|
|
|
|
case AttributeList::AT_ThisCall:
|
|
|
|
case AttributeList::AT_Pascal:
|
2013-08-30 12:39:01 +08:00
|
|
|
case AttributeList::AT_MSABI:
|
|
|
|
case AttributeList::AT_SysVABI:
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Pcs:
|
2012-10-17 06:30:41 +08:00
|
|
|
case AttributeList::AT_PnaclCall:
|
2012-12-25 16:53:55 +08:00
|
|
|
case AttributeList::AT_IntelOclBicc:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleCallConvAttr(S, D, Attr);
|
2010-02-06 05:31:56 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_OpenCLKernel:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<OpenCLKernelAttr>(S, D, Attr); break;
|
2013-03-24 21:58:12 +08:00
|
|
|
case AttributeList::AT_OpenCLImageAccess:
|
|
|
|
handleOpenCLImageAccessAttr(S, D, Attr);
|
|
|
|
break;
|
2012-05-23 05:28:12 +08:00
|
|
|
|
|
|
|
// Microsoft attributes:
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_MsStruct:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<MsStructAttr>(S, D, Attr);
|
2012-05-23 05:28:12 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Uuid:
|
2011-07-02 08:01:44 +08:00
|
|
|
handleUuidAttr(S, D, Attr);
|
2010-12-19 14:50:37 +08:00
|
|
|
break;
|
2013-12-19 07:44:18 +08:00
|
|
|
case AttributeList::AT_MSInheritance:
|
|
|
|
handleSimpleAttribute<MSInheritanceAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ForceInline:
|
2013-12-03 03:30:36 +08:00
|
|
|
handleSimpleAttribute<ForceInlineAttr>(S, D, Attr); break;
|
2013-05-20 22:02:37 +08:00
|
|
|
case AttributeList::AT_SelectAny:
|
2013-12-03 03:30:36 +08:00
|
|
|
handleSimpleAttribute<SelectAnyAttr>(S, D, Attr); break;
|
2011-07-29 01:21:07 +08:00
|
|
|
|
|
|
|
// Thread safety attributes:
|
2013-05-18 07:02:59 +08:00
|
|
|
case AttributeList::AT_AssertExclusiveLock:
|
|
|
|
handleAssertExclusiveLockAttr(S, D, Attr);
|
|
|
|
break;
|
|
|
|
case AttributeList::AT_AssertSharedLock:
|
|
|
|
handleAssertSharedLockAttr(S, D, Attr);
|
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_GuardedVar:
|
2013-12-02 23:02:49 +08:00
|
|
|
handleSimpleAttribute<GuardedVarAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_PtGuardedVar:
|
2012-07-24 02:48:41 +08:00
|
|
|
handlePtGuardedVarAttr(S, D, Attr);
|
2011-07-29 01:21:07 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ScopedLockable:
|
2013-11-28 03:35:27 +08:00
|
|
|
handleSimpleAttribute<ScopedLockableAttr>(S, D, Attr); break;
|
2013-02-26 14:58:27 +08:00
|
|
|
case AttributeList::AT_NoSanitizeAddress:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<NoSanitizeAddressAttr>(S, D, Attr);
|
2012-01-25 03:25:38 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_NoThreadSafetyAnalysis:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<NoThreadSafetyAnalysisAttr>(S, D, Attr);
|
2013-02-26 14:58:27 +08:00
|
|
|
break;
|
|
|
|
case AttributeList::AT_NoSanitizeThread:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<NoSanitizeThreadAttr>(S, D, Attr);
|
2013-02-26 14:58:27 +08:00
|
|
|
break;
|
|
|
|
case AttributeList::AT_NoSanitizeMemory:
|
2013-11-27 23:24:06 +08:00
|
|
|
handleSimpleAttribute<NoSanitizeMemoryAttr>(S, D, Attr);
|
2011-07-29 01:21:07 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_Lockable:
|
2013-11-28 03:35:27 +08:00
|
|
|
handleSimpleAttribute<LockableAttr>(S, D, Attr); break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_GuardedBy:
|
2011-07-29 04:12:35 +08:00
|
|
|
handleGuardedByAttr(S, D, Attr);
|
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_PtGuardedBy:
|
2012-07-24 02:48:41 +08:00
|
|
|
handlePtGuardedByAttr(S, D, Attr);
|
2011-07-29 04:12:35 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ExclusiveLockFunction:
|
2012-07-24 02:48:41 +08:00
|
|
|
handleExclusiveLockFunctionAttr(S, D, Attr);
|
2011-07-29 04:12:35 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ExclusiveLocksRequired:
|
2012-07-24 02:48:41 +08:00
|
|
|
handleExclusiveLocksRequiredAttr(S, D, Attr);
|
2011-07-29 04:12:35 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_ExclusiveTrylockFunction:
|
2012-07-24 02:48:41 +08:00
|
|
|
handleExclusiveTrylockFunctionAttr(S, D, Attr);
|
2011-07-29 04:12:35 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_LockReturned:
|
2011-07-29 04:12:35 +08:00
|
|
|
handleLockReturnedAttr(S, D, Attr);
|
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_LocksExcluded:
|
2011-07-29 04:12:35 +08:00
|
|
|
handleLocksExcludedAttr(S, D, Attr);
|
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_SharedLockFunction:
|
2012-07-24 02:48:41 +08:00
|
|
|
handleSharedLockFunctionAttr(S, D, Attr);
|
2011-07-29 04:12:35 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_SharedLocksRequired:
|
2012-07-24 02:48:41 +08:00
|
|
|
handleSharedLocksRequiredAttr(S, D, Attr);
|
2011-07-29 04:12:35 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_SharedTrylockFunction:
|
2012-07-24 02:48:41 +08:00
|
|
|
handleSharedTrylockFunctionAttr(S, D, Attr);
|
2011-07-29 04:12:35 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_UnlockFunction:
|
2011-07-29 04:12:35 +08:00
|
|
|
handleUnlockFunAttr(S, D, Attr);
|
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_AcquiredBefore:
|
2012-07-24 02:48:41 +08:00
|
|
|
handleAcquiredBeforeAttr(S, D, Attr);
|
2011-07-29 04:12:35 +08:00
|
|
|
break;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_AcquiredAfter:
|
2012-07-24 02:48:41 +08:00
|
|
|
handleAcquiredAfterAttr(S, D, Attr);
|
2011-07-29 04:12:35 +08:00
|
|
|
break;
|
2011-07-29 01:21:07 +08:00
|
|
|
|
2013-10-12 06:30:48 +08:00
|
|
|
// Consumed analysis attributes.
|
2013-08-31 06:56:34 +08:00
|
|
|
case AttributeList::AT_Consumable:
|
|
|
|
handleConsumableAttr(S, D, Attr);
|
|
|
|
break;
|
2013-10-05 05:28:06 +08:00
|
|
|
case AttributeList::AT_CallableWhen:
|
|
|
|
handleCallableWhenAttr(S, D, Attr);
|
2013-08-13 05:20:55 +08:00
|
|
|
break;
|
2013-10-18 07:23:53 +08:00
|
|
|
case AttributeList::AT_ParamTypestate:
|
|
|
|
handleParamTypestateAttr(S, D, Attr);
|
|
|
|
break;
|
2013-09-04 04:11:38 +08:00
|
|
|
case AttributeList::AT_ReturnTypestate:
|
|
|
|
handleReturnTypestateAttr(S, D, Attr);
|
|
|
|
break;
|
2013-10-12 07:03:26 +08:00
|
|
|
case AttributeList::AT_SetTypestate:
|
|
|
|
handleSetTypestateAttr(S, D, Attr);
|
|
|
|
break;
|
2013-10-30 04:28:41 +08:00
|
|
|
case AttributeList::AT_TestTypestate:
|
|
|
|
handleTestTypestateAttr(S, D, Attr);
|
2013-10-12 07:03:26 +08:00
|
|
|
break;
|
2013-08-13 05:20:55 +08:00
|
|
|
|
2012-08-17 08:08:38 +08:00
|
|
|
// Type safety attributes.
|
|
|
|
case AttributeList::AT_ArgumentWithTypeTag:
|
|
|
|
handleArgumentWithTypeTagAttr(S, D, Attr);
|
|
|
|
break;
|
|
|
|
case AttributeList::AT_TypeTagForDatatype:
|
|
|
|
handleTypeTagForDatatypeAttr(S, D, Attr);
|
|
|
|
break;
|
|
|
|
|
2008-06-29 08:43:07 +08:00
|
|
|
default:
|
2010-01-10 20:58:08 +08:00
|
|
|
// Ask target about the attribute.
|
|
|
|
const TargetAttributesSema &TargetAttrs = S.getTargetAttributesSema();
|
|
|
|
if (!TargetAttrs.ProcessDeclAttribute(scope, D, Attr, S))
|
2012-06-20 06:09:27 +08:00
|
|
|
S.Diag(Attr.getLoc(), Attr.isDeclspecAttribute() ?
|
|
|
|
diag::warn_unhandled_ms_attribute_ignored :
|
|
|
|
diag::warn_unknown_attribute_ignored) << Attr.getName();
|
2008-06-29 08:43:07 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ProcessDeclAttributeList - Apply all the decl attributes in the specified
|
|
|
|
/// attribute list to the specified decl, ignoring any type attributes.
|
2010-12-02 06:13:54 +08:00
|
|
|
void Sema::ProcessDeclAttributeList(Scope *S, Decl *D,
|
2011-01-21 10:08:45 +08:00
|
|
|
const AttributeList *AttrList,
|
2013-01-17 09:30:42 +08:00
|
|
|
bool IncludeCXX11Attributes) {
|
|
|
|
for (const AttributeList* l = AttrList; l; l = l->getNext())
|
2013-08-29 08:47:48 +08:00
|
|
|
ProcessDeclAttribute(*this, S, D, *l, IncludeCXX11Attributes);
|
2010-02-24 06:00:30 +08:00
|
|
|
|
2013-12-14 00:15:28 +08:00
|
|
|
// FIXME: We should be able to handle these cases in TableGen.
|
2010-02-24 06:00:30 +08:00
|
|
|
// GCC accepts
|
|
|
|
// static int a9 __attribute__((weakref));
|
|
|
|
// but that looks really pointless. We reject it.
|
2013-08-29 08:47:48 +08:00
|
|
|
if (D->hasAttr<WeakRefAttr>() && !D->hasAttr<AliasAttr>()) {
|
2010-02-24 06:00:30 +08:00
|
|
|
Diag(AttrList->getLoc(), diag::err_attribute_weakref_without_alias) <<
|
2013-01-17 07:49:06 +08:00
|
|
|
cast<NamedDecl>(D)->getNameAsString();
|
|
|
|
D->dropAttr<WeakRefAttr>();
|
2010-02-24 06:00:30 +08:00
|
|
|
return;
|
2008-06-29 08:43:07 +08:00
|
|
|
}
|
2013-12-14 00:15:28 +08:00
|
|
|
|
|
|
|
if (!D->hasAttr<OpenCLKernelAttr>()) {
|
|
|
|
// These attributes cannot be applied to a non-kernel function.
|
|
|
|
if (D->hasAttr<ReqdWorkGroupSizeAttr>()) {
|
|
|
|
Diag(D->getLocation(), diag::err_opencl_kernel_attr)
|
|
|
|
<< "reqd_work_group_size";
|
|
|
|
D->setInvalidDecl();
|
|
|
|
}
|
|
|
|
if (D->hasAttr<WorkGroupSizeHintAttr>()) {
|
|
|
|
Diag(D->getLocation(), diag::err_opencl_kernel_attr)
|
|
|
|
<< "work_group_size_hint";
|
|
|
|
D->setInvalidDecl();
|
|
|
|
}
|
|
|
|
if (D->hasAttr<VecTypeHintAttr>()) {
|
|
|
|
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << "vec_type_hint";
|
|
|
|
D->setInvalidDecl();
|
|
|
|
}
|
|
|
|
}
|
2008-06-29 08:43:07 +08:00
|
|
|
}
|
|
|
|
|
2011-10-13 17:41:32 +08:00
|
|
|
// Annotation attributes are the only attributes allowed after an access
|
|
|
|
// specifier.
|
|
|
|
bool Sema::ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
|
|
|
|
const AttributeList *AttrList) {
|
|
|
|
for (const AttributeList* l = AttrList; l; l = l->getNext()) {
|
2012-06-20 07:57:03 +08:00
|
|
|
if (l->getKind() == AttributeList::AT_Annotate) {
|
2011-10-13 17:41:32 +08:00
|
|
|
handleAnnotateAttr(*this, ASDecl, *l);
|
|
|
|
} else {
|
|
|
|
Diag(l->getLoc(), diag::err_only_annotate_after_access_spec);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-01 13:17:03 +08:00
|
|
|
/// checkUnusedDeclAttributes - Check a list of attributes to see if it
|
|
|
|
/// contains any decl attributes that we should warn about.
|
|
|
|
static void checkUnusedDeclAttributes(Sema &S, const AttributeList *A) {
|
|
|
|
for ( ; A; A = A->getNext()) {
|
|
|
|
// Only warn if the attribute is an unignored, non-type attribute.
|
2013-01-29 18:02:16 +08:00
|
|
|
if (A->isUsedAsTypeAttr() || A->isInvalid()) continue;
|
2011-10-01 13:17:03 +08:00
|
|
|
if (A->getKind() == AttributeList::IgnoredAttribute) continue;
|
|
|
|
|
|
|
|
if (A->getKind() == AttributeList::UnknownAttribute) {
|
|
|
|
S.Diag(A->getLoc(), diag::warn_unknown_attribute_ignored)
|
|
|
|
<< A->getName() << A->getRange();
|
|
|
|
} else {
|
|
|
|
S.Diag(A->getLoc(), diag::warn_attribute_not_on_decl)
|
|
|
|
<< A->getName() << A->getRange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// checkUnusedDeclAttributes - Given a declarator which is not being
|
|
|
|
/// used to build a declaration, complain about any decl attributes
|
|
|
|
/// which might be lying around on it.
|
|
|
|
void Sema::checkUnusedDeclAttributes(Declarator &D) {
|
|
|
|
::checkUnusedDeclAttributes(*this, D.getDeclSpec().getAttributes().getList());
|
|
|
|
::checkUnusedDeclAttributes(*this, D.getAttributes());
|
|
|
|
for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i)
|
|
|
|
::checkUnusedDeclAttributes(*this, D.getTypeObject(i).getAttrs());
|
|
|
|
}
|
|
|
|
|
2009-07-30 11:15:39 +08:00
|
|
|
/// DeclClonePragmaWeak - clone existing decl (maybe definition),
|
2012-06-15 05:40:34 +08:00
|
|
|
/// \#pragma weak needs a non-definition decl and source may not have one.
|
2011-09-07 12:05:06 +08:00
|
|
|
NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
|
|
|
|
SourceLocation Loc) {
|
2009-07-31 10:52:19 +08:00
|
|
|
assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
|
2009-07-30 11:15:39 +08:00
|
|
|
NamedDecl *NewD = 0;
|
|
|
|
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
|
2011-09-07 12:05:06 +08:00
|
|
|
FunctionDecl *NewFD;
|
|
|
|
// FIXME: Missing call to CheckFunctionDeclaration().
|
|
|
|
// FIXME: Mangling?
|
|
|
|
// FIXME: Is the qualifier info correct?
|
|
|
|
// FIXME: Is the DeclContext correct?
|
|
|
|
NewFD = FunctionDecl::Create(FD->getASTContext(), FD->getDeclContext(),
|
|
|
|
Loc, Loc, DeclarationName(II),
|
|
|
|
FD->getType(), FD->getTypeSourceInfo(),
|
2013-04-04 03:27:57 +08:00
|
|
|
SC_None, false/*isInlineSpecified*/,
|
2011-09-07 12:05:06 +08:00
|
|
|
FD->hasPrototype(),
|
|
|
|
false/*isConstexprSpecified*/);
|
|
|
|
NewD = NewFD;
|
|
|
|
|
|
|
|
if (FD->getQualifier())
|
2011-02-25 10:25:35 +08:00
|
|
|
NewFD->setQualifierInfo(FD->getQualifierLoc());
|
2011-09-07 12:05:06 +08:00
|
|
|
|
|
|
|
// Fake up parameter variables; they are declared as if this were
|
|
|
|
// a typedef.
|
|
|
|
QualType FDTy = FD->getType();
|
|
|
|
if (const FunctionProtoType *FT = FDTy->getAs<FunctionProtoType>()) {
|
|
|
|
SmallVector<ParmVarDecl*, 16> Params;
|
|
|
|
for (FunctionProtoType::arg_type_iterator AI = FT->arg_type_begin(),
|
|
|
|
AE = FT->arg_type_end(); AI != AE; ++AI) {
|
|
|
|
ParmVarDecl *Param = BuildParmVarDeclForTypedef(NewFD, Loc, *AI);
|
|
|
|
Param->setScopeInfo(0, Params.size());
|
|
|
|
Params.push_back(Param);
|
|
|
|
}
|
2011-09-22 02:16:56 +08:00
|
|
|
NewFD->setParams(Params);
|
2010-03-15 18:12:16 +08:00
|
|
|
}
|
2009-07-30 11:15:39 +08:00
|
|
|
} else if (VarDecl *VD = dyn_cast<VarDecl>(ND)) {
|
|
|
|
NewD = VarDecl::Create(VD->getASTContext(), VD->getDeclContext(),
|
2011-03-08 16:55:46 +08:00
|
|
|
VD->getInnerLocStart(), VD->getLocation(), II,
|
2009-12-07 10:54:59 +08:00
|
|
|
VD->getType(), VD->getTypeSourceInfo(),
|
2013-04-04 03:27:57 +08:00
|
|
|
VD->getStorageClass());
|
2010-03-15 18:12:16 +08:00
|
|
|
if (VD->getQualifier()) {
|
|
|
|
VarDecl *NewVD = cast<VarDecl>(NewD);
|
2011-02-25 10:25:35 +08:00
|
|
|
NewVD->setQualifierInfo(VD->getQualifierLoc());
|
2010-03-15 18:12:16 +08:00
|
|
|
}
|
2009-07-30 11:15:39 +08:00
|
|
|
}
|
|
|
|
return NewD;
|
|
|
|
}
|
|
|
|
|
2012-06-15 05:40:34 +08:00
|
|
|
/// DeclApplyPragmaWeak - A declaration (maybe definition) needs \#pragma weak
|
2009-07-30 11:15:39 +08:00
|
|
|
/// applied to it, possibly with an alias.
|
2009-07-31 10:52:19 +08:00
|
|
|
void Sema::DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W) {
|
2009-09-09 02:10:11 +08:00
|
|
|
if (W.getUsed()) return; // only do this once
|
|
|
|
W.setUsed(true);
|
|
|
|
if (W.getAlias()) { // clone decl, impersonate __attribute(weak,alias(...))
|
|
|
|
IdentifierInfo *NDId = ND->getIdentifier();
|
2011-09-07 12:05:06 +08:00
|
|
|
NamedDecl *NewD = DeclClonePragmaWeak(ND, W.getAlias(), W.getLocation());
|
2010-08-19 07:23:40 +08:00
|
|
|
NewD->addAttr(::new (Context) AliasAttr(W.getLocation(), Context,
|
|
|
|
NDId->getName()));
|
|
|
|
NewD->addAttr(::new (Context) WeakAttr(W.getLocation(), Context));
|
2009-09-09 02:10:11 +08:00
|
|
|
WeakTopLevelDecl.push_back(NewD);
|
|
|
|
// FIXME: "hideous" code from Sema::LazilyCreateBuiltin
|
|
|
|
// to insert Decl at TU scope, sorry.
|
|
|
|
DeclContext *SavedContext = CurContext;
|
|
|
|
CurContext = Context.getTranslationUnitDecl();
|
|
|
|
PushOnScopeChains(NewD, S);
|
|
|
|
CurContext = SavedContext;
|
|
|
|
} else { // just add weak to existing
|
2010-08-19 07:23:40 +08:00
|
|
|
ND->addAttr(::new (Context) WeakAttr(W.getLocation(), Context));
|
2009-07-30 11:15:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-03 05:41:48 +08:00
|
|
|
void Sema::ProcessPragmaWeak(Scope *S, Decl *D) {
|
2010-10-27 08:59:00 +08:00
|
|
|
// It's valid to "forward-declare" #pragma weak, in which case we
|
|
|
|
// have to do this.
|
2013-03-03 05:41:48 +08:00
|
|
|
LoadExternalWeakUndeclaredIdentifiers();
|
|
|
|
if (!WeakUndeclaredIdentifiers.empty()) {
|
|
|
|
NamedDecl *ND = NULL;
|
|
|
|
if (VarDecl *VD = dyn_cast<VarDecl>(D))
|
|
|
|
if (VD->isExternC())
|
|
|
|
ND = VD;
|
|
|
|
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
|
|
|
if (FD->isExternC())
|
|
|
|
ND = FD;
|
|
|
|
if (ND) {
|
|
|
|
if (IdentifierInfo *Id = ND->getIdentifier()) {
|
|
|
|
llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator I
|
|
|
|
= WeakUndeclaredIdentifiers.find(Id);
|
|
|
|
if (I != WeakUndeclaredIdentifiers.end()) {
|
|
|
|
WeakInfo W = I->second;
|
|
|
|
DeclApplyPragmaWeak(S, ND, W);
|
|
|
|
WeakUndeclaredIdentifiers[Id] = W;
|
2010-10-27 08:59:00 +08:00
|
|
|
}
|
2009-07-30 11:15:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-03 05:41:48 +08:00
|
|
|
}
|
2009-07-30 11:15:39 +08:00
|
|
|
|
2013-03-03 05:41:48 +08:00
|
|
|
/// ProcessDeclAttributes - Given a declarator (PD) with attributes indicated in
|
|
|
|
/// it, apply them to D. This is a bit tricky because PD can have attributes
|
|
|
|
/// specified in many different places, and we need to find and apply them all.
|
2013-08-29 08:47:48 +08:00
|
|
|
void Sema::ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD) {
|
2008-06-29 08:23:49 +08:00
|
|
|
// Apply decl attributes from the DeclSpec if present.
|
2010-12-24 10:08:15 +08:00
|
|
|
if (const AttributeList *Attrs = PD.getDeclSpec().getAttributes().getList())
|
2013-08-29 08:47:48 +08:00
|
|
|
ProcessDeclAttributeList(S, D, Attrs);
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2008-06-29 08:23:49 +08:00
|
|
|
// Walk the declarator structure, applying decl attributes that were in a type
|
|
|
|
// position to the decl itself. This handles cases like:
|
|
|
|
// int *__attr__(x)** D;
|
|
|
|
// when X is a decl attribute.
|
|
|
|
for (unsigned i = 0, e = PD.getNumTypeObjects(); i != e; ++i)
|
|
|
|
if (const AttributeList *Attrs = PD.getTypeObject(i).getAttrs())
|
2013-08-29 08:47:48 +08:00
|
|
|
ProcessDeclAttributeList(S, D, Attrs, /*IncludeCXX11Attributes=*/false);
|
2009-07-25 03:02:52 +08:00
|
|
|
|
2008-06-29 08:23:49 +08:00
|
|
|
// Finally, apply any attributes on the decl itself.
|
|
|
|
if (const AttributeList *Attrs = PD.getAttributes())
|
2013-08-29 08:47:48 +08:00
|
|
|
ProcessDeclAttributeList(S, D, Attrs);
|
2008-06-29 08:23:49 +08:00
|
|
|
}
|
2009-11-04 10:18:39 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
/// Is the given declaration allowed to use a forbidden type?
|
|
|
|
static bool isForbiddenTypeAllowed(Sema &S, Decl *decl) {
|
|
|
|
// Private ivars are always okay. Unfortunately, people don't
|
|
|
|
// always properly make their ivars private, even in system headers.
|
|
|
|
// Plus we need to make fields okay, too.
|
2011-09-27 05:23:35 +08:00
|
|
|
// Function declarations in sys headers will be marked unavailable.
|
|
|
|
if (!isa<FieldDecl>(decl) && !isa<ObjCPropertyDecl>(decl) &&
|
|
|
|
!isa<FunctionDecl>(decl))
|
2011-06-16 07:02:42 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Require it to be declared in a system header.
|
|
|
|
return S.Context.getSourceManager().isInSystemHeader(decl->getLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Handle a delayed forbidden-type diagnostic.
|
|
|
|
static void handleDelayedForbiddenType(Sema &S, DelayedDiagnostic &diag,
|
|
|
|
Decl *decl) {
|
|
|
|
if (decl && isForbiddenTypeAllowed(S, decl)) {
|
|
|
|
decl->addAttr(new (S.Context) UnavailableAttr(diag.Loc, S.Context,
|
|
|
|
"this system declaration uses an unsupported type"));
|
|
|
|
return;
|
|
|
|
}
|
2012-03-11 15:00:24 +08:00
|
|
|
if (S.getLangOpts().ObjCAutoRefCount)
|
2011-10-04 06:11:57 +08:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(decl)) {
|
2012-06-02 18:20:41 +08:00
|
|
|
// FIXME: we may want to suppress diagnostics for all
|
2011-10-04 06:11:57 +08:00
|
|
|
// kind of forbidden type messages on unavailable functions.
|
|
|
|
if (FD->hasAttr<UnavailableAttr>() &&
|
|
|
|
diag.getForbiddenTypeDiagnostic() ==
|
|
|
|
diag::err_arc_array_param_no_ownership) {
|
|
|
|
diag.Triggered = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
S.Diag(diag.Loc, diag.getForbiddenTypeDiagnostic())
|
|
|
|
<< diag.getForbiddenTypeOperand() << diag.getForbiddenTypeArgument();
|
|
|
|
diag.Triggered = true;
|
|
|
|
}
|
|
|
|
|
2012-05-07 14:16:41 +08:00
|
|
|
void Sema::PopParsingDeclaration(ParsingDeclState state, Decl *decl) {
|
|
|
|
assert(DelayedDiagnostics.getCurrentPool());
|
2012-05-07 14:16:58 +08:00
|
|
|
DelayedDiagnosticPool &poppedPool = *DelayedDiagnostics.getCurrentPool();
|
2012-05-07 14:16:41 +08:00
|
|
|
DelayedDiagnostics.popWithoutEmitting(state);
|
|
|
|
|
|
|
|
// When delaying diagnostics to run in the context of a parsed
|
|
|
|
// declaration, we only want to actually emit anything if parsing
|
|
|
|
// succeeds.
|
|
|
|
if (!decl) return;
|
|
|
|
|
|
|
|
// We emit all the active diagnostics in this pool or any of its
|
|
|
|
// parents. In general, we'll get one pool for the decl spec
|
|
|
|
// and a child pool for each declarator; in a decl group like:
|
|
|
|
// deprecated_typedef foo, *bar, baz();
|
|
|
|
// only the declarator pops will be passed decls. This is correct;
|
|
|
|
// we really do need to consider delayed diagnostics from the decl spec
|
|
|
|
// for each of the different declarations.
|
2012-05-07 14:16:58 +08:00
|
|
|
const DelayedDiagnosticPool *pool = &poppedPool;
|
2012-05-07 14:16:41 +08:00
|
|
|
do {
|
2012-05-07 14:16:58 +08:00
|
|
|
for (DelayedDiagnosticPool::pool_iterator
|
2012-05-07 14:16:41 +08:00
|
|
|
i = pool->pool_begin(), e = pool->pool_end(); i != e; ++i) {
|
|
|
|
// This const_cast is a bit lame. Really, Triggered should be mutable.
|
|
|
|
DelayedDiagnostic &diag = const_cast<DelayedDiagnostic&>(*i);
|
2011-02-14 15:13:47 +08:00
|
|
|
if (diag.Triggered)
|
2010-01-27 11:50:35 +08:00
|
|
|
continue;
|
|
|
|
|
2011-02-14 15:13:47 +08:00
|
|
|
switch (diag.Kind) {
|
2010-01-27 11:50:35 +08:00
|
|
|
case DelayedDiagnostic::Deprecation:
|
2013-12-19 07:30:06 +08:00
|
|
|
case DelayedDiagnostic::Unavailable:
|
|
|
|
// Don't bother giving deprecation/unavailable diagnostics if
|
|
|
|
// the decl is invalid.
|
2012-01-27 04:04:03 +08:00
|
|
|
if (!decl->isInvalidDecl())
|
2013-12-19 07:30:06 +08:00
|
|
|
HandleDelayedAvailabilityCheck(diag, decl);
|
2010-01-27 11:50:35 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DelayedDiagnostic::Access:
|
2012-05-07 14:16:41 +08:00
|
|
|
HandleDelayedAccessCheck(diag, decl);
|
2010-01-27 11:50:35 +08:00
|
|
|
break;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
case DelayedDiagnostic::ForbiddenType:
|
2012-05-07 14:16:41 +08:00
|
|
|
handleDelayedForbiddenType(*this, diag, decl);
|
2011-06-16 07:02:42 +08:00
|
|
|
break;
|
2009-11-04 10:18:39 +08:00
|
|
|
}
|
|
|
|
}
|
2012-05-07 14:16:41 +08:00
|
|
|
} while ((pool = pool->getParent()));
|
2010-01-27 11:50:35 +08:00
|
|
|
}
|
|
|
|
|
2012-05-07 14:16:58 +08:00
|
|
|
/// Given a set of delayed diagnostics, re-emit them as if they had
|
|
|
|
/// been delayed in the current context instead of in the given pool.
|
|
|
|
/// Essentially, this just moves them to the current pool.
|
|
|
|
void Sema::redelayDiagnostics(DelayedDiagnosticPool &pool) {
|
|
|
|
DelayedDiagnosticPool *curPool = DelayedDiagnostics.getCurrentPool();
|
|
|
|
assert(curPool && "re-emitting in undelayed context not supported");
|
|
|
|
curPool->steal(pool);
|
|
|
|
}
|
|
|
|
|
2010-01-27 11:50:35 +08:00
|
|
|
static bool isDeclDeprecated(Decl *D) {
|
|
|
|
do {
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
if (D->isDeprecated())
|
2010-01-27 11:50:35 +08:00
|
|
|
return true;
|
2011-10-07 07:23:27 +08:00
|
|
|
// A category implicitly has the availability of the interface.
|
|
|
|
if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(D))
|
|
|
|
return CatD->getClassInterface()->isDeprecated();
|
2010-01-27 11:50:35 +08:00
|
|
|
} while ((D = cast_or_null<Decl>(D->getDeclContext())));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-19 07:30:06 +08:00
|
|
|
static bool isDeclUnavailable(Decl *D) {
|
|
|
|
do {
|
|
|
|
if (D->isUnavailable())
|
|
|
|
return true;
|
|
|
|
// A category implicitly has the availability of the interface.
|
|
|
|
if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(D))
|
|
|
|
return CatD->getClassInterface()->isUnavailable();
|
|
|
|
} while ((D = cast_or_null<Decl>(D->getDeclContext())));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-09 05:52:41 +08:00
|
|
|
static void
|
2013-12-19 07:30:06 +08:00
|
|
|
DoEmitAvailabilityWarning(Sema &S,
|
|
|
|
DelayedDiagnostic::DDKind K,
|
|
|
|
Decl *Ctx,
|
|
|
|
const NamedDecl *D,
|
|
|
|
StringRef Message,
|
|
|
|
SourceLocation Loc,
|
|
|
|
const ObjCInterfaceDecl *UnknownObjCClass,
|
|
|
|
const ObjCPropertyDecl *ObjCProperty) {
|
|
|
|
|
|
|
|
// Diagnostics for deprecated or unavailable.
|
|
|
|
unsigned diag, diag_message, diag_fwdclass_message;
|
|
|
|
|
|
|
|
// Matches 'diag::note_property_attribute' options.
|
|
|
|
unsigned property_note_select;
|
|
|
|
|
|
|
|
// Matches diag::note_availability_specified_here.
|
|
|
|
unsigned available_here_select_kind;
|
|
|
|
|
|
|
|
// Don't warn if our current context is deprecated or unavailable.
|
|
|
|
switch (K) {
|
|
|
|
case DelayedDiagnostic::Deprecation:
|
|
|
|
if (isDeclDeprecated(Ctx))
|
|
|
|
return;
|
|
|
|
diag = diag::warn_deprecated;
|
|
|
|
diag_message = diag::warn_deprecated_message;
|
|
|
|
diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
|
|
|
|
property_note_select = /* deprecated */ 0;
|
|
|
|
available_here_select_kind = /* deprecated */ 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DelayedDiagnostic::Unavailable:
|
|
|
|
if (isDeclUnavailable(Ctx))
|
|
|
|
return;
|
|
|
|
diag = diag::err_unavailable;
|
|
|
|
diag_message = diag::err_unavailable_message;
|
|
|
|
diag_fwdclass_message = diag::warn_unavailable_fwdclass_message;
|
|
|
|
property_note_select = /* unavailable */ 1;
|
|
|
|
available_here_select_kind = /* unavailable */ 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Neither a deprecation or unavailable kind");
|
|
|
|
}
|
|
|
|
|
2012-08-09 05:52:41 +08:00
|
|
|
DeclarationName Name = D->getDeclName();
|
|
|
|
if (!Message.empty()) {
|
2013-12-19 07:30:06 +08:00
|
|
|
S.Diag(Loc, diag_message) << Name << Message;
|
|
|
|
if (ObjCProperty)
|
|
|
|
S.Diag(ObjCProperty->getLocation(), diag::note_property_attribute)
|
|
|
|
<< ObjCProperty->getDeclName() << property_note_select;
|
2012-08-09 05:52:41 +08:00
|
|
|
} else if (!UnknownObjCClass) {
|
2013-12-19 07:30:06 +08:00
|
|
|
S.Diag(Loc, diag) << Name;
|
|
|
|
if (ObjCProperty)
|
|
|
|
S.Diag(ObjCProperty->getLocation(), diag::note_property_attribute)
|
|
|
|
<< ObjCProperty->getDeclName() << property_note_select;
|
2012-08-09 05:52:41 +08:00
|
|
|
} else {
|
2013-12-19 07:30:06 +08:00
|
|
|
S.Diag(Loc, diag_fwdclass_message) << Name;
|
2012-08-09 05:52:41 +08:00
|
|
|
S.Diag(UnknownObjCClass->getLocation(), diag::note_forward_class);
|
|
|
|
}
|
2010-01-27 11:50:35 +08:00
|
|
|
|
2013-12-19 07:30:06 +08:00
|
|
|
S.Diag(D->getLocation(), diag::note_availability_specified_here)
|
|
|
|
<< D << available_here_select_kind;
|
2009-11-04 10:18:39 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 07:30:06 +08:00
|
|
|
void Sema::HandleDelayedAvailabilityCheck(DelayedDiagnostic &DD,
|
|
|
|
Decl *Ctx) {
|
|
|
|
DD.Triggered = true;
|
|
|
|
DoEmitAvailabilityWarning(*this,
|
|
|
|
(DelayedDiagnostic::DDKind) DD.Kind,
|
|
|
|
Ctx,
|
|
|
|
DD.getDeprecationDecl(),
|
|
|
|
DD.getDeprecationMessage(),
|
|
|
|
DD.Loc,
|
|
|
|
DD.getUnknownObjCClass(),
|
|
|
|
DD.getObjCProperty());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::EmitAvailabilityWarning(AvailabilityDiagnostic AD,
|
|
|
|
NamedDecl *D, StringRef Message,
|
|
|
|
SourceLocation Loc,
|
|
|
|
const ObjCInterfaceDecl *UnknownObjCClass,
|
|
|
|
const ObjCPropertyDecl *ObjCProperty) {
|
2009-11-04 10:18:39 +08:00
|
|
|
// Delay if we're currently parsing a declaration.
|
2011-02-14 15:13:47 +08:00
|
|
|
if (DelayedDiagnostics.shouldDelayDiagnostics()) {
|
2013-12-19 07:30:06 +08:00
|
|
|
DelayedDiagnostics.add(DelayedDiagnostic::makeAvailability(AD, Loc, D,
|
|
|
|
UnknownObjCClass,
|
|
|
|
ObjCProperty,
|
|
|
|
Message));
|
2009-11-04 10:18:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-19 07:30:06 +08:00
|
|
|
Decl *Ctx = cast<Decl>(getCurLexicalContext());
|
|
|
|
DelayedDiagnostic::DDKind K;
|
|
|
|
switch (AD) {
|
|
|
|
case AD_Deprecation:
|
|
|
|
K = DelayedDiagnostic::Deprecation;
|
|
|
|
break;
|
|
|
|
case AD_Unavailable:
|
|
|
|
K = DelayedDiagnostic::Unavailable;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DoEmitAvailabilityWarning(*this, K, Ctx, D, Message, Loc,
|
|
|
|
UnknownObjCClass, ObjCProperty);
|
2009-11-04 10:18:39 +08:00
|
|
|
}
|