PR c++/85746: Don't fold __builtin_constant_p prematurely

2019-10-22  Marc Glisse  <marc.glisse@inria.fr>

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
This commit is contained in:
Marc Glisse 2019-10-22 16:42:38 +02:00 committed by Marc Glisse
parent 761a3a95ee
commit b09a67eaa1
4 changed files with 22 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2019-10-22 Marc Glisse <marc.glisse@inria.fr>
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 <richard.sandiford@arm.com>
* cp-tree.h (STF_USER_VISIBLE): New constant.

View File

@ -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)

View File

@ -1,3 +1,8 @@
2019-10-22 Marc Glisse <marc.glisse@inria.fr>
PR c++/85746
* g++.dg/pr85746.C: New file.
2019-10-22 Richard Biener <rguenther@suse.de>
PR tree-optimization/92173

View File

@ -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" } } */