aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2013-04-03 11:17:44 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2013-04-03 11:17:44 +0200
commit4e7d7b3d5d5cefd5e19a736a83c3077f7c95baad (patch)
treeee1f834718a018ae1e4059bf0a7d4d879d20def1
parente6c9d234044bae3de1941cb7d654dc9d3425fd1b (diff)
downloadgcc-4e7d7b3d5d5cefd5e19a736a83c3077f7c95baad.zip
gcc-4e7d7b3d5d5cefd5e19a736a83c3077f7c95baad.tar.gz
gcc-4e7d7b3d5d5cefd5e19a736a83c3077f7c95baad.tar.bz2
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
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/builtins.c6
-rw-r--r--gcc/c/ChangeLog8
-rw-r--r--gcc/c/c-parser.c15
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr19449.c20
-rw-r--r--gcc/tree.h4
7 files changed, 61 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index db0f7a6..1d14dd4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 68b6a2c..efab82e 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -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;
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index a76fb3e..771a557 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -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
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 2ae4622..f60f141 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -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;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4a6c3b8..c726525 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr19449.c b/gcc/testsuite/gcc.c-torture/execute/pr19449.c
new file mode 100644
index 0000000..63cc2e7
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr19449.c
@@ -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;
+}
diff --git a/gcc/tree.h b/gcc/tree.h
index 985512a..f911459 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -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);