https://github.com/StephenYoung2754 created 
https://github.com/llvm/llvm-project/pull/157585

# Summary
Avoid diagnostics in `CheckStructurallyEquivalentAttributes` when  
`StructuralEquivalenceContext::Complain` is `false`.

# Details
The original code always emitted diagnostics on attribute mismatches:
```cpp
Context.Diag2(DiagnoseDecl->getLocation(),
              diag::warn_odr_tag_type_with_attributes)
```
This caused an assertion failure in `Diag2` when `Complain == false`:
```cpp
assert(Complain && "Not allowed to complain");
```

The patch adds an early return in non-complaining mode:
```cpp
if (!Context.Complain)
  return false;
```
This prevents diagnostics from being emitted when they are not allowed.

# Testing
- Existing structural equivalence tests continue to pass.  
- In non-complaining mode, attribute mismatches no longer trigger assertions.  
- No regressions observed in `check-clang`.

# Issue
Fixes #153916


>From 41d2b7628de0471145979ae67a7af750dc8ac77a Mon Sep 17 00:00:00 2001
From: StephenYoung2754 <[email protected]>
Date: Tue, 9 Sep 2025 08:55:15 +0800
Subject: [PATCH] [AST] StructuralEquivalence: avoid diagnostics when
 Complain=false in CheckStructurallyEquivalentAttributes

---
 clang/lib/AST/ASTStructuralEquivalence.cpp | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 1292c30d47589..94512488d0738 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -471,15 +471,18 @@ 
CheckStructurallyEquivalentAttributes(StructuralEquivalenceContext &Context,
   if (D2->hasAttrs())
     D2Attr = *D2->getAttrs().begin();
   if ((D1Attr || D2Attr) && !D1->isImplicit() && !D2->isImplicit()) {
-    const auto *DiagnoseDecl = cast<TypeDecl>(PrimaryDecl ? PrimaryDecl : D2);
-    Context.Diag2(DiagnoseDecl->getLocation(),
-                  diag::warn_odr_tag_type_with_attributes)
-        << Context.ToCtx.getTypeDeclType(DiagnoseDecl)
-        << (PrimaryDecl != nullptr);
-    if (D1Attr)
-      Context.Diag1(D1Attr->getLoc(), diag::note_odr_attr_here) << D1Attr;
-    if (D2Attr)
-      Context.Diag1(D2Attr->getLoc(), diag::note_odr_attr_here) << D2Attr;
+      if (!Context.Complain)
+          return false;
+      const auto *DiagnoseDecl = cast<TypeDecl>(PrimaryDecl ? PrimaryDecl : 
D2);
+      Context.Diag2(DiagnoseDecl->getLocation(),
+              diag::warn_odr_tag_type_with_attributes)
+          << Context.ToCtx.getTypeDeclType(DiagnoseDecl)
+          << (PrimaryDecl != nullptr);
+      if (D1Attr)
+          Context.Diag1(D1Attr->getLoc(), diag::note_odr_attr_here) << D1Attr;
+      if (D2Attr)
+          Context.Diag2(D2Attr->getLoc(), diag::note_odr_attr_here) << D2Attr;
+      return false;
   }
 
   // The above diagnostic is a warning which defaults to an error. If treated

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to