[cfe-commits] r115862 - in /cfe/trunk: docs/LanguageExtensions.html include/clang/Basic/Attr.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaExpr.cpp test/Sema/attr-unavailable-message.c

Fariborz Jahanian fjahanian at apple.com
Wed Oct 6 16:12:32 PDT 2010


Author: fjahanian
Date: Wed Oct  6 18:12:32 2010
New Revision: 115862

URL: http://llvm.org/viewvc/llvm-project?rev=115862&view=rev
Log:
Patch for adding message to unavailable attribute.
And its documentation.
Finishes off // rdar: // 6734520.

Added:
    cfe/trunk/test/Sema/attr-unavailable-message.c
Modified:
    cfe/trunk/docs/LanguageExtensions.html
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/docs/LanguageExtensions.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.html?rev=115862&r1=115861&r2=115862&view=diff
==============================================================================
--- cfe/trunk/docs/LanguageExtensions.html (original)
+++ cfe/trunk/docs/LanguageExtensions.html Wed Oct  6 18:12:32 2010
@@ -23,6 +23,7 @@
 <li><a href="#has_include">Include File Checking Macros</a></li>
 <li><a href="#builtinmacros">Builtin Macros</a></li>
 <li><a href="#vectors">Vectors and Extended Vectors</a></li>
+<li><a href="#deprecated">Deprecated and Unavailable attribute with Message</a></li>
 <li><a href="#checking_language_features">Checks for Standard Language Features</a></li>
   <ul>
   <li><a href="#cxx_exceptions">C++ exceptions</a></li>
@@ -267,6 +268,14 @@
 <p>See also <a href="#__builtin_shufflevector">__builtin_shufflevector</a>.</p>
 
 <!-- ======================================================================= -->
+<h2 id="deprecated">Deprecated and Unavailable attribute with Message</h2>
+<!-- ======================================================================= -->
+
+<p> Optional string message can be added to Deprecated and Available attributes. </p>
+
+<p> Message will be added to deprecated warning or unavailable error if present. </p>
+
+<!-- ======================================================================= -->
 <h2 id="checking_language_features">Checks for Standard Language Features</h2>
 <!-- ======================================================================= -->
 

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=115862&r1=115861&r2=115862&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Oct  6 18:12:32 2010
@@ -374,6 +374,7 @@
 
 def Unavailable : Attr {
   let Spellings = ["unavailable"];
+  let Args = [StringArgument<"Message">];
 }
 
 def Unused : Attr {

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=115862&r1=115861&r2=115862&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Oct  6 18:12:32 2010
@@ -1748,6 +1748,7 @@
 def warn_deprecated_message : Warning<"%0 is deprecated: %1">,
     InGroup<DeprecatedDeclarations>;
 def err_unavailable : Error<"%0 is unavailable">;
+def err_unavailable_message : Error<"%0 is unavailable: %1">;
 def note_unavailable_here : Note<
   "function has been explicitly marked %select{unavailable|deleted}0 here">;
 def warn_not_enough_argument : Warning<

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=115862&r1=115861&r2=115862&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Oct  6 18:12:32 2010
@@ -929,12 +929,26 @@
 
 static void HandleUnavailableAttr(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;
   }
-
-  d->addAttr(::new (S.Context) UnavailableAttr(Attr.getLoc(), S.Context));
+  // Handle the case where unavailable 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) << "unavailable";
+      return;
+    }
+  }
+  else
+    SE = StringLiteral::CreateEmpty(S.Context, 1);
+  d->addAttr(::new (S.Context) UnavailableAttr(Attr.getLoc(), S.Context,
+                                               SE->getString()));
 }
 
 static void HandleVisibilityAttr(Decl *d, const AttributeList &Attr, Sema &S) {

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=115862&r1=115861&r2=115862&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Oct  6 18:12:32 2010
@@ -64,8 +64,12 @@
   }
 
   // See if the decl is unavailable
-  if (D->getAttr<UnavailableAttr>()) {
-    Diag(Loc, diag::err_unavailable) << D->getDeclName();
+  if (const UnavailableAttr *UA = D->getAttr<UnavailableAttr>()) {
+    if (UA->getMessage().empty())
+      Diag(Loc, diag::err_unavailable) << D->getDeclName();
+    else
+      Diag(Loc, diag::err_unavailable_message) 
+        << D->getDeclName() << UA->getMessage().data();
     Diag(D->getLocation(), diag::note_unavailable_here) << 0;
   }
 

Added: cfe/trunk/test/Sema/attr-unavailable-message.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-unavailable-message.c?rev=115862&view=auto
==============================================================================
--- cfe/trunk/test/Sema/attr-unavailable-message.c (added)
+++ cfe/trunk/test/Sema/attr-unavailable-message.c Wed Oct  6 18:12:32 2010
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar: //6734520
+
+int foo(int)  __attribute__((__unavailable__("USE IFOO INSTEAD"))); // expected-note {{function has been explicitly marked unavailable here}}
+double dfoo(double)  __attribute__((__unavailable__("NO LONGER"))); // expected-note 2 {{function has been explicitly marked unavailable here}}
+
+void bar() __attribute__((__unavailable__)); // expected-note {{explicitly marked unavailable}}
+
+void test_foo() {
+  int ir = foo(1); // expected-error {{'foo' is unavailable: USE IFOO INSTEAD}}
+  double dr = dfoo(1.0); // expected-error {{'dfoo' is unavailable: NO LONGER}}
+
+  void (*fp)() = &bar; // expected-error {{'bar' is unavailable}}
+
+  double (*fp4)(double) = dfoo;  // expected-error {{'dfoo' is unavailable: NO LONGER}}
+}





More information about the cfe-commits mailing list