From: glisse Date: Tue, 22 Oct 2019 14:42:38 +0000 (+0000) Subject: PR c++/85746: Don't fold __builtin_constant_p prematurely X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57f5992bc1ca544d597e99b7bf5eaa2b30c164d1;p=thirdparty%2Fgcc.git 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@277292 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d09f391be61c..d2b1fe457cb9 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 60d4b9ad0248..2e1b9b765491 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 0581b5f50c91..fd272807d0ba 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 000000000000..25f6795c6d61 --- /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" } } */