gcc/gcc11-pr116034.patch
Marek Polacek ffa87db2cc 11.5.0-2
Apply two patches

Resolves: RHEL-50054
2024-07-22 18:12:47 -04:00

48 lines
1.4 KiB
Diff

2024-07-22 Jakub Jelinek <jakub@redhat.com>
Andrew Pinski <quic_apinski@quicinc.com>
PR tree-optimization/116034
* tree-sra.c (maybe_rewrite_mem_ref_base): Only use IMAGPART_EXPR
if MEM_REF offset is equal to element type size.
* gcc.dg/pr116034.c: New test.
--- gcc/tree-ssa.c.jj 2024-03-11 11:00:46.768915988 +0100
+++ gcc/tree-ssa.c 2024-07-22 21:27:02.115530861 +0200
@@ -1506,7 +1506,10 @@ maybe_rewrite_mem_ref_base (tree *tp, bi
}
else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
&& useless_type_conversion_p (TREE_TYPE (*tp),
- TREE_TYPE (TREE_TYPE (sym))))
+ TREE_TYPE (TREE_TYPE (sym)))
+ && (integer_zerop (TREE_OPERAND (*tp, 1))
+ || tree_int_cst_equal (TREE_OPERAND (*tp, 1),
+ TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
{
*tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
? REALPART_EXPR : IMAGPART_EXPR,
--- gcc/testsuite/gcc.dg/pr116034.c.jj 2024-07-22 21:39:50.050994243 +0200
+++ gcc/testsuite/gcc.dg/pr116034.c 2024-07-22 21:39:32.432213042 +0200
@@ -0,0 +1,21 @@
+/* PR tree-optimization/116034 */
+/* { dg-do run } */
+/* { dg-options "-O1 -fno-strict-aliasing" } */
+
+int g;
+
+static inline int
+foo (_Complex unsigned short c)
+{
+ __builtin_memmove (&g, 1 + (char *) &c, 2);
+ return g;
+}
+
+int
+main ()
+{
+ if (__SIZEOF_SHORT__ == 2
+ && __CHAR_BIT__ == 8
+ && foo (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ? 0x0100 : 1) != 1)
+ __builtin_abort ();
+}