r268793 - Availability: set location when creating attribute for tvos, watchos.
Manman Ren via cfe-commits
cfe-commits at lists.llvm.org
Fri May 6 14:04:02 PDT 2016
Author: mren
Date: Fri May 6 16:04:01 2016
New Revision: 268793
URL: http://llvm.org/viewvc/llvm-project?rev=268793&view=rev
Log:
Availability: set location when creating attribute for tvos, watchos.
When inferring availability attributes for tvos, watchos from ios, we
use the same source location and set the implicit bit to true.
So when emitting diagnostics on inferred attributes, we have a source
location.
rdar://25893544
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/attr-availability-tvos.c
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=268793&r1=268792&r2=268793&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri May 6 16:04:01 2016
@@ -2158,6 +2158,7 @@ public:
/// Attribute merging methods. Return true if a new attribute was added.
AvailabilityAttr *mergeAvailabilityAttr(NamedDecl *D, SourceRange Range,
IdentifierInfo *Platform,
+ bool Implicit,
VersionTuple Introduced,
VersionTuple Deprecated,
VersionTuple Obsoleted,
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=268793&r1=268792&r2=268793&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri May 6 16:04:01 2016
@@ -2204,7 +2204,8 @@ static bool mergeDeclAttribute(Sema &S,
unsigned AttrSpellingListIndex = Attr->getSpellingListIndex();
if (const auto *AA = dyn_cast<AvailabilityAttr>(Attr))
NewAttr = S.mergeAvailabilityAttr(D, AA->getRange(), AA->getPlatform(),
- AA->getIntroduced(), AA->getDeprecated(),
+ AA->isImplicit(), AA->getIntroduced(),
+ AA->getDeprecated(),
AA->getObsoleted(), AA->getUnavailable(),
AA->getMessage(), AA->getStrict(),
AA->getReplacement(), AMK,
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=268793&r1=268792&r2=268793&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri May 6 16:04:01 2016
@@ -1957,6 +1957,7 @@ static bool versionsMatch(const VersionT
AvailabilityAttr *Sema::mergeAvailabilityAttr(NamedDecl *D, SourceRange Range,
IdentifierInfo *Platform,
+ bool Implicit,
VersionTuple Introduced,
VersionTuple Deprecated,
VersionTuple Obsoleted,
@@ -2001,14 +2002,14 @@ AvailabilityAttr *Sema::mergeAvailabilit
// If there is an existing availability attribute for this platform that
// is explicit and the new one is implicit use the explicit one and
// discard the new implicit attribute.
- if (OldAA->getRange().isValid() && Range.isInvalid()) {
+ if (!OldAA->isImplicit() && Implicit) {
return nullptr;
}
// If there is an existing attribute for this platform that is implicit
// and the new attribute is explicit then erase the old one and
// continue processing the attributes.
- if (Range.isValid() && OldAA->getRange().isInvalid()) {
+ if (!Implicit && OldAA->isImplicit()) {
Attrs.erase(Attrs.begin() + i);
--e;
continue;
@@ -2107,11 +2108,13 @@ AvailabilityAttr *Sema::mergeAvailabilit
if (!checkAvailabilityAttr(*this, Range, Platform, MergedIntroduced,
MergedDeprecated, MergedObsoleted) &&
!OverrideOrImpl) {
- return ::new (Context) AvailabilityAttr(Range, Context, Platform,
+ auto *Avail = ::new (Context) AvailabilityAttr(Range, Context, Platform,
Introduced, Deprecated,
Obsoleted, IsUnavailable, Message,
IsStrict, Replacement,
AttrSpellingListIndex);
+ Avail->setImplicit(Implicit);
+ return Avail;
}
return nullptr;
}
@@ -2149,6 +2152,7 @@ static void handleAvailabilityAttr(Sema
Replacement = SE->getString();
AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(ND, Attr.getRange(), II,
+ false/*Implicit*/,
Introduced.Version,
Deprecated.Version,
Obsoleted.Version,
@@ -2192,8 +2196,9 @@ static void handleAvailabilityAttr(Sema
auto NewObsoleted = adjustWatchOSVersion(Obsoleted.Version);
AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(ND,
- SourceRange(),
+ Attr.getRange(),
NewII,
+ true/*Implicit*/,
NewIntroduced,
NewDeprecated,
NewObsoleted,
@@ -2216,8 +2221,9 @@ static void handleAvailabilityAttr(Sema
if (NewII) {
AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(ND,
- SourceRange(),
+ Attr.getRange(),
NewII,
+ true/*Implicit*/,
Introduced.Version,
Deprecated.Version,
Obsoleted.Version,
Modified: cfe/trunk/test/Sema/attr-availability-tvos.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-availability-tvos.c?rev=268793&r1=268792&r2=268793&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-availability-tvos.c (original)
+++ cfe/trunk/test/Sema/attr-availability-tvos.c Fri May 6 16:04:01 2016
@@ -27,6 +27,12 @@ void test_transcribed_availability() {
f9(0);
}
+__attribute__((availability(ios,introduced=9_0,deprecated=9_0,message="" ))) // expected-note{{previous attribute is here}} \
+ // expected-note{{previous attribute is here}}
+__attribute__((availability(ios,introduced=7_0))) // expected-warning{{availability does not match previous declaration}} \
+ // expected-warning{{availability does not match previous declaration}}
+void f10(int);
+
// Test tvOS specific attributes.
void f0_tvos(int) __attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0_tvos' has been explicitly marked deprecated here}}
void f1_tvos(int) __attribute__((availability(tvos,introduced=2.1)));
More information about the cfe-commits
mailing list