]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c, c++: Fix vector enum division handling [PR123437]
authorJakub Jelinek <jakub@redhat.com>
Fri, 16 Jan 2026 10:03:18 +0000 (11:03 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 16 Jan 2026 10:03:18 +0000 (11:03 +0100)
To my surprise we accept generic vectors with enumeral element
types (unlike e.g. _Complex) and we don't actually try to
perform "integral" promotions for those either (which for scalars
promotes ENUMERAL_TYPE operands to their underlying type or
promoted underlying type).  I'm afraid it is inappropriate
to change the promotions at this point in stage4, that would
be a significant user visible change (though sure for a feature
that hopefully nobody actually uses).  Anyway, in GCC 16
development some assertions that RDIV_EXPR is only used for floating
(scalar/vector/complex) operands were added and those now trigger
on trying to divide vectors where both operands are enum vectors.
THis is due to the FEs using RDIV_EXPR instead of TRUNC_DIV_EXPR
when the operands (after promotions) don't have INTEGER_TYPE (or for C
BITINT_TYPE) operands.

This patch just adds vector enum to that.

2026-01-16  Jakub Jelinek  <jakub@redhat.com>
    Peter Damianov  <peter0x44@disroot.org>

PR c/123437
* c-typeck.cc (build_binary_op): Don't use RDIV_EXPR
resultcode if both types are integral, _BitInt or
newly VECTOR_TYPE of ENUMERAL_TYPE.

* typeck.cc (cp_build_binary_op): Don't use RDIV_EXPR
resultcode if both types are integral, _BitInt or
newly VECTOR_TYPE of ENUMERAL_TYPE.

* c-c++-common/pr123437.c: New test.

gcc/c/c-typeck.cc
gcc/cp/typeck.cc
gcc/testsuite/c-c++-common/pr123437.c [new file with mode: 0644]

index 04b33111f629f8cb3ef9565618b16751f0f72ca5..60ed44c2f6729264fc0157f2c6cc23afa9cdb232 100644 (file)
@@ -14469,8 +14469,10 @@ build_binary_op (location_t location, enum tree_code code,
          if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
            tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
 
-         if (!(((tcode0 == INTEGER_TYPE || tcode0 == BITINT_TYPE)
-                && (tcode1 == INTEGER_TYPE || tcode1 == BITINT_TYPE))
+         if (!(((tcode0 == INTEGER_TYPE || tcode0 == BITINT_TYPE
+                 || (tcode0 == ENUMERAL_TYPE && code0 == VECTOR_TYPE))
+                && (tcode1 == INTEGER_TYPE || tcode1 == BITINT_TYPE
+                    || (tcode1 == ENUMERAL_TYPE && code1 == VECTOR_TYPE)))
                || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE)))
            resultcode = RDIV_EXPR;
          else
index 290359c938e8ed4cf944b7dfd37df6db33923f3d..980f2d115a6649c3442aa37d652973bca1450ea9 100644 (file)
@@ -5858,7 +5858,10 @@ cp_build_binary_op (const op_location_t &location,
          if (tcode1 == COMPLEX_TYPE || tcode1 == VECTOR_TYPE)
            tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
 
-         if (!(tcode0 == INTEGER_TYPE && tcode1 == INTEGER_TYPE))
+         if (!((tcode0 == INTEGER_TYPE
+                || (tcode0 == ENUMERAL_TYPE && code0 == VECTOR_TYPE))
+               && (tcode1 == INTEGER_TYPE
+                   || (tcode1 == ENUMERAL_TYPE && code1 == VECTOR_TYPE))))
            resultcode = RDIV_EXPR;
          else
            {
diff --git a/gcc/testsuite/c-c++-common/pr123437.c b/gcc/testsuite/c-c++-common/pr123437.c
new file mode 100644 (file)
index 0000000..41ddf05
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR c/123437 */
+/* { dg-do compile } */
+
+enum E { F };
+typedef enum E V __attribute__ ((vector_size (16)));
+V x, y, z;
+
+void
+foo ()
+{
+  z = x / y;
+}