]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/106513 - fix mistake in bswap symbolic number shifts
authorRichard Biener <rguenther@suse.de>
Wed, 10 Aug 2022 13:45:22 +0000 (15:45 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 10 Aug 2022 14:38:41 +0000 (16:38 +0200)
This fixes a mistake in typing a local variable in the symbolic
shift routine.

PR tree-optimization/106513
* gimple-ssa-store-merging.cc (do_shift_rotate): Use uint64_t
for head_marker.

* gcc.dg/torture/pr106513.c: New testcase.

gcc/gimple-ssa-store-merging.cc
gcc/testsuite/gcc.dg/torture/pr106513.c [new file with mode: 0644]

index 0640168bcc4570c3bc14cadcb65665a1ab942a36..b80b8eac4444d4bf580d5eb52c1fca4f431305b5 100644 (file)
@@ -263,7 +263,7 @@ do_shift_rotate (enum tree_code code,
                 int count)
 {
   int i, size = TYPE_PRECISION (n->type) / BITS_PER_UNIT;
-  unsigned head_marker;
+  uint64_t head_marker;
 
   if (count < 0
       || count >= TYPE_PRECISION (n->type)
diff --git a/gcc/testsuite/gcc.dg/torture/pr106513.c b/gcc/testsuite/gcc.dg/torture/pr106513.c
new file mode 100644 (file)
index 0000000..aa4f4d5
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+
+typedef __INT64_TYPE__ int64_t;
+
+__attribute__((noinline)) int64_t
+swap64 (int64_t n)
+{
+  return (((n & (((int64_t) 0xff) )) << 56) |
+          ((n & (((int64_t) 0xff) << 8)) << 40) |
+          ((n & (((int64_t) 0xff) << 16)) << 24) |
+          ((n & (((int64_t) 0xff) << 24)) << 8) |
+          ((n & (((int64_t) 0xff) << 32)) >> 8) |
+          ((n & (((int64_t) 0xff) << 40)) >> 24) |
+          ((n & (((int64_t) 0xff) << 48)) >> 40) |
+          ((n & ((int64_t)(0xffull << 56))) >> 56));
+}
+
+int main (void)
+{
+  volatile int64_t n = 0x8000000000000000ll;
+
+  if (swap64(n) != 0xffffffffffffff80ll)
+    __builtin_abort ();
+
+  return 0;
+}