[cfe-commits] r67868 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/Basic/DiagnosticSemaKinds.td lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaDeclAttr.cpp test/Sema/attr-regparm.c

Eli Friedman eli.friedman at gmail.com
Fri Mar 27 14:06:48 PDT 2009


Author: efriedma
Date: Fri Mar 27 16:06:47 2009
New Revision: 67868

URL: http://llvm.org/viewvc/llvm-project?rev=67868&view=rev
Log:
Finish off semantic analysis for regparm, and remove the warning.  Also 
remove a redundant error in CodeGen.


Added:
    cfe/trunk/test/Sema/attr-regparm.c
Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=67868&r1=67867&r2=67868&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Fri Mar 27 16:06:47 2009
@@ -547,9 +547,13 @@
 };
 
 class RegparmAttr : public Attr {
+  unsigned NumParams;
+
 public:
-  RegparmAttr() : Attr(Regparm) {}
-    
+  RegparmAttr(unsigned np) : Attr(Regparm), NumParams(np) {}
+
+  unsigned getNumParams() { return NumParams; }
+
   // Implement isa/cast/dyncast/etc.
     
   static bool classof(const Attr *A) { return A->getKind() == Regparm; }

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=67868&r1=67867&r2=67868&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Mar 27 16:06:47 2009
@@ -435,6 +435,10 @@
 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">;
+def err_attribute_regparm_invalid_number : Error<
+  "'regparm' parameter must be between 0 and 3 inclusive">;
 
 
 // Clang-Specific Attributes

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=67868&r1=67867&r2=67868&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Mar 27 16:06:47 2009
@@ -311,9 +311,6 @@
   
   if (D->getAttr<NoinlineAttr>())
     F->addFnAttr(llvm::Attribute::NoInline);
-  
-  if (D->getAttr<RegparmAttr>())
-    ErrorUnsupported(D, "regparm attribute");
 }
 
 void CodeGenModule::SetMethodAttributes(const ObjCMethodDecl *MD,

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=67868&r1=67867&r2=67868&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Mar 27 16:06:47 2009
@@ -1447,17 +1447,39 @@
 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()));
 }
 
 //===----------------------------------------------------------------------===//
@@ -1520,10 +1542,7 @@
   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;

Added: cfe/trunk/test/Sema/attr-regparm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-regparm.c?rev=67868&view=auto

==============================================================================
--- cfe/trunk/test/Sema/attr-regparm.c (added)
+++ cfe/trunk/test/Sema/attr-regparm.c Fri Mar 27 16:06:47 2009
@@ -0,0 +1,7 @@
+// 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)}}





More information about the cfe-commits mailing list