| Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 1 | //===-- TargetAttributesSema.cpp - Encapsulate target attributes-*- C++ -*-===// | 
|  | 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 contains semantic analysis implementation for target-specific | 
|  | 11 | // attributes. | 
|  | 12 | // | 
|  | 13 | //===----------------------------------------------------------------------===// | 
|  | 14 |  | 
| Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 15 | #include "TargetAttributesSema.h" | 
| John McCall | 384aff8 | 2010-08-25 07:42:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" | 
| Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "clang/Basic/TargetInfo.h" | 
|  | 18 | #include "clang/Sema/SemaInternal.h" | 
| Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/Triple.h" | 
|  | 20 |  | 
|  | 21 | using namespace clang; | 
|  | 22 |  | 
|  | 23 | TargetAttributesSema::~TargetAttributesSema() {} | 
|  | 24 | bool TargetAttributesSema::ProcessDeclAttribute(Scope *scope, Decl *D, | 
|  | 25 | const AttributeList &Attr, Sema &S) const { | 
|  | 26 | return false; | 
|  | 27 | } | 
|  | 28 |  | 
|  | 29 | static void HandleMSP430InterruptAttr(Decl *d, | 
|  | 30 | const AttributeList &Attr, Sema &S) { | 
|  | 31 | // Check the attribute arguments. | 
|  | 32 | if (Attr.getNumArgs() != 1) { | 
|  | 33 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; | 
|  | 34 | return; | 
|  | 35 | } | 
|  | 36 |  | 
|  | 37 | // FIXME: Check for decl - it should be void ()(void). | 
|  | 38 |  | 
|  | 39 | Expr *NumParamsExpr = static_cast<Expr *>(Attr.getArg(0)); | 
|  | 40 | llvm::APSInt NumParams(32); | 
|  | 41 | if (!NumParamsExpr->isIntegerConstantExpr(NumParams, S.Context)) { | 
|  | 42 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int) | 
|  | 43 | << "interrupt" << NumParamsExpr->getSourceRange(); | 
|  | 44 | return; | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | unsigned Num = NumParams.getLimitedValue(255); | 
|  | 48 | if ((Num & 1) || Num > 30) { | 
|  | 49 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds) | 
|  | 50 | << "interrupt" << (int)NumParams.getSExtValue() | 
|  | 51 | << NumParamsExpr->getSourceRange(); | 
|  | 52 | return; | 
|  | 53 | } | 
|  | 54 |  | 
| Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 55 | d->addAttr(::new (S.Context) MSP430InterruptAttr(Attr.getLoc(), S.Context, Num)); | 
|  | 56 | d->addAttr(::new (S.Context) UsedAttr(Attr.getLoc(), S.Context)); | 
| Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 57 | } | 
|  | 58 |  | 
|  | 59 | namespace { | 
|  | 60 | class MSP430AttributesSema : public TargetAttributesSema { | 
|  | 61 | public: | 
|  | 62 | MSP430AttributesSema() { } | 
|  | 63 | bool ProcessDeclAttribute(Scope *scope, Decl *D, | 
|  | 64 | const AttributeList &Attr, Sema &S) const { | 
|  | 65 | if (Attr.getName()->getName() == "interrupt") { | 
|  | 66 | HandleMSP430InterruptAttr(D, Attr, S); | 
|  | 67 | return true; | 
|  | 68 | } | 
|  | 69 | return false; | 
|  | 70 | } | 
|  | 71 | }; | 
|  | 72 | } | 
|  | 73 |  | 
| Wesley Peck | 276fdf4 | 2010-12-19 19:57:51 +0000 | [diff] [blame] | 74 | static void HandleMBlazeInterruptHandlerAttr(Decl *d, const AttributeList &Attr, | 
|  | 75 | Sema &S) { | 
|  | 76 | // Check the attribute arguments. | 
|  | 77 | if (Attr.getNumArgs() != 0) { | 
|  | 78 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; | 
|  | 79 | return; | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | // FIXME: Check for decl - it should be void ()(void). | 
|  | 83 |  | 
|  | 84 | d->addAttr(::new (S.Context) MBlazeInterruptHandlerAttr(Attr.getLoc(), | 
|  | 85 | S.Context)); | 
|  | 86 | d->addAttr(::new (S.Context) UsedAttr(Attr.getLoc(), S.Context)); | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | static void HandleMBlazeSaveVolatilesAttr(Decl *d, const AttributeList &Attr, | 
|  | 90 | Sema &S) { | 
|  | 91 | // Check the attribute arguments. | 
|  | 92 | if (Attr.getNumArgs() != 0) { | 
|  | 93 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; | 
|  | 94 | return; | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | // FIXME: Check for decl - it should be void ()(void). | 
|  | 98 |  | 
|  | 99 | d->addAttr(::new (S.Context) MBlazeSaveVolatilesAttr(Attr.getLoc(), | 
|  | 100 | S.Context)); | 
|  | 101 | d->addAttr(::new (S.Context) UsedAttr(Attr.getLoc(), S.Context)); | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 |  | 
|  | 105 | namespace { | 
|  | 106 | class MBlazeAttributesSema : public TargetAttributesSema { | 
|  | 107 | public: | 
|  | 108 | MBlazeAttributesSema() { } | 
|  | 109 | bool ProcessDeclAttribute(Scope *scope, Decl *D, const AttributeList &Attr, | 
|  | 110 | Sema &S) const { | 
|  | 111 | if (Attr.getName()->getName() == "interrupt_handler") { | 
|  | 112 | HandleMBlazeInterruptHandlerAttr(D, Attr, S); | 
|  | 113 | return true; | 
|  | 114 | } else if (Attr.getName()->getName() == "save_volatiles") { | 
|  | 115 | HandleMBlazeSaveVolatilesAttr(D, Attr, S); | 
|  | 116 | return true; | 
|  | 117 | } | 
|  | 118 | return false; | 
|  | 119 | } | 
|  | 120 | }; | 
|  | 121 | } | 
|  | 122 |  | 
| Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 123 | static void HandleX86ForceAlignArgPointerAttr(Decl *D, | 
|  | 124 | const AttributeList& Attr, | 
|  | 125 | Sema &S) { | 
|  | 126 | // Check the attribute arguments. | 
|  | 127 | if (Attr.getNumArgs() != 0) { | 
|  | 128 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; | 
|  | 129 | return; | 
|  | 130 | } | 
|  | 131 |  | 
| Charles Davis | ab44216 | 2010-02-17 00:44:47 +0000 | [diff] [blame] | 132 | // If we try to apply it to a function pointer, don't warn, but don't | 
|  | 133 | // do anything, either. It doesn't matter anyway, because there's nothing | 
|  | 134 | // special about calling a force_align_arg_pointer function. | 
| Charles Davis | beaf5ed | 2010-02-18 04:39:19 +0000 | [diff] [blame] | 135 | ValueDecl *VD = dyn_cast<ValueDecl>(D); | 
| Charles Davis | ab44216 | 2010-02-17 00:44:47 +0000 | [diff] [blame] | 136 | if (VD && VD->getType()->isFunctionPointerType()) | 
| Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 137 | return; | 
| Charles Davis | beaf5ed | 2010-02-18 04:39:19 +0000 | [diff] [blame] | 138 | // Also don't warn on function pointer typedefs. | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 139 | TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D); | 
| Charles Davis | e01c063 | 2010-02-18 04:56:59 +0000 | [diff] [blame] | 140 | if (TD && (TD->getUnderlyingType()->isFunctionPointerType() || | 
|  | 141 | TD->getUnderlyingType()->isFunctionType())) | 
| Charles Davis | beaf5ed | 2010-02-18 04:39:19 +0000 | [diff] [blame] | 142 | return; | 
| Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 143 | // Attribute can only be applied to function types. | 
| Charles Davis | 9c00be5 | 2010-02-10 23:26:12 +0000 | [diff] [blame] | 144 | if (!isa<FunctionDecl>(D)) { | 
| Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 145 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) | 
|  | 146 | << Attr.getName() << /* function */0; | 
|  | 147 | return; | 
|  | 148 | } | 
|  | 149 |  | 
| Argyrios Kyrtzidis | 768d6ca | 2011-09-13 16:05:58 +0000 | [diff] [blame] | 150 | D->addAttr(::new (S.Context) X86ForceAlignArgPointerAttr(Attr.getRange(), | 
|  | 151 | S.Context)); | 
| Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 152 | } | 
|  | 153 |  | 
| Michael Han | 51d8c52 | 2013-01-24 16:46:58 +0000 | [diff] [blame] | 154 | DLLImportAttr *Sema::mergeDLLImportAttr(Decl *D, SourceRange Range, | 
|  | 155 | unsigned AttrSpellingListIndex) { | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 156 | if (D->hasAttr<DLLExportAttr>()) { | 
|  | 157 | Diag(Range.getBegin(), diag::warn_attribute_ignored) << "dllimport"; | 
| Rafael Espindola | 599f1b7 | 2012-05-13 03:25:18 +0000 | [diff] [blame] | 158 | return NULL; | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 159 | } | 
|  | 160 |  | 
|  | 161 | if (D->hasAttr<DLLImportAttr>()) | 
| Rafael Espindola | 599f1b7 | 2012-05-13 03:25:18 +0000 | [diff] [blame] | 162 | return NULL; | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 163 |  | 
| Reid Kleckner | beba3e8 | 2013-05-20 21:53:29 +0000 | [diff] [blame^] | 164 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { | 
|  | 165 | if (VD->hasDefinition()) { | 
|  | 166 | // dllimport cannot be applied to definitions. | 
|  | 167 | Diag(D->getLocation(), diag::warn_attribute_invalid_on_definition) | 
|  | 168 | << "dllimport"; | 
|  | 169 | return NULL; | 
|  | 170 | } | 
|  | 171 | } | 
|  | 172 |  | 
| Michael Han | 51d8c52 | 2013-01-24 16:46:58 +0000 | [diff] [blame] | 173 | return ::new (Context) DLLImportAttr(Range, Context, | 
|  | 174 | AttrSpellingListIndex); | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 175 | } | 
|  | 176 |  | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 177 | static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) { | 
|  | 178 | // check the attribute arguments. | 
|  | 179 | if (Attr.getNumArgs() != 0) { | 
|  | 180 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; | 
|  | 181 | return; | 
|  | 182 | } | 
|  | 183 |  | 
|  | 184 | // Attribute can be applied only to functions or variables. | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 185 | FunctionDecl *FD = dyn_cast<FunctionDecl>(D); | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 186 | if (!FD && !isa<VarDecl>(D)) { | 
| Ted Kremenek | 240670c | 2010-02-21 05:12:56 +0000 | [diff] [blame] | 187 | // Apparently Visual C++ thinks it is okay to not emit a warning | 
|  | 188 | // in this case, so only emit a warning when -fms-extensions is not | 
|  | 189 | // specified. | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 190 | if (!S.getLangOpts().MicrosoftExt) | 
| Ted Kremenek | 240670c | 2010-02-21 05:12:56 +0000 | [diff] [blame] | 191 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) | 
|  | 192 | << Attr.getName() << 2 /*variable and function*/; | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 193 | return; | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | // Currently, the dllimport attribute is ignored for inlined functions. | 
|  | 197 | // Warning is emitted. | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 198 | if (FD && FD->isInlineSpecified()) { | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 199 | S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllimport"; | 
|  | 200 | return; | 
|  | 201 | } | 
|  | 202 |  | 
| Michael Han | 51d8c52 | 2013-01-24 16:46:58 +0000 | [diff] [blame] | 203 | unsigned Index = Attr.getAttributeSpellingListIndex(); | 
|  | 204 | DLLImportAttr *NewAttr = S.mergeDLLImportAttr(D, Attr.getRange(), Index); | 
| Rafael Espindola | 599f1b7 | 2012-05-13 03:25:18 +0000 | [diff] [blame] | 205 | if (NewAttr) | 
|  | 206 | D->addAttr(NewAttr); | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 207 | } | 
|  | 208 |  | 
| Michael Han | 51d8c52 | 2013-01-24 16:46:58 +0000 | [diff] [blame] | 209 | DLLExportAttr *Sema::mergeDLLExportAttr(Decl *D, SourceRange Range, | 
|  | 210 | unsigned AttrSpellingListIndex) { | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 211 | if (DLLImportAttr *Import = D->getAttr<DLLImportAttr>()) { | 
|  | 212 | Diag(Import->getLocation(), diag::warn_attribute_ignored) << "dllimport"; | 
|  | 213 | D->dropAttr<DLLImportAttr>(); | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 214 | } | 
|  | 215 |  | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 216 | if (D->hasAttr<DLLExportAttr>()) | 
| Rafael Espindola | 599f1b7 | 2012-05-13 03:25:18 +0000 | [diff] [blame] | 217 | return NULL; | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 218 |  | 
| Michael Han | 51d8c52 | 2013-01-24 16:46:58 +0000 | [diff] [blame] | 219 | return ::new (Context) DLLExportAttr(Range, Context, | 
|  | 220 | AttrSpellingListIndex); | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 221 | } | 
|  | 222 |  | 
|  | 223 | static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) { | 
|  | 224 | // check the attribute arguments. | 
|  | 225 | if (Attr.getNumArgs() != 0) { | 
|  | 226 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; | 
|  | 227 | return; | 
|  | 228 | } | 
|  | 229 |  | 
|  | 230 | // Attribute can be applied only to functions or variables. | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 231 | FunctionDecl *FD = dyn_cast<FunctionDecl>(D); | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 232 | if (!FD && !isa<VarDecl>(D)) { | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 233 | S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) | 
|  | 234 | << Attr.getName() << 2 /*variable and function*/; | 
|  | 235 | return; | 
|  | 236 | } | 
|  | 237 |  | 
|  | 238 | // Currently, the dllexport attribute is ignored for inlined functions, unless | 
|  | 239 | // the -fkeep-inline-functions flag has been used. Warning is emitted; | 
| Rafael Espindola | 98ae834 | 2012-05-10 02:50:16 +0000 | [diff] [blame] | 240 | if (FD && FD->isInlineSpecified()) { | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 241 | // FIXME: ... unless the -fkeep-inline-functions flag has been used. | 
|  | 242 | S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllexport"; | 
|  | 243 | return; | 
|  | 244 | } | 
|  | 245 |  | 
| Michael Han | 51d8c52 | 2013-01-24 16:46:58 +0000 | [diff] [blame] | 246 | unsigned Index = Attr.getAttributeSpellingListIndex(); | 
|  | 247 | DLLExportAttr *NewAttr = S.mergeDLLExportAttr(D, Attr.getRange(), Index); | 
| Rafael Espindola | 599f1b7 | 2012-05-13 03:25:18 +0000 | [diff] [blame] | 248 | if (NewAttr) | 
|  | 249 | D->addAttr(NewAttr); | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 250 | } | 
|  | 251 |  | 
| Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 252 | namespace { | 
|  | 253 | class X86AttributesSema : public TargetAttributesSema { | 
|  | 254 | public: | 
|  | 255 | X86AttributesSema() { } | 
|  | 256 | bool ProcessDeclAttribute(Scope *scope, Decl *D, | 
|  | 257 | const AttributeList &Attr, Sema &S) const { | 
| Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 258 | const llvm::Triple &Triple(S.Context.getTargetInfo().getTriple()); | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 259 | if (Triple.getOS() == llvm::Triple::Win32 || | 
| NAKAMURA Takumi | 0aa2057 | 2011-02-17 08:51:38 +0000 | [diff] [blame] | 260 | Triple.getOS() == llvm::Triple::MinGW32) { | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 261 | switch (Attr.getKind()) { | 
| Sean Hunt | 8e083e7 | 2012-06-19 23:57:03 +0000 | [diff] [blame] | 262 | case AttributeList::AT_DLLImport: HandleDLLImportAttr(D, Attr, S); | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 263 | return true; | 
| Sean Hunt | 8e083e7 | 2012-06-19 23:57:03 +0000 | [diff] [blame] | 264 | case AttributeList::AT_DLLExport: HandleDLLExportAttr(D, Attr, S); | 
| Charles Davis | f0122fe | 2010-02-16 18:27:26 +0000 | [diff] [blame] | 265 | return true; | 
|  | 266 | default:                          break; | 
|  | 267 | } | 
|  | 268 | } | 
| Eli Friedman | 9afbfbe | 2011-09-30 18:53:25 +0000 | [diff] [blame] | 269 | if (Triple.getArch() != llvm::Triple::x86_64 && | 
| Benjamin Kramer | f2cee5c | 2011-09-30 20:32:22 +0000 | [diff] [blame] | 270 | (Attr.getName()->getName() == "force_align_arg_pointer" || | 
|  | 271 | Attr.getName()->getName() == "__force_align_arg_pointer__")) { | 
| Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 272 | HandleX86ForceAlignArgPointerAttr(D, Attr, S); | 
|  | 273 | return true; | 
|  | 274 | } | 
|  | 275 | return false; | 
|  | 276 | } | 
|  | 277 | }; | 
|  | 278 | } | 
|  | 279 |  | 
| Reed Kotler | 7dfd182 | 2013-01-16 17:10:28 +0000 | [diff] [blame] | 280 | static void HandleMips16Attr(Decl *D, const AttributeList &Attr, Sema &S) { | 
|  | 281 | // check the attribute arguments. | 
|  | 282 | if (Attr.hasParameterOrArguments()) { | 
|  | 283 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; | 
|  | 284 | return; | 
|  | 285 | } | 
|  | 286 | // Attribute can only be applied to function types. | 
|  | 287 | if (!isa<FunctionDecl>(D)) { | 
|  | 288 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type) | 
|  | 289 | << Attr.getName() << /* function */0; | 
|  | 290 | return; | 
|  | 291 | } | 
| Michael Han | 51d8c52 | 2013-01-24 16:46:58 +0000 | [diff] [blame] | 292 | D->addAttr(::new (S.Context) Mips16Attr(Attr.getRange(), S.Context, | 
|  | 293 | Attr.getAttributeSpellingListIndex())); | 
| Reed Kotler | 7dfd182 | 2013-01-16 17:10:28 +0000 | [diff] [blame] | 294 | } | 
|  | 295 |  | 
|  | 296 | static void HandleNoMips16Attr(Decl *D, const AttributeList &Attr, Sema &S) { | 
|  | 297 | // check the attribute arguments. | 
|  | 298 | if (Attr.hasParameterOrArguments()) { | 
|  | 299 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; | 
|  | 300 | return; | 
|  | 301 | } | 
|  | 302 | // Attribute can only be applied to function types. | 
|  | 303 | if (!isa<FunctionDecl>(D)) { | 
|  | 304 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type) | 
|  | 305 | << Attr.getName() << /* function */0; | 
|  | 306 | return; | 
|  | 307 | } | 
| Michael Han | 51d8c52 | 2013-01-24 16:46:58 +0000 | [diff] [blame] | 308 | D->addAttr(::new (S.Context) | 
|  | 309 | NoMips16Attr(Attr.getRange(), S.Context, | 
|  | 310 | Attr.getAttributeSpellingListIndex())); | 
| Reed Kotler | 7dfd182 | 2013-01-16 17:10:28 +0000 | [diff] [blame] | 311 | } | 
|  | 312 |  | 
|  | 313 | namespace { | 
|  | 314 | class MipsAttributesSema : public TargetAttributesSema { | 
|  | 315 | public: | 
|  | 316 | MipsAttributesSema() { } | 
|  | 317 | bool ProcessDeclAttribute(Scope *scope, Decl *D, const AttributeList &Attr, | 
|  | 318 | Sema &S) const { | 
|  | 319 | if (Attr.getName()->getName() == "mips16") { | 
|  | 320 | HandleMips16Attr(D, Attr, S); | 
|  | 321 | return true; | 
|  | 322 | } else if (Attr.getName()->getName() == "nomips16") { | 
|  | 323 | HandleNoMips16Attr(D, Attr, S); | 
|  | 324 | return true; | 
|  | 325 | } | 
|  | 326 | return false; | 
|  | 327 | } | 
|  | 328 | }; | 
|  | 329 | } | 
|  | 330 |  | 
| Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 331 | const TargetAttributesSema &Sema::getTargetAttributesSema() const { | 
|  | 332 | if (TheTargetAttributesSema) | 
|  | 333 | return *TheTargetAttributesSema; | 
|  | 334 |  | 
| Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 335 | const llvm::Triple &Triple(Context.getTargetInfo().getTriple()); | 
| Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 336 | switch (Triple.getArch()) { | 
| Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 337 | case llvm::Triple::msp430: | 
|  | 338 | return *(TheTargetAttributesSema = new MSP430AttributesSema); | 
| Wesley Peck | 276fdf4 | 2010-12-19 19:57:51 +0000 | [diff] [blame] | 339 | case llvm::Triple::mblaze: | 
|  | 340 | return *(TheTargetAttributesSema = new MBlazeAttributesSema); | 
| Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 341 | case llvm::Triple::x86: | 
| Eli Friedman | 9afbfbe | 2011-09-30 18:53:25 +0000 | [diff] [blame] | 342 | case llvm::Triple::x86_64: | 
| Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 343 | return *(TheTargetAttributesSema = new X86AttributesSema); | 
| Reed Kotler | 7dfd182 | 2013-01-16 17:10:28 +0000 | [diff] [blame] | 344 | case llvm::Triple::mips: | 
|  | 345 | case llvm::Triple::mipsel: | 
|  | 346 | return *(TheTargetAttributesSema = new MipsAttributesSema); | 
| Eli Friedman | 9afbfbe | 2011-09-30 18:53:25 +0000 | [diff] [blame] | 347 | default: | 
|  | 348 | return *(TheTargetAttributesSema = new TargetAttributesSema); | 
| Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 349 | } | 
|  | 350 | } |