Skip to content

Commit cf6982b

Browse files
committed
[C23] AST equivalence of attributes
Implicitly declared types (like __NSConstantString_tag, etc) will be declared with visibility attributes. This causes problems when merging ASTs because we currently reject declaration merging for declarations with attributes. This relaxes that restriction somewhat; implicit declarations can now have attributes when merging; we assume that if the compiler generated it, it's fine.
1 parent 83dfdd8 commit cf6982b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

clang/lib/AST/ASTStructuralEquivalence.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,9 @@ CheckStructurallyEquivalentAttributes(StructuralEquivalenceContext &Context,
456456
const Decl *D1, const Decl *D2,
457457
const Decl *PrimaryDecl = nullptr) {
458458
// If either declaration has an attribute on it, we treat the declarations
459-
// as not being structurally equivalent.
459+
// as not being structurally equivalent unless both declarations are implicit
460+
// (ones generated by the compiler like __NSConstantString_tag).
461+
//
460462
// FIXME: this should be handled on a case-by-case basis via tablegen in
461463
// Attr.td. There are multiple cases to consider: one declaration with the
462464
// attribute, another without it; different attribute syntax|spellings for
@@ -468,7 +470,7 @@ CheckStructurallyEquivalentAttributes(StructuralEquivalenceContext &Context,
468470
D1Attr = *D1->getAttrs().begin();
469471
if (D2->hasAttrs())
470472
D2Attr = *D2->getAttrs().begin();
471-
if (D1Attr || D2Attr) {
473+
if ((D1Attr || D2Attr) && !D1->isImplicit() && !D2->isImplicit()) {
472474
const auto *DiagnoseDecl = cast<TypeDecl>(PrimaryDecl ? PrimaryDecl : D2);
473475
Context.Diag2(DiagnoseDecl->getLocation(),
474476
diag::warn_odr_tag_type_with_attributes)

0 commit comments

Comments
 (0)