summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2016-03-16 18:50:49 +0000
committerManman Ren <manman.ren@gmail.com>2016-03-16 18:50:49 +0000
commitc7890fed01f8c8accba188236d781af26845cb2c (patch)
treeca661b70f24fefdf86060bc7290322c3b53fb4e0 /clang/lib
parent8a46c067ed8d06b953fd94a4089a9168c3f82bb2 (diff)
downloadbcm5719-llvm-c7890fed01f8c8accba188236d781af26845cb2c.tar.gz
bcm5719-llvm-c7890fed01f8c8accba188236d781af26845cb2c.zip
Add an optional string argument to DeprecatedAttr for Fix-It.
We only add this to __attribute__((deprecated)). Differential Revision: http://reviews.llvm.org/D17865 llvm-svn: 263652
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Lex/PPMacroExpansion.cpp1
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp40
2 files changed, 37 insertions, 4 deletions
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index 62166b22ba3..36255a81144 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1079,6 +1079,7 @@ static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) {
.Case("attribute_cf_returns_retained", true)
.Case("attribute_cf_returns_on_parameters", true)
.Case("attribute_deprecated_with_message", true)
+ .Case("attribute_deprecated_with_replacement", true)
.Case("attribute_ext_vector_type", true)
.Case("attribute_ns_returns_not_retained", true)
.Case("attribute_ns_returns_retained", true)
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 725b08a422a..18065cb52d8 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5136,12 +5136,27 @@ static void handleDeprecatedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
}
}
+ // Handle the cases where the attribute has a text message.
+ StringRef Str, Replacement;
+ if (Attr.isArgExpr(0) && Attr.getArgAsExpr(0) &&
+ !S.checkStringLiteralArgumentAttr(Attr, 0, Str))
+ return;
+
+ // Only support a single optional message for Declspec and CXX11.
+ if (Attr.isDeclspecAttribute() || Attr.isCXX11Attribute())
+ checkAttributeAtMostNumArgs(S, Attr, 1);
+ else if (Attr.isArgExpr(1) && Attr.getArgAsExpr(1) &&
+ !S.checkStringLiteralArgumentAttr(Attr, 1, Replacement))
+ return;
+
if (!S.getLangOpts().CPlusPlus14)
if (Attr.isCXX11Attribute() &&
!(Attr.hasScope() && Attr.getScopeName()->isStr("gnu")))
S.Diag(Attr.getLoc(), diag::ext_cxx14_attr) << Attr.getName();
- handleAttrWithMessage<DeprecatedAttr>(S, D, Attr);
+ D->addAttr(::new (S.Context) DeprecatedAttr(Attr.getRange(), S.Context, Str,
+ Replacement,
+ Attr.getAttributeSpellingListIndex()));
}
static void handleNoSanitizeAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -6209,18 +6224,35 @@ static void DoEmitAvailabilityWarning(Sema &S, Sema::AvailabilityDiagnostic K,
break;
}
+ CharSourceRange UseRange;
+ StringRef Replacement;
+ if (K == Sema::AD_Deprecation) {
+ if (auto attr = D->getAttr<DeprecatedAttr>())
+ Replacement = attr->getReplacement();
+
+ if (!Replacement.empty())
+ UseRange =
+ CharSourceRange::getCharRange(Loc, S.getLocForEndOfToken(Loc));
+ }
+
if (!Message.empty()) {
- S.Diag(Loc, diag_message) << D << Message;
+ S.Diag(Loc, diag_message) << D << Message
+ << (UseRange.isValid() ?
+ FixItHint::CreateReplacement(UseRange, Replacement) : FixItHint());
if (ObjCProperty)
S.Diag(ObjCProperty->getLocation(), diag::note_property_attribute)
<< ObjCProperty->getDeclName() << property_note_select;
} else if (!UnknownObjCClass) {
- S.Diag(Loc, diag) << D;
+ S.Diag(Loc, diag) << D
+ << (UseRange.isValid() ?
+ FixItHint::CreateReplacement(UseRange, Replacement) : FixItHint());
if (ObjCProperty)
S.Diag(ObjCProperty->getLocation(), diag::note_property_attribute)
<< ObjCProperty->getDeclName() << property_note_select;
} else {
- S.Diag(Loc, diag_fwdclass_message) << D;
+ S.Diag(Loc, diag_fwdclass_message) << D
+ << (UseRange.isValid() ?
+ FixItHint::CreateReplacement(UseRange, Replacement) : FixItHint());
S.Diag(UnknownObjCClass->getLocation(), diag::note_forward_class);
}
OpenPOWER on IntegriCloud