Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 76b091f

Browse files
committed
[APINotes] Preserve attributes from inactive versions.
...by wrapping them in another (new) attribute, SwiftVersionedAttr. This can track both attributes that would be added and those that would be removed. This doesn't support other kinds of changes that can be made via API notes, such as nullability or wholesale type changes, but it's a place to start, and possibly sufficient for our goals. Part of rdar://problem/28618121.
1 parent 99c41b4 commit 76b091f

File tree

4 files changed

+182
-90
lines changed

4 files changed

+182
-90
lines changed

include/clang/AST/Attr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "clang/Basic/Sanitizers.h"
2525
#include "clang/Basic/SourceLocation.h"
2626
#include "clang/Basic/VersionTuple.h"
27+
#include "llvm/ADT/PointerEmbeddedInt.h"
2728
#include "llvm/ADT/StringSwitch.h"
2829
#include "llvm/Support/ErrorHandling.h"
2930
#include "llvm/Support/raw_ostream.h"

include/clang/Basic/Attr.td

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,44 @@ def SwiftImportPropertyAsAccessors : InheritableAttr {
14831483
let Documentation = [Undocumented];
14841484
}
14851485

1486+
def SwiftVersioned : Attr {
1487+
// This attribute has no spellings as it is only ever created implicitly
1488+
// from API notes.
1489+
let Spellings = [];
1490+
let Args = [VersionArgument<"Version">];
1491+
let SemaHandler = 0;
1492+
let Documentation = [Undocumented];
1493+
let AdditionalMembers = [{
1494+
private:
1495+
llvm::PointerUnion<const Attr *,
1496+
llvm::PointerEmbeddedInt<attr::Kind>> attrOrKind;
1497+
bool hasBeenSet() const {
1498+
return !attrOrKind.is<const Attr *>() || !attrOrKind.isNull();
1499+
}
1500+
public:
1501+
bool isRemoval() const {
1502+
assert(hasBeenSet());
1503+
return !attrOrKind.is<const Attr *>();
1504+
}
1505+
const Attr *getAttrToAdd() const {
1506+
assert(hasBeenSet());
1507+
return attrOrKind.get<const Attr *>();
1508+
}
1509+
attr::Kind getAttrToRemove() const {
1510+
assert(hasBeenSet());
1511+
return attrOrKind.get<llvm::PointerEmbeddedInt<attr::Kind>>();
1512+
}
1513+
void setAttrToAdd(const Attr *attr) {
1514+
assert(!hasBeenSet());
1515+
attrOrKind = attr;
1516+
}
1517+
void setAttrToRemove(attr::Kind kind) {
1518+
assert(!hasBeenSet());
1519+
attrOrKind = kind;
1520+
}
1521+
}];
1522+
}
1523+
14861524
def ReqdWorkGroupSize : InheritableAttr {
14871525
let Spellings = [GNU<"reqd_work_group_size">];
14881526
let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,

0 commit comments

Comments
 (0)