Hi!

The function that calls targetm.emit_call_builtin___clear_cache
asserts that each of the begin and end operands has either ptr_mode or
Pmode.
On most targets that is the same mode, but e.g. on aarch64 -mabi=ilp32
or a few others it is different.  When a target has a clear cache
non-library handler, it will use create_address_operand which will do the
conversion to the right mode automatically, but when emitting a library
call, we just say the operands are ptr_mode even when they can be Pmode
too; in that case we need to convert explicitly.

Fixed thusly, tested on the testcase with cross to aarch64 -mabi=ilp32,
bootstrapped/regtested on x86_64-linux and i686-linux (I really don't
have aarch64 ilp32 testing setup), ok for trunk?

2020-12-07  Jakub Jelinek  <ja...@redhat.com>

        PR target/98147
        * builtins.c (default_emit_call_builtin___clear_cache): Call
        convert_memory_address to ptr_mode on both begin and end.

        * gcc.dg/pr98147.c: New test.

--- gcc/builtins.c.jj   2020-12-04 08:08:06.350436898 +0100
+++ gcc/builtins.c      2020-12-05 14:47:09.555476027 +0100
@@ -7790,8 +7790,8 @@ default_emit_call_builtin___clear_cache
 
   emit_library_call (callee,
                     LCT_NORMAL, VOIDmode,
-                    begin, ptr_mode,
-                    end, ptr_mode);
+                    convert_memory_address (ptr_mode, begin), ptr_mode,
+                    convert_memory_address (ptr_mode, end), ptr_mode);
 }
 
 /* Emit a call to __builtin___clear_cache, unless the target specifies
--- gcc/testsuite/gcc.dg/pr98147.c.jj   2020-12-05 14:49:53.817626223 +0100
+++ gcc/testsuite/gcc.dg/pr98147.c      2020-12-05 14:48:20.984671644 +0100
@@ -0,0 +1,10 @@
+/* PR target/98147 */
+
+char buffer[32] = "foo bar";
+
+int
+main ()
+{
+  __builtin___clear_cache (buffer, buffer + 32);
+  return 0;
+}

        Jakub

Reply via email to