This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix char/short __sync_fetch_and_xxx (PR target/28924)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]