Skip to content

[Clang][NFC] Update diagnostic handling for C2y compatibility in parser#209920

Open
bassiounix wants to merge 2 commits into
mainfrom
users/bassiounix/clang/if-decl-diagcompat
Open

[Clang][NFC] Update diagnostic handling for C2y compatibility in parser#209920
bassiounix wants to merge 2 commits into
mainfrom
users/bassiounix/clang/if-decl-diagcompat

Conversation

@bassiounix

Copy link
Copy Markdown
Member

Follow-up on #198244 after #209241

@bassiounix bassiounix requested review from Sirraide and cor3ntin July 15, 2026 23:43
@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 15, 2026
@bassiounix bassiounix requested a review from AaronBallman July 15, 2026 23:43
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: Muhammad Bassiouni (bassiounix)

Changes

Follow-up on #198244 after #209241


Full diff: https://github.com/llvm/llvm-project/pull/209920.diff

3 Files Affected:

  • (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+1-6)
  • (modified) clang/lib/Parse/ParseExprCXX.cpp (+1-3)
  • (modified) clang/lib/Parse/ParseStmt.cpp (+1-3)
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index cfd35fba7ea07..e083a87cc62fb 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -169,12 +169,7 @@ def ext_c2y_generic_with_type_arg : Extension<
 def warn_c2y_compat_generic_with_type_arg : Warning<
   "passing a type argument as the first operand to '_Generic' is incompatible "
   "with C standards before C2y">, InGroup<CPre2yCompat>, DefaultIgnore;
-def warn_c2y_compat_decl_statement : Warning<
-  "'%select{if|switch}0' declaration statements are incompatible with "
-  "C standards before C2y">, DefaultIgnore, InGroup<CPre2yCompat>;
-def ext_c2y_decl_statement : Extension<
-  "'%select{if|switch}0' declaration statements are a C2y extension">,
-  InGroup<C2y>;
+defm decl_statement : C2yCompat<"'%select{if|switch}0' declaration statements are">;
 
 def ext_c99_feature : Extension<
   "'%0' is a C99 extension">, InGroup<C99>;
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index bb0cfaad4bc36..b2b1e74b07133 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1908,9 +1908,7 @@ Sema::ConditionResult Parser::ParseCondition(StmtResult *InitStmt,
                                   : diag::ext_init_statement)
           << (CK == Sema::ConditionKind::Switch);
     else
-      Diag(Tok.getLocation(), getLangOpts().C2y
-                                  ? diag::warn_c2y_compat_decl_statement
-                                  : diag::ext_c2y_decl_statement)
+      DiagCompat(Tok.getLocation(), diag_compat::decl_statement)
           << (CK == Sema::ConditionKind::Switch);
   };
 
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 75374f608c5ea..65f63bb5756e1 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -1340,9 +1340,7 @@ bool Parser::ParseParenExprOrCondition(StmtResult *InitStmt,
             << Cond.get().first->getSourceRange();
     } else if (Cond.get().first != nullptr)
       // Handle: if (int decl = 0) {}.
-      Diag(Cond.get().first->getBeginLoc(),
-           getLangOpts().C2y ? diag::warn_c2y_compat_decl_statement
-                             : diag::ext_c2y_decl_statement)
+      DiagCompat(Cond.get().first->getBeginLoc(), diag_compat::decl_statement)
           << (CK == Sema::ConditionKind::Switch);
   }
 

@bassiounix bassiounix requested a review from vgvassilev July 15, 2026 23:43

@Fznamznon Fznamznon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -169,12 +169,7 @@ def ext_c2y_generic_with_type_arg : Extension<
def warn_c2y_compat_generic_with_type_arg : Warning<

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this patch but we probably need to switch this one too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I only updated the ones in DiagnosticSemaKinds.td in my patch; we should do this file as well

Comment thread clang/include/clang/Basic/DiagnosticParseKinds.td Outdated
@@ -169,12 +169,7 @@ def ext_c2y_generic_with_type_arg : Extension<
def warn_c2y_compat_generic_with_type_arg : Warning<

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I only updated the ones in DiagnosticSemaKinds.td in my patch; we should do this file as well

@bassiounix bassiounix requested a review from Sirraide July 16, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants