Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ static const llvm::StringSet<> ValueTraits = {
"is_pointer_interconvertible_base_of",
"is_polymorphic",
"is_reference",
"is_replaceable",
"is_rvalue_reference",
"is_same",
"is_scalar",
Expand Down
2 changes: 0 additions & 2 deletions clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2044,8 +2044,6 @@ The following type trait primitives are supported by Clang. Those traits marked
is trivially relocatable, as defined by the C++26 standard [meta.unary.prop].
Note that when relocating the caller code should ensure that if the object is polymorphic,
the dynamic type is of the most derived type. Padding bytes should not be copied.
* ``__builtin_is_replaceable`` (C++): Returns true if an object
is replaceable, as defined by the C++26 standard [meta.unary.prop].
* ``__is_trivially_equality_comparable`` (Clang): Returns true if comparing two
objects of the provided type is known to be equivalent to comparing their
object representations. Note that types containing padding bytes are never
Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
public:
struct CXXRecordDeclRelocationInfo {
unsigned IsRelocatable;
unsigned IsReplaceable;
};
std::optional<CXXRecordDeclRelocationInfo>
getRelocationInfoForCXXRecord(const CXXRecordDecl *) const;
Expand Down
8 changes: 0 additions & 8 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1952,14 +1952,6 @@ def TriviallyRelocatable : InheritableAttr {
let Documentation = [InternalOnly];
}

def Replaceable : InheritableAttr {
let Spellings = [CustomKeyword<"replaceable_if_eligible">];
let SemaHandler = 0;
// Omitted from docs, since this is language syntax, not an attribute, as far
// as users are concerned.
let Documentation = [InternalOnly];
}

def MinSize : InheritableAttr {
let Spellings = [Clang<"minsize">];
let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
Expand Down
21 changes: 11 additions & 10 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1077,23 +1077,24 @@ def ext_ms_abstract_keyword : ExtWarn<
"'abstract' keyword is a Microsoft extension">,
InGroup<MicrosoftAbstract>;

def ext_relocatable_keyword : ExtWarn<
"'%select{trivially_relocatable_if_eligible|replaceable_if_eligible}0' "
"keyword is a C++2c extension">,
InGroup<CXX26>;
def warn_relocatable_keyword : Warning<
"'%select{trivially_relocatable|replaceable}0_if_eligible' "
"keyword is incompatible with standards before C++2c">,
DefaultIgnore, InGroup<CXXPre26Compat>;
def ext_relocatable_keyword
: ExtWarn<
"'trivially_relocatable_if_eligible' keyword is a C++2c extension">,
InGroup<CXX26>;
def warn_relocatable_keyword
: Warning<"'trivially_relocatable_if_eligible' keyword is incompatible "
"with standards before C++2c">,
DefaultIgnore,
InGroup<CXXPre26Compat>;

def err_access_specifier_interface : Error<
"interface types cannot specify '%select{private|protected}0' access">;

def err_duplicate_class_virt_specifier : Error<
"class already marked '%0'">;

def err_duplicate_class_relocation_specifier : Error<
"class already marked '%select{trivially_relocatable_if_eligible|replaceable_if_eligible}0'">;
def err_duplicate_class_relocation_specifier
: Error<"class already marked 'trivially_relocatable_if_eligible'">;

def err_duplicate_virt_specifier : Error<
"class member already marked '%0'">;
Expand Down
3 changes: 0 additions & 3 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,6 @@ def err_user_defined_msg_constexpr : Error<
def note_unsatisfied_trait
: Note<"%0 is not %enum_select<TraitName>{"
"%TriviallyRelocatable{trivially relocatable}|"
"%Replaceable{replaceable}|"
"%TriviallyCopyable{trivially copyable}|"
"%Empty{empty}|"
"%StandardLayout{standard-layout}|"
Expand All @@ -1792,8 +1791,6 @@ def note_unsatisfied_trait_reason
"class type}|"
"%NTRBase{has a non-trivially-relocatable base %1}|"
"%NTRField{has a non-trivially-relocatable member %1 of type %2}|"
"%NonReplaceableBase{has a non-replaceable base %1}|"
"%NonReplaceableField{has a non-replaceable member %1 of type %2}|"
"%NTCBase{has a non-trivially-copyable base %1}|"
"%NTCField{has a non-trivially-copyable member %1 of type %2}|"
"%NonEmptyMember{has a non-static data member %1 of type %2}|"
Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
TYPE_TRAIT_1(__builtin_is_cpp_trivially_relocatable, IsCppTriviallyRelocatable, KEYCXX)
TYPE_TRAIT_1(__is_trivially_relocatable, IsTriviallyRelocatable, KEYCXX)
TYPE_TRAIT_1(__is_bitwise_cloneable, IsBitwiseCloneable, KEYALL)
TYPE_TRAIT_1(__builtin_is_replaceable, IsReplaceable, KEYCXX)
TYPE_TRAIT_1(__builtin_structured_binding_size, StructuredBindingSize, KEYCXX)


Expand Down
9 changes: 2 additions & 7 deletions clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2835,7 +2835,6 @@ class Parser : public CodeCompletionHandler {
mutable IdentifierInfo *Ident_GNU_final;
mutable IdentifierInfo *Ident_override;
mutable IdentifierInfo *Ident_trivially_relocatable_if_eligible;
mutable IdentifierInfo *Ident_replaceable_if_eligible;

/// Representation of a class that has been parsed, including
/// any member function declarations or definitions that need to be
Expand Down Expand Up @@ -3129,7 +3128,7 @@ class Parser : public CodeCompletionHandler {

/// isClassCompatibleKeyword - Determine whether the next token is a C++11
/// 'final', a C++26 'trivially_relocatable_if_eligible',
/// 'replaceable_if_eligible', or Microsoft 'sealed' or 'abstract' contextual
/// or Microsoft 'sealed' or 'abstract' contextual
/// keyword.
bool isClassCompatibleKeyword() const;

Expand Down Expand Up @@ -3603,12 +3602,8 @@ class Parser : public CodeCompletionHandler {
bool isCXX2CTriviallyRelocatableKeyword() const;
void ParseCXX2CTriviallyRelocatableSpecifier(SourceLocation &TRS);

bool isCXX2CReplaceableKeyword(Token Tok) const;
bool isCXX2CReplaceableKeyword() const;
void ParseCXX2CReplaceableSpecifier(SourceLocation &MRS);

/// 'final', a C++26 'trivially_relocatable_if_eligible',
/// 'replaceable_if_eligible', or Microsoft 'sealed' or 'abstract' contextual
/// or Microsoft 'sealed' or 'abstract' contextual
/// keyword.
bool isClassCompatibleKeyword(Token Tok) const;

Expand Down
9 changes: 1 addition & 8 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -4366,7 +4366,6 @@ class Sema final : public SemaBase {
bool IsFinalSpelledSealed,
bool IsAbstract,
SourceLocation TriviallyRelocatable,
SourceLocation Replaceable,
SourceLocation LBraceLoc);

/// ActOnTagFinishDefinition - Invoked once we have finished parsing
Expand All @@ -4375,7 +4374,7 @@ class Sema final : public SemaBase {
SourceRange BraceRange);

ASTContext::CXXRecordDeclRelocationInfo
CheckCXX2CRelocatableAndReplaceable(const clang::CXXRecordDecl *D);
CheckCXX2CRelocatable(const clang::CXXRecordDecl *D);

void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context);

Expand Down Expand Up @@ -8733,12 +8732,6 @@ class Sema final : public SemaBase {
bool IsCXXTriviallyRelocatableType(QualType T);
bool IsCXXTriviallyRelocatableType(const CXXRecordDecl &RD);

//// Determines if a type is replaceable
/// according to the C++26 rules.
// FIXME: This is in Sema because it requires
// overload resolution, can we move to ASTContext?
bool IsCXXReplaceableType(QualType T);

/// Check the operands of ?: under C++ semantics.
///
/// See C++ [expr.cond]. Note that LHS is never null, even for the GNU x ?: y
Expand Down
49 changes: 5 additions & 44 deletions clang/lib/Parse/ParseDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2498,40 +2498,13 @@ void Parser::ParseCXX2CTriviallyRelocatableSpecifier(SourceLocation &TRS) {

Diag(Tok.getLocation(), getLangOpts().CPlusPlus26
? diag::warn_relocatable_keyword
: diag::ext_relocatable_keyword)
<< /*relocatable*/ 0;
: diag::ext_relocatable_keyword);

TRS = ConsumeToken();
}

bool Parser::isCXX2CReplaceableKeyword(Token Tok) const {
if (!getLangOpts().CPlusPlus || Tok.isNot(tok::identifier))
return false;
if (!Ident_replaceable_if_eligible)
Ident_replaceable_if_eligible =
&PP.getIdentifierTable().get("replaceable_if_eligible");
IdentifierInfo *II = Tok.getIdentifierInfo();
return II == Ident_replaceable_if_eligible;
}

bool Parser::isCXX2CReplaceableKeyword() const {
return isCXX2CReplaceableKeyword(Tok);
}

void Parser::ParseCXX2CReplaceableSpecifier(SourceLocation &MRS) {
assert(isCXX2CReplaceableKeyword() &&
"expected a replaceable_if_eligible specifier");

Diag(Tok.getLocation(), getLangOpts().CPlusPlus26
? diag::warn_relocatable_keyword
: diag::ext_relocatable_keyword)
<< /*replaceable*/ 1;

MRS = ConsumeToken();
}

bool Parser::isClassCompatibleKeyword(Token Tok) const {
if (isCXX2CTriviallyRelocatableKeyword(Tok) || isCXX2CReplaceableKeyword(Tok))
if (isCXX2CTriviallyRelocatableKeyword(Tok))
return true;
VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(Tok);
return Specifier == VirtSpecifiers::VS_Final ||
Expand Down Expand Up @@ -3587,7 +3560,6 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
bool IsFinalSpelledSealed = false;
bool IsAbstract = false;
SourceLocation TriviallyRelocatable;
SourceLocation Replaceable;

// Parse the optional 'final' keyword.
if (getLangOpts().CPlusPlus && Tok.is(tok::identifier)) {
Expand All @@ -3599,23 +3571,12 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
auto Skipped = Tok;
ConsumeToken();
Diag(Skipped, diag::err_duplicate_class_relocation_specifier)
<< /*trivial_relocatable*/ 0 << TriviallyRelocatable;
<< TriviallyRelocatable;
} else {
ParseCXX2CTriviallyRelocatableSpecifier(TriviallyRelocatable);
}
continue;
}
if (isCXX2CReplaceableKeyword(Tok)) {
if (Replaceable.isValid()) {
auto Skipped = Tok;
ConsumeToken();
Diag(Skipped, diag::err_duplicate_class_relocation_specifier)
<< /*replaceable*/ 1 << Replaceable;
} else {
ParseCXX2CReplaceableSpecifier(Replaceable);
}
continue;
}
break;
}
if (isCXX11FinalKeyword()) {
Expand Down Expand Up @@ -3654,7 +3615,7 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
Diag(FinalLoc, diag::ext_warn_gnu_final);
}
assert((FinalLoc.isValid() || AbstractLoc.isValid() ||
TriviallyRelocatable.isValid() || Replaceable.isValid()) &&
TriviallyRelocatable.isValid()) &&
"not a class definition");

// Parse any C++11 attributes after 'final' keyword.
Expand Down Expand Up @@ -3729,7 +3690,7 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
if (TagDecl)
Actions.ActOnStartCXXMemberDeclarations(
getCurScope(), TagDecl, FinalLoc, IsFinalSpelledSealed, IsAbstract,
TriviallyRelocatable, Replaceable, T.getOpenLocation());
TriviallyRelocatable, T.getOpenLocation());

// C++ 11p3: Members of a class defined with the keyword class are private
// by default. Members of a class defined with the keywords struct or union
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ void Parser::Initialize() {
Ident_abstract = nullptr;
Ident_override = nullptr;
Ident_trivially_relocatable_if_eligible = nullptr;
Ident_replaceable_if_eligible = nullptr;
Ident_GNU_final = nullptr;
Ident_import = nullptr;
Ident_module = nullptr;
Expand Down
13 changes: 6 additions & 7 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18794,10 +18794,12 @@ bool Sema::ActOnDuplicateDefinition(Scope *S, Decl *Prev,
return true;
}

void Sema::ActOnStartCXXMemberDeclarations(
Scope *S, Decl *TagD, SourceLocation FinalLoc, bool IsFinalSpelledSealed,
bool IsAbstract, SourceLocation TriviallyRelocatable,
SourceLocation Replaceable, SourceLocation LBraceLoc) {
void Sema::ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagD,
SourceLocation FinalLoc,
bool IsFinalSpelledSealed,
bool IsAbstract,
SourceLocation TriviallyRelocatable,
SourceLocation LBraceLoc) {
AdjustDeclIfTemplate(TagD);
CXXRecordDecl *Record = cast<CXXRecordDecl>(TagD);

Expand All @@ -18820,9 +18822,6 @@ void Sema::ActOnStartCXXMemberDeclarations(
Record->addAttr(
TriviallyRelocatableAttr::Create(Context, TriviallyRelocatable));

if (Replaceable.isValid())
Record->addAttr(ReplaceableAttr::Create(Context, Replaceable));

// C++ [class]p2:
// [...] The class-name is also inserted into the scope of the
// class itself; this is known as the injected-class-name. For
Expand Down
Loading