summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/Parse/AttributeList.cpp5
-rw-r--r--clang/Sema/SemaDecl.cpp11
-rw-r--r--clang/Sema/SemaExpr.cpp4
-rw-r--r--clang/include/clang/AST/Attr.h13
-rw-r--r--clang/include/clang/Basic/DiagnosticKinds.def2
-rw-r--r--clang/include/clang/Parse/AttributeList.h3
6 files changed, 34 insertions, 4 deletions
diff --git a/clang/Parse/AttributeList.cpp b/clang/Parse/AttributeList.cpp
index 4ceece8f27a..4fac91fa572 100644
--- a/clang/Parse/AttributeList.cpp
+++ b/clang/Parse/AttributeList.cpp
@@ -61,7 +61,10 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
if (!memcmp(Str, "annotate", 8)) return AT_annotate;
if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
break;
- case 11:
+ case 10:
+ if (!memcmp(Str, "deprecated", 10)) return AT_deprecated;
+ break;
+ case 11:
if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
break;
case 13:
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index df6dd5c2e18..26528485db1 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/Sema/SemaDecl.cpp
@@ -255,6 +255,8 @@ FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, ScopedDecl *OldD) {
Diag(OldD->getLocation(), diag::err_previous_definition);
return New;
}
+
+ // FIXME: propagate old Attrs to the New decl
QualType OldQType = Old->getCanonicalType();
QualType NewQType = New->getCanonicalType();
@@ -1778,6 +1780,9 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
vDecl->setType(newType);
}
break;
+ case AttributeList::AT_deprecated:
+ New->addAttr(new DeprecatedAttr());
+ break;
case AttributeList::AT_aligned:
HandleAlignedAttribute(New, Attr);
break;
@@ -1791,7 +1796,11 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
HandleNoReturnAttribute(New, Attr);
break;
default:
- // FIXME: add other attributes...
+#if 0
+ // TODO: when we have the full set of attributes, warn about unknown ones.
+ Diag(Attr->getLoc(), diag::warn_attribute_ignored,
+ Attr->getName()->getName());
+#endif
break;
}
}
diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp
index 3d60866c015..5b5b2d235ce 100644
--- a/clang/Sema/SemaExpr.cpp
+++ b/clang/Sema/SemaExpr.cpp
@@ -100,6 +100,10 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
}
}
if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
+ // check if referencing an identifier with __attribute__((deprecated)).
+ if (VD->getAttr<DeprecatedAttr>())
+ Diag(Loc, diag::warn_deprecated, VD->getName());
+
// Only create DeclRefExpr's for valid Decl's.
if (VD->isInvalidDecl())
return true;
diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 25172884604..0e5ae58efac 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -26,7 +26,8 @@ public:
Aligned,
Packed,
Annotate,
- NoReturn
+ NoReturn,
+ Deprecated
};
private:
@@ -107,6 +108,16 @@ public:
static bool classof(const NoReturnAttr *A) { return true; }
};
+class DeprecatedAttr : public Attr {
+public:
+ DeprecatedAttr() : Attr(Deprecated) {}
+
+ // Implement isa/cast/dyncast/etc.
+
+ static bool classof(const Attr *A) { return A->getKind() == Deprecated; }
+ static bool classof(const DeprecatedAttr *A) { return true; }
+};
+
} // end namespace clang
#endif
diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def
index 21f348216da..3d0a3f8815f 100644
--- a/clang/include/clang/Basic/DiagnosticKinds.def
+++ b/clang/include/clang/Basic/DiagnosticKinds.def
@@ -617,6 +617,8 @@ DIAG(err_unexpected_typedef, ERROR,
"unexpected type name '%0': expected expression")
DIAG(err_undeclared_var_use, ERROR,
"use of undeclared identifier '%0'")
+DIAG(warn_deprecated, WARNING,
+ "'%0' is deprecated")
DIAG(err_redefinition, ERROR,
"redefinition of '%0'")
DIAG(err_static_non_static, ERROR,
diff --git a/clang/include/clang/Parse/AttributeList.h b/clang/include/clang/Parse/AttributeList.h
index a6a699ef8ba..6300b984b5b 100644
--- a/clang/include/clang/Parse/AttributeList.h
+++ b/clang/include/clang/Parse/AttributeList.h
@@ -49,7 +49,8 @@ public:
AT_aligned,
AT_packed,
AT_annotate,
- AT_noreturn
+ AT_noreturn,
+ AT_deprecated
};
IdentifierInfo *getName() const { return AttrName; }
OpenPOWER on IntegriCloud