[clang] [C23] Implement WG14 N3037 (PR #132939)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 9 10:01:41 PDT 2025


================
@@ -450,6 +453,41 @@ class StmtComparer {
 };
 } // namespace
 
+static bool
+CheckStructurallyEquivalentAttributes(StructuralEquivalenceContext &Context,
+                                      const Decl *D1, const Decl *D2,
+                                      const Decl *PrimaryDecl = nullptr) {
+  // If either declaration has an attribute on it, we treat the declarations
+  // as not being structurally equivalent.
+  // FIXME: this should be handled on a case-by-case basis via tablegen in
+  // Attr.td. There are multiple cases to consider: one declation with the
+  // attribute, another without it; different attribute syntax|spellings for
+  // the same semantic attribute, differences in attribute arguments, order
+  // in which attributes are applied, how to merge attributes if the types are
+  // structurally equivalent, etc.
+  const Attr *D1Attr = nullptr, *D2Attr = nullptr;
+  if (D1->hasAttrs())
+    D1Attr = *D1->getAttrs().begin();
+  if (D2->hasAttrs())
+    D2Attr = *D2->getAttrs().begin();
+  if (D1Attr || D2Attr) {
+    const auto *DiagnoseDecl = cast<TypeDecl>(PrimaryDecl ? PrimaryDecl : D2);
----------------
AaronBallman wrote:

> Looks like this issue has been discussed here: [#153916 (comment)](https://github.com/llvm/llvm-project/issues/153916#issuecomment-3197249376)

Yeah, as mentioned in my comment as well as Cyndy's, there's a bigger issue with serialization that I've not been able to resolve; I may need help from @Bigcheese @ChuanqiXu9 as serialization experts. It's not trivial to fix, at least from what I was trying before sabbatical. I'll try to get back on this one, but it might be next week before I have the bandwidth.


https://github.com/llvm/llvm-project/pull/132939


More information about the cfe-commits mailing list