Fix PR middle-end/87623

Message ID 11161033.vSsJUddlNR@polaris
State New
Headers show
  • Fix PR middle-end/87623
Related show

Commit Message

Eric Botcazou Oct. 17, 2018, 5:54 p.m.
The compiler generates wrong code on the attached testcase using the 
scalar_storage_order attribute when optimization is enabled because it
respectively coaslesces the LHSes and the RHSes of the two consecutive 
comparisons without checking that both sides have same scalar storage order 
(but it does check that the two LHSes and the two RHSes respectively do).

The fix is trivial since the infrastructure is already present so I have 
applied it on all active branches as obvious after testing on x86-64/Linux.

2018-10-17  Eric Botcazou  <>

	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  Eric Botcazou  <>

	* gcc.c-torture/execute/pr87623.c: New test.

Eric Botcazou


Index: fold-const.c
--- fold-const.c	(revision 265139)
+++ fold-const.c	(working copy)
@@ -6009,12 +6009,13 @@  fold_truth_andor_1 (location_t loc, enum
   /* 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)