Skip to content

Commit 4d21645

Browse files
committed
Remove the specifier wrapper, stash the location in attributes
1 parent ca47986 commit 4d21645

File tree

8 files changed

+45
-94
lines changed

8 files changed

+45
-94
lines changed

clang/include/clang/AST/DeclCXX.h

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -127,33 +127,6 @@ class AccessSpecDecl : public Decl {
127127
static bool classofKind(Kind K) { return K == AccessSpec; }
128128
};
129129

130-
enum class RelocatableOrReplaceableClassSpecifierKind {
131-
Relocatable,
132-
Replaceable
133-
};
134-
135-
template <RelocatableOrReplaceableClassSpecifierKind MK>
136-
class BasicRelocatableOrReplaceableClassSpecifier {
137-
public:
138-
BasicRelocatableOrReplaceableClassSpecifier() = default;
139-
BasicRelocatableOrReplaceableClassSpecifier(SourceLocation Begin)
140-
: Loc(Begin) {}
141-
void Set(SourceLocation Begin) { Loc = Begin; }
142-
143-
bool isSet() const { return !Loc.isInvalid(); }
144-
145-
SourceLocation getLocation() const { return Loc; }
146-
147-
private:
148-
SourceLocation Loc;
149-
};
150-
151-
using TriviallyRelocatableSpecifier =
152-
BasicRelocatableOrReplaceableClassSpecifier<
153-
RelocatableOrReplaceableClassSpecifierKind::Relocatable>;
154-
using ReplaceableSpecifier = BasicRelocatableOrReplaceableClassSpecifier<
155-
RelocatableOrReplaceableClassSpecifierKind::Replaceable>;
156-
157130
/// Represents a base class of a C++ class.
158131
///
159132
/// Each CXXBaseSpecifier represents a single, direct base class (or
@@ -376,10 +349,6 @@ class CXXRecordDecl : public RecordDecl {
376349
/// This is actually currently stored in reverse order.
377350
LazyDeclPtr FirstFriend;
378351

379-
TriviallyRelocatableSpecifier TriviallyRelocatableSpecifier;
380-
381-
ReplaceableSpecifier ReplaceableSpecifier;
382-
383352
DefinitionData(CXXRecordDecl *D);
384353

385354
/// Retrieve the set of direct base classes.
@@ -1528,14 +1497,6 @@ class CXXRecordDecl : public RecordDecl {
15281497
return isLiteral() && data().StructuralIfLiteral;
15291498
}
15301499

1531-
TriviallyRelocatableSpecifier getTriviallyRelocatableSpecifier() const {
1532-
return data().TriviallyRelocatableSpecifier;
1533-
}
1534-
1535-
ReplaceableSpecifier getReplaceableSpecifier() const {
1536-
return data().ReplaceableSpecifier;
1537-
}
1538-
15391500
bool isTriviallyRelocatable() const { return data().IsTriviallyRelocatable; }
15401501

15411502
void setIsTriviallyRelocatable(bool Set) {
@@ -1975,13 +1936,6 @@ class CXXRecordDecl : public RecordDecl {
19751936
return K >= firstCXXRecord && K <= lastCXXRecord;
19761937
}
19771938
void markAbstract() { data().Abstract = true; }
1978-
1979-
void setTriviallyRelocatableSpecifier(TriviallyRelocatableSpecifier TRS) {
1980-
data().TriviallyRelocatableSpecifier = TRS;
1981-
}
1982-
void setReplaceableSpecifier(ReplaceableSpecifier MRS) {
1983-
data().ReplaceableSpecifier = MRS;
1984-
}
19851939
};
19861940

19871941
/// Store information needed for an explicit specifier.

clang/include/clang/Basic/Attr.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,22 @@ def Final : InheritableAttr {
17981798
let Documentation = [InternalOnly];
17991799
}
18001800

1801+
def TriviallyRelocatable : InheritableAttr {
1802+
let Spellings = [CustomKeyword<"trivially_relocatable_if_eligible">];
1803+
let SemaHandler = 0;
1804+
// Omitted from docs, since this is language syntax, not an attribute, as far
1805+
// as users are concerned.
1806+
let Documentation = [InternalOnly];
1807+
}
1808+
1809+
def Replaceable : InheritableAttr {
1810+
let Spellings = [CustomKeyword<"replaceable_if_eligible">];
1811+
let SemaHandler = 0;
1812+
// Omitted from docs, since this is language syntax, not an attribute, as far
1813+
// as users are concerned.
1814+
let Documentation = [InternalOnly];
1815+
}
1816+
18011817
def MinSize : InheritableAttr {
18021818
let Spellings = [Clang<"minsize">];
18031819
let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;

clang/include/clang/Parse/Parser.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,12 +3174,11 @@ class Parser : public CodeCompletionHandler {
31743174

31753175
bool isCXX2CTriviallyRelocatableKeyword(Token Tok) const;
31763176
bool isCXX2CTriviallyRelocatableKeyword() const;
3177-
void
3178-
ParseCXX2CTriviallyRelocatableSpecifier(TriviallyRelocatableSpecifier &TRS);
3177+
void ParseCXX2CTriviallyRelocatableSpecifier(SourceLocation &TRS);
31793178

31803179
bool isCXX2CReplaceableKeyword(Token Tok) const;
31813180
bool isCXX2CReplaceableKeyword() const;
3182-
void ParseCXX2CReplaceableSpecifier(ReplaceableSpecifier &MRS);
3181+
void ParseCXX2CReplaceableSpecifier(SourceLocation &MRS);
31833182

31843183
bool isClassCompatibleKeyword(Token Tok) const;
31853184
bool isClassCompatibleKeyword() const;

clang/include/clang/Sema/Sema.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,19 +3976,16 @@ class Sema final : public SemaBase {
39763976
/// Invoked when we enter a tag definition that we're skipping.
39773977
SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD);
39783978

3979-
TriviallyRelocatableSpecifier
3980-
ActOnTriviallyRelocatableSpecifier(SourceLocation Loc);
3981-
3982-
ReplaceableSpecifier ActOnReplaceableSpecifier(SourceLocation Loc);
3983-
39843979
/// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
39853980
/// C++ record definition's base-specifiers clause and are starting its
39863981
/// member declarations.
3987-
void ActOnStartCXXMemberDeclarations(
3988-
Scope *S, Decl *TagDecl, SourceLocation FinalLoc,
3989-
bool IsFinalSpelledSealed, bool IsAbstract,
3990-
TriviallyRelocatableSpecifier TriviallyRelocatable,
3991-
ReplaceableSpecifier Replaceable, SourceLocation LBraceLoc);
3982+
void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
3983+
SourceLocation FinalLoc,
3984+
bool IsFinalSpelledSealed,
3985+
bool IsAbstract,
3986+
SourceLocation TriviallyRelocatable,
3987+
SourceLocation Replaceable,
3988+
SourceLocation LBraceLoc);
39923989

39933990
/// ActOnTagFinishDefinition - Invoked once we have finished parsing
39943991
/// the definition of a tag (enumeration, class, struct, or union).

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,8 +2707,7 @@ bool Parser::isCXX2CTriviallyRelocatableKeyword() const {
27072707
return isCXX2CTriviallyRelocatableKeyword(Tok);
27082708
}
27092709

2710-
void Parser::ParseCXX2CTriviallyRelocatableSpecifier(
2711-
TriviallyRelocatableSpecifier &TRS) {
2710+
void Parser::ParseCXX2CTriviallyRelocatableSpecifier(SourceLocation &TRS) {
27122711
assert(isCXX2CTriviallyRelocatableKeyword() &&
27132712
"expected a trivially_relocatable specifier");
27142713

@@ -2717,7 +2716,7 @@ void Parser::ParseCXX2CTriviallyRelocatableSpecifier(
27172716
: diag::ext_relocatable_keyword)
27182717
<< /*relocatable*/ 0;
27192718

2720-
TRS = Actions.ActOnTriviallyRelocatableSpecifier(ConsumeToken());
2719+
TRS = ConsumeToken();
27212720
}
27222721

27232722
bool Parser::isCXX2CReplaceableKeyword(Token Tok) const {
@@ -2734,7 +2733,7 @@ bool Parser::isCXX2CReplaceableKeyword() const {
27342733
return isCXX2CReplaceableKeyword(Tok);
27352734
}
27362735

2737-
void Parser::ParseCXX2CReplaceableSpecifier(ReplaceableSpecifier &MRS) {
2736+
void Parser::ParseCXX2CReplaceableSpecifier(SourceLocation &MRS) {
27382737
assert(isCXX2CReplaceableKeyword() &&
27392738
"expected a replaceable_if_eligible specifier");
27402739

@@ -2743,7 +2742,7 @@ void Parser::ParseCXX2CReplaceableSpecifier(ReplaceableSpecifier &MRS) {
27432742
: diag::ext_relocatable_keyword)
27442743
<< /*replaceable*/ 1;
27452744

2746-
MRS = Actions.ActOnReplaceableSpecifier(ConsumeToken());
2745+
MRS = ConsumeToken();
27472746
}
27482747

27492748
/// isClassCompatibleKeyword - Determine whether the next token is a C++11
@@ -3868,31 +3867,30 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
38683867
SourceLocation AbstractLoc;
38693868
bool IsFinalSpelledSealed = false;
38703869
bool IsAbstract = false;
3871-
TriviallyRelocatableSpecifier TriviallyRelocatable;
3872-
ReplaceableSpecifier Replacable;
3870+
SourceLocation TriviallyRelocatable;
3871+
SourceLocation Replacable;
38733872

38743873
// Parse the optional 'final' keyword.
38753874
if (getLangOpts().CPlusPlus && Tok.is(tok::identifier)) {
38763875
while (true) {
38773876
VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(Tok);
38783877
if (Specifier == VirtSpecifiers::VS_None) {
38793878
if (isCXX2CTriviallyRelocatableKeyword(Tok)) {
3880-
if (TriviallyRelocatable.isSet()) {
3879+
if (TriviallyRelocatable.isValid()) {
38813880
auto Skipped = Tok;
38823881
ConsumeToken();
38833882
Diag(Skipped, diag::err_duplicate_class_relocation_specifier)
3884-
<< /*trivial_relocatable*/ 0
3885-
<< TriviallyRelocatable.getLocation();
3883+
<< /*trivial_relocatable*/ 0 << TriviallyRelocatable;
38863884
} else {
38873885
ParseCXX2CTriviallyRelocatableSpecifier(TriviallyRelocatable);
38883886
}
38893887
continue;
38903888
} else if (isCXX2CReplaceableKeyword(Tok)) {
3891-
if (Replacable.isSet()) {
3889+
if (Replacable.isValid()) {
38923890
auto Skipped = Tok;
38933891
ConsumeToken();
38943892
Diag(Skipped, diag::err_duplicate_class_relocation_specifier)
3895-
<< /*replaceable*/ 1 << Replacable.getLocation();
3893+
<< /*replaceable*/ 1 << Replacable;
38963894
} else {
38973895
ParseCXX2CReplaceableSpecifier(Replacable);
38983896
}
@@ -3937,7 +3935,7 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
39373935
Diag(FinalLoc, diag::ext_warn_gnu_final);
39383936
}
39393937
assert((FinalLoc.isValid() || AbstractLoc.isValid() ||
3940-
TriviallyRelocatable.isSet() || Replacable.isSet()) &&
3938+
TriviallyRelocatable.isValid() || Replacable.isValid()) &&
39413939
"not a class definition");
39423940

39433941
// Parse any C++11 attributes after 'final' keyword.

clang/lib/Sema/SemaDecl.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18318,19 +18318,10 @@ bool Sema::ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody) {
1831818318
return true;
1831918319
}
1832018320

18321-
TriviallyRelocatableSpecifier
18322-
Sema::ActOnTriviallyRelocatableSpecifier(SourceLocation Loc) {
18323-
return {Loc};
18324-
}
18325-
18326-
ReplaceableSpecifier Sema::ActOnReplaceableSpecifier(SourceLocation Loc) {
18327-
return {Loc};
18328-
}
18329-
1833018321
void Sema::ActOnStartCXXMemberDeclarations(
1833118322
Scope *S, Decl *TagD, SourceLocation FinalLoc, bool IsFinalSpelledSealed,
18332-
bool IsAbstract, TriviallyRelocatableSpecifier TriviallyRelocatable,
18333-
ReplaceableSpecifier Replaceable, SourceLocation LBraceLoc) {
18323+
bool IsAbstract, SourceLocation TriviallyRelocatable,
18324+
SourceLocation Replaceable, SourceLocation LBraceLoc) {
1833418325
AdjustDeclIfTemplate(TagD);
1833518326
CXXRecordDecl *Record = cast<CXXRecordDecl>(TagD);
1833618327

@@ -18349,11 +18340,12 @@ void Sema::ActOnStartCXXMemberDeclarations(
1834918340
: FinalAttr::Keyword_final));
1835018341
}
1835118342

18352-
if (TriviallyRelocatable.isSet() && !Record->isInvalidDecl())
18353-
Record->setTriviallyRelocatableSpecifier(TriviallyRelocatable);
18343+
if (TriviallyRelocatable.isValid())
18344+
Record->addAttr(
18345+
TriviallyRelocatableAttr::Create(Context, TriviallyRelocatable));
1835418346

18355-
if (Replaceable.isSet() && !Record->isInvalidDecl())
18356-
Record->setReplaceableSpecifier(Replaceable);
18347+
if (Replaceable.isValid())
18348+
Record->addAttr(ReplaceableAttr::Create(Context, Replaceable));
1835718349

1835818350
// C++ [class]p2:
1835918351
// [...] The class-name is also inserted into the scope of the

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7463,9 +7463,8 @@ void Sema::CheckCXX2CRelocatableAndReplaceable(CXXRecordDecl *D) {
74637463

74647464
assert(D->hasDefinition());
74657465

7466-
bool MarkedCXX2CReplaceable = D->getReplaceableSpecifier().isSet();
7467-
bool MarkedTriviallyRelocatable =
7468-
D->getTriviallyRelocatableSpecifier().isSet();
7466+
bool MarkedCXX2CReplaceable = D->hasAttr<ReplaceableAttr>();
7467+
bool MarkedTriviallyRelocatable = D->hasAttr<TriviallyRelocatableAttr>();
74697468

74707469
// This is part of "eligible for replacement", however we defer it
74717470
// to avoid extraneous computations.

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,10 +3690,6 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
36903690
// Start the definition of this instantiation.
36913691
Instantiation->startDefinition();
36923692

3693-
Instantiation->setTriviallyRelocatableSpecifier(
3694-
Pattern->getTriviallyRelocatableSpecifier());
3695-
Instantiation->setReplaceableSpecifier(Pattern->getReplaceableSpecifier());
3696-
36973693
// The instantiation is visible here, even if it was first declared in an
36983694
// unimported module.
36993695
Instantiation->setVisibleDespiteOwningModule();

0 commit comments

Comments
 (0)