Skip to content
Merged
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
7 changes: 0 additions & 7 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,6 @@ C23 Feature Support
scope.
- Fixed a bug where you could not cast a null pointer constant to type
``nullptr_t``. Fixes #GH133644.
- Implemented `WG14 N3037 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3037.pdf>`_
which allows tag types to be redefined within the same translation unit so
long as both definitions are structurally equivalent (same tag types, same
tag names, same tag members, etc). As a result of this paper, ``-Wvisibility``
is no longer diagnosed in C23 if the parameter is a complete tag type (it
does still fire when the parameter is an incomplete tag type as that cannot
be completed).
- Fixed a failed assertion with an invalid parameter to the ``#embed``
directive. Fixes #GH126940.
- Fixed a crash when a declaration of a ``constexpr`` variable with an invalid
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 @@ -3354,7 +3354,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
QualType mergeTransparentUnionType(QualType, QualType,
bool OfBlockPointer=false,
bool Unqualified = false);
QualType mergeTagDefinitions(QualType, QualType);

QualType mergeObjCGCQualifiers(QualType, QualType);

Expand Down
11 changes: 3 additions & 8 deletions clang/include/clang/AST/ASTStructuralEquivalence.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ struct StructuralEquivalenceContext {
/// key: (from, to, IgnoreTemplateParmDepth)
using NonEquivalentDeclSet = llvm::DenseSet<std::tuple<Decl *, Decl *, int>>;

/// The language options to use for making a structural equivalence check.
const LangOptions &LangOpts;

/// AST contexts for which we are checking structural equivalence.
ASTContext &FromCtx, &ToCtx;

Expand Down Expand Up @@ -79,17 +76,15 @@ struct StructuralEquivalenceContext {
/// Whether to ignore comparing the depth of template param(TemplateTypeParm)
bool IgnoreTemplateParmDepth;

StructuralEquivalenceContext(const LangOptions &LangOpts, ASTContext &FromCtx,
ASTContext &ToCtx,
StructuralEquivalenceContext(ASTContext &FromCtx, ASTContext &ToCtx,
NonEquivalentDeclSet &NonEquivalentDecls,
StructuralEquivalenceKind EqKind,
bool StrictTypeSpelling = false,
bool Complain = true,
bool ErrorOnTagTypeMismatch = false,
bool IgnoreTemplateParmDepth = false)
: LangOpts(LangOpts), FromCtx(FromCtx), ToCtx(ToCtx),
NonEquivalentDecls(NonEquivalentDecls), EqKind(EqKind),
StrictTypeSpelling(StrictTypeSpelling),
: FromCtx(FromCtx), ToCtx(ToCtx), NonEquivalentDecls(NonEquivalentDecls),
EqKind(EqKind), StrictTypeSpelling(StrictTypeSpelling),
ErrorOnTagTypeMismatch(ErrorOnTagTypeMismatch), Complain(Complain),
IgnoreTemplateParmDepth(IgnoreTemplateParmDepth) {}

Expand Down
23 changes: 4 additions & 19 deletions clang/include/clang/Basic/DiagnosticASTKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -480,23 +480,16 @@ def warn_odr_function_type_inconsistent : Warning<
"external function %0 declared with incompatible types in different "
"translation units (%1 vs. %2)">,
InGroup<ODR>;
def warn_odr_tag_type_with_attributes : Warning<
"type %0 has %select{an attribute|a member with an attribute}1 which "
"currently causes the types to be treated as though they are incompatible">,
InGroup<ODR>, DefaultError;
def note_odr_attr_here : Note<"attribute %0 here">;
def err_odr_tag_type_inconsistent
: Error<"type %0 has incompatible definitions%select{| in different "
"translation units}1">;
: Error<"type %0 has incompatible definitions in different translation "
"units">;
def warn_odr_tag_type_inconsistent
: Warning<"type %0 has incompatible definitions%select{| in different "
"translation units}1">,
: Warning<"type %0 has incompatible definitions in different translation "
"units">,
InGroup<ODR>;
def note_odr_tag_kind_here: Note<
"%0 is a %select{struct|interface|union|class|enum}1 here">;
def note_odr_field : Note<"field %0 has type %1 here">;
def note_odr_field_bit_width : Note<"bit-field %0 has bit-width %1 here">;
def note_odr_field_not_bit_field : Note<"field %0 is not a bit-field">;
def note_odr_field_name : Note<"field has name %0 here">;
def note_odr_missing_field : Note<"no corresponding field here">;
def note_odr_base : Note<"class has base type %0">;
Expand All @@ -507,14 +500,6 @@ def note_odr_number_of_bases : Note<
"class has %0 base %plural{1:class|:classes}0">;
def note_odr_enumerator : Note<"enumerator %0 with value %1 here">;
def note_odr_missing_enumerator : Note<"no corresponding enumerator here">;
def note_odr_incompatible_fixed_underlying_type : Note<
"enumeration %0 declared with incompatible fixed underlying types (%1 vs. "
"%2)">;
def note_odr_fixed_underlying_type : Note<
"enumeration %0 has fixed underlying type here">;
def note_odr_missing_fixed_underlying_type : Note<
"enumeration %0 missing fixed underlying type here">;

def err_odr_field_type_inconsistent : Error<
"field %0 declared with incompatible types in different "
"translation units (%1 vs. %2)">;
Expand Down
16 changes: 1 addition & 15 deletions clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1964,21 +1964,6 @@ class Parser : public CodeCompletionHandler {
const ParsedTemplateInfo &TemplateInfo,
AccessSpecifier AS, DeclSpecContext DSC);

/// ParseEnumBody - Parse a {} enclosed enumerator-list.
/// \verbatim
/// enumerator-list:
/// enumerator
/// enumerator-list ',' enumerator
/// enumerator:
/// enumeration-constant attributes[opt]
/// enumeration-constant attributes[opt] '=' constant-expression
/// enumeration-constant:
/// identifier
/// \endverbatim
///
void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
SkipBodyInfo *SkipBody = nullptr);

/// ParseStructUnionBody
/// \verbatim
/// struct-contents:
Expand All @@ -1991,6 +1976,7 @@ class Parser : public CodeCompletionHandler {
/// [OBC] '@' 'defs' '(' class-name ')'
/// \endverbatim
///
void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
void ParseStructUnionBody(SourceLocation StartLoc, DeclSpec::TST TagType,
RecordDecl *TagDecl);

Expand Down
3 changes: 1 addition & 2 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -4811,8 +4811,7 @@ class Sema final : public SemaBase {
Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
SourceLocation IdLoc, IdentifierInfo *Id,
const ParsedAttributesView &Attrs,
SourceLocation EqualLoc, Expr *Val,
SkipBodyInfo *SkipBody = nullptr);
SourceLocation EqualLoc, Expr *Val);
void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S,
const ParsedAttributesView &Attr);
Expand Down
25 changes: 1 addition & 24 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "clang/AST/APValue.h"
#include "clang/AST/ASTConcept.h"
#include "clang/AST/ASTMutationListener.h"
#include "clang/AST/ASTStructuralEquivalence.h"
#include "clang/AST/ASTTypeTraits.h"
#include "clang/AST/Attr.h"
#include "clang/AST/AttrIterator.h"
Expand Down Expand Up @@ -12358,28 +12357,6 @@ static QualType mergeEnumWithInteger(ASTContext &Context, const EnumType *ET,
return {};
}

QualType ASTContext::mergeTagDefinitions(QualType LHS, QualType RHS) {
// C17 and earlier and C++ disallow two tag definitions within the same TU
// from being compatible.
if (LangOpts.CPlusPlus || !LangOpts.C23)
return {};

// Nameless tags are comparable only within outer definitions. At the top
// level they are not comparable.
const TagDecl *LTagD = LHS->getAsTagDecl(), *RTagD = RHS->getAsTagDecl();
if (!LTagD->getIdentifier() || !RTagD->getIdentifier())
return {};

// C23, on the other hand, requires the members to be "the same enough", so
// we use a structural equivalence check.
StructuralEquivalenceContext::NonEquivalentDeclSet NonEquivalentDecls;
StructuralEquivalenceContext Ctx(
getLangOpts(), *this, *this, NonEquivalentDecls,
StructuralEquivalenceKind::Default, /*StrictTypeSpelling=*/false,
/*Complain=*/false, /*ErrorOnTagTypeMismatch=*/true);
return Ctx.IsEquivalent(LHS, RHS) ? LHS : QualType{};
}

QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, bool OfBlockPointer,
bool Unqualified, bool BlockReturnType,
bool IsConditionalOperator) {
Expand Down Expand Up @@ -12701,7 +12678,7 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, bool OfBlockPointer,
/*AllowCXX=*/false, IsConditionalOperator);
case Type::Record:
case Type::Enum:
return mergeTagDefinitions(LHS, RHS);
return {};
case Type::Builtin:
// Only exactly equal builtin types are compatible, which is tested above.
return {};
Expand Down
14 changes: 6 additions & 8 deletions clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2723,9 +2723,8 @@ bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
}

StructuralEquivalenceContext Ctx(
Importer.getToContext().getLangOpts(), Importer.getFromContext(),
Importer.getToContext(), Importer.getNonEquivalentDecls(),
getStructuralEquivalenceKind(Importer),
Importer.getFromContext(), Importer.getToContext(),
Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer),
/*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
IgnoreTemplateParmDepth);
return Ctx.IsEquivalent(From, To);
Expand Down Expand Up @@ -4587,8 +4586,7 @@ static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,

ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
StructuralEquivalenceContext Ctx(
Importer.getToContext().getLangOpts(), FD1->getASTContext(),
FD2->getASTContext(), NonEquivalentDecls,
FD1->getASTContext(), FD2->getASTContext(), NonEquivalentDecls,
StructuralEquivalenceKind::Default,
/* StrictTypeSpelling = */ false, /* Complain = */ false);
return Ctx.IsEquivalent(FD1, FD2);
Expand Down Expand Up @@ -10885,8 +10883,8 @@ bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To,
}
}

StructuralEquivalenceContext Ctx(
getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
getStructuralEquivalenceKind(*this), false, Complain);
StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
getStructuralEquivalenceKind(*this), false,
Complain);
return Ctx.IsEquivalent(From, To);
}
Loading