From b09a67eaa107c96203db449af6461f1d35665f57 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Tue, 22 Oct 2019 16:42:38 +0200 Subject: [PATCH] PR c++/85746: Don't fold __builtin_constant_p prematurely 2019-10-22 Marc Glisse gcc/cp/ * constexpr.c (cxx_eval_builtin_function_call): Only set force_folding_builtin_constant_p if manifestly_const_eval. gcc/testsuite/ * g++.dg/pr85746.C: New file. From-SVN: r277292 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/pr85746.C | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/pr85746.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d09f391be61..d2b1fe457cb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-10-22 Marc Glisse + + PR c++/85746 + * constexpr.c (cxx_eval_builtin_function_call): Only set + force_folding_builtin_constant_p if manifestly_const_eval. + 2019-10-22 Richard Sandiford * cp-tree.h (STF_USER_VISIBLE): New constant. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 60d4b9ad024..2e1b9b76549 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1260,7 +1260,7 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun, } bool save_ffbcp = force_folding_builtin_constant_p; - force_folding_builtin_constant_p = true; + force_folding_builtin_constant_p |= ctx->manifestly_const_eval; tree save_cur_fn = current_function_decl; /* Return name of ctx->call->fundef->decl for __builtin_FUNCTION (). */ if (fndecl_built_in_p (fun, BUILT_IN_FUNCTION) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0581b5f50c9..fd272807d0b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-22 Marc Glisse + + PR c++/85746 + * g++.dg/pr85746.C: New file. + 2019-10-22 Richard Biener PR tree-optimization/92173 diff --git a/gcc/testsuite/g++.dg/pr85746.C b/gcc/testsuite/g++.dg/pr85746.C new file mode 100644 index 00000000000..25f6795c6d6 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr85746.C @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-gimple" } */ + +int f(int a,int b){ + // The front-end should not fold this to 0. + int c = __builtin_constant_p(a < b); + return c; +} + +/* { dg-final { scan-tree-dump "__builtin_constant_p" "gimple" } } */ -- 2.11.4.GIT