re PR c++/79379 (ICE with #pragma GCC ivdep)
authorJakub Jelinek <jakub@redhat.com>
Mon, 6 Feb 2017 20:06:16 +0000 (21:06 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 6 Feb 2017 20:06:16 +0000 (21:06 +0100)
PR c++/79379
* constexpr.c (cxx_eval_constant_expression): Handle ANNOTATE_EXPR.
(potential_constant_expression_1): Likewise.

* g++.dg/cpp1y/constexpr-79379.C: New test.

From-SVN: r245220

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/constexpr-79379.C [new file with mode: 0644]

index a318c7fb8b8d71b021c230e61b9ab37b3cb51ae1..0e3e38cef0831465032d61be2a16dae1365f491e 100644 (file)
@@ -1,5 +1,9 @@
 2017-02-06  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/79379
+       * constexpr.c (cxx_eval_constant_expression): Handle ANNOTATE_EXPR.
+       (potential_constant_expression_1): Likewise.
+
        PR c++/79377
        * tree.c (build_min_non_dep_op_overload): For POST{INC,DEC}REMENT_EXPR
        allow one fewer than expected arguments if flag_permissive.
index f9bc518641b5908f4fccef41bfeb2d8760bbb805..bb45f1e805998a0ccd17c40f2dfe71e3972963a0 100644 (file)
@@ -4518,6 +4518,14 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
         *non_constant_p = true;
       return t;
 
+    case ANNOTATE_EXPR:
+      gcc_assert (tree_to_uhwi (TREE_OPERAND (t, 1)) == annot_expr_ivdep_kind);
+      r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
+                                       lval,
+                                       non_constant_p, overflow_p,
+                                       jump_target);
+      break;
+
     default:
       if (STATEMENT_CODE_P (TREE_CODE (t)))
        {
@@ -5689,6 +5697,10 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
        return false;
       }
 
+    case ANNOTATE_EXPR:
+      gcc_assert (tree_to_uhwi (TREE_OPERAND (t, 1)) == annot_expr_ivdep_kind);
+      return RECUR (TREE_OPERAND (t, 0), rval);
+
     default:
       if (objc_is_property_ref (t))
        return false;
index 3313268a639cc0467bc336a49e85c485278252fe..6737cf46e3cdb2ce9f0e8e214a0693643746bf9e 100644 (file)
@@ -1,5 +1,8 @@
 2017-02-06  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/79379
+       * g++.dg/cpp1y/constexpr-79379.C: New test.
+
        PR c++/79377
        * g++.dg/lookup/pr79377.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-79379.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-79379.C
new file mode 100644 (file)
index 0000000..db0981d
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/79379
+// { dg-do compile { target c++14 } }
+// { dg-options "-O2" }
+
+template <int N>
+constexpr int
+foo (int x)
+{
+  int q[64] = { 0 }, r = 0;
+#pragma GCC ivdep
+  for (int i = 0; i < x; ++i)
+    q[i] += 2;
+  for (int i = 0; i < x; ++i)
+    r += q[i];
+  return r + N;
+}
+
+constexpr int a = foo<0> (17);
+static_assert (a == 34, "");