re PR inline-asm/85172 (internal compiler error: unexpected expression '<statement...
authorJakub Jelinek <jakub@redhat.com>
Wed, 4 Apr 2018 19:55:56 +0000 (21:55 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 4 Apr 2018 19:55:56 +0000 (21:55 +0200)
PR inline-asm/85172
* constexpr.c (cxx_eval_builtin_function_call): For calls to
builtin_valid_in_constant_expr_p functions, don't call
cxx_eval_constant_expression if argument is not
potential_constant_expression.

* g++.dg/ext/builtin13.C: New test.
* g++.dg/ext/atomic-4.C: New test.

From-SVN: r259104

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/atomic-4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin13.C [new file with mode: 0644]

index 71bde9886301c950a583a2277dc58d25b6a91ba3..a691763669f3126df8f4b45a9c32f097d426a1a0 100644 (file)
@@ -1,5 +1,11 @@
 2018-04-04  Jakub Jelinek  <jakub@redhat.com>
 
+       PR inline-asm/85172
+       * constexpr.c (cxx_eval_builtin_function_call): For calls to
+       builtin_valid_in_constant_expr_p functions, don't call
+       cxx_eval_constant_expression if argument is not
+       potential_constant_expression.
+
        PR c++/85146
        * cp-tree.h (calculate_bases, calculate_direct_bases): Add complain
        argument.
index 201f27d8e6649397984c748a899c16673476a6d5..3cc196b4d17abec7673b2c046ed8479cce972de7 100644 (file)
@@ -1189,8 +1189,14 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun,
   bool dummy1 = false, dummy2 = false;
   for (i = 0; i < nargs; ++i)
     {
-      args[i] = cxx_eval_constant_expression (&new_ctx, CALL_EXPR_ARG (t, i),
-                                             false, &dummy1, &dummy2);
+      args[i] = CALL_EXPR_ARG (t, i);
+      /* If builtin_valid_in_constant_expr_p is true,
+        potential_constant_expression_1 has not recursed into the arguments
+        of the builtin, verify it here.  */
+      if (!builtin_valid_in_constant_expr_p (fun)
+         || potential_constant_expression (args[i]))
+       args[i] = cxx_eval_constant_expression (&new_ctx, args[i], false,
+                                               &dummy1, &dummy2);
       if (bi_const_p)
        /* For __built_in_constant_p, fold all expressions with constant values
           even if they aren't C++ constant-expressions.  */
index 7806777a3637a3a3bfc1b8f2394286669456a1d6..fe56c9d6804e2258bbe646ba088377e758b9d73d 100644 (file)
@@ -1,5 +1,9 @@
 2018-04-04  Jakub Jelinek  <jakub@redhat.com>
 
+       PR inline-asm/85172
+       * g++.dg/ext/builtin13.C: New test.
+       * g++.dg/ext/atomic-4.C: New test.
+
        PR c++/85146
        * g++.dg/ext/bases2.C: Expect extra error diagnostics.
        * g++.dg/ext/bases3.C: New test.
diff --git a/gcc/testsuite/g++.dg/ext/atomic-4.C b/gcc/testsuite/g++.dg/ext/atomic-4.C
new file mode 100644 (file)
index 0000000..1eba117
--- /dev/null
@@ -0,0 +1,9 @@
+// PR inline-asm/85172
+// { dg-do compile }
+// { dg-options "" }
+
+int
+foo (int *p)
+{
+  return !__atomic_always_lock_free (4, ({ __asm (""); p; }));
+}
diff --git a/gcc/testsuite/g++.dg/ext/builtin13.C b/gcc/testsuite/g++.dg/ext/builtin13.C
new file mode 100644 (file)
index 0000000..7007fe8
--- /dev/null
@@ -0,0 +1,9 @@
+// PR inline-asm/85172
+// { dg-do compile }
+// { dg-options "" }
+
+int
+foo ()
+{
+  return !__builtin_constant_p (({ __asm (""); 0; }));
+}