https://github.com/mstorsjo created 
https://github.com/llvm/llvm-project/pull/159338

This avoids the following kind of warning when built with GCC:

    ../../clang/lib/Sema/SemaStmtAttr.cpp: In function ‘clang::Attr* 
ProcessStmtAttribute(clang::Sema&, clang::Stmt*, const clang::ParsedAttr&, 
clang::SourceRange)’:
    ../../clang/lib/Sema/SemaStmtAttr.cpp:677:30: warning: enumerated mismatch 
in conditional expression: ‘clang::diag::<unnamed enum>’ vs 
‘clang::diag::<unnamed enum>’ [-Wenum-compare]
      676 |       S.Diag(A.getLoc(), A.isRegularKeywordAttribute()
          |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      677 |                              ? 
diag::err_keyword_not_supported_on_targe
          |                              
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      678 |                              : 
diag::warn_unhandled_ms_attribute_ignore )
          |                              
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These enums are non-overlapping, but due they are defined in different enum 
scopes due to how they are generated with tablegen.

From 80607ae5154313cbafe506cc1bb72486b530521d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <[email protected]>
Date: Wed, 17 Sep 2025 14:25:50 +0300
Subject: [PATCH] [clang] Avoid warnings about enum mismatch in ternary
 expressions. NFC.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This avoids the following kind of warning when built with GCC:

    ../../clang/lib/Sema/SemaStmtAttr.cpp: In function ‘clang::Attr* 
ProcessStmtAttribute(clang::Sema&, clang::Stmt*, const clang::ParsedAttr&, 
clang::SourceRange)’:
    ../../clang/lib/Sema/SemaStmtAttr.cpp:677:30: warning: enumerated mismatch 
in conditional expression: ‘clang::diag::<unnamed enum>’ vs 
‘clang::diag::<unnamed enum>’ [-Wenum-compare]
      676 |       S.Diag(A.getLoc(), A.isRegularKeywordAttribute()
          |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      677 |                              ? 
diag::err_keyword_not_supported_on_targe
          |                              
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      678 |                              : 
diag::warn_unhandled_ms_attribute_ignore )
          |                              
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These enums are non-overlapping, but due they are defined in different
enum scopes due to how they are generated with tablegen.
---
 clang/lib/Sema/SemaDeclAttr.cpp | 6 ++++--
 clang/lib/Sema/SemaStmtAttr.cpp | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 44906456f3371..7b3dc80e38913 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6837,8 +6837,10 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
       !AL.existsInTarget(S.Context.getTargetInfo())) {
     if (AL.isRegularKeywordAttribute() || AL.isDeclspecAttribute()) {
       S.Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
-                              ? diag::err_keyword_not_supported_on_target
-                              : diag::warn_unhandled_ms_attribute_ignored)
+                              ? static_cast<unsigned>(
+                                    diag::err_keyword_not_supported_on_target)
+                              : static_cast<unsigned>(
+                                    diag::warn_unhandled_ms_attribute_ignored))
           << AL.getAttrName() << AL.getRange();
     } else {
       S.DiagnoseUnknownAttribute(AL);
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 77aa7164d4555..8cac790e969fa 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -674,8 +674,10 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const 
ParsedAttr &A,
          A.existsInTarget(*Aux)))) {
     if (A.isRegularKeywordAttribute() || A.isDeclspecAttribute()) {
       S.Diag(A.getLoc(), A.isRegularKeywordAttribute()
-                             ? diag::err_keyword_not_supported_on_target
-                             : diag::warn_unhandled_ms_attribute_ignored)
+                             ? static_cast<unsigned>(
+                                   diag::err_keyword_not_supported_on_target)
+                             : static_cast<unsigned>(
+                                   diag::warn_unhandled_ms_attribute_ignored))
           << A << A.getRange();
     } else {
       S.DiagnoseUnknownAttribute(A);

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

Reply via email to