re PR c/19449 (__builtin_constant_p cannot resolve to const when optimizing)

PR c/19449
	* tree.h (force_folding_builtin_constant_p): New decl.
	* builtins.c (force_folding_builtin_constant_p): New variable.
	(fold_builtin_constant_p): Fold immediately also if
	force_folding_builtin_constant_p.

	* c-parser.c (c_parser_get_builtin_args): Add choose_expr_p
	argument.  If set, or it temporarily for parsing of the first
	argument into force_folding_builtin_constant_p.
	(c_parser_postfix_expression): Adjust callers.

	* gcc.c-torture/execute/pr19449.c: New test.

From-SVN: r197393
This commit is contained in:
Jakub Jelinek 2013-04-03 11:17:44 +02:00 committed by Jakub Jelinek
parent e6c9d23404
commit 4e7d7b3d5d
7 changed files with 61 additions and 5 deletions

View File

@ -1,3 +1,11 @@
2013-04-03 Jakub Jelinek <jakub@redhat.com>
PR c/19449
* tree.h (force_folding_builtin_constant_p): New decl.
* builtins.c (force_folding_builtin_constant_p): New variable.
(fold_builtin_constant_p): Fold immediately also if
force_folding_builtin_constant_p.
2013-04-03 Richard Biener <rguenther@suse.de>
PR tree-optimization/56812

View File

@ -75,6 +75,9 @@ const char * built_in_names[(int) END_BUILTINS] =
initialized to NULL_TREE. */
builtin_info_type builtin_info;
/* Non-zero if __builtin_constant_p should be folded right away. */
bool force_folding_builtin_constant_p;
static const char *c_getstr (tree);
static rtx c_readstr (const char *, enum machine_mode);
static int target_char_cast (tree, char *);
@ -6974,7 +6977,8 @@ fold_builtin_constant_p (tree arg)
|| AGGREGATE_TYPE_P (TREE_TYPE (arg))
|| POINTER_TYPE_P (TREE_TYPE (arg))
|| cfun == 0
|| folding_initializer)
|| folding_initializer
|| force_folding_builtin_constant_p)
return integer_zero_node;
return NULL_TREE;

View File

@ -1,3 +1,11 @@
2013-04-03 Jakub Jelinek <jakub@redhat.com>
PR c/19449
* c-parser.c (c_parser_get_builtin_args): Add choose_expr_p
argument. If set, or it temporarily for parsing of the first
argument into force_folding_builtin_constant_p.
(c_parser_postfix_expression): Adjust callers.
2013-03-21 Richard Biener <rguenther@suse.de>
* c-objc-common.c (c_tree_printer): Use DECL_HAS_DEBUG_EXPR_P

View File

@ -6114,11 +6114,13 @@ c_parser_alignof_expression (c_parser *parser)
stores the arguments in CEXPR_LIST. */
static bool
c_parser_get_builtin_args (c_parser *parser, const char *bname,
vec<c_expr_t, va_gc> **ret_cexpr_list)
vec<c_expr_t, va_gc> **ret_cexpr_list,
bool choose_expr_p)
{
location_t loc = c_parser_peek_token (parser)->location;
vec<c_expr_t, va_gc> *cexpr_list;
c_expr_t expr;
bool saved_force_folding_builtin_constant_p;
*ret_cexpr_list = NULL;
if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
@ -6135,7 +6137,12 @@ c_parser_get_builtin_args (c_parser *parser, const char *bname,
return true;
}
saved_force_folding_builtin_constant_p
= force_folding_builtin_constant_p;
force_folding_builtin_constant_p |= choose_expr_p;
expr = c_parser_expr_no_commas (parser, NULL);
force_folding_builtin_constant_p
= saved_force_folding_builtin_constant_p;
vec_alloc (cexpr_list, 1);
C_EXPR_APPEND (cexpr_list, expr);
while (c_parser_next_token_is (parser, CPP_COMMA))
@ -6509,7 +6516,7 @@ c_parser_postfix_expression (c_parser *parser)
c_parser_consume_token (parser);
if (!c_parser_get_builtin_args (parser,
"__builtin_choose_expr",
&cexpr_list))
&cexpr_list, true))
{
expr.value = error_mark_node;
break;
@ -6591,7 +6598,7 @@ c_parser_postfix_expression (c_parser *parser)
c_parser_consume_token (parser);
if (!c_parser_get_builtin_args (parser,
"__builtin_complex",
&cexpr_list))
&cexpr_list, false))
{
expr.value = error_mark_node;
break;
@ -6653,7 +6660,7 @@ c_parser_postfix_expression (c_parser *parser)
c_parser_consume_token (parser);
if (!c_parser_get_builtin_args (parser,
"__builtin_shuffle",
&cexpr_list))
&cexpr_list, false))
{
expr.value = error_mark_node;
break;

View File

@ -1,3 +1,8 @@
2013-04-03 Jakub Jelinek <jakub@redhat.com>
PR c/19449
* gcc.c-torture/execute/pr19449.c: New test.
2013-04-03 Richard Biener <rguenther@suse.de>
PR tree-optimization/56812

View File

@ -0,0 +1,20 @@
/* PR c/19449 */
extern void abort (void);
int y;
int z = __builtin_choose_expr (!__builtin_constant_p (y), 3, 4);
int
foo (int x)
{
return __builtin_choose_expr (!__builtin_constant_p (x), 3, y++);
}
int
main ()
{
if (y || z != 3 || foo (4) != 3)
abort ();
return 0;
}

View File

@ -5855,6 +5855,10 @@ fold_build_pointer_plus_hwi_loc (location_t loc, tree ptr, HOST_WIDE_INT off)
fold_build_pointer_plus_hwi_loc (UNKNOWN_LOCATION, p, o)
/* In builtins.c */
/* Non-zero if __builtin_constant_p should be folded right away. */
extern bool force_folding_builtin_constant_p;
extern bool avoid_folding_inline_builtin (tree);
extern tree fold_call_expr (location_t, tree, bool);
extern tree fold_builtin_fputs (location_t, tree, tree, bool, bool, tree);