]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Add support for vec_dup to constexpr [PR118445]
authorAndrew Pinski <quic_apinski@quicinc.com>
Mon, 13 Jan 2025 18:14:45 +0000 (10:14 -0800)
committerAndrew Pinski <quic_apinski@quicinc.com>
Tue, 14 Jan 2025 00:41:41 +0000 (16:41 -0800)
With the addition of supporting operations on the SVE scalable vector types,
the vec_duplicate tree will show up in expressions and the constexpr handling
was not done for this tree code.
This is a simple fix to treat VEC_DUPLICATE like any other unary operator and allows
the constexpr-add-1.C testcase to work.

Built and tested for aarch64-linux-gnu.

PR c++/118445

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_constant_expression): Handle VEC_DUPLICATE like
a "normal" unary operator.
(potential_constant_expression_1): Likewise.

gcc/testsuite/ChangeLog:

* g++.target/aarch64/sve/constexpr-add-1.C: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/cp/constexpr.cc
gcc/testsuite/g++.target/aarch64/sve/constexpr-add-1.C [new file with mode: 0644]

index 1345bc124efbc7901d77a96745e4dc34e625da3b..0896576fd28e744d3c4a51b7cc84f5e227e7b636 100644 (file)
@@ -8005,6 +8005,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
     case BIT_NOT_EXPR:
     case TRUTH_NOT_EXPR:
     case FIXED_CONVERT_EXPR:
+    case VEC_DUPLICATE_EXPR:
       r = cxx_eval_unary_expression (ctx, t, lval,
                                     non_constant_p, overflow_p);
       break;
@@ -10344,6 +10345,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
     case UNARY_PLUS_EXPR:
     case UNARY_LEFT_FOLD_EXPR:
     case UNARY_RIGHT_FOLD_EXPR:
+    case VEC_DUPLICATE_EXPR:
     unary:
       return RECUR (TREE_OPERAND (t, 0), rval);
 
diff --git a/gcc/testsuite/g++.target/aarch64/sve/constexpr-add-1.C b/gcc/testsuite/g++.target/aarch64/sve/constexpr-add-1.C
new file mode 100644 (file)
index 0000000..4348956
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+
+/* PR C++/118445 */
+
+#include <arm_sve.h>
+
+/* See if constexpr handles VEC_DUPLICATE and SVE. */
+constexpr svfloat32_t f(svfloat32_t b, float a)
+{
+  return b + a;
+}
+
+svfloat32_t g(void)
+{
+  return f((svfloat32_t){1.0}, 2.0);
+}