From: Jakub Jelinek Date: Wed, 4 Apr 2018 19:55:56 +0000 (+0200) Subject: re PR inline-asm/85172 (internal compiler error: unexpected expression '' of kind asm_expr) 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 71bde988630..a691763669f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 2018-04-04 Jakub Jelinek + 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. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 201f27d8e66..3cc196b4d17 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7806777a363..fe56c9d6804 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2018-04-04 Jakub Jelinek + 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 index 00000000000..1eba11773e9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/atomic-4.C @@ -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 index 00000000000..7007fe8a6ef --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin13.C @@ -0,0 +1,9 @@ +// PR inline-asm/85172 +// { dg-do compile } +// { dg-options "" } + +int +foo () +{ + return !__builtin_constant_p (({ __asm (""); 0; })); +}