static void HandleRegparmAttr(Decl *d, const AttributeList &Attr, Sema &S) {
// check the attribute arguments.
if (Attr.getNumArgs() != 1) {
- S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
return;
}
-
+
if (!isFunctionOrMethod(d)) {
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
<< "regparm" << 0 /*function*/;
return;
}
-
- d->addAttr(::new (S.Context) RegparmAttr());
+
+ Expr *NumParamsExpr = static_cast<Expr *>(Attr.getArg(0));
+ llvm::APSInt NumParams(32);
+ if (!NumParamsExpr->isIntegerConstantExpr(NumParams, S.Context)) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int)
+ << "regparm" << NumParamsExpr->getSourceRange();
+ return;
+ }
+
+ if (NumParams.getLimitedValue(4) > 3) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_regparm_invalid_number)
+ << NumParamsExpr->getSourceRange();
+ return;
+ }
+
+ const char *TargetPrefix = S.Context.Target.getTargetPrefix();
+ unsigned PointerWidth = S.Context.Target.getPointerWidth(0);
+ if (strcmp(TargetPrefix, "x86") || PointerWidth != 32) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_regparm_wrong_platform)
+ << NumParamsExpr->getSourceRange();
+ return;
+ }
+
+ d->addAttr(::new (S.Context) RegparmAttr(NumParams.getZExtValue()));
}
//===----------------------------------------------------------------------===//
case AttributeList::AT_cleanup: HandleCleanupAttr (D, Attr, S); break;
case AttributeList::AT_nodebug: HandleNodebugAttr (D, Attr, S); break;
case AttributeList::AT_noinline: HandleNoinlineAttr (D, Attr, S); break;
- case AttributeList::AT_regparm:
- HandleRegparmAttr (D, Attr, S);
- S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
- break;
+ case AttributeList::AT_regparm: HandleRegparmAttr (D, Attr, S); break;
case AttributeList::IgnoredAttribute:
// Just ignore
break;
--- /dev/null
+// RUN: clang-cc -triple i386-apple-darwin9 -fsyntax-only -verify %s
+
+__attribute((regparm(2))) int x(void);
+__attribute((regparm(1.0))) int x(void); // expected-error{{'regparm' attribute requires integer constant}}
+__attribute((regparm(-1))) int x(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
+__attribute((regparm(5))) int x(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
+__attribute((regparm(5,3))) int x(void); // expected-error{{attribute requires 1 argument(s)}}