[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-23 Thread via llvm-branch-commits

github-actions[bot] wrote:

@cor3ntin (or anyone else). If you would like to add a note about this fix in 
the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/139396
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-23 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/139396
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-23 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/139396

>From 070cf62530eab91d68521787e08418343b9ca28b Mon Sep 17 00:00:00 2001
From: cor3ntin 
Date: Tue, 18 Mar 2025 16:45:37 +0100
Subject: [PATCH] [Clang] Demote mixed enumeration arithmetic error to a
 warning (#131811)

In C++, defaulted to an error.

C++ removed these features but the removal negatively impacts users.

Fixes #92340
---
 clang/docs/ReleaseNotes.rst  | 3 +++
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +-
 clang/lib/Sema/SemaExpr.cpp  | 2 +-
 clang/test/SemaCXX/cxx2c-enum-compare.cpp| 5 +++--
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2f43dc4021fd8..774a00b4feef5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -314,6 +314,9 @@ C++2c Feature Support
 
 - Implemented `P3176R1 The Oxford variadic comma `_
 
+- The error produced when doing arithmetic operations on enums of different 
types
+  can be disabled with ``-Wno-enum-enum-conversion``. (#GH92340)
+
 C++23 Feature Support
 ^
 - Removed the restriction to literal types in constexpr functions in C++23 
mode.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ec2a140e04d5b..7180447e250ce 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
   "%sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
   InGroup;
-def err_conv_mixed_enum_types_cxx26 : Error<
+
+def err_conv_mixed_enum_types: Error <
   "invalid %sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2">;
+def _warn_conv_mixed_enum_types_cxx26 : Warning <
+  err_conv_mixed_enum_types.Summary>,
+  InGroup, DefaultError;
 
 def warn_arith_conv_mixed_anon_enum_types : Warning<
   warn_arith_conv_mixed_enum_types.Summary>,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e253e3a17328f..23d0f9532d4f8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1519,7 +1519,7 @@ static void checkEnumArithmeticConversions(Sema &S, Expr 
*LHS, Expr *RHS,
 // In C++ 26, usual arithmetic conversions between 2 different enum types
 // are ill-formed.
 if (S.getLangOpts().CPlusPlus26)
-  DiagID = diag::err_conv_mixed_enum_types_cxx26;
+  DiagID = diag::_warn_conv_mixed_enum_types_cxx26;
 else if (!L->castAs()->getDecl()->hasNameForLinkage() ||
  !R->castAs()->getDecl()->hasNameForLinkage()) {
   // If either enumeration type is unnamed, it's less likely that the
diff --git a/clang/test/SemaCXX/cxx2c-enum-compare.cpp 
b/clang/test/SemaCXX/cxx2c-enum-compare.cpp
index f47278a60725e..96fbd368b1696 100644
--- a/clang/test/SemaCXX/cxx2c-enum-compare.cpp
+++ b/clang/test/SemaCXX/cxx2c-enum-compare.cpp
@@ -1,9 +1,10 @@
-// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify -triple 
%itanium_abi_triple
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both,expected
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify=both 
-Wno-enum-enum-conversion
 
 enum E1 { e };
 enum E2 { f };
 void test() {
-int b = e <= 3.7; // expected-error {{invalid comparison of enumeration 
type 'E1' with floating-point type 'double'}}
+int b = e <= 3.7; // both-error {{invalid comparison of enumeration type 
'E1' with floating-point type 'double'}}
 int k = f - e; // expected-error {{invalid arithmetic between different 
enumeration types ('E2' and 'E1')}}
 int x = 1 ? e : f; // expected-error {{invalid conditional expression 
between different enumeration types ('E1' and 'E2')}}
 }

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


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-19 Thread Aaron Ballman via llvm-branch-commits


@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
   "%sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
   InGroup;
-def err_conv_mixed_enum_types_cxx26 : Error<
+
+def err_conv_mixed_enum_types: Error <
   "invalid %sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2">;
+def warn_conv_mixed_enum_types_cxx26 : Warning <
+  err_conv_mixed_enum_types.Summary>,
+  InGroup, DefaultError;

AaronBallman wrote:

> The issue is that TableGen sorts the enums alphabetically, so adding a new 
> value will change the name->integer mapping for approximately half of the 
> enum. Maybe ABI break is the wrong term here, but it means than an app built 
> against 20.1.4, for example will stop working if 20.1.4 libraries are 
> replaced by 20.1.5 libraries, which is something we want to avoid even if 
> it's not technically an ABI break.

Ah okay, that's good to know, thank you!

https://github.com/llvm/llvm-project/pull/139396
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-17 Thread Tom Stellard via llvm-branch-commits


@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
   "%sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
   InGroup;
-def err_conv_mixed_enum_types_cxx26 : Error<
+
+def err_conv_mixed_enum_types: Error <
   "invalid %sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2">;
+def warn_conv_mixed_enum_types_cxx26 : Warning <
+  err_conv_mixed_enum_types.Summary>,
+  InGroup, DefaultError;

tstellar wrote:

I think so, yes.  Someone could verify by looking at the generated .inc file.

https://github.com/llvm/llvm-project/pull/139396
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-17 Thread via llvm-branch-commits


@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
   "%sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
   InGroup;
-def err_conv_mixed_enum_types_cxx26 : Error<
+
+def err_conv_mixed_enum_types: Error <
   "invalid %sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2">;
+def warn_conv_mixed_enum_types_cxx26 : Warning <
+  err_conv_mixed_enum_types.Summary>,
+  InGroup, DefaultError;

cor3ntin wrote:

So presumably, if we renamed it to z_error_xxx it would be fine?

https://github.com/llvm/llvm-project/pull/139396
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-16 Thread Tom Stellard via llvm-branch-commits


@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
   "%sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
   InGroup;
-def err_conv_mixed_enum_types_cxx26 : Error<
+
+def err_conv_mixed_enum_types: Error <
   "invalid %sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2">;
+def warn_conv_mixed_enum_types_cxx26 : Warning <
+  err_conv_mixed_enum_types.Summary>,
+  InGroup, DefaultError;

tstellar wrote:

The issue is that TableGen sorts the enums alphabetically, so adding a new 
value will change the name->integer mapping for approximately half of the enum. 
 Maybe ABI break is the wrong term here, but it means than an app built against 
20.1.4, for example will stop working if 20.1.4 libraries are replaced by 
20.1.5 libraries, which is something we want to avoid even if it's not 
technically an ABI break.

https://github.com/llvm/llvm-project/pull/139396
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-14 Thread Aaron Ballman via llvm-branch-commits


@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
   "%sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
   InGroup;
-def err_conv_mixed_enum_types_cxx26 : Error<
+
+def err_conv_mixed_enum_types: Error <
   "invalid %sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2">;
+def warn_conv_mixed_enum_types_cxx26 : Warning <
+  err_conv_mixed_enum_types.Summary>,
+  InGroup, DefaultError;

AaronBallman wrote:

I don't disagree (it does add a new enum value), but I am starting to think 
this ABI requirement is onerous enough to be worth rethinking the scope of it. 
The point to the ABI requirement is that you should be able to use Clang as a 
library interchangeably between the dot releases. The platform calling 
convention ABI does not change when an enumeration gains a new enumerator, nor 
does name mangling behavior change. In fact, adding an enumerator can only 
increase the number of valid integer values that can be represented by the 
enumeration, which means the addition won't introduce new UB but could remove 
UB by widening the range of valid values. So I think this kind of change isn't 
introducing a kind of ABI break we need to avoid.

Or am I missing something?

https://github.com/llvm/llvm-project/pull/139396
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-13 Thread Tom Stellard via llvm-branch-commits


@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
   "%sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
   InGroup;
-def err_conv_mixed_enum_types_cxx26 : Error<
+
+def err_conv_mixed_enum_types: Error <
   "invalid %sub{select_arith_conv_kind}0 "
   "different enumeration types%diff{ ($ and $)|}1,2">;
+def warn_conv_mixed_enum_types_cxx26 : Warning <
+  err_conv_mixed_enum_types.Summary>,
+  InGroup, DefaultError;

tstellar wrote:

Unfortunately our ABI checker job doesn't really work, but I think this is an 
ABI break, because it's adding a new enum value.

https://github.com/llvm/llvm-project/pull/139396
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-12 Thread Aaron Ballman via llvm-branch-commits

https://github.com/AaronBallman approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/139396
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang][Backport] Demote mixed enumeration arithmetic error to a warning (#131811) (PR #139396)

2025-05-10 Thread via llvm-branch-commits

https://github.com/cor3ntin edited 
https://github.com/llvm/llvm-project/pull/139396
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits