]> granicus.if.org Git - clang/commitdiff
Sema for fastcall/stdcall stuff. Tests will follow.
authorAnton Korobeynikov <asl@math.spbu.ru>
Tue, 23 Dec 2008 22:24:07 +0000 (22:24 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Tue, 23 Dec 2008 22:24:07 +0000 (22:24 +0000)
Patch by Ilya Okonsky!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61394 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticKinds.def
lib/Sema/SemaDeclAttr.cpp

index 8f15d2e4d788da367ca6df88f656d07c38a194cb..7675710a34b51b77f2675d7249a13e73887628f7 100644 (file)
@@ -803,6 +803,8 @@ DIAG(err_objc_decls_may_only_appear_in_global_scope, ERROR,
      "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 @@ DIAG(err_as_qualified_auto_decl, ERROR,
      "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,
index 7275589c8cf2da7c7e2738c7b6740152ce3e377d..81283a85606b196b5e7bb53f0452fa1a37fca587 100644 (file)
@@ -684,7 +684,7 @@ static void HandleDLLImportAttr(Decl *d, const AttributeList &Attr, Sema &S) {
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
     return;
   }
-  
+
   d->addAttr(new DLLImportAttr());
 }
 
@@ -694,27 +694,54 @@ static void HandleDLLExportAttr(Decl *d, const AttributeList &Attr, Sema &S) {
     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());
 }