]> granicus.if.org Git - clang/commitdiff
Add support for cdecl attribute. (As far as I know, it doesn't affect CodeGen
authorEli Friedman <eli.friedman@gmail.com>
Mon, 9 Nov 2009 18:38:53 +0000 (18:38 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 9 Nov 2009 18:38:53 +0000 (18:38 +0000)
unless we start implementing command-line switches which override the default
calling convention, so the effect is mostly to silence unknown attribute
warnings.)

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

include/clang/AST/Attr.h
include/clang/Parse/AttributeList.h
lib/Frontend/PCHReaderDecl.cpp
lib/Frontend/PCHWriter.cpp
lib/Parse/AttributeList.cpp
lib/Sema/SemaDeclAttr.cpp
test/Sema/callingconv.c

index f7a47364a7f611a5dd49a0c637726d74ac400de8..b36ff1229376caa6f406b09f38adefeb3072f280 100644 (file)
@@ -50,6 +50,7 @@ public:
     Annotate,
     AsmLabel, // Represent GCC asm label extension.
     Blocks,
+    CDecl,
     Cleanup,
     Const,
     Constructor,
@@ -442,6 +443,7 @@ DEF_SIMPLE_ATTR(DLLImport);
 DEF_SIMPLE_ATTR(DLLExport);
 DEF_SIMPLE_ATTR(FastCall);
 DEF_SIMPLE_ATTR(StdCall);
+DEF_SIMPLE_ATTR(CDecl);
 DEF_SIMPLE_ATTR(TransparentUnion);
 DEF_SIMPLE_ATTR(ObjCNSObject);
 DEF_SIMPLE_ATTR(ObjCException);
index 9fcc845cb00640d3a5e66c3ae985ee8ee43a6ef9..81bb3007baea871179206272cea0d4285561a2fa 100644 (file)
@@ -57,6 +57,7 @@ public:
     AT_analyzer_noreturn,
     AT_annotate,
     AT_blocks,
+    AT_cdecl,
     AT_cleanup,
     AT_const,
     AT_constructor,
index b9ece21f74c3e52dae756f538df34c9bdfd9d29b..775ce76c92d87e0b16f45f71df17d9a7b8bbfd12 100644 (file)
@@ -442,6 +442,8 @@ Attr *PCHReader::ReadAttributes() {
                                   (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
       break;
 
+    SIMPLE_ATTR(CDecl);
+
     case Attr::Cleanup:
       New = ::new (*Context) CleanupAttr(
                                   cast<FunctionDecl>(GetDecl(Record[Idx++])));
index 436428b3755271b02b21ccae8e4ef485d44fec07..82922a93b5928f5562125db372c791041cf6ee3d 100644 (file)
@@ -1768,6 +1768,9 @@ void PCHWriter::WriteAttributeRecord(const Attr *Attr) {
       Record.push_back(cast<BlocksAttr>(Attr)->getType()); // FIXME: stable
       break;
 
+    case Attr::CDecl:
+      break;
+
     case Attr::Cleanup:
       AddDeclRef(cast<CleanupAttr>(Attr)->getFunctionDecl(), Record);
       break;
index 344ce9e90e554615e1a4ddcb066a0903426804db..dde4bc866ac571b4c92f0e56d6f61115aa5818a7 100644 (file)
@@ -59,6 +59,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
     .Case("mode", AT_mode)
     .Case("used", AT_used)
     .Case("alias", AT_alias)
+    .Case("cdecl", AT_cdecl)
     .Case("const", AT_const)
     .Case("packed", AT_packed)
     .Case("malloc", AT_malloc)
index 18f57da76912793ad9a7ad3060f0fb18893f8bb7..803be138c2626a9d4f21334b53f84f2780f799e1 100644 (file)
@@ -1008,6 +1008,38 @@ static void HandleSectionAttr(Decl *D, const AttributeList &Attr, Sema &S) {
 
 }
 
+static void HandleCDeclAttr(Decl *d, const AttributeList &Attr, Sema &S) {
+  // 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)
+      << Attr.getName() << 0 /*function*/;
+    return;
+  }
+
+  // cdecl and fastcall attributes are mutually incompatible.
+  if (d->getAttr<FastCallAttr>()) {
+    S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
+      << "cdecl" << "fastcall";
+    return;
+  }
+
+  // cdecl and stdcall attributes are mutually incompatible.
+  if (d->getAttr<StdCallAttr>()) {
+    S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
+      << "cdecl" << "stdcall";
+    return;
+  }
+
+  d->addAttr(::new (S.Context) CDeclAttr());
+}
+
+
 static void HandleStdCallAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   // Attribute has no arguments.
   if (Attr.getNumArgs() != 0) {
@@ -1822,6 +1854,7 @@ static void ProcessDeclAttribute(Scope *scope, Decl *D,
   case AttributeList::AT_analyzer_noreturn:
     HandleAnalyzerNoReturnAttr  (D, Attr, S); break;
   case AttributeList::AT_annotate:    HandleAnnotateAttr  (D, Attr, S); break;
+  case AttributeList::AT_cdecl:       HandleCDeclAttr     (D, Attr, S); break;
   case AttributeList::AT_constructor: HandleConstructorAttr(D, Attr, S); break;
   case AttributeList::AT_deprecated:  HandleDeprecatedAttr(D, Attr, S); break;
   case AttributeList::AT_destructor:  HandleDestructorAttr(D, Attr, S); break;
index 102115b3bf2ba111b79bcb50e1ee173b4727df47..f65aab463f5729e430cc4ff41c2f417931f9491f 100644 (file)
@@ -17,3 +17,7 @@ void __attribute__((fastcall)) test1(void) {
 
 void __attribute__((fastcall)) test2(int a, ...) { // expected-error {{variadic function cannot use 'fastcall' calling convention}}
 }
+
+void __attribute__((cdecl)) ctest0() {}
+
+void __attribute__((cdecl(1))) ctest1(float x) {} // expected-error {{attribute requires 0 argument(s)}}