From 264a76cdf382c507f4d43e64c89f1503f003ac95 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Fri, 3 Apr 2009 23:38:25 +0000 Subject: [PATCH] Provide sema proper values of maximal number of arguments passed in registers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68413 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 4 ++-- include/clang/Basic/TargetInfo.h | 7 +++++++ lib/Basic/Targets.cpp | 2 ++ lib/Sema/SemaDeclAttr.cpp | 13 ++++++------- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 815b8b5ae6..1bdabadf45 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -436,9 +436,9 @@ def err_attribute_cleanup_func_arg_incompatible_type : Error< "'cleanup' function %0 parameter has type %1 which is incompatible with " "type %2">; def err_attribute_regparm_wrong_platform : Error< - "'regparm' is not valid on platforms other than x86-32">; + "'regparm' is not valid on this platform">; def err_attribute_regparm_invalid_number : Error< - "'regparm' parameter must be between 0 and 3 inclusive">; + "'regparm' parameter must be between 0 and %0 inclusive">; // Clang-Specific Attributes diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index 2cb15f12f3..8018a17c9e 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -48,6 +48,7 @@ protected: const char *DescriptionString; const char *UserLabelPrefix; const llvm::fltSemantics *FloatFormat, *DoubleFormat, *LongDoubleFormat; + unsigned char RegParmMax, SSERegParmMax; // TargetInfo Constructor. Default initializes all fields. TargetInfo(const std::string &T); @@ -304,6 +305,12 @@ public: return -1; return 0; } + + // getRegParmMax - Returns maximal number of args passed in registers. + unsigned getRegParmMax() const { + return RegParmMax; + } + protected: virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return PointerWidth; diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 5f5ba60e85..40bc31381d 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -633,6 +633,7 @@ public: SizeType = UnsignedInt; PtrDiffType = SignedInt; IntPtrType = SignedInt; + RegParmMax = 3; } virtual const char *getVAListDeclaration() const { return "typedef char* __builtin_va_list;"; @@ -762,6 +763,7 @@ public: LongDoubleAlign = 128; IntMaxType = SignedLong; UIntMaxType = UnsignedLong; + RegParmMax = 6; DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 40e4971d2b..a68ddf6c00 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -1465,17 +1465,16 @@ static void HandleRegparmAttr(Decl *d, const AttributeList &Attr, Sema &S) { return; } - if (NumParams.getLimitedValue(4) > 3) { - S.Diag(Attr.getLoc(), diag::err_attribute_regparm_invalid_number) + if (S.Context.Target.getRegParmMax() == 0) { + S.Diag(Attr.getLoc(), diag::err_attribute_regparm_wrong_platform) << 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(); + // FIXME: we need to honour command line settings also... + if (NumParams.getLimitedValue(4) > S.Context.Target.getRegParmMax()) { + S.Diag(Attr.getLoc(), diag::err_attribute_regparm_invalid_number) + << S.Context.Target.getRegParmMax() << NumParamsExpr->getSourceRange(); return; } -- 2.40.0