aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@gcc.gnu.org>2018-10-17 17:49:28 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2018-10-17 17:49:28 +0000
commit1906e1a6072d3ef64553707125d8132b24df3dcb (patch)
tree693c71ceecea588f3fb1ff65e813037c0d60417f /gcc
parent54994253d3fc00bcb7d3e9359ff31a81c0e4543a (diff)
downloadgcc-1906e1a6072d3ef64553707125d8132b24df3dcb.zip
gcc-1906e1a6072d3ef64553707125d8132b24df3dcb.tar.gz
gcc-1906e1a6072d3ef64553707125d8132b24df3dcb.tar.bz2
re PR middle-end/87623 (bytes swapped in register when comparing cause fail when compiled with -O1 or higher)
PR middle-end/87623 * fold-const.c (fold_truth_andor_1): If the right side is not constant, bail out if both sides do not have the same storage order. From-SVN: r265242
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/fold-const.c5
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr87623.c34
4 files changed, 48 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4cfd821..d26780e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,4 +1,10 @@
-2018-10-09 Aldy Hernandez <aldyh@redhat.com>
+2018-10-17 Eric Botcazou <ebotcazou@adacore.com>
+
+ PR middle-end/87623
+ * fold-const.c (fold_truth_andor_1): If the right side is not constant,
+ bail out if both sides do not have the same storage order.
+
+2018-10-17 Aldy Hernandez <aldyh@redhat.com>
* bitmap.c (bitmap_head::dump): New.
* bitmap.h (bitmap_head): Add dump().
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 4977eef..5399288 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -6009,12 +6009,13 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
}
/* If the right sides are not constant, do the same for it. Also,
- disallow this optimization if a size or signedness mismatch occurs
- between the left and right sides. */
+ disallow this optimization if a size, signedness or storage order
+ mismatch occurs between the left and right sides. */
if (l_const == 0)
{
if (ll_bitsize != lr_bitsize || rl_bitsize != rr_bitsize
|| ll_unsignedp != lr_unsignedp || rl_unsignedp != rr_unsignedp
+ || ll_reversep != lr_reversep
/* Make sure the two fields on the right
correspond to the left without being swapped. */
|| ll_bitpos - rl_bitpos != lr_bitpos - rr_bitpos)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0f75b6d..1e62206 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2018-10-17 Eric Botcazou <ebotcazou@adacore.com>
+
+ * gcc.c-torture/execute/pr87623.c: New test.
+
2018-10-17 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/84705
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr87623.c b/gcc/testsuite/gcc.c-torture/execute/pr87623.c
new file mode 100644
index 0000000..54d8b5e
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr87623.c
@@ -0,0 +1,34 @@
+/* PR middle-end/87623 */
+/* Testcase by George Thopas <george.thopas@gmail.com> */
+
+struct be {
+ unsigned short pad[1];
+ unsigned char a;
+ unsigned char b;
+} __attribute__((scalar_storage_order("big-endian")));
+
+typedef struct be t_be;
+
+struct le {
+ unsigned short pad[3];
+ unsigned char a;
+ unsigned char b;
+};
+
+typedef struct le t_le;
+
+int a_or_b_different(t_be *x,t_le *y)
+{
+ return (x->a != y->a) || (x->b != y->b);
+}
+
+int main (void)
+{
+ t_be x = { .a=1, .b=2 };
+ t_le y = { .a=1, .b=2 };
+
+ if (a_or_b_different(&x,&y))
+ __builtin_abort ();
+
+ return 0;
+}