[cfe-commits] r61394 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaDeclAttr.cpp

Anton Korobeynikov asl at math.spbu.ru
Tue Dec 23 14:24:08 PST 2008


Author: asl
Date: Tue Dec 23 16:24:07 2008
New Revision: 61394

URL: http://llvm.org/viewvc/llvm-project?rev=61394&view=rev
Log:
Sema for fastcall/stdcall stuff. Tests will follow.
Patch by Ilya Okonsky!

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=61394&r1=61393&r2=61394&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue Dec 23 16:24:07 2008
@@ -803,6 +803,8 @@
      "Objective-C declarations may only appear in global scope")
 
 // Attributes
+DIAG(err_attributes_are_not_compatible, ERROR,
+     "%0 and %1 attributes are not compatible")
 DIAG(err_attribute_wrong_number_arguments, ERROR,
      "attribute requires %0 argument(s)")
 DIAG(err_attribute_missing_parameter_name, ERROR,
@@ -851,6 +853,8 @@
      "automatic variable qualified with an address space")
 DIAG(err_attribute_annotate_no_string, ERROR,
      "argument to annotate attribute was not a string literal")
+DIAG(warn_redeclaration_without_attribute_prev_attribute_ignored, WARNING,
+  "'%0' redeclared without %1 attribute: previous %1 ignored")
 DIAG(warn_attribute_ignored, WARNING,
      "%0 attribute ignored")
 DIAG(warn_attribute_weak_on_field, WARNING,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Dec 23 16:24:07 2008
@@ -684,7 +684,7 @@
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
     return;
   }
-  
+
   d->addAttr(new DLLImportAttr());
 }
 
@@ -694,27 +694,54 @@
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
     return;
   }
-  
+
   d->addAttr(new DLLExportAttr());
 }
 
 static void HandleStdCallAttr(Decl *d, const AttributeList &Attr, Sema &S) {
-  // check the attribute arguments.
+  // Attribute has no arguments.
   if (Attr.getNumArgs() != 0) {
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
     return;
   }
-  
+
+  // Attribute can be applied only to functions.
+  if (!isa<FunctionDecl>(d)) {
+    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+      << "stdcall" << "function";
+    return;
+  }
+
+  // stdcall and fastcall attributes are mutually incompatible.
+  if (d->getAttr<FastCallAttr>()) {
+    S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
+      << "stdcall" << "fastcall";
+    return;
+  }
+
   d->addAttr(new StdCallAttr());
 }
 
 static void HandleFastCallAttr(Decl *d, const AttributeList &Attr, Sema &S) {
-  // check the attribute arguments.
+  // Attribute has no arguments.
   if (Attr.getNumArgs() != 0) {
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
     return;
   }
-  
+
+  if (!isa<FunctionDecl>(d)) {
+    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+      << "fastcall" << "function";
+    return;
+  }
+
+  // stdcall and fastcall attributes are mutually incompatible.
+  if (d->getAttr<StdCallAttr>()) {
+    S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
+      << "fastcall" << "stdcall";
+    return;
+  }
+
   d->addAttr(new FastCallAttr());
 }
 





More information about the cfe-commits mailing list