Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 1 | //===--- SemaDeclAttr.cpp - Declaration Attribute Handling ----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements decl-related attribute processing. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Sema.h" |
| 15 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | e0ad215 | 2008-08-11 06:23:49 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclObjC.h" |
| 17 | #include "clang/AST/Expr.h" |
Daniel Dunbar | cc7b160 | 2008-08-11 03:45:03 +0000 | [diff] [blame] | 18 | #include "clang/Basic/Diagnostic.h" |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 19 | #include "clang/Basic/TargetInfo.h" |
Daniel Dunbar | 8d03cbe | 2008-08-11 03:27:53 +0000 | [diff] [blame] | 20 | #include "clang/Parse/DeclSpec.h" |
Ted Kremenek | 26151d1 | 2008-07-22 16:56:21 +0000 | [diff] [blame] | 21 | #include <llvm/ADT/StringExtras.h> |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
Chris Lattner | 2024f0a | 2008-06-29 00:16:31 +0000 | [diff] [blame] | 24 | //===----------------------------------------------------------------------===// |
| 25 | // Helper functions |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 28 | static const FunctionType *getFunctionType(Decl *d) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 29 | QualType Ty; |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 30 | if (ValueDecl *decl = dyn_cast<ValueDecl>(d)) |
| 31 | Ty = decl->getType(); |
| 32 | else if (FieldDecl *decl = dyn_cast<FieldDecl>(d)) |
| 33 | Ty = decl->getType(); |
| 34 | else if (TypedefDecl* decl = dyn_cast<TypedefDecl>(d)) |
| 35 | Ty = decl->getUnderlyingType(); |
| 36 | else |
| 37 | return 0; |
| 38 | |
| 39 | if (Ty->isFunctionPointerType()) |
| 40 | Ty = Ty->getAsPointerType()->getPointeeType(); |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 41 | |
| 42 | return Ty->getAsFunctionType(); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Daniel Dunbar | d1d847c | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 45 | // FIXME: We should provide an abstraction around a method or function |
| 46 | // to provide the following bits of information. |
| 47 | |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 48 | /// isFunctionOrMethod - Return true if the given decl has function |
| 49 | /// type (function or function-typed variable) or an Objective-C |
| 50 | /// method. |
Daniel Dunbar | d1d847c | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 51 | static bool isFunctionOrMethod(Decl *d) { |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 52 | return getFunctionType(d) || isa<ObjCMethodDecl>(d); |
Daniel Dunbar | d1d847c | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 55 | /// hasFunctionProto - Return true if the given decl has a argument |
| 56 | /// information. This decl should have already passed |
| 57 | /// isFunctionOrMethod. |
| 58 | static bool hasFunctionProto(Decl *d) { |
| 59 | if (const FunctionType *FnTy = getFunctionType(d)) { |
| 60 | return isa<FunctionTypeProto>(FnTy); |
| 61 | } else { |
| 62 | assert(isa<ObjCMethodDecl>(d)); |
| 63 | return true; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /// getFunctionOrMethodNumArgs - Return number of function or method |
| 68 | /// arguments. It is an error to call this on a K&R function (use |
| 69 | /// hasFunctionProto first). |
Daniel Dunbar | d1d847c | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 70 | static unsigned getFunctionOrMethodNumArgs(Decl *d) { |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 71 | if (const FunctionType *FnTy = getFunctionType(d)) { |
| 72 | const FunctionTypeProto *proto = cast<FunctionTypeProto>(FnTy); |
Daniel Dunbar | d1d847c | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 73 | return proto->getNumArgs(); |
| 74 | } else { |
| 75 | return cast<ObjCMethodDecl>(d)->getNumParams(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | static QualType getFunctionOrMethodArgType(Decl *d, unsigned Idx) { |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 80 | if (const FunctionType *FnTy = getFunctionType(d)) { |
| 81 | const FunctionTypeProto *proto = cast<FunctionTypeProto>(FnTy); |
Daniel Dunbar | d1d847c | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 82 | return proto->getArgType(Idx); |
| 83 | } else { |
| 84 | return cast<ObjCMethodDecl>(d)->getParamDecl(Idx)->getType(); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | static bool isFunctionOrMethodVariadic(Decl *d) { |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 89 | if (const FunctionType *FnTy = getFunctionType(d)) { |
| 90 | const FunctionTypeProto *proto = cast<FunctionTypeProto>(FnTy); |
Daniel Dunbar | d1d847c | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 91 | return proto->isVariadic(); |
| 92 | } else { |
| 93 | return cast<ObjCMethodDecl>(d)->isVariadic(); |
| 94 | } |
| 95 | } |
| 96 | |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 97 | static inline bool isNSStringType(QualType T, ASTContext &Ctx) { |
Chris Lattner | d5a56aa | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 98 | const PointerType *PT = T->getAsPointerType(); |
| 99 | if (!PT) |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 100 | return false; |
| 101 | |
Chris Lattner | d5a56aa | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 102 | const ObjCInterfaceType *ClsT =PT->getPointeeType()->getAsObjCInterfaceType(); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 103 | if (!ClsT) |
| 104 | return false; |
| 105 | |
| 106 | IdentifierInfo* ClsName = ClsT->getDecl()->getIdentifier(); |
| 107 | |
| 108 | // FIXME: Should we walk the chain of classes? |
| 109 | return ClsName == &Ctx.Idents.get("NSString") || |
| 110 | ClsName == &Ctx.Idents.get("NSMutableString"); |
| 111 | } |
| 112 | |
Daniel Dunbar | bddb14a | 2008-09-26 03:32:58 +0000 | [diff] [blame] | 113 | static inline bool isCFStringType(QualType T, ASTContext &Ctx) { |
| 114 | const PointerType *PT = T->getAsPointerType(); |
| 115 | if (!PT) |
| 116 | return false; |
| 117 | |
| 118 | const RecordType *RT = PT->getPointeeType()->getAsRecordType(); |
| 119 | if (!RT) |
| 120 | return false; |
| 121 | |
| 122 | const RecordDecl *RD = RT->getDecl(); |
| 123 | if (RD->getTagKind() != TagDecl::TK_struct) |
| 124 | return false; |
| 125 | |
| 126 | return RD->getIdentifier() == &Ctx.Idents.get("__CFString"); |
| 127 | } |
| 128 | |
Chris Lattner | 2024f0a | 2008-06-29 00:16:31 +0000 | [diff] [blame] | 129 | //===----------------------------------------------------------------------===// |
Chris Lattner | 2024f0a | 2008-06-29 00:16:31 +0000 | [diff] [blame] | 130 | // Attribute Implementations |
| 131 | //===----------------------------------------------------------------------===// |
| 132 | |
Daniel Dunbar | 8716a01 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 133 | // FIXME: All this manual attribute parsing code is gross. At the |
| 134 | // least add some helper functions to check most argument patterns (# |
| 135 | // and types of args). |
| 136 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 137 | static void HandleExtVectorTypeAttr(Decl *d, const AttributeList &Attr, |
| 138 | Sema &S) { |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 139 | TypedefDecl *tDecl = dyn_cast<TypedefDecl>(d); |
| 140 | if (tDecl == 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 141 | S.Diag(Attr.getLoc(), diag::err_typecheck_ext_vector_not_typedef); |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 142 | return; |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 145 | QualType curType = tDecl->getUnderlyingType(); |
| 146 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 147 | if (Attr.getNumArgs() != 1) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 148 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 149 | std::string("1")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 150 | return; |
| 151 | } |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 152 | Expr *sizeExpr = static_cast<Expr *>(Attr.getArg(0)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 153 | llvm::APSInt vecSize(32); |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 154 | if (!sizeExpr->isIntegerConstantExpr(vecSize, S.Context)) { |
| 155 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int, |
| 156 | "ext_vector_type", sizeExpr->getSourceRange()); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | // unlike gcc's vector_size attribute, we do not allow vectors to be defined |
| 160 | // in conjunction with complex types (pointers, arrays, functions, etc.). |
Chris Lattner | d5a56aa | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 161 | if (!curType->isIntegerType() && !curType->isRealFloatingType()) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 162 | S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type, |
Chris Lattner | d5a56aa | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 163 | curType.getAsString()); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 164 | return; |
| 165 | } |
| 166 | // unlike gcc's vector_size attribute, the size is specified as the |
| 167 | // number of elements, not the number of bytes. |
| 168 | unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue()); |
| 169 | |
| 170 | if (vectorSize == 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 171 | S.Diag(Attr.getLoc(), diag::err_attribute_zero_size, |
| 172 | sizeExpr->getSourceRange()); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 173 | return; |
| 174 | } |
| 175 | // Instantiate/Install the vector type, the number of elements is > 0. |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 176 | tDecl->setUnderlyingType(S.Context.getExtVectorType(curType, vectorSize)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 177 | // Remember this typedef decl, we will need it later for diagnostics. |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 178 | S.ExtVectorDecls.push_back(tDecl); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 181 | |
| 182 | /// HandleVectorSizeAttribute - this attribute is only applicable to |
| 183 | /// integral and float scalars, although arrays, pointers, and function |
| 184 | /// return values are allowed in conjunction with this construct. Aggregates |
| 185 | /// with this attribute are invalid, even if they are of the same size as a |
| 186 | /// corresponding scalar. |
| 187 | /// The raw attribute should contain precisely 1 argument, the vector size |
| 188 | /// for the variable, measured in bytes. If curType and rawAttr are well |
| 189 | /// formed, this routine will return a new vector type. |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 190 | static void HandleVectorSizeAttr(Decl *D, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 191 | QualType CurType; |
| 192 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) |
| 193 | CurType = VD->getType(); |
| 194 | else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) |
| 195 | CurType = TD->getUnderlyingType(); |
| 196 | else { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 197 | S.Diag(D->getLocation(), diag::err_attr_wrong_decl, |
| 198 | std::string("vector_size"), |
| 199 | SourceRange(Attr.getLoc(), Attr.getLoc())); |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 200 | return; |
| 201 | } |
| 202 | |
| 203 | // Check the attribute arugments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 204 | if (Attr.getNumArgs() != 1) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 205 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 206 | std::string("1")); |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 207 | return; |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 208 | } |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 209 | Expr *sizeExpr = static_cast<Expr *>(Attr.getArg(0)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 210 | llvm::APSInt vecSize(32); |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 211 | if (!sizeExpr->isIntegerConstantExpr(vecSize, S.Context)) { |
| 212 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int, |
| 213 | "vector_size", sizeExpr->getSourceRange()); |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 214 | return; |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 215 | } |
| 216 | // navigate to the base type - we need to provide for vector pointers, |
| 217 | // vector arrays, and functions returning vectors. |
Chris Lattner | d5a56aa | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 218 | if (CurType->isPointerType() || CurType->isArrayType() || |
| 219 | CurType->isFunctionType()) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 220 | assert(0 && "HandleVector(): Complex type construction unimplemented"); |
| 221 | /* FIXME: rebuild the type from the inside out, vectorizing the inner type. |
| 222 | do { |
| 223 | if (PointerType *PT = dyn_cast<PointerType>(canonType)) |
| 224 | canonType = PT->getPointeeType().getTypePtr(); |
| 225 | else if (ArrayType *AT = dyn_cast<ArrayType>(canonType)) |
| 226 | canonType = AT->getElementType().getTypePtr(); |
| 227 | else if (FunctionType *FT = dyn_cast<FunctionType>(canonType)) |
| 228 | canonType = FT->getResultType().getTypePtr(); |
| 229 | } while (canonType->isPointerType() || canonType->isArrayType() || |
| 230 | canonType->isFunctionType()); |
| 231 | */ |
| 232 | } |
| 233 | // the base type must be integer or float. |
Chris Lattner | d5a56aa | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 234 | if (!CurType->isIntegerType() && !CurType->isRealFloatingType()) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 235 | S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type, |
Chris Lattner | d5a56aa | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 236 | CurType.getAsString()); |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 237 | return; |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 238 | } |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 239 | unsigned typeSize = static_cast<unsigned>(S.Context.getTypeSize(CurType)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 240 | // vecSize is specified in bytes - convert to bits. |
| 241 | unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue() * 8); |
| 242 | |
| 243 | // the vector size needs to be an integral multiple of the type size. |
| 244 | if (vectorSize % typeSize) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 245 | S.Diag(Attr.getLoc(), diag::err_attribute_invalid_size, |
| 246 | sizeExpr->getSourceRange()); |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 247 | return; |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 248 | } |
| 249 | if (vectorSize == 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 250 | S.Diag(Attr.getLoc(), diag::err_attribute_zero_size, |
| 251 | sizeExpr->getSourceRange()); |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 252 | return; |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 253 | } |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 254 | |
| 255 | // Success! Instantiate the vector type, the number of elements is > 0, and |
| 256 | // not required to be a power of 2, unlike GCC. |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 257 | CurType = S.Context.getVectorType(CurType, vectorSize/typeSize); |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 258 | |
| 259 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) |
| 260 | VD->setType(CurType); |
| 261 | else |
| 262 | cast<TypedefDecl>(D)->setUnderlyingType(CurType); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 265 | static void HandlePackedAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 266 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 267 | if (Attr.getNumArgs() > 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 268 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 269 | std::string("0")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 270 | return; |
| 271 | } |
| 272 | |
| 273 | if (TagDecl *TD = dyn_cast<TagDecl>(d)) |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 274 | TD->addAttr(new PackedAttr(1)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 275 | else if (FieldDecl *FD = dyn_cast<FieldDecl>(d)) { |
| 276 | // If the alignment is less than or equal to 8 bits, the packed attribute |
| 277 | // has no effect. |
| 278 | if (!FD->getType()->isIncompleteType() && |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 279 | S.Context.getTypeAlign(FD->getType()) <= 8) |
| 280 | S.Diag(Attr.getLoc(), |
| 281 | diag::warn_attribute_ignored_for_field_of_type, |
| 282 | Attr.getName()->getName(), FD->getType().getAsString()); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 283 | else |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 284 | FD->addAttr(new PackedAttr(1)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 285 | } else |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 286 | S.Diag(Attr.getLoc(), diag::warn_attribute_ignored, |
| 287 | Attr.getName()->getName()); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Ted Kremenek | 4e5bb12 | 2008-07-15 22:26:48 +0000 | [diff] [blame] | 290 | static void HandleIBOutletAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
| 291 | // check the attribute arguments. |
| 292 | if (Attr.getNumArgs() > 0) { |
| 293 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 294 | std::string("0")); |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | // The IBOutlet attribute only applies to instance variables of Objective-C |
| 299 | // classes. |
| 300 | if (ObjCIvarDecl *ID = dyn_cast<ObjCIvarDecl>(d)) |
| 301 | ID->addAttr(new IBOutletAttr()); |
| 302 | else |
| 303 | S.Diag(Attr.getLoc(), diag::err_attribute_iboutlet_non_ivar); |
| 304 | } |
| 305 | |
Ted Kremenek | c0af254 | 2008-07-21 21:53:04 +0000 | [diff] [blame] | 306 | static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Ted Kremenek | c0af254 | 2008-07-21 21:53:04 +0000 | [diff] [blame] | 307 | // GCC ignores the nonnull attribute on K&R style function |
| 308 | // prototypes, so we ignore it as well |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 309 | if (!isFunctionOrMethod(d) || !hasFunctionProto(d)) { |
Ted Kremenek | c0af254 | 2008-07-21 21:53:04 +0000 | [diff] [blame] | 310 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type, |
| 311 | "nonnull", "function"); |
| 312 | return; |
| 313 | } |
| 314 | |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 315 | unsigned NumArgs = getFunctionOrMethodNumArgs(d); |
Ted Kremenek | c0af254 | 2008-07-21 21:53:04 +0000 | [diff] [blame] | 316 | |
| 317 | // The nonnull attribute only applies to pointers. |
| 318 | llvm::SmallVector<unsigned, 10> NonNullArgs; |
| 319 | |
| 320 | for (AttributeList::arg_iterator I=Attr.arg_begin(), |
| 321 | E=Attr.arg_end(); I!=E; ++I) { |
| 322 | |
| 323 | |
| 324 | // The argument must be an integer constant expression. |
| 325 | Expr *Ex = static_cast<Expr *>(Attr.getArg(0)); |
| 326 | llvm::APSInt ArgNum(32); |
| 327 | if (!Ex->isIntegerConstantExpr(ArgNum, S.Context)) { |
| 328 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int, |
| 329 | "nonnull", Ex->getSourceRange()); |
| 330 | return; |
| 331 | } |
| 332 | |
| 333 | unsigned x = (unsigned) ArgNum.getZExtValue(); |
| 334 | |
| 335 | if (x < 1 || x > NumArgs) { |
| 336 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds, |
Ted Kremenek | 26151d1 | 2008-07-22 16:56:21 +0000 | [diff] [blame] | 337 | "nonnull", llvm::utostr_32(I.getArgNum()), Ex->getSourceRange()); |
Ted Kremenek | c0af254 | 2008-07-21 21:53:04 +0000 | [diff] [blame] | 338 | return; |
| 339 | } |
Ted Kremenek | 178cee2 | 2008-07-21 22:09:15 +0000 | [diff] [blame] | 340 | |
| 341 | --x; |
Ted Kremenek | c0af254 | 2008-07-21 21:53:04 +0000 | [diff] [blame] | 342 | |
| 343 | // Is the function argument a pointer type? |
Ted Kremenek | ba57bd9 | 2008-11-18 06:52:58 +0000 | [diff] [blame] | 344 | QualType T = getFunctionOrMethodArgType(d, x); |
| 345 | if (!T->isPointerType() && !T->isBlockPointerType()) { |
Ted Kremenek | c0af254 | 2008-07-21 21:53:04 +0000 | [diff] [blame] | 346 | // FIXME: Should also highlight argument in decl. |
| 347 | S.Diag(Attr.getLoc(), diag::err_nonnull_pointers_only, |
| 348 | "nonnull", Ex->getSourceRange()); |
Ted Kremenek | 7af441b | 2008-09-01 19:57:52 +0000 | [diff] [blame] | 349 | continue; |
Ted Kremenek | c0af254 | 2008-07-21 21:53:04 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | NonNullArgs.push_back(x); |
| 353 | } |
| 354 | |
Ted Kremenek | 7af441b | 2008-09-01 19:57:52 +0000 | [diff] [blame] | 355 | // If no arguments were specified to __attribute__((nonnull)) then all |
| 356 | // pointer arguments have a nonnull attribute. |
| 357 | if (NonNullArgs.empty()) { |
Ted Kremenek | ba57bd9 | 2008-11-18 06:52:58 +0000 | [diff] [blame] | 358 | for (unsigned I = 0, E = getFunctionOrMethodNumArgs(d); I != E; ++I) { |
| 359 | QualType T = getFunctionOrMethodArgType(d, I); |
| 360 | if (T->isPointerType() || T->isBlockPointerType()) |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 361 | NonNullArgs.push_back(I); |
Ted Kremenek | ba57bd9 | 2008-11-18 06:52:58 +0000 | [diff] [blame] | 362 | } |
Ted Kremenek | 7af441b | 2008-09-01 19:57:52 +0000 | [diff] [blame] | 363 | |
| 364 | if (NonNullArgs.empty()) { |
| 365 | S.Diag(Attr.getLoc(), diag::warn_attribute_nonnull_no_pointers); |
| 366 | return; |
| 367 | } |
Ted Kremenek | c0af254 | 2008-07-21 21:53:04 +0000 | [diff] [blame] | 368 | } |
Ted Kremenek | 7af441b | 2008-09-01 19:57:52 +0000 | [diff] [blame] | 369 | |
| 370 | unsigned* start = &NonNullArgs[0]; |
| 371 | unsigned size = NonNullArgs.size(); |
| 372 | std::sort(start, start + size); |
| 373 | d->addAttr(new NonNullAttr(start, size)); |
Ted Kremenek | c0af254 | 2008-07-21 21:53:04 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 376 | static void HandleAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 377 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 378 | if (Attr.getNumArgs() != 1) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 379 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 380 | std::string("1")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 381 | return; |
| 382 | } |
| 383 | |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 384 | Expr *Arg = static_cast<Expr*>(Attr.getArg(0)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 385 | Arg = Arg->IgnoreParenCasts(); |
| 386 | StringLiteral *Str = dyn_cast<StringLiteral>(Arg); |
| 387 | |
| 388 | if (Str == 0 || Str->isWide()) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 389 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string, |
| 390 | "alias", std::string("1")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 391 | return; |
| 392 | } |
| 393 | |
| 394 | const char *Alias = Str->getStrData(); |
| 395 | unsigned AliasLen = Str->getByteLength(); |
| 396 | |
| 397 | // FIXME: check if target symbol exists in current file |
| 398 | |
| 399 | d->addAttr(new AliasAttr(std::string(Alias, AliasLen))); |
| 400 | } |
| 401 | |
Daniel Dunbar | 0a2da71 | 2008-10-28 00:17:57 +0000 | [diff] [blame] | 402 | static void HandleAlwaysInlineAttr(Decl *d, const AttributeList &Attr, |
| 403 | Sema &S) { |
| 404 | // check the attribute arguments. |
| 405 | if (Attr.getNumArgs() != 0) { |
| 406 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 407 | std::string("0")); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | d->addAttr(new AlwaysInlineAttr()); |
| 412 | } |
| 413 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 414 | static void HandleNoReturnAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 415 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 416 | if (Attr.getNumArgs() != 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 417 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 418 | std::string("0")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 419 | return; |
| 420 | } |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 421 | |
| 422 | if (!isFunctionOrMethod(d)) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 423 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type, |
| 424 | "noreturn", "function"); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 425 | return; |
| 426 | } |
| 427 | |
| 428 | d->addAttr(new NoReturnAttr()); |
| 429 | } |
| 430 | |
Ted Kremenek | ce13e1e | 2008-07-25 04:39:19 +0000 | [diff] [blame] | 431 | static void HandleUnusedAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
| 432 | // check the attribute arguments. |
| 433 | if (Attr.getNumArgs() != 0) { |
| 434 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 435 | std::string("0")); |
| 436 | return; |
| 437 | } |
| 438 | |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 439 | if (!isa<VarDecl>(d) && !isFunctionOrMethod(d)) { |
Ted Kremenek | ce13e1e | 2008-07-25 04:39:19 +0000 | [diff] [blame] | 440 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type, |
Ted Kremenek | 4159e8a | 2008-08-07 01:02:05 +0000 | [diff] [blame] | 441 | "unused", "variable and function"); |
Ted Kremenek | ce13e1e | 2008-07-25 04:39:19 +0000 | [diff] [blame] | 442 | return; |
| 443 | } |
| 444 | |
| 445 | d->addAttr(new UnusedAttr()); |
| 446 | } |
| 447 | |
Daniel Dunbar | 8716a01 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 448 | static void HandleConstructorAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
| 449 | // check the attribute arguments. |
| 450 | if (Attr.getNumArgs() != 0 && Attr.getNumArgs() != 1) { |
| 451 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, "0 or 1"); |
| 452 | return; |
| 453 | } |
| 454 | |
| 455 | int priority = 65535; // FIXME: Do not hardcode such constants. |
| 456 | if (Attr.getNumArgs() > 0) { |
| 457 | Expr *E = static_cast<Expr *>(Attr.getArg(0)); |
| 458 | llvm::APSInt Idx(32); |
| 459 | if (!E->isIntegerConstantExpr(Idx, S.Context)) { |
| 460 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_int, |
| 461 | "constructor", "1", E->getSourceRange()); |
| 462 | return; |
| 463 | } |
| 464 | priority = Idx.getZExtValue(); |
| 465 | } |
| 466 | |
| 467 | FunctionDecl *Fn = dyn_cast<FunctionDecl>(d); |
| 468 | if (!Fn) { |
| 469 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type, |
| 470 | "constructor", "function"); |
| 471 | return; |
| 472 | } |
| 473 | |
| 474 | d->addAttr(new ConstructorAttr(priority)); |
| 475 | } |
| 476 | |
| 477 | static void HandleDestructorAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
| 478 | // check the attribute arguments. |
| 479 | if (Attr.getNumArgs() != 0 && Attr.getNumArgs() != 1) { |
| 480 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, "0 or 1"); |
| 481 | return; |
| 482 | } |
| 483 | |
| 484 | int priority = 65535; // FIXME: Do not hardcode such constants. |
| 485 | if (Attr.getNumArgs() > 0) { |
| 486 | Expr *E = static_cast<Expr *>(Attr.getArg(0)); |
| 487 | llvm::APSInt Idx(32); |
| 488 | if (!E->isIntegerConstantExpr(Idx, S.Context)) { |
| 489 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_int, |
| 490 | "destructor", "1", E->getSourceRange()); |
| 491 | return; |
| 492 | } |
| 493 | priority = Idx.getZExtValue(); |
| 494 | } |
| 495 | |
Anders Carlsson | 03e4965 | 2008-08-22 22:10:48 +0000 | [diff] [blame] | 496 | if (!isa<FunctionDecl>(d)) { |
Daniel Dunbar | 8716a01 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 497 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type, |
| 498 | "destructor", "function"); |
| 499 | return; |
| 500 | } |
| 501 | |
| 502 | d->addAttr(new DestructorAttr(priority)); |
| 503 | } |
| 504 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 505 | static void HandleDeprecatedAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 506 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 507 | if (Attr.getNumArgs() != 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 508 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 509 | std::string("0")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 510 | return; |
| 511 | } |
| 512 | |
| 513 | d->addAttr(new DeprecatedAttr()); |
| 514 | } |
| 515 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 516 | static void HandleVisibilityAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 517 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 518 | if (Attr.getNumArgs() != 1) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 519 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 520 | std::string("1")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 521 | return; |
| 522 | } |
| 523 | |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 524 | Expr *Arg = static_cast<Expr*>(Attr.getArg(0)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 525 | Arg = Arg->IgnoreParenCasts(); |
| 526 | StringLiteral *Str = dyn_cast<StringLiteral>(Arg); |
| 527 | |
| 528 | if (Str == 0 || Str->isWide()) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 529 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string, |
| 530 | "visibility", std::string("1")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 531 | return; |
| 532 | } |
| 533 | |
| 534 | const char *TypeStr = Str->getStrData(); |
| 535 | unsigned TypeLen = Str->getByteLength(); |
| 536 | VisibilityAttr::VisibilityTypes type; |
| 537 | |
| 538 | if (TypeLen == 7 && !memcmp(TypeStr, "default", 7)) |
| 539 | type = VisibilityAttr::DefaultVisibility; |
| 540 | else if (TypeLen == 6 && !memcmp(TypeStr, "hidden", 6)) |
| 541 | type = VisibilityAttr::HiddenVisibility; |
| 542 | else if (TypeLen == 8 && !memcmp(TypeStr, "internal", 8)) |
| 543 | type = VisibilityAttr::HiddenVisibility; // FIXME |
| 544 | else if (TypeLen == 9 && !memcmp(TypeStr, "protected", 9)) |
| 545 | type = VisibilityAttr::ProtectedVisibility; |
| 546 | else { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 547 | S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported, |
| 548 | "visibility", TypeStr); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 549 | return; |
| 550 | } |
| 551 | |
| 552 | d->addAttr(new VisibilityAttr(type)); |
| 553 | } |
| 554 | |
Anders Carlsson | d83141a5 | 2008-08-23 23:22:21 +0000 | [diff] [blame] | 555 | static void HandleObjCGCAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Anders Carlsson | e0f00b3 | 2008-08-24 16:33:25 +0000 | [diff] [blame] | 556 | if (!Attr.getParameterName()) { |
Anders Carlsson | d83141a5 | 2008-08-23 23:22:21 +0000 | [diff] [blame] | 557 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string, |
| 558 | "objc_gc", std::string("1")); |
| 559 | return; |
| 560 | } |
| 561 | |
| 562 | if (Attr.getNumArgs() != 0) { |
| 563 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 564 | std::string("1")); |
| 565 | return; |
| 566 | } |
| 567 | |
| 568 | const char *TypeStr = Attr.getParameterName()->getName(); |
| 569 | unsigned TypeLen = Attr.getParameterName()->getLength(); |
| 570 | |
| 571 | ObjCGCAttr::GCAttrTypes type; |
| 572 | |
| 573 | if (TypeLen == 4 && !memcmp(TypeStr, "weak", 4)) |
| 574 | type = ObjCGCAttr::Weak; |
Anders Carlsson | e0f00b3 | 2008-08-24 16:33:25 +0000 | [diff] [blame] | 575 | else if (TypeLen == 6 && !memcmp(TypeStr, "strong", 6)) |
Anders Carlsson | d83141a5 | 2008-08-23 23:22:21 +0000 | [diff] [blame] | 576 | type = ObjCGCAttr::Strong; |
| 577 | else { |
| 578 | S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported, |
| 579 | "objc_gc", TypeStr); |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | d->addAttr(new ObjCGCAttr(type)); |
| 584 | } |
| 585 | |
Steve Naroff | e1cecba | 2008-09-18 16:44:58 +0000 | [diff] [blame] | 586 | static void HandleBlocksAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
| 587 | if (!Attr.getParameterName()) { |
| 588 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string, |
| 589 | "blocks", std::string("1")); |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | if (Attr.getNumArgs() != 0) { |
| 594 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 595 | std::string("1")); |
| 596 | return; |
| 597 | } |
| 598 | const char *TypeStr = Attr.getParameterName()->getName(); |
| 599 | unsigned TypeLen = Attr.getParameterName()->getLength(); |
| 600 | |
| 601 | BlocksAttr::BlocksAttrTypes type; |
| 602 | |
| 603 | if (TypeLen == 5 && !memcmp(TypeStr, "byref", 5)) |
| 604 | type = BlocksAttr::ByRef; |
| 605 | else { |
| 606 | S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported, |
| 607 | "blocks", TypeStr); |
| 608 | return; |
| 609 | } |
| 610 | |
| 611 | d->addAttr(new BlocksAttr(type)); |
| 612 | } |
| 613 | |
Anders Carlsson | 244d99b | 2008-10-05 18:05:59 +0000 | [diff] [blame] | 614 | static void HandleSentinelAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
| 615 | // check the attribute arguments. |
| 616 | if (Attr.getNumArgs() > 2) { |
| 617 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, "0, 1 or 2"); |
| 618 | return; |
| 619 | } |
| 620 | |
| 621 | int sentinel = 0; |
| 622 | if (Attr.getNumArgs() > 0) { |
| 623 | Expr *E = static_cast<Expr *>(Attr.getArg(0)); |
| 624 | llvm::APSInt Idx(32); |
| 625 | if (!E->isIntegerConstantExpr(Idx, S.Context)) { |
| 626 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_int, |
| 627 | "sentinel", "1", E->getSourceRange()); |
| 628 | return; |
| 629 | } |
| 630 | sentinel = Idx.getZExtValue(); |
| 631 | |
| 632 | if (sentinel < 0) { |
| 633 | S.Diag(Attr.getLoc(), diag::err_attribute_sentinel_less_than_zero, |
| 634 | E->getSourceRange()); |
| 635 | return; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | int nullPos = 0; |
| 640 | if (Attr.getNumArgs() > 1) { |
| 641 | Expr *E = static_cast<Expr *>(Attr.getArg(1)); |
| 642 | llvm::APSInt Idx(32); |
| 643 | if (!E->isIntegerConstantExpr(Idx, S.Context)) { |
| 644 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_int, |
| 645 | "sentinel", "2", E->getSourceRange()); |
| 646 | return; |
| 647 | } |
| 648 | nullPos = Idx.getZExtValue(); |
| 649 | |
| 650 | if (nullPos > 1 || nullPos < 0) { |
| 651 | // FIXME: This error message could be improved, it would be nice |
| 652 | // to say what the bounds actually are. |
| 653 | S.Diag(Attr.getLoc(), diag::err_attribute_sentinel_not_zero_or_one, |
| 654 | E->getSourceRange()); |
| 655 | return; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(d)) { |
| 660 | QualType FT = FD->getType(); |
| 661 | if (!FT->getAsFunctionTypeProto()->isVariadic()) { |
| 662 | S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic); |
| 663 | return; |
| 664 | } |
| 665 | } else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(d)) { |
| 666 | if (!MD->isVariadic()) { |
| 667 | S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic); |
| 668 | return; |
| 669 | } |
| 670 | } else { |
| 671 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type, |
| 672 | "sentinel", "function or method"); |
| 673 | return; |
| 674 | } |
| 675 | |
| 676 | // FIXME: Actually create the attribute. |
| 677 | } |
| 678 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 679 | static void HandleWeakAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 680 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 681 | if (Attr.getNumArgs() != 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 682 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 683 | std::string("0")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 684 | return; |
| 685 | } |
| 686 | |
| 687 | d->addAttr(new WeakAttr()); |
| 688 | } |
| 689 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 690 | static void HandleDLLImportAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 691 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 692 | if (Attr.getNumArgs() != 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 693 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 694 | std::string("0")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 695 | return; |
| 696 | } |
| 697 | |
| 698 | d->addAttr(new DLLImportAttr()); |
| 699 | } |
| 700 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 701 | static void HandleDLLExportAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 702 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 703 | if (Attr.getNumArgs() != 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 704 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 705 | std::string("0")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 706 | return; |
| 707 | } |
| 708 | |
| 709 | d->addAttr(new DLLExportAttr()); |
| 710 | } |
| 711 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 712 | static void HandleStdCallAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 713 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 714 | if (Attr.getNumArgs() != 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 715 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 716 | std::string("0")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 717 | return; |
| 718 | } |
| 719 | |
| 720 | d->addAttr(new StdCallAttr()); |
| 721 | } |
| 722 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 723 | static void HandleFastCallAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 724 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 725 | if (Attr.getNumArgs() != 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 726 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 727 | std::string("0")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 728 | return; |
| 729 | } |
| 730 | |
| 731 | d->addAttr(new FastCallAttr()); |
| 732 | } |
| 733 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 734 | static void HandleNothrowAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 735 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 736 | if (Attr.getNumArgs() != 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 737 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 738 | std::string("0")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 739 | return; |
| 740 | } |
| 741 | |
| 742 | d->addAttr(new NoThrowAttr()); |
| 743 | } |
| 744 | |
Anders Carlsson | dd6791c | 2008-10-05 23:32:53 +0000 | [diff] [blame] | 745 | static void HandleConstAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
| 746 | // check the attribute arguments. |
| 747 | if (Attr.getNumArgs() != 0) { |
| 748 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 749 | std::string("0")); |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | d->addAttr(new ConstAttr()); |
| 754 | } |
| 755 | |
| 756 | static void HandlePureAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
| 757 | // check the attribute arguments. |
| 758 | if (Attr.getNumArgs() != 0) { |
| 759 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 760 | std::string("0")); |
| 761 | return; |
| 762 | } |
| 763 | |
| 764 | d->addAttr(new PureAttr()); |
| 765 | } |
| 766 | |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 767 | /// Handle __attribute__((format(type,idx,firstarg))) attributes |
| 768 | /// based on http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 769 | static void HandleFormatAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 770 | |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 771 | if (!Attr.getParameterName()) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 772 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string, |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 773 | "format", std::string("1")); |
| 774 | return; |
| 775 | } |
| 776 | |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 777 | if (Attr.getNumArgs() != 2) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 778 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 779 | std::string("3")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 780 | return; |
| 781 | } |
| 782 | |
Daniel Dunbar | 0ea2047 | 2008-10-19 02:04:16 +0000 | [diff] [blame] | 783 | if (!isFunctionOrMethod(d) || !hasFunctionProto(d)) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 784 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type, |
| 785 | "format", "function"); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 786 | return; |
| 787 | } |
| 788 | |
| 789 | // FIXME: in C++ the implicit 'this' function parameter also counts. |
| 790 | // this is needed in order to be compatible with GCC |
| 791 | // the index must start in 1 and the limit is numargs+1 |
Daniel Dunbar | d1d847c | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 792 | unsigned NumArgs = getFunctionOrMethodNumArgs(d); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 793 | unsigned FirstIdx = 1; |
| 794 | |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 795 | const char *Format = Attr.getParameterName()->getName(); |
| 796 | unsigned FormatLen = Attr.getParameterName()->getLength(); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 797 | |
| 798 | // Normalize the argument, __foo__ becomes foo. |
| 799 | if (FormatLen > 4 && Format[0] == '_' && Format[1] == '_' && |
| 800 | Format[FormatLen - 2] == '_' && Format[FormatLen - 1] == '_') { |
| 801 | Format += 2; |
| 802 | FormatLen -= 4; |
| 803 | } |
| 804 | |
| 805 | bool Supported = false; |
| 806 | bool is_NSString = false; |
| 807 | bool is_strftime = false; |
Daniel Dunbar | bddb14a | 2008-09-26 03:32:58 +0000 | [diff] [blame] | 808 | bool is_CFString = false; |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 809 | |
| 810 | switch (FormatLen) { |
| 811 | default: break; |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 812 | case 5: Supported = !memcmp(Format, "scanf", 5); break; |
| 813 | case 6: Supported = !memcmp(Format, "printf", 6); break; |
| 814 | case 7: Supported = !memcmp(Format, "strfmon", 7); break; |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 815 | case 8: |
Daniel Dunbar | bddb14a | 2008-09-26 03:32:58 +0000 | [diff] [blame] | 816 | Supported = (is_strftime = !memcmp(Format, "strftime", 8)) || |
| 817 | (is_NSString = !memcmp(Format, "NSString", 8)) || |
| 818 | (is_CFString = !memcmp(Format, "CFString", 8)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 819 | break; |
| 820 | } |
| 821 | |
| 822 | if (!Supported) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 823 | S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported, |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 824 | "format", Attr.getParameterName()->getName()); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 825 | return; |
| 826 | } |
| 827 | |
| 828 | // checks for the 2nd argument |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 829 | Expr *IdxExpr = static_cast<Expr *>(Attr.getArg(0)); |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 830 | llvm::APSInt Idx(32); |
| 831 | if (!IdxExpr->isIntegerConstantExpr(Idx, S.Context)) { |
| 832 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_int, |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 833 | "format", std::string("2"), IdxExpr->getSourceRange()); |
| 834 | return; |
| 835 | } |
| 836 | |
| 837 | if (Idx.getZExtValue() < FirstIdx || Idx.getZExtValue() > NumArgs) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 838 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds, |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 839 | "format", std::string("2"), IdxExpr->getSourceRange()); |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | // FIXME: Do we need to bounds check? |
| 844 | unsigned ArgIdx = Idx.getZExtValue() - 1; |
| 845 | |
| 846 | // make sure the format string is really a string |
Daniel Dunbar | d1d847c | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 847 | QualType Ty = getFunctionOrMethodArgType(d, ArgIdx); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 848 | |
Daniel Dunbar | bddb14a | 2008-09-26 03:32:58 +0000 | [diff] [blame] | 849 | if (is_CFString) { |
| 850 | if (!isCFStringType(Ty, S.Context)) { |
| 851 | S.Diag(Attr.getLoc(), diag::err_format_attribute_not, |
| 852 | "a CFString", IdxExpr->getSourceRange()); |
| 853 | return; |
| 854 | } |
| 855 | } else if (is_NSString) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 856 | // FIXME: do we need to check if the type is NSString*? What are |
| 857 | // the semantics? |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 858 | if (!isNSStringType(Ty, S.Context)) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 859 | // FIXME: Should highlight the actual expression that has the |
| 860 | // wrong type. |
Daniel Dunbar | bddb14a | 2008-09-26 03:32:58 +0000 | [diff] [blame] | 861 | S.Diag(Attr.getLoc(), diag::err_format_attribute_not, |
| 862 | "an NSString", IdxExpr->getSourceRange()); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 863 | return; |
| 864 | } |
| 865 | } else if (!Ty->isPointerType() || |
| 866 | !Ty->getAsPointerType()->getPointeeType()->isCharType()) { |
| 867 | // FIXME: Should highlight the actual expression that has the |
| 868 | // wrong type. |
Daniel Dunbar | bddb14a | 2008-09-26 03:32:58 +0000 | [diff] [blame] | 869 | S.Diag(Attr.getLoc(), diag::err_format_attribute_not, |
| 870 | "a string type", IdxExpr->getSourceRange()); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 871 | return; |
| 872 | } |
| 873 | |
| 874 | // check the 3rd argument |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 875 | Expr *FirstArgExpr = static_cast<Expr *>(Attr.getArg(1)); |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 876 | llvm::APSInt FirstArg(32); |
| 877 | if (!FirstArgExpr->isIntegerConstantExpr(FirstArg, S.Context)) { |
| 878 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_int, |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 879 | "format", std::string("3"), FirstArgExpr->getSourceRange()); |
| 880 | return; |
| 881 | } |
| 882 | |
| 883 | // check if the function is variadic if the 3rd argument non-zero |
| 884 | if (FirstArg != 0) { |
Daniel Dunbar | d1d847c | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 885 | if (isFunctionOrMethodVariadic(d)) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 886 | ++NumArgs; // +1 for ... |
| 887 | } else { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 888 | S.Diag(d->getLocation(), diag::err_format_attribute_requires_variadic); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 889 | return; |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | // strftime requires FirstArg to be 0 because it doesn't read from any variable |
| 894 | // the input is just the current time + the format string |
| 895 | if (is_strftime) { |
| 896 | if (FirstArg != 0) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 897 | S.Diag(Attr.getLoc(), diag::err_format_strftime_third_parameter, |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 898 | FirstArgExpr->getSourceRange()); |
| 899 | return; |
| 900 | } |
| 901 | // if 0 it disables parameter checking (to use with e.g. va_list) |
| 902 | } else if (FirstArg != 0 && FirstArg != NumArgs) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 903 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds, |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 904 | "format", std::string("3"), FirstArgExpr->getSourceRange()); |
| 905 | return; |
| 906 | } |
| 907 | |
| 908 | d->addAttr(new FormatAttr(std::string(Format, FormatLen), |
| 909 | Idx.getZExtValue(), FirstArg.getZExtValue())); |
| 910 | } |
| 911 | |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 912 | static void HandleTransparentUnionAttr(Decl *d, const AttributeList &Attr, |
| 913 | Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 914 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 915 | if (Attr.getNumArgs() != 0) { |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 916 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 917 | std::string("0")); |
| 918 | return; |
| 919 | } |
| 920 | |
Eli Friedman | 283b362 | 2008-09-02 05:19:23 +0000 | [diff] [blame] | 921 | // FIXME: This shouldn't be restricted to typedefs |
| 922 | TypedefDecl *TD = dyn_cast<TypedefDecl>(d); |
| 923 | if (!TD || !TD->getUnderlyingType()->isUnionType()) { |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 924 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type, |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 925 | "transparent_union", "union"); |
| 926 | return; |
| 927 | } |
| 928 | |
Eli Friedman | 283b362 | 2008-09-02 05:19:23 +0000 | [diff] [blame] | 929 | RecordDecl* RD = TD->getUnderlyingType()->getAsUnionType()->getDecl(); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 930 | |
Eli Friedman | 283b362 | 2008-09-02 05:19:23 +0000 | [diff] [blame] | 931 | // FIXME: Should we do a check for RD->isDefinition()? |
| 932 | |
| 933 | // FIXME: This isn't supposed to be restricted to pointers, but otherwise |
| 934 | // we might silently generate incorrect code; see following code |
| 935 | for (int i = 0; i < RD->getNumMembers(); i++) { |
| 936 | if (!RD->getMember(i)->getType()->isPointerType()) { |
| 937 | S.Diag(Attr.getLoc(), diag::warn_transparent_union_nonpointer); |
| 938 | return; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | // FIXME: This is a complete hack; we should be properly propagating |
| 943 | // transparent_union through Sema. That said, this is close enough to |
| 944 | // correctly compile all the common cases of transparent_union without |
| 945 | // errors or warnings |
| 946 | QualType NewTy = S.Context.VoidPtrTy; |
| 947 | NewTy.addConst(); |
| 948 | TD->setUnderlyingType(NewTy); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 951 | static void HandleAnnotateAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 952 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 953 | if (Attr.getNumArgs() != 1) { |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 954 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 955 | std::string("1")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 956 | return; |
| 957 | } |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 958 | Expr *argExpr = static_cast<Expr *>(Attr.getArg(0)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 959 | StringLiteral *SE = dyn_cast<StringLiteral>(argExpr); |
| 960 | |
| 961 | // Make sure that there is a string literal as the annotation's single |
| 962 | // argument. |
| 963 | if (!SE) { |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 964 | S.Diag(Attr.getLoc(), diag::err_attribute_annotate_no_string); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 965 | return; |
| 966 | } |
| 967 | d->addAttr(new AnnotateAttr(std::string(SE->getStrData(), |
| 968 | SE->getByteLength()))); |
| 969 | } |
| 970 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 971 | static void HandleAlignedAttr(Decl *d, const AttributeList &Attr, Sema &S) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 972 | // check the attribute arguments. |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 973 | if (Attr.getNumArgs() > 1) { |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 974 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 975 | std::string("1")); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 976 | return; |
| 977 | } |
| 978 | |
| 979 | unsigned Align = 0; |
Chris Lattner | 1c15113 | 2008-06-28 23:36:30 +0000 | [diff] [blame] | 980 | if (Attr.getNumArgs() == 0) { |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 981 | // FIXME: This should be the target specific maximum alignment. |
| 982 | // (For now we just use 128 bits which is the maximum on X86. |
| 983 | Align = 128; |
| 984 | return; |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 985 | } |
Chris Lattner | b0011ca | 2008-06-28 23:50:44 +0000 | [diff] [blame] | 986 | |
| 987 | Expr *alignmentExpr = static_cast<Expr *>(Attr.getArg(0)); |
| 988 | llvm::APSInt Alignment(32); |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 989 | if (!alignmentExpr->isIntegerConstantExpr(Alignment, S.Context)) { |
| 990 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int, |
| 991 | "aligned", alignmentExpr->getSourceRange()); |
Chris Lattner | b0011ca | 2008-06-28 23:50:44 +0000 | [diff] [blame] | 992 | return; |
| 993 | } |
| 994 | d->addAttr(new AlignedAttr(Alignment.getZExtValue() * 8)); |
Chris Lattner | 6953a07 | 2008-06-26 18:38:35 +0000 | [diff] [blame] | 995 | } |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 996 | |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 997 | /// HandleModeAttr - This attribute modifies the width of a decl with |
Chris Lattner | 8ed14aa | 2008-06-28 23:48:25 +0000 | [diff] [blame] | 998 | /// primitive type. |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 999 | /// |
| 1000 | /// Despite what would be logical, the mode attribute is a decl attribute, |
| 1001 | /// not a type attribute: 'int ** __attribute((mode(HI))) *G;' tries to make |
| 1002 | /// 'G' be HImode, not an intermediate pointer. |
| 1003 | /// |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1004 | static void HandleModeAttr(Decl *D, const AttributeList &Attr, Sema &S) { |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1005 | // This attribute isn't documented, but glibc uses it. It changes |
| 1006 | // the width of an int or unsigned int to the specified size. |
| 1007 | |
| 1008 | // Check that there aren't any arguments |
| 1009 | if (Attr.getNumArgs() != 0) { |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1010 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments, |
| 1011 | std::string("0")); |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1012 | return; |
| 1013 | } |
| 1014 | |
| 1015 | IdentifierInfo *Name = Attr.getParameterName(); |
| 1016 | if (!Name) { |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1017 | S.Diag(Attr.getLoc(), diag::err_attribute_missing_parameter_name); |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1018 | return; |
| 1019 | } |
| 1020 | const char *Str = Name->getName(); |
| 1021 | unsigned Len = Name->getLength(); |
| 1022 | |
| 1023 | // Normalize the attribute name, __foo__ becomes foo. |
| 1024 | if (Len > 4 && Str[0] == '_' && Str[1] == '_' && |
| 1025 | Str[Len - 2] == '_' && Str[Len - 1] == '_') { |
| 1026 | Str += 2; |
| 1027 | Len -= 4; |
| 1028 | } |
| 1029 | |
| 1030 | unsigned DestWidth = 0; |
| 1031 | bool IntegerMode = true; |
| 1032 | switch (Len) { |
| 1033 | case 2: |
| 1034 | if (!memcmp(Str, "QI", 2)) { DestWidth = 8; break; } |
| 1035 | if (!memcmp(Str, "HI", 2)) { DestWidth = 16; break; } |
| 1036 | if (!memcmp(Str, "SI", 2)) { DestWidth = 32; break; } |
| 1037 | if (!memcmp(Str, "DI", 2)) { DestWidth = 64; break; } |
| 1038 | if (!memcmp(Str, "TI", 2)) { DestWidth = 128; break; } |
| 1039 | if (!memcmp(Str, "SF", 2)) { DestWidth = 32; IntegerMode = false; break; } |
| 1040 | if (!memcmp(Str, "DF", 2)) { DestWidth = 64; IntegerMode = false; break; } |
| 1041 | if (!memcmp(Str, "XF", 2)) { DestWidth = 96; IntegerMode = false; break; } |
| 1042 | if (!memcmp(Str, "TF", 2)) { DestWidth = 128; IntegerMode = false; break; } |
| 1043 | break; |
| 1044 | case 4: |
| 1045 | // FIXME: glibc uses 'word' to define register_t; this is narrower than a |
| 1046 | // pointer on PIC16 and other embedded platforms. |
| 1047 | if (!memcmp(Str, "word", 4)) |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1048 | DestWidth = S.Context.Target.getPointerWidth(0); |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1049 | if (!memcmp(Str, "byte", 4)) |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1050 | DestWidth = S.Context.Target.getCharWidth(); |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1051 | break; |
| 1052 | case 7: |
| 1053 | if (!memcmp(Str, "pointer", 7)) |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1054 | DestWidth = S.Context.Target.getPointerWidth(0); |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1055 | break; |
| 1056 | } |
| 1057 | |
| 1058 | QualType OldTy; |
| 1059 | if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) |
| 1060 | OldTy = TD->getUnderlyingType(); |
| 1061 | else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) |
| 1062 | OldTy = VD->getType(); |
| 1063 | else { |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1064 | S.Diag(D->getLocation(), diag::err_attr_wrong_decl, "mode", |
| 1065 | SourceRange(Attr.getLoc(), Attr.getLoc())); |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1066 | return; |
| 1067 | } |
| 1068 | |
| 1069 | // FIXME: Need proper fixed-width types |
| 1070 | QualType NewTy; |
| 1071 | switch (DestWidth) { |
| 1072 | case 0: |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1073 | S.Diag(Attr.getLoc(), diag::err_unknown_machine_mode, Name->getName()); |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1074 | return; |
| 1075 | default: |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1076 | S.Diag(Attr.getLoc(), diag::err_unsupported_machine_mode, Name->getName()); |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1077 | return; |
| 1078 | case 8: |
| 1079 | assert(IntegerMode); |
| 1080 | if (OldTy->isSignedIntegerType()) |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1081 | NewTy = S.Context.SignedCharTy; |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1082 | else |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1083 | NewTy = S.Context.UnsignedCharTy; |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1084 | break; |
| 1085 | case 16: |
| 1086 | assert(IntegerMode); |
| 1087 | if (OldTy->isSignedIntegerType()) |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1088 | NewTy = S.Context.ShortTy; |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1089 | else |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1090 | NewTy = S.Context.UnsignedShortTy; |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1091 | break; |
| 1092 | case 32: |
| 1093 | if (!IntegerMode) |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1094 | NewTy = S.Context.FloatTy; |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1095 | else if (OldTy->isSignedIntegerType()) |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1096 | NewTy = S.Context.IntTy; |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1097 | else |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1098 | NewTy = S.Context.UnsignedIntTy; |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1099 | break; |
| 1100 | case 64: |
| 1101 | if (!IntegerMode) |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1102 | NewTy = S.Context.DoubleTy; |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1103 | else if (OldTy->isSignedIntegerType()) |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1104 | NewTy = S.Context.LongLongTy; |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1105 | else |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1106 | NewTy = S.Context.UnsignedLongLongTy; |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1107 | break; |
| 1108 | } |
| 1109 | |
| 1110 | if (!OldTy->getAsBuiltinType()) |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1111 | S.Diag(Attr.getLoc(), diag::err_mode_not_primitive); |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1112 | else if (!(IntegerMode && OldTy->isIntegerType()) && |
| 1113 | !(!IntegerMode && OldTy->isFloatingType())) { |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 1114 | S.Diag(Attr.getLoc(), diag::err_mode_wrong_type); |
Chris Lattner | dc78956 | 2008-06-27 22:18:37 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | // Install the new type. |
| 1118 | if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) |
| 1119 | TD->setUnderlyingType(NewTy); |
| 1120 | else |
| 1121 | cast<ValueDecl>(D)->setType(NewTy); |
| 1122 | } |
Chris Lattner | a72440d | 2008-06-29 00:23:49 +0000 | [diff] [blame] | 1123 | |
| 1124 | //===----------------------------------------------------------------------===// |
| 1125 | // Top Level Sema Entry Points |
| 1126 | //===----------------------------------------------------------------------===// |
| 1127 | |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 1128 | /// HandleDeclAttribute - Apply the specific attribute to the specified decl if |
| 1129 | /// the attribute applies to decls. If the attribute is a type attribute, just |
| 1130 | /// silently ignore it. |
| 1131 | static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) { |
| 1132 | switch (Attr.getKind()) { |
Daniel Dunbar | 8716a01 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 1133 | case AttributeList::AT_IBOutlet: HandleIBOutletAttr (D, Attr, S); break; |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 1134 | case AttributeList::AT_address_space: |
| 1135 | // Ignore this, this is a type attribute, handled by ProcessTypeAttributes. |
| 1136 | break; |
Daniel Dunbar | 8716a01 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 1137 | case AttributeList::AT_alias: HandleAliasAttr (D, Attr, S); break; |
| 1138 | case AttributeList::AT_aligned: HandleAlignedAttr (D, Attr, S); break; |
Daniel Dunbar | 0a2da71 | 2008-10-28 00:17:57 +0000 | [diff] [blame] | 1139 | case AttributeList::AT_always_inline: |
| 1140 | HandleAlwaysInlineAttr (D, Attr, S); break; |
Daniel Dunbar | 8716a01 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 1141 | case AttributeList::AT_annotate: HandleAnnotateAttr (D, Attr, S); break; |
| 1142 | case AttributeList::AT_constructor: HandleConstructorAttr(D, Attr, S); break; |
| 1143 | case AttributeList::AT_deprecated: HandleDeprecatedAttr(D, Attr, S); break; |
| 1144 | case AttributeList::AT_destructor: HandleDestructorAttr(D, Attr, S); break; |
| 1145 | case AttributeList::AT_dllexport: HandleDLLExportAttr (D, Attr, S); break; |
| 1146 | case AttributeList::AT_dllimport: HandleDLLImportAttr (D, Attr, S); break; |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 1147 | case AttributeList::AT_ext_vector_type: |
| 1148 | HandleExtVectorTypeAttr(D, Attr, S); |
| 1149 | break; |
Daniel Dunbar | 8716a01 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 1150 | case AttributeList::AT_fastcall: HandleFastCallAttr (D, Attr, S); break; |
| 1151 | case AttributeList::AT_format: HandleFormatAttr (D, Attr, S); break; |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 1152 | case AttributeList::AT_mode: HandleModeAttr (D, Attr, S); break; |
Daniel Dunbar | 8716a01 | 2008-07-31 22:40:48 +0000 | [diff] [blame] | 1153 | case AttributeList::AT_nonnull: HandleNonNullAttr (D, Attr, S); break; |
| 1154 | case AttributeList::AT_noreturn: HandleNoReturnAttr (D, Attr, S); break; |
| 1155 | case AttributeList::AT_nothrow: HandleNothrowAttr (D, Attr, S); break; |
| 1156 | case AttributeList::AT_packed: HandlePackedAttr (D, Attr, S); break; |
| 1157 | case AttributeList::AT_stdcall: HandleStdCallAttr (D, Attr, S); break; |
| 1158 | case AttributeList::AT_unused: HandleUnusedAttr (D, Attr, S); break; |
| 1159 | case AttributeList::AT_vector_size: HandleVectorSizeAttr(D, Attr, S); break; |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 1160 | case AttributeList::AT_visibility: HandleVisibilityAttr(D, Attr, S); break; |
| 1161 | case AttributeList::AT_weak: HandleWeakAttr (D, Attr, S); break; |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 1162 | case AttributeList::AT_transparent_union: |
| 1163 | HandleTransparentUnionAttr(D, Attr, S); |
| 1164 | break; |
Anders Carlsson | d83141a5 | 2008-08-23 23:22:21 +0000 | [diff] [blame] | 1165 | case AttributeList::AT_objc_gc: HandleObjCGCAttr (D, Attr, S); break; |
Steve Naroff | e1cecba | 2008-09-18 16:44:58 +0000 | [diff] [blame] | 1166 | case AttributeList::AT_blocks: HandleBlocksAttr (D, Attr, S); break; |
Anders Carlsson | 244d99b | 2008-10-05 18:05:59 +0000 | [diff] [blame] | 1167 | case AttributeList::AT_sentinel: HandleSentinelAttr (D, Attr, S); break; |
Anders Carlsson | dd6791c | 2008-10-05 23:32:53 +0000 | [diff] [blame] | 1168 | case AttributeList::AT_const: HandleConstAttr (D, Attr, S); break; |
| 1169 | case AttributeList::AT_pure: HandlePureAttr (D, Attr, S); break; |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 1170 | default: |
| 1171 | #if 0 |
| 1172 | // TODO: when we have the full set of attributes, warn about unknown ones. |
| 1173 | S.Diag(Attr->getLoc(), diag::warn_attribute_ignored, |
| 1174 | Attr->getName()->getName()); |
| 1175 | #endif |
| 1176 | break; |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | /// ProcessDeclAttributeList - Apply all the decl attributes in the specified |
| 1181 | /// attribute list to the specified decl, ignoring any type attributes. |
| 1182 | void Sema::ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList) { |
| 1183 | while (AttrList) { |
| 1184 | ProcessDeclAttribute(D, *AttrList, *this); |
| 1185 | AttrList = AttrList->getNext(); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | |
Chris Lattner | a72440d | 2008-06-29 00:23:49 +0000 | [diff] [blame] | 1190 | /// ProcessDeclAttributes - Given a declarator (PD) with attributes indicated in |
| 1191 | /// it, apply them to D. This is a bit tricky because PD can have attributes |
| 1192 | /// specified in many different places, and we need to find and apply them all. |
| 1193 | void Sema::ProcessDeclAttributes(Decl *D, const Declarator &PD) { |
| 1194 | // Apply decl attributes from the DeclSpec if present. |
| 1195 | if (const AttributeList *Attrs = PD.getDeclSpec().getAttributes()) |
| 1196 | ProcessDeclAttributeList(D, Attrs); |
Chris Lattner | 703c52d | 2008-06-29 00:43:07 +0000 | [diff] [blame] | 1197 | |
Chris Lattner | a72440d | 2008-06-29 00:23:49 +0000 | [diff] [blame] | 1198 | // Walk the declarator structure, applying decl attributes that were in a type |
| 1199 | // position to the decl itself. This handles cases like: |
| 1200 | // int *__attr__(x)** D; |
| 1201 | // when X is a decl attribute. |
| 1202 | for (unsigned i = 0, e = PD.getNumTypeObjects(); i != e; ++i) |
| 1203 | if (const AttributeList *Attrs = PD.getTypeObject(i).getAttrs()) |
| 1204 | ProcessDeclAttributeList(D, Attrs); |
| 1205 | |
| 1206 | // Finally, apply any attributes on the decl itself. |
| 1207 | if (const AttributeList *Attrs = PD.getAttributes()) |
| 1208 | ProcessDeclAttributeList(D, Attrs); |
| 1209 | } |
| 1210 | |