This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix char/short __sync_fetch_and_xxx (PR target/28924)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 5 Oct 2006 09:32:39 -0400
- Subject: [PATCH] Fix char/short __sync_fetch_and_xxx (PR target/28924)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
The attached testcase ICEs, because (set (reg:HI ...) (const_int 0xffff))
is unrecognizable instruction. The problem is that the given CONST_INT is
not valid HImode constant (should have been sign-extended to HOST_WID_INT)
and that comes from argument promotion - although __sync_fetch_and_add_2
is prototyped with unsigned short as second argument, the actual value
seen in the arglist has int type and expand_expr honor's mode of
TREE_TYPE (expr) rather than tmode.
Fixed by converting val to the type of the __sync_fetch_and_XXX_N builtin's
second argument before expanding.
Ok for trunk?
2006-10-05 Jakub Jelinek <jakub@redhat.com>
PR target/28924
* builtins.c (expand_builtin_sync_operation): fold_convert 2nd argument
to mode's type if it is promoted.
* gcc.c-torture/compile/20061005-1.c: New test.
--- gcc/builtins.c.jj 2006-10-05 00:28:41.000000000 +0200
+++ gcc/builtins.c 2006-10-05 15:08:09.000000000 +0200
@@ -5488,12 +5488,16 @@ expand_builtin_sync_operation (enum mach
rtx target, bool ignore)
{
rtx val, mem;
+ tree value, type;
/* Expand the operands. */
mem = get_builtin_sync_mem (TREE_VALUE (arglist), mode);
arglist = TREE_CHAIN (arglist);
- val = expand_expr (TREE_VALUE (arglist), NULL, mode, EXPAND_NORMAL);
+ value = TREE_VALUE (arglist);
+ type = lang_hooks.types.type_for_size (GET_MODE_BITSIZE (mode), true);
+ value = fold_convert (type, value);
+ val = expand_expr (value, NULL, mode, EXPAND_NORMAL);
if (ignore)
return expand_sync_operation (mem, val, code);
--- gcc/testsuite/gcc.c-torture/compile/20061005-1.c.jj 2006-10-05 15:09:55.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/compile/20061005-1.c 2006-10-05 15:09:32.000000000 +0200
@@ -0,0 +1,17 @@
+/* PR target/28924 */
+
+char c;
+
+void
+testc (void)
+{
+ (void) __sync_fetch_and_add (&c, -1);
+}
+
+short s;
+
+void
+tests (void)
+{
+ (void) __sync_fetch_and_add (&s, -1);
+}
Jakub