[cfe-commits] r115842 - in /cfe/trunk: include/clang/Basic/Attr.td include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/DelayedDiagnostic.h include/clang/Sema/Sema.h lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExpr.cpp test/Sema/attr-deprecated-message.c
Fariborz Jahanian
fjahanian at apple.com
Wed Oct 6 14:18:44 PDT 2010
Author: fjahanian
Date: Wed Oct 6 16:18:44 2010
New Revision: 115842
URL: http://llvm.org/viewvc/llvm-project?rev=115842&view=rev
Log:
Add message to attribute(deprecated).
attribute(unavailable) to do next.
// rdar:// 6734520.
Added:
cfe/trunk/test/Sema/attr-deprecated-message.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/DelayedDiagnostic.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=115842&r1=115841&r2=115842&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Oct 6 16:18:44 2010
@@ -172,6 +172,7 @@
def Deprecated : Attr {
let Spellings = ["deprecated"];
+ let Args = [StringArgument<"Message">];
}
def Destructor : Attr {
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=115842&r1=115841&r2=115842&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Oct 6 16:18:44 2010
@@ -1745,6 +1745,8 @@
def err_undeclared_use : Error<"use of undeclared %0">;
def warn_deprecated : Warning<"%0 is deprecated">,
InGroup<DeprecatedDeclarations>;
+def warn_deprecated_message : Warning<"%0 is deprecated: %1">,
+ InGroup<DeprecatedDeclarations>;
def err_unavailable : Error<"%0 is unavailable">;
def note_unavailable_here : Note<
"function has been explicitly marked %select{unavailable|deleted}0 here">;
Modified: cfe/trunk/include/clang/Sema/DelayedDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DelayedDiagnostic.h?rev=115842&r1=115841&r2=115842&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/DelayedDiagnostic.h (original)
+++ cfe/trunk/include/clang/Sema/DelayedDiagnostic.h Wed Oct 6 16:18:44 2010
@@ -121,7 +121,7 @@
union {
/// Deprecation.
- struct { NamedDecl *Decl; } DeprecationData;
+ struct { NamedDecl *Decl; const char* Message; } DeprecationData;
/// Access control.
char AccessData[sizeof(AccessedEntity)];
@@ -135,12 +135,14 @@
}
static DelayedDiagnostic makeDeprecation(SourceLocation Loc,
- NamedDecl *D) {
+ NamedDecl *D,
+ const char *Msg) {
DelayedDiagnostic DD;
DD.Kind = Deprecation;
DD.Triggered = false;
DD.Loc = Loc;
DD.DeprecationData.Decl = D;
+ DD.DeprecationData.Message = Msg;
return DD;
}
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=115842&r1=115841&r2=115842&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Oct 6 16:18:44 2010
@@ -1649,7 +1649,8 @@
ParsingDeclStackState PushParsingDeclaration();
void PopParsingDeclaration(ParsingDeclStackState S, Decl *D);
- void EmitDeprecationWarning(NamedDecl *D, SourceLocation Loc);
+ void EmitDeprecationWarning(NamedDecl *D, const char *Message,
+ SourceLocation Loc);
void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=115842&r1=115841&r2=115842&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Oct 6 16:18:44 2010
@@ -903,12 +903,28 @@
static void HandleDeprecatedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
// check the attribute arguments.
- if (Attr.getNumArgs() != 0) {
- S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+ int noArgs = Attr.getNumArgs();
+ if (noArgs > 1) {
+ S.Diag(Attr.getLoc(),
+ diag::err_attribute_wrong_number_arguments) << "0 or 1";
return;
}
+ // Handle the case where deprecated attribute has a text message.
+ StringLiteral *SE;
+ if (noArgs == 1) {
+ Expr *ArgExpr = static_cast<Expr *>(Attr.getArg(0));
+ SE = dyn_cast<StringLiteral>(ArgExpr);
+ if (!SE) {
+ S.Diag(ArgExpr->getLocStart(),
+ diag::err_attribute_not_string) << "deprecated";
+ return;
+ }
+ }
+ else
+ SE = StringLiteral::CreateEmpty(S.Context, 1);
- d->addAttr(::new (S.Context) DeprecatedAttr(Attr.getLoc(), S.Context));
+ d->addAttr(::new (S.Context) DeprecatedAttr(Attr.getLoc(), S.Context,
+ SE->getString()));
}
static void HandleUnavailableAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@@ -2536,20 +2552,30 @@
return;
DD.Triggered = true;
- Diag(DD.Loc, diag::warn_deprecated)
- << DD.DeprecationData.Decl->getDeclName();
+ if (strlen(DD.DeprecationData.Message))
+ Diag(DD.Loc, diag::warn_deprecated_message)
+ << DD.DeprecationData.Decl->getDeclName()
+ << DD.DeprecationData.Message;
+ else
+ Diag(DD.Loc, diag::warn_deprecated)
+ << DD.DeprecationData.Decl->getDeclName();
}
-void Sema::EmitDeprecationWarning(NamedDecl *D, SourceLocation Loc) {
+void Sema::EmitDeprecationWarning(NamedDecl *D, const char * Message,
+ SourceLocation Loc) {
// Delay if we're currently parsing a declaration.
if (ParsingDeclDepth) {
- DelayedDiagnostics.push_back(DelayedDiagnostic::makeDeprecation(Loc, D));
+ DelayedDiagnostics.push_back(DelayedDiagnostic::makeDeprecation(Loc, D,
+ Message));
return;
}
// Otherwise, don't warn if our current context is deprecated.
if (isDeclDeprecated(cast<Decl>(CurContext)))
return;
-
- Diag(Loc, diag::warn_deprecated) << D->getDeclName();
+ if (strlen(Message))
+ Diag(Loc, diag::warn_deprecated_message) << D->getDeclName()
+ << Message;
+ else
+ Diag(Loc, diag::warn_deprecated) << D->getDeclName();
}
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=115842&r1=115841&r2=115842&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Oct 6 16:18:44 2010
@@ -1622,9 +1622,13 @@
// If the interface declared this method, and it was deprecated there,
// mark it deprecated here.
if (InterfaceMD)
- if (Attr *DA = InterfaceMD->getAttr<DeprecatedAttr>())
- ObjCMethod->addAttr(::new (Context) DeprecatedAttr(DA->getLocation(),
- Context));
+ if (Attr *DA = InterfaceMD->getAttr<DeprecatedAttr>()) {
+ StringLiteral *SE = StringLiteral::CreateEmpty(Context, 1);
+ ObjCMethod->addAttr(::new (Context)
+ DeprecatedAttr(DA->getLocation(),
+ Context,
+ SE->getString()));
+ }
return ObjCMethod;
}
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=115842&r1=115841&r2=115842&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Oct 6 16:18:44 2010
@@ -57,8 +57,10 @@
///
bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
// See if the decl is deprecated.
- if (D->getAttr<DeprecatedAttr>()) {
- EmitDeprecationWarning(D, Loc);
+ if (const DeprecatedAttr *DA = D->getAttr<DeprecatedAttr>()) {
+ const char *Message =
+ DA->getMessage().empty() ? "" : DA->getMessage().data();
+ EmitDeprecationWarning(D, Message, Loc);
}
// See if the decl is unavailable
Added: cfe/trunk/test/Sema/attr-deprecated-message.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-deprecated-message.c?rev=115842&view=auto
==============================================================================
--- cfe/trunk/test/Sema/attr-deprecated-message.c (added)
+++ cfe/trunk/test/Sema/attr-deprecated-message.c Wed Oct 6 16:18:44 2010
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+// rdar: // 6734520
+
+typedef int INT1 __attribute__((deprecated("Please avoid INT1")));
+
+typedef INT1 INT2 __attribute__ ((__deprecated__("Please avoid INT2")));
+
+typedef INT1 INT1a; // expected-warning {{'INT1' is deprecated: Please avoid INT1}}
+
+typedef INT1 INT1b __attribute__ ((deprecated("Please avoid INT1b")));
+
+INT1 should_be_unavailable; // expected-warning {{'INT1' is deprecated: Please avoid INT1}}
+INT1a should_not_be_deprecated;
+
+INT1 f1(void) __attribute__ ((deprecated("Please avoid f1")));
+INT1 f2(void); // expected-warning {{'INT1' is deprecated: Please avoid INT1}}
+
+typedef enum {red, green, blue} Color __attribute__((deprecated("Please avoid Color")));
+
+
+Color c1; // expected-warning {{'Color' is deprecated: Please avoid Color}}
+
+int g1;
+int g2 __attribute__ ((deprecated("Please avoid g2")));
+
+int func1()
+{
+ int (*pf)() = f1; // expected-warning {{'f1' is deprecated: Please avoid f1}}
+ int i = f2();
+ return g1 + g2; // expected-warning {{'g2' is deprecated: Please avoid g2}}
+}
More information about the cfe-commits
mailing list