aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2008-12-23 22:24:07 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2008-12-23 22:24:07 +0000
commit7b0a52f982e3514425fc8a3c8fc728f17c27c08e (patch)
treed77110436f6fc205fcd70f1bb874748abbca6e81
parent5cc3709b843c799e268f944b7bf9dbdc79cefe8d (diff)
Sema for fastcall/stdcall stuff. Tests will follow.
Patch by Ilya Okonsky! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61394 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticKinds.def4
-rw-r--r--lib/Sema/SemaDeclAttr.cpp39
2 files changed, 37 insertions, 6 deletions
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def
index 8f15d2e4d7..7675710a34 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -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,
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 7275589c8c..81283a8560 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -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());
}